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;
64  Eigen::Vector3d eq;
71 
73  inline void setBasis(const double r)
74  {
75  // Choose for an initial ep the direction, among (X, Y, Z), which is further away from u0.
76  Eigen::Index minIdx;
77  d[CURRENT].u.cwiseAbs().minCoeff(&minIdx);
78  #if EIGEN_VERSION_AT_LEAST(3,4,0)
79  ep.setUnit(minIdx);
80  #else
81  if (minIdx == IDX_X) { ep = Eigen::Vector3d::UnitX(); }
82  else if (minIdx == IDX_Y) { ep = Eigen::Vector3d::UnitY(); }
83  else { ep = Eigen::Vector3d::UnitZ(); }
84  #endif
85  // Gram-Schmidt orthonormalization of (u0, ep).
86  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
87  ep.normalize();
88 
89  // Complete the basis with a vector product.
90  eq = d[CURRENT].u.cross(ep);
91 
92  // Rotate (ep, eq) by the random angle.
93  Eigen::Vector3d new_ep = cos(r) * ep - sin(r) * eq;
94  eq = sin(r) * ep + cos(r) * eq;
95  ep = new_ep;
96 
97  // The basis (u0, ep, eq) should already be orthonormal. An extra orthonormalization could
98  // reduce the rounding errors.
99  if (PARANOID_ORTHONORMALIZATION)
100  {
101  // Modified Gram-Schmidt orthonormalization.
102  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
103  ep.normalize();
104  eq -= eq.dot(d[CURRENT].u) * d[CURRENT].u;
105  eq -= eq.dot(ep) * ep;
106  eq.normalize();
107  }
108  }
109 
113  inline void evolution(void) { d[step::CURRENT] = d[step::NEXT]; }
114 
122  inline void make_evol(const double vp , const double vq ,
123  const double dt )
124  {
125  d[NEXT].v = vp * ep + vq * eq;
126  d[NEXT].u = d[CURRENT].u + dt * d[NEXT].v;
127  d[NEXT].u.normalize();
128  }
129 
131  inline double proj_ep(void) const { return d[NEXT].v.dot(ep); }
132 
134  inline double proj_eq(void) const { return d[NEXT].v.dot(eq); }
135 
137  inline const Eigen::Vector3d get_u(step k ) const
138  { return d[k].u; }
139 
141  inline const Eigen::Vector3d get_v(step k ) const
142  { return d[k].v; }
143 
144  }; // end struct node
145 
147 template <step K>
148 Eigen::Vector3d get_u(Node const &n ) { return n.d[K].u; }
149 
151 template <step K>
152 Eigen::Vector3d get_v(Node const &n ) { return n.d[K].v; }
153 
155 template <step K>
156 double get_phi(Node const &n ) { return n.d[K].phi; }
157 
159 template <step K>
160 double get_phiv(Node const &n ) { return n.d[K].phiv; }
161 
163 inline double get_u_comp(Node const &n , index idx )
164  { return n.d[NEXT].u(idx); }
165 
167 inline double get_v_comp(Node const &n , index idx )
168  { return n.d[NEXT].v(idx); }
169 
171 inline void set_phi(Node &n, double val) { n.d[NEXT].phi = val; }
172 
174 inline void set_phiv(Node &n, double val) { n.d[NEXT].phiv = val; }
175 
176  } // end namespace Nodes
177 
178 #endif /* node_h */
constexpr double u[NPI]
Definition: facette.h:20
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:174
void set_phi(Node &n, double val)
Definition: node.h:171
step
Definition: node.h:27
double get_u_comp(Node const &n, index idx)
Definition: node.h:163
double get_phiv(Node const &n)
Definition: node.h:160
double sq(const double x)
Definition: node.h:42
Eigen::Vector3d get_u(Node const &n)
Definition: node.h:148
Eigen::Vector3d get_v(Node const &n)
Definition: node.h:152
double get_phi(Node const &n)
Definition: node.h:156
double get_v_comp(Node const &n, index idx)
Definition: node.h:167
Definition: node.h:61
double proj_ep(void) const
Definition: node.h:131
Eigen::Vector3d eq
Definition: node.h:64
const Eigen::Vector3d get_u(step k) const
Definition: node.h:137
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:122
const Eigen::Vector3d get_v(step k) const
Definition: node.h:141
void evolution(void)
Definition: node.h:113
void setBasis(const double r)
Definition: node.h:73
double proj_eq(void) const
Definition: node.h:134
dataNode d[NB_DATANODE]
Definition: node.h:70
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