glucat  0.8.4
PyClical.h
Go to the documentation of this file.
1 /***************************************************************************
2  GluCat : Generic library of universal Clifford algebra templates
3  PyClical.h : C++ definitions needed by PyClical
4  -------------------
5  copyright : (C) 2008-2012 by Paul C. Leopardi
6  ***************************************************************************
7 
8  This library is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with this library. If not, see <http://www.gnu.org/licenses/>.
20 
21  ***************************************************************************
22  This library is based on a prototype written by Arvind Raja and was
23  licensed under the LGPL with permission of the author. See Arvind Raja,
24  "Object-oriented implementations of Clifford algebras in C++: a prototype",
25  in Ablamowicz, Lounesto and Parra (eds.)
26  "Clifford algebras with numeric and symbolic computations", Birkhauser, 1996.
27  ***************************************************************************
28  See also Arvind Raja's original header comments in glucat/glucat.h
29  ***************************************************************************/
30 // References for algorithms:
31 // [DL]:
32 // C. Doran and A. Lasenby, "Geometric algebra for physicists", Cambridge, 2003.
33 
34 #include "glucat/glucat.h"
35 
36 typedef glucat::tuning
37  <
48  >
50 
51 #include "glucat/glucat_imp.h"
52 #include <iostream>
53 #include <sstream>
54 #include <iomanip>
55 #include <limits>
56 
59 template <typename Scalar_T>
60 inline PyObject* PyFloat_FromDouble(Scalar_T v)
62 
63 
64 // String representations for use by PyClical Python classes.
65 
66 typedef std::string String;
67 
69 template<typename Index_Set_T>
70 inline String index_set_to_repr(const Index_Set_T& ist)
71 {
72  std::ostringstream os;
73  os << "index_set(" << ist << ")";
74  return os.str();
75 }
76 
78 template<typename Index_Set_T>
79 inline String index_set_to_str(const Index_Set_T& ist)
80 {
81  std::ostringstream os;
82  os << ist;
83  return os.str();
84 }
85 
87 template<typename Multivector_T>
88 inline String clifford_to_repr(const Multivector_T& mv)
89 {
90  typedef typename Multivector_T::scalar_t scalar_t;
91  std::ostringstream os;
92  os << std::setprecision(std::numeric_limits<scalar_t>::digits10 + 1);
93  os << "clifford(\"" << mv << "\")";
94  return os.str();
95 }
96 
98 template<typename Multivector_T>
99 inline String clifford_to_str(const Multivector_T& mv)
100 {
101  typedef typename Multivector_T::scalar_t scalar_t;
102  std::ostringstream os;
104  os << 0.0;
105  else
106  os << std::setprecision(4) << mv.truncated(scalar_t(1.0e-4));
107  return os.str();
108 }
109 
110 
112 namespace cga3
113 {
115  template<typename Multivector_T>
116  inline Multivector_T cga3(const Multivector_T& x)
117  {
118  typedef Multivector_T cl;
119  typedef typename cl::index_set_t ist;
120  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
121 
122  return (cl(ist(4)) - x) * ninf3 * (x - cl(ist(4)));
123  }
124 
126  template<typename Multivector_T>
127  inline Multivector_T cga3std(const Multivector_T& X)
128  {
129  typedef Multivector_T cl;
130  typedef typename cl::index_set_t ist;
131  typedef typename cl::scalar_t scalar_t;
132  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
133 
134  return scalar_t(-2.0) * X / (X & ninf3);
135  }
136 
138  template<typename Multivector_T>
139  inline Multivector_T agc3(const Multivector_T& X)
140  {
141  typedef Multivector_T cl;
142  typedef typename cl::index_set_t ist;
143  typedef typename cl::scalar_t scalar_t;
144 
145  const cl& cga3stdX = cga3std(X);
146  return (cl(ist(1))*cga3stdX[ist(1)] +
147  cl(ist(2))*cga3stdX[ist(2)] +
148  cl(ist(3))*cga3stdX[ist(3)]) / scalar_t(2.0);
149  }
150 }
151 
152 
153 // Specifications of the IndexSet and Clifford C++ classes for use with PyClical.
154 
155 using namespace glucat;
156 const index_t lo_ndx = DEFAULT_LO;
159 
160 typedef double scalar_t;
162 
164 
165 // Do not warn about unused values. This affects clang++ as well as g++.
166 
167 #pragma GCC diagnostic ignored "-Wunused-value"
168 
169 #if defined(__clang__)
170 // Do not warn about unused functions. The affects clang++ only.
171 
172 # pragma clang diagnostic ignored "-Wunused-function"
173 
174 // Do not warn about unneeded internal declarations. The affects clang++ only.
175 
176 # pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
177 #endif
PyClical.cl
cl
Definition: PyClical.pyx:1860
glucat::DEFAULT_Fast_Size_Threshold
const unsigned int DEFAULT_Fast_Size_Threshold
Definition: global.h:160
PyClical.e
def e(obj)
Definition: PyClical.pyx:1886
glucat::DEFAULT_Sqrt_Max_Steps
const unsigned int DEFAULT_Sqrt_Max_Steps
Definition: global.h:156
clifford_to_repr
String clifford_to_repr(const Multivector_T &mv)
The “official” string representation of Multivector_T mv.
Definition: PyClical.h:88
glucat::tuning
Tuning policy.
Definition: global.h:181
glucat_imp.h
glucat::DEFAULT_Inv_Fast_Dim_Threshold
const unsigned int DEFAULT_Inv_Fast_Dim_Threshold
Definition: global.h:161
glucat::DEFAULT_Log_Max_Inner_Steps
const unsigned int DEFAULT_Log_Max_Inner_Steps
Definition: global.h:158
glucat::DEFAULT_Div_Max_Steps
const unsigned int DEFAULT_Div_Max_Steps
Definition: global.h:155
PyClical.ist
ist
Definition: PyClical.pyx:1878
PyFloat_FromDouble
PyObject * PyFloat_FromDouble(Scalar_T v)
Definition: PyClical.h:60
IndexSet
index_set< lo_ndx, hi_ndx > IndexSet
Definition: PyClical.h:158
index_set_to_str
String index_set_to_str(const Index_Set_T &ist)
The "informal" string representation of Index_Set_T ist.
Definition: PyClical.h:79
hi_ndx
const index_t hi_ndx
Definition: PyClical.h:157
glucat::DEFAULT_Basis_Max_Count
const unsigned int DEFAULT_Basis_Max_Count
Definition: global.h:159
glucat::index_t
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:106
Tune_P
glucat::tuning< glucat::DEFAULT_Mult_Matrix_Threshold, glucat::DEFAULT_Div_Max_Steps, glucat::DEFAULT_Sqrt_Max_Steps, glucat::DEFAULT_Log_Max_Outer_Steps, glucat::DEFAULT_Log_Max_Inner_Steps, glucat::DEFAULT_Basis_Max_Count, glucat::DEFAULT_Fast_Size_Threshold, glucat::DEFAULT_Inv_Fast_Dim_Threshold, glucat::DEFAULT_Products_Size_Threshold, glucat::precision_promoted > Tune_P
Definition: PyClical.h:49
cga3
Definitions for 3D Conformal Geometric Algebra [DL].
Definition: PyClical.h:113
glucat::precision_promoted
@ precision_promoted
Definition: global.h:150
scalar_t
double scalar_t
Definition: PyClical.h:160
glucat::index_set
Index set class based on std::bitset<> in Gnu standard C++ library.
Definition: index_set.h:74
glucat::DEFAULT_HI
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:140
cga3::cga3std
Multivector_T cga3std(const Multivector_T &X)
Convert CGA3 null vector to standard Conformal Geometric Algebra null vector [DL (10....
Definition: PyClical.h:127
glucat::abs
Scalar_T abs(const Multivector< Scalar_T, LO, HI > &val)
Absolute value == sqrt(norm)
Definition: clifford_algebra_imp.h:520
glucat::matrix_multi
A matrix_multi<Scalar_T,LO,HI> is a matrix approximation to a multivector.
Definition: framed_multi.h:68
glucat::DEFAULT_Products_Size_Threshold
const unsigned int DEFAULT_Products_Size_Threshold
Definition: global.h:162
clifford_to_str
String clifford_to_str(const Multivector_T &mv)
The "informal" string representation of Multivector_T mv.
Definition: PyClical.h:99
glucat::numeric_traits
Extra traits which extend numeric limits.
Definition: scalar.h:76
index_set_to_repr
String index_set_to_repr(const Index_Set_T &ist)
The “official” string representation of Index_Set_T ist.
Definition: PyClical.h:70
epsilon
const scalar_t epsilon
Definition: PyClical.h:163
cga3::agc3
Multivector_T agc3(const Multivector_T &X)
Convert CGA3 null vector to Euclidean 3D vector [DL (10.50)].
Definition: PyClical.h:139
glucat
Definition: clifford_algebra.h:39
glucat::DEFAULT_Mult_Matrix_Threshold
const unsigned int DEFAULT_Mult_Matrix_Threshold
Definition: global.h:154
glucat.h
String
std::string String
Definition: PyClical.h:66
PyClical.ninf3
def ninf3
Definition: PyClical.pyx:1908
glucat::DEFAULT_Log_Max_Outer_Steps
const unsigned int DEFAULT_Log_Max_Outer_Steps
Definition: global.h:157
lo_ndx
const index_t lo_ndx
Definition: PyClical.h:156
cga3::cga3
Multivector_T cga3(const Multivector_T &x)
Convert Euclidean 3D vector to Conformal Geometric Algebra null vector [DL (10.50)].
Definition: PyClical.h:116
Clifford
matrix_multi< scalar_t > Clifford
Definition: PyClical.h:161