glucat  0.12.0
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-2021 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_config.h"
35 #include "glucat/glucat.h"
36 #include "glucat/glucat_imp.h"
37 #include <iostream>
38 #include <sstream>
39 #include <iomanip>
40 #include <limits>
41 
44 template <typename Scalar_T>
45 inline PyObject* PyFloat_FromDouble(Scalar_T v)
47 
48 
49 // String representations for use by PyClical Python classes.
50 
51 using String = std::string;
52 
54 
56 template<typename Index_Set_T>
57 inline String index_set_to_repr(const Index_Set_T& ist)
58 {
59  std::ostringstream os;
60  os << "index_set(" << ist << ")";
61  return os.str();
62 }
63 
65 template<typename Index_Set_T>
66 inline String index_set_to_str(const Index_Set_T& ist)
67 {
68  std::ostringstream os;
69  os << ist;
70  return os.str();
71 }
72 
74 template<typename Multivector_T>
75 inline String clifford_to_repr(const Multivector_T& mv)
76 {
77  using scalar_t = typename Multivector_T::scalar_t;
78  std::ostringstream os;
79  os << std::setprecision(std::numeric_limits<scalar_t>::digits10 + 1);
80  os << "clifford(\"" << mv << "\")";
81  return os.str();
82 }
83 
85 template<typename Multivector_T>
86 inline String clifford_to_str(const Multivector_T& mv)
87 {
88  using scalar_t = typename Multivector_T::scalar_t;
89  std::ostringstream os;
91  os << 0.0;
92  else
93  os << std::setprecision(4) << mv.truncated(scalar_t(1.0e-4));
94  return os.str();
95 }
96 
97 
99 namespace cga3
100 {
102  template<typename Multivector_T>
103  inline Multivector_T cga3(const Multivector_T& x)
104  {
105  using cl = Multivector_T;
106  using ist = typename cl::index_set_t;
107  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
108 
109  return (cl(ist(4)) - x) * ninf3 * (x - cl(ist(4)));
110  }
111 
113  template<typename Multivector_T>
114  inline Multivector_T cga3std(const Multivector_T& X)
115  {
116  using cl = Multivector_T;
117  using ist = typename cl::index_set_t;
118  using scalar_t = typename cl::scalar_t;
119  static const cl ninf3 = cl(ist(4)) + cl(ist(-1));
120 
121  return scalar_t(-2.0) * X / (X & ninf3);
122  }
123 
125  template<typename Multivector_T>
126  inline Multivector_T agc3(const Multivector_T& X)
127  {
128  using cl = Multivector_T;
129  using ist = typename cl::index_set_t;
130  using scalar_t = typename cl::scalar_t;
131 
132  const cl& cga3stdX = cga3std(X);
133  return (cl(ist(1))*cga3stdX[ist(1)] +
134  cl(ist(2))*cga3stdX[ist(2)] +
135  cl(ist(3))*cga3stdX[ist(3)]) / scalar_t(2.0);
136  }
137 }
138 
139 
140 // Specifications of the IndexSet and Clifford C++ classes for use with PyClical.
141 
142 using namespace glucat;
143 const index_t lo_ndx = DEFAULT_LO;
146 
147 using scalar_t = double;
149 
151 
152 // Do not warn about unused values. This affects clang++ as well as g++.
153 
154 #pragma GCC diagnostic ignored "-Wunused-value"
155 
156 #if defined(__clang__)
157 // Do not warn about unused functions. The affects clang++ only.
158 
159 # pragma clang diagnostic ignored "-Wunused-function"
160 
161 // Do not warn about unneeded internal declarations. The affects clang++ only.
162 
163 # pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
164 #endif
String glucat_package_version
Definition: PyClical.h:53
const index_t lo_ndx
Definition: PyClical.h:143
String clifford_to_str(const Multivector_T &mv)
The "informal" string representation of Multivector_T mv.
Definition: PyClical.h:86
String index_set_to_repr(const Index_Set_T &ist)
The “official” string representation of Index_Set_T ist.
Definition: PyClical.h:57
double scalar_t
Definition: PyClical.h:147
Extra traits which extend numeric limits.
Definition: scalar.h:47
const scalar_t epsilon
Definition: PyClical.h:150
A matrix_multi<Scalar_T,LO,HI,Tune_P> is a matrix approximation to a multivector. ...
Definition: framed_multi.h:59
String clifford_to_repr(const Multivector_T &mv)
The “official” string representation of Multivector_T mv.
Definition: PyClical.h:75
Multivector_T cga3(const Multivector_T &x)
Convert Euclidean 3D vector to Conformal Geometric Algebra null vector [DL (10.50)].
Definition: PyClical.h:103
#define GLUCAT_PACKAGE_VERSION
auto abs(const Multivector< Scalar_T, LO, HI, Tune_P > &val) -> Scalar_T
Absolute value == sqrt(norm)
Definitions for 3D Conformal Geometric Algebra [DL].
Definition: PyClical.h:99
PyObject * PyFloat_FromDouble(Scalar_T v)
Definition: PyClical.h:45
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:77
Index set class based on std::bitset<> in Gnu standard C++ library.
Definition: index_set.h:45
String index_set_to_str(const Index_Set_T &ist)
The "informal" string representation of Index_Set_T ist.
Definition: PyClical.h:66
def e(obj)
Definition: PyClical.pyx:1936
const index_t hi_ndx
Definition: PyClical.h:144
Multivector_T cga3std(const Multivector_T &X)
Convert CGA3 null vector to standard Conformal Geometric Algebra null vector [DL (10.52)].
Definition: PyClical.h:114
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:111
std::string String
Definition: PyClical.h:51
def ninf3
Definition: PyClical.pyx:1958
Multivector_T agc3(const Multivector_T &X)
Convert CGA3 null vector to Euclidean 3D vector [DL (10.50)].
Definition: PyClical.h:126