Feellgood
node.h
Go to the documentation of this file.
1 #ifndef node_h
2 #define node_h
3 
8 //#include <memory>
9 #include <iostream>
10 #include <eigen3/Eigen/Dense>
11 #include "config.h"
12 
17 namespace Nodes
18  {
20  const int DIM = 3;
21 
23  const int NB_DATANODE = 2;
24 
26  enum step
27  {
28  CURRENT = 0,
29  NEXT = 1
30  };
31 
33  enum index
34  {
35  IDX_UNDEF = -1,
36  IDX_X = 0,
37  IDX_Y = 1,
38  IDX_Z = 2
39  };
40 
42 inline double sq(const double x) { return x * x; }
43 
48 struct dataNode
49  {
50  Eigen::Vector3d u;
51  Eigen::Vector3d v;
52  double phi;
53  double phiv;
54  };
55 
60 struct Node
61  {
62  Eigen::Vector3d p;
63  Eigen::Vector3d ep;
65  Eigen::Vector3d eq;
72 
74  inline void setBasis(const double r)
75  {
76  // Choose for an initial ep the direction, among (X, Y, Z), which is further away from u0.
77  Eigen::Index minIdx;
78  d[CURRENT].u.cwiseAbs().minCoeff(&minIdx);
79  ep.setUnit(minIdx);
80  // Gram-Schmidt orthonormalization of (u0, ep).
81  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
82  ep.normalize();
83 
84  // Complete the basis with a vector product.
85  eq = d[CURRENT].u.cross(ep);
86 
87  // Rotate (ep, eq) by the random angle.
88  Eigen::Vector3d new_ep = cos(r) * ep - sin(r) * eq;
89  eq = sin(r) * ep + cos(r) * eq;
90  ep = new_ep;
91 
92  // The basis (u0, ep, eq) should already be orthonormal. An extra orthonormalization could
93  // reduce the rounding errors.
94  if (PARANOID_ORTHONORMALIZATION)
95  {
96  // Modified Gram-Schmidt orthonormalization.
97  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
98  ep.normalize();
99  eq -= eq.dot(d[CURRENT].u) * d[CURRENT].u;
100  eq -= eq.dot(ep) * ep;
101  eq.normalize();
102  }
103  }
104 
108  inline void evolution(void) { d[step::CURRENT] = d[step::NEXT]; }
109 
117  inline void make_evol(const double vp , const double vq ,
118  const double dt )
119  {
120  d[NEXT].v = vp * ep + vq * eq;
121  d[NEXT].u = d[CURRENT].u + dt * d[NEXT].v;
122  d[NEXT].u.normalize();
123  }
124 
126  inline double proj_ep(void) const { return d[NEXT].v.dot(ep); }
127 
129  inline double proj_eq(void) const { return d[NEXT].v.dot(eq); }
130 
132  inline const Eigen::Vector3d get_u(step k ) const
133  { return d[k].u; }
134 
136  inline const Eigen::Vector3d get_v(step k ) const
137  { return d[k].v; }
138 
139  }; // end struct node
140 
142 template <step K>
143 Eigen::Vector3d get_u(Node const &n ) { return n.d[K].u; }
144 
146 template <step K>
147 Eigen::Vector3d get_v(Node const &n ) { return n.d[K].v; }
148 
150 template <step K>
151 double get_phi(Node const &n ) { return n.d[K].phi; }
152 
154 template <step K>
155 double get_phiv(Node const &n ) { return n.d[K].phiv; }
156 
158 inline double get_u_comp(Node const &n , index idx )
159  { return n.d[NEXT].u(idx); }
160 
162 inline double get_v_comp(Node const &n , index idx )
163  { return n.d[NEXT].v(idx); }
164 
166 inline void set_phi(Node &n, double val) { n.d[NEXT].phi = val; }
167 
169 inline void set_phiv(Node &n, double val) { n.d[NEXT].phiv = val; }
170 
171  } // end namespace Nodes
172 
173 #endif /* node_h */
constexpr double u[NPI]
Definition: facette.h:46
const int NB_DATANODE
Definition: node.h:23
index
Definition: node.h:34
const int DIM
Definition: node.h:20
void set_phiv(Node &n, double val)
Definition: node.h:169
void set_phi(Node &n, double val)
Definition: node.h:166
step
Definition: node.h:27
double get_u_comp(Node const &n, index idx)
Definition: node.h:158
double get_phiv(Node const &n)
Definition: node.h:155
double sq(const double x)
Definition: node.h:42
Eigen::Vector3d get_u(Node const &n)
Definition: node.h:143
Eigen::Vector3d get_v(Node const &n)
Definition: node.h:147
double get_phi(Node const &n)
Definition: node.h:151
double get_v_comp(Node const &n, index idx)
Definition: node.h:162
Definition: node.h:61
double proj_ep(void) const
Definition: node.h:126
Eigen::Vector3d eq
Definition: node.h:65
const Eigen::Vector3d get_u(step k) const
Definition: node.h:132
Eigen::Vector3d ep
Definition: node.h:63
Eigen::Vector3d p
Definition: node.h:62
void make_evol(const double vp, const double vq, const double dt)
Definition: node.h:117
const Eigen::Vector3d get_v(step k) const
Definition: node.h:136
void evolution(void)
Definition: node.h:108
void setBasis(const double r)
Definition: node.h:74
double proj_eq(void) const
Definition: node.h:129
dataNode d[NB_DATANODE]
Definition: node.h:71
Definition: node.h:49
double phi
Definition: node.h:52
Eigen::Vector3d v
Definition: node.h:51
double phiv
Definition: node.h:53
Eigen::Vector3d u
Definition: node.h:50