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  ep.setUnit(minIdx);
79  // Gram-Schmidt orthonormalization of (u0, ep).
80  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
81  ep.normalize();
82 
83  // Complete the basis with a vector product.
84  eq = d[CURRENT].u.cross(ep);
85 
86  // Rotate (ep, eq) by the random angle.
87  Eigen::Vector3d new_ep = cos(r) * ep - sin(r) * eq;
88  eq = sin(r) * ep + cos(r) * eq;
89  ep = new_ep;
90 
91  // The basis (u0, ep, eq) should already be orthonormal. An extra orthonormalization could
92  // reduce the rounding errors.
93  if (PARANOID_ORTHONORMALIZATION)
94  {
95  // Modified Gram-Schmidt orthonormalization.
96  ep -= ep.dot(d[CURRENT].u) * d[CURRENT].u;
97  ep.normalize();
98  eq -= eq.dot(d[CURRENT].u) * d[CURRENT].u;
99  eq -= eq.dot(ep) * ep;
100  eq.normalize();
101  }
102  }
103 
107  inline void evolution(void) { d[step::CURRENT] = d[step::NEXT]; }
108 
116  inline void make_evol(const double vp , const double vq ,
117  const double dt )
118  {
119  d[NEXT].v = vp * ep + vq * eq;
120  d[NEXT].u = d[CURRENT].u + dt * d[NEXT].v;
121  d[NEXT].u.normalize();
122  }
123 
125  inline double proj_ep(void) const { return d[NEXT].v.dot(ep); }
126 
128  inline double proj_eq(void) const { return d[NEXT].v.dot(eq); }
129 
131  inline const Eigen::Vector3d get_u(step k ) const
132  { return d[k].u; }
133 
135  inline const Eigen::Vector3d get_v(step k ) const
136  { return d[k].v; }
137 
138  }; // end struct node
139 
141 template <step K>
142 Eigen::Vector3d get_u(Node const &n ) { return n.d[K].u; }
143 
145 template <step K>
146 Eigen::Vector3d get_v(Node const &n ) { return n.d[K].v; }
147 
149 template <step K>
150 double get_phi(Node const &n ) { return n.d[K].phi; }
151 
153 template <step K>
154 double get_phiv(Node const &n ) { return n.d[K].phiv; }
155 
157 inline double get_u_comp(Node const &n , index idx )
158  { return n.d[NEXT].u(idx); }
159 
161 inline double get_v_comp(Node const &n , index idx )
162  { return n.d[NEXT].v(idx); }
163 
165 inline void set_phi(Node &n, double val) { n.d[NEXT].phi = val; }
166 
168 inline void set_phiv(Node &n, double val) { n.d[NEXT].phiv = val; }
169 
170  } // end namespace Nodes
171 
172 #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:168
void set_phi(Node &n, double val)
Definition: node.h:165
step
Definition: node.h:27
double get_u_comp(Node const &n, index idx)
Definition: node.h:157
double get_phiv(Node const &n)
Definition: node.h:154
double sq(const double x)
Definition: node.h:42
Eigen::Vector3d get_u(Node const &n)
Definition: node.h:142
Eigen::Vector3d get_v(Node const &n)
Definition: node.h:146
double get_phi(Node const &n)
Definition: node.h:150
double get_v_comp(Node const &n, index idx)
Definition: node.h:161
Definition: node.h:61
double proj_ep(void) const
Definition: node.h:125
Eigen::Vector3d eq
Definition: node.h:64
const Eigen::Vector3d get_u(step k) const
Definition: node.h:131
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:116
const Eigen::Vector3d get_v(step k) const
Definition: node.h:135
void evolution(void)
Definition: node.h:107
void setBasis(const double r)
Definition: node.h:73
double proj_eq(void) const
Definition: node.h:128
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