glucat  0.8.2
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 
58 template <typename Scalar_T>
59 inline PyObject* PyFloat_FromDouble(Scalar_T v)
61 
62 
63 // String representations for use by PyClical Python classes.
64 
65 typedef std::string String;
66 
68 template<typename Index_Set_T>
69 inline String index_set_to_repr(const Index_Set_T& ist)
70 {
71  std::ostringstream os;
72  os << "index_set(" << ist << ")";
73  return os.str();
74 }
75 
77 template<typename Index_Set_T>
78 inline String index_set_to_str(const Index_Set_T& ist)
79 {
80  std::ostringstream os;
81  os << ist;
82  return os.str();
83 }
84 
86 template<typename Multivector_T>
87 inline String clifford_to_repr(const Multivector_T& mv)
88 {
89  typedef typename Multivector_T::scalar_t scalar_t;
90  std::ostringstream os;
91  os << std::setprecision(std::numeric_limits<scalar_t>::digits10 + 1);
92  os << "clifford(\"" << mv << "\")";
93  return os.str();
94 }
95 
97 template<typename Multivector_T>
98 inline String clifford_to_str(const Multivector_T& mv)
99 {
100  typedef typename Multivector_T::scalar_t scalar_t;
101  std::ostringstream os;
102  if (abs(mv) < std::numeric_limits<scalar_t>::epsilon())
103  os << 0.0;
104  else
105  os << std::setprecision(4) << mv.truncated(scalar_t(1.0e-4));
106  return os.str();
107 }
108 
109 
111 namespace cga3
112 {
114  template<typename Multivector_T>
115  inline Multivector_T cga3(const Multivector_T& x)
116  {
117  typedef Multivector_T cl;
118  typedef typename cl::index_set_t ist;
119  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
120 
121  return (cl(ist(4)) - x) * ninf3 * (x - cl(ist(4)));
122  }
123 
125  template<typename Multivector_T>
126  inline Multivector_T cga3std(const Multivector_T& X)
127  {
128  typedef Multivector_T cl;
129  typedef typename cl::index_set_t ist;
130  typedef typename cl::scalar_t scalar_t;
131  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
132 
133  return scalar_t(-2.0) * X / (X & ninf3);
134  }
135 
137  template<typename Multivector_T>
138  inline Multivector_T agc3(const Multivector_T& X)
139  {
140  typedef Multivector_T cl;
141  typedef typename cl::index_set_t ist;
142  typedef typename cl::scalar_t scalar_t;
143 
144  const cl& cga3stdX = cga3std(X);
145  return (cl(ist(1))*cga3stdX[ist(1)] +
146  cl(ist(2))*cga3stdX[ist(2)] +
147  cl(ist(3))*cga3stdX[ist(3)]) / scalar_t(2.0);
148  }
149 }
150 
151 
152 // Specifications of the IndexSet and Clifford C++ classes for use with PyClical.
153 
154 using namespace glucat;
155 const index_t lo_ndx = DEFAULT_LO;
158 
159 typedef double scalar_t;
161 
162 
163 // Do not warn about unused values. This affects clang++ as well as g++.
164 
165 #pragma GCC diagnostic ignored "-Wunused-value"
166 
167 #if defined(__clang__)
168 // Do not warn about unused functions. The affects clang++ only.
169 
170 # pragma clang diagnostic ignored "-Wunused-function"
171 
172 // Do not warn about unneeded internal declarations. The affects clang++ only.
173 
174 # pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
175 #endif
const index_t lo_ndx
Definition: PyClical.h:155
String clifford_to_str(const Multivector_T &mv)
The "informal" string representation of Multivector_T mv.
Definition: PyClical.h:98
String index_set_to_repr(const Index_Set_T &ist)
The “official” string representation of Index_Set_T ist.
Definition: PyClical.h:69
index_set< lo_ndx, hi_ndx > IndexSet
Definition: PyClical.h:157
Scalar_T abs(const Multivector< Scalar_T, LO, HI > &val)
Absolute value == sqrt(norm)
const unsigned int DEFAULT_Products_Size_Threshold
Definition: global.h:133
Extra traits which extend numeric limits.
Definition: scalar.h:46
const unsigned int DEFAULT_Mult_Matrix_Threshold
Definition: global.h:125
Tuning policy.
Definition: global.h:151
A matrix_multi<Scalar_T,LO,HI> is a matrix approximation to a multivector.
Definition: framed_multi.h:68
String clifford_to_repr(const Multivector_T &mv)
The “official” string representation of Multivector_T mv.
Definition: PyClical.h:87
Multivector_T cga3(const Multivector_T &x)
Convert Euclidean 3D vector to Conformal Geometric Algebra null vector [DL (10.50)].
Definition: PyClical.h:115
const unsigned int DEFAULT_Log_Max_Outer_Steps
Definition: global.h:128
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
const unsigned int DEFAULT_Sqrt_Max_Steps
Definition: global.h:127
matrix_multi< scalar_t > Clifford
Definition: PyClical.h:160
Definitions for 3D Conformal Geometric Algebra [DL].
Definition: PyClical.h:111
const unsigned int DEFAULT_Fast_Size_Threshold
Definition: global.h:131
const unsigned int DEFAULT_Inv_Fast_Dim_Threshold
Definition: global.h:132
const unsigned int DEFAULT_Div_Max_Steps
Definition: global.h:126
PyObject * PyFloat_FromDouble(Scalar_T v)
Definition: PyClical.h:59
Index set class based on std::bitset<> in Gnu standard C++ library.
Definition: index_set.h:45
double scalar_t
Definition: PyClical.h:159
const unsigned int DEFAULT_Log_Max_Inner_Steps
Definition: global.h:129
String index_set_to_str(const Index_Set_T &ist)
The "informal" string representation of Index_Set_T ist.
Definition: PyClical.h:78
const unsigned int DEFAULT_Basis_Max_Count
Definition: global.h:130
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:77
def e(obj)
Definition: PyClical.pyx:1887
const index_t hi_ndx
Definition: PyClical.h:156
Multivector_T cga3std(const Multivector_T &X)
Convert CGA3 null vector to standard Conformal Geometric Algebra null vector [DL (10.52)].
Definition: PyClical.h:126
std::string String
Definition: PyClical.h:65
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:111
def ninf3
Definition: PyClical.pyx:1909
Multivector_T agc3(const Multivector_T &X)
Convert CGA3 null vector to Euclidean 3D vector [DL (10.50)].
Definition: PyClical.h:138