versor  3.0
C++11 library for Geometric algebra
vsr_differential.h
1 /*
2  * =====================================================================================
3  *
4  * Filename: vsr_differential.h
5  *
6  * Description: differential geometry routines
7  *
8  * Version: 1.0
9  * Created: 11/04/2014 14:58:36
10  * Revision: none
11  * Compiler: gcc
12  *
13  * Author: Pablo Colapinto (), gmail -> wolftype
14  *
15  * =====================================================================================
16  */
17 
18 
19 #ifndef vsr_differential_INC
20 #define vsr_differential_INC
21 
22 #include "space/vsr_cga3D_op.h" //<-- assume cga3d for now
23 #include "vsr_graph.h"
24 
25 namespace vsr { namespace cga {
26 
27 //simplicial variable (2D facets in 3D space)
28 //we will generalize this . . .
29 struct Simplicial2 {
30 
31  Vec ea, eb;
33  Biv pss;
34  Vec ra, rb;
35  VSR_PRECISION area, la, lb;
36 
37  Simplicial2(){}
38 
40  // and makes edge vectors, their lengths, tangent pseudoscalar, area, reciprocal frames
41  template<class T>
42  Simplicial2(const T& a, const T& b, const T& c){
43  ea = b-a; la = ea.norm();
44  eb = c-a; lb = eb.norm();
45  tpss=ea^eb;
46  area = tpss.rnorm() * .5;
47  pss = !(tpss);
48  ra = (eb<=pss);
49  rb = (-ea<=pss);
50  }
51 
52  void print(){
53  ea.print();
54  eb.print();
55  }
56 
58  // finds difference along edges, dots that with edge vectors,
59  // uses resultant scalar value to weigh reciprocals
60  // (sum these together?)
61  template<class T>
62  vector<Vec> derivative1(const T& n, const T& na, const T& nb){
63  vector<Vec> v;
64  //diff along edges
65  auto dna = na - n;
66  auto dnb = nb - n;
67  // coefficients
68  auto wa = dna <= ea;
69  auto wb = dnb <= eb;
70  // weighted reciprocals
71  v.push_back(ra*wa);
72  v.push_back(rb*wb);
73  return v;
74  }
75 
76  //exterior derivative / differential
77  template<class T>
78  Biv derivative(const T& n, const T& na, const T& nb){
79  //diff along edges
80  auto dna = na - n;
81  auto dnb = nb - n;
82  // coefficients (project difference onto tangent space)
83  auto wa = dna <= ea;
84  auto wb = dnb <= eb;
85  // weighted reciprocals
86  return ((ra*wa)^(rb*wb)) * area; //q: divide by area sums after
87  }
88 
89  //wedged derivative / differential
90  Biv derivative(const float& n, const float& na, const float& nb){
91  //diff along edges
92  auto dna = na - n;
93  auto dnb = nb - n;
94 
95  // coefficients
96  auto wa = dna;// <= ea;
97  auto wb = dnb;// <= eb;
98  // cout << wa << " " << wb << endl;
99  // weighted reciprocals
100  return ((ra*wa)^(rb*wb)) ; //q: divide by area sums after
101  }
102 
103 
104  // sum of weights across recipcrocals
105  template<class T>
106  Vec derivative2(const T& n, const T& na, const T& nb){
107  //diff along edges
108  auto dna = na - n;
109  auto dnb = nb - n;
110  // coefficients
111  auto aw1 = dna <= rb;
112  auto bw1 = dna <= ra;
113 
114  auto aw2 = dnb <= rb;
115  auto bw2 = dnb <= ra;
116 
117  // weighted reciprocals
118  return ((ra*aw1)+(rb*bw1)) ; //q: divide by area? or after
119  }
120 
121  //Derivative of only edge A (for ccw integration around a node)
122  template<class T>
123  Vec derivativeA(const T& na, const T& nb){
124  //diff along edge
125  auto dna = nb - na;
126  // coefficients of change in a direction
127  auto wa = dna <= ea;
128  // weighted reciprocal
129  return ra*wa ; //q: multiply recip by length or multiply by dot? or after
130  }
131 
132 
134  // finds difference along edges, dots that with edge vectors,
135  // uses resultant scalar value to weigh reciprocals
136  // SUMS these together
137  template<class T>
138  Vec derivative0(const T& n, const T& na, const T& nb){
139  //diff along edges
140  auto dna = na - n;
141  auto dnb = nb - n;
142  // coefficients (amt of change in ea and eb directions)
143  auto wa = dna <= ea;
144  auto wb = dnb <= eb;
145  // return sum of weighted reciprocals
146  return ( (ra*wa)+(rb*wb) ); //q: divid by area? or after sum
147  }
148 
149  Vec derivative0(const float& n, const float& na, const float& nb){
150  //diff along edges
151  auto dna = na - n;
152  auto dnb = nb - n;
153  // coefficients
154  auto wa = dna;// <= ea;
155  auto wb = dnb;// <= eb;
156  // return sum of weighted reciprocals
157  return ( (ra*wa)+(rb*wb) ); //q: divid by area? or after sum
158  }
159 
160 
163  template<class T>
164  Vec gradient(const T& n, const T& na, const T& nb) {
165  //diff along edges
166  auto dna = na - n;
167  auto dnb = nb - n;
168 
169  auto sa = dna <= (ra^(na-n));
170  auto sb = dnb <= (rb^(nb-n));
171 
172  // return sum of weighted reciprocals
173  return ( sa + sb ); //q: divid by area? or after sum
174  }
175 
176  Vec gradient(const float& n, const float& na, const float& nb){
177  //diff along edges
178  auto dna = na - n;
179  auto dnb = nb - n;
180  // return sum of weighted reciprocals
181  return ( (ra*dna)+(rb*dnb) ); //q: divid by area? or after sum
182  }
183 
185  // finds direct difference along outer edge, wedges with gradient
186  template<class T>
187  Biv exterior_derivative(const T& n, const T& na, const T& nb){
188 
189  //diff along outer edge
190  auto F = nb - na;
191  auto deriv = derivative0(n,na,nb);
192 
193  return ( deriv ^ F );
194  }
195 
196 
198  // finds direct difference along outer edge, wedges with gradient
199  template<class T>
200  auto full_derivative(const T& n, const T& na, const T& nb) -> decltype( Vec() * T() ){
201 
202  auto fa = na - n;
203  auto fb = nb - n;
204 
205  auto ta = ra*fa;
206  auto tb = rb*fb;
207 
208  return ( ta+tb );
209  }
210 
211 
212  float deficit(){
213  return acos( (eb.unit()<=ea.unit())[0] );
214  }
215 
216 
217  Point center(){
218  return Round::loc( Round::null(0,0,0) ^ Round::null(ea) ^ Round::null(eb));
219  }
220 
221  //assumes s is next ccw, with shared edge eb
222  Vec cotan( Simplicial2& s){
223  Vec dual = s.center() - center();
224  float wt = dual.norm()/lb;
225  return eb * wt;
226  }
227 
228  /*-----------------------------------------------------------------------------
229  * Questions:
230  *
231  * 1. sum weighted bases or return separate?
232  * 2. divide result by area?
233  * 3. wedge around a node and sum . . . (exterior differential)
234  *-----------------------------------------------------------------------------*/
235 
236  //weighted reciprocals
237  /* Vec wra() { return ra * la; } */
238  /* Vec wrb() { return rb * lb; } */
239 
240  //given a node, get edge vectors
241  /* template<class T> */
242  /* static vector<Simplicial2> Domain(const typename HEGraph<T>::Node& n){ */
243  /* vector<Simplicial2> v; */
244  /* const auto& ta = n.data(); */
245  /* for (auto& i : n.valence() ){ */
246  /* auto& tb = i->a(); */
247  /* auto& tc = i->next->a(); */
248  /* v.push_back( Simplicial2(ta,tb,tc) ); */
249  /* } */
250  /* return v; */
251  /* } */
252 
253 };
254 
255 //generic simplicial variable (in progress)
256 template<int DIM>
257 struct Simplicial {
258  using TVEC = NEVec<DIM>;
259  //using TPSS = NEPSS<DIM>;
260 };
261 
262 
263 //given a facet, get reciprocal
264 
265 
266 
267 //given a half edge graph, get normals
268 
269 
270 } } //vsr::cga::
271 
272 #endif /* ----- #ifndef vsr_differential_INC ----- */
Biv pss
Tangent Pseudoscalar.
Definition: vsr_differential.h:33
Biv tpss
tmp
Definition: vsr_differential.h:32
Common Operations Specific to CGA3D.
Simplicial2(const T &a, const T &b, const T &c)
Constructor takes three coordinates,.
Definition: vsr_differential.h:42
NVec< 5 > Vec
Vector
Definition: vsr_cga3D_types.h:62
Generic Geometric Number Types (templated on an algebra and a basis )
Definition: vsr_algebra.h:69
static Point loc(const A &s)
Location (normalizd) of a Round Element (shorthand)
Definition: vsr_cga3D_round.h:146
void print()
Printing.
Definition: vsr_multivector.h:135
Biv exterior_derivative(const T &n, const T &na, const T &nb)
Vector Derivative of some T-valued function defined on points.
Definition: vsr_differential.h:187
vector< Vec > derivative1(const T &n, const T &na, const T &nb)
Vector Derivative of some T-valued function defined on points.
Definition: vsr_differential.h:62
Pnt Point
Null Vector \(p=\{e_1,e_2,e_3,n_o,n_\infty\}\)
Definition: vsr_cga3D_types.h:128
Vec eb
edges
Definition: vsr_differential.h:31
VSR_PRECISION lb
edge lengths
Definition: vsr_differential.h:35
Definition: vsr_differential.h:29
the versor library namespace
Definition: vsr_algebra.h:29
Definition: vsr_differential.h:257
Vec gradient(const T &n, const T &na, const T &nb)
Gradient of some T-valued function defined on points ignore ea and eb...
Definition: vsr_differential.h:164
Vec rb
reciprocal frames (a suitable basis for FEM)
Definition: vsr_differential.h:34
static Point null(const Vec &v)
Null Point from a vec.
auto full_derivative(const T &n, const T &na, const T &nb) -> decltype(Vec()*T())
Vector Derivative of some T-valued function defined on points.
Definition: vsr_differential.h:200
Vec derivative0(const T &n, const T &na, const T &nb)
Vector Derivative of some T-valued function defined on points.
Definition: vsr_differential.h:138