Feellgood
node.h
Go to the documentation of this file.
1 #ifndef node_h
2 #define node_h
3 
8 #include <iostream>
9 #include <eigen3/Eigen/Dense>
10 #include "config.h"
11 
16 namespace Nodes
17  {
19  const int DIM = 3;
20 
22  const int NB_DATANODE = 2;
23 
25  enum step
26  {
27  CURRENT = 0,
28  NEXT = 1
29  };
30 
32  enum index
33  {
34  IDX_UNDEF = -1,
35  IDX_X = 0,
36  IDX_Y = 1,
37  IDX_Z = 2
38  };
39 
41 inline double sq(const double x) { return x * x; }
42 
47 struct dataNode
48  {
49  Eigen::Vector3d u;
50  Eigen::Vector3d v;
51  double phi;
52  double phiv;
53  };
54 
59 struct Node
60  {
61  Eigen::Vector3d p;
62  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(const step k ) const
132  { return d[k].u; }
133 
135  inline const Eigen::Vector3d get_v(const step k ) const
136  { return d[k].v; }
137 
138  }; // end struct node
139 
141 template <step K>
142 Eigen::Vector3d get_u(const Node &n ) { return n.d[K].u; }
143 
145 template <step K>
146 Eigen::Vector3d get_v(const Node &n ) { return n.d[K].v; }
147 
149 template <step K>
150 double get_phi(const Node &n ) { return n.d[K].phi; }
151 
153 template <step K>
154 double get_phiv(const Node &n ) { return n.d[K].phiv; }
155 
157 inline double get_u_comp(const Node &n , const index idx )
158  { return n.d[NEXT].u(idx); }
159 
161 inline double get_v_comp(const Node &n , const index idx )
162  { return n.d[NEXT].v(idx); }
163 
165 inline void set_phi(Node &n, const double val) { n.d[NEXT].phi = val; }
166 
168 inline void set_phiv(Node &n, const double val) { n.d[NEXT].phiv = val; }
169 
170  } // end namespace Nodes
171 
172 #endif /* node_h */
const int NB_DATANODE
Definition: node.h:22
void set_phi(Node &n, const double val)
Definition: node.h:165
void set_phiv(Node &n, const double val)
Definition: node.h:168
index
Definition: node.h:33
double get_u_comp(const Node &n, const index idx)
Definition: node.h:157
Eigen::Vector3d get_u(const Node &n)
Definition: node.h:142
double get_phiv(const Node &n)
Definition: node.h:154
double get_v_comp(const Node &n, const index idx)
Definition: node.h:161
const int DIM
Definition: node.h:19
step
Definition: node.h:26
Eigen::Vector3d get_v(const Node &n)
Definition: node.h:146
double sq(const double x)
Definition: node.h:41
double get_phi(const Node &n)
Definition: node.h:150
constexpr double u[NPI]
Definition: tetra.h:57
Definition: node.h:60
double proj_ep(void) const
Definition: node.h:125
Eigen::Vector3d eq
Definition: node.h:64
const Eigen::Vector3d get_u(const step k) const
Definition: node.h:131
const Eigen::Vector3d get_v(const step k) const
Definition: node.h:135
Eigen::Vector3d ep
Definition: node.h:62
Eigen::Vector3d p
Definition: node.h:61
void make_evol(const double vp, const double vq, const double dt)
Definition: node.h:116
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:48
double phi
Definition: node.h:51
Eigen::Vector3d v
Definition: node.h:50
double phiv
Definition: node.h:52
Eigen::Vector3d u
Definition: node.h:49