Feellgood
mesh.h
Go to the documentation of this file.
1 #ifndef mesh_h
2 #define mesh_h
3 
8 #include <algorithm>
9 #pragma GCC diagnostic push
10 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
11 #include <execution>
12 #pragma GCC diagnostic pop
13 
14 #include "facette.h"
15 #include "node.h"
16 #include "tetra.h"
17 #include "feellgoodSettings.h"
18 
19 namespace Mesh
20  {
21 
26 class mesh
27  {
28 public:
31  inline mesh(Settings const &mySets )
32  {
33  readMesh(mySets);
34  indexReorder(mySets.paramTetra);
35 
36  if (mySets.verbose)
37  { std::cout << " reindexed\n"; }
38 
39  double xmin = minNodes(Nodes::IDX_X);
40  double xmax = maxNodes(Nodes::IDX_X);
41 
42  double ymin = minNodes(Nodes::IDX_Y);
43  double ymax = maxNodes(Nodes::IDX_Y);
44 
45  double zmin = minNodes(Nodes::IDX_Z);
46  double zmax = maxNodes(Nodes::IDX_Z);
47 
48  l = Eigen::Vector3d(xmax - xmin, ymax - ymin, zmax - zmin);
49  c = Eigen::Vector3d(0.5 * (xmax + xmin), 0.5 * (ymax + ymin), 0.5 * (zmax + zmin));
50 
51  // Find the longest axis of the sample.
52  Nodes::index long_axis;
53  if (l.x() > l.y())
54  {
55  if (l.x() > l.z())
56  long_axis = Nodes::IDX_X;
57  else
58  long_axis = Nodes::IDX_Z;
59  }
60  else
61  {
62  if (l.y() > l.z())
63  long_axis = Nodes::IDX_Y;
64  else
65  long_axis = Nodes::IDX_Z;
66  }
67  sortNodes(long_axis);
68 
69  vol = std::transform_reduce(EXEC_POL, tet.begin(), tet.end(), 0.0, std::plus{},
70  [](Tetra::Tet const &te) { return te.calc_vol(); });
71  }
72 
74  inline int getNbNodes(void) const { return node.size(); }
75 
77  inline int getNbFacs(void) const { return fac.size(); }
78 
80  inline int getNbTets(void) const { return tet.size(); }
81 
83  inline const Eigen::Vector3d getNode_p(const int i) const { return node[i].p; }
84 
86  inline const Eigen::Vector3d getNode_u(const int i) const { return node[i].get_u(Nodes::NEXT); }
87 
89  inline const Eigen::Vector3d getNode_v(const int i) const { return node[i].get_v(Nodes::NEXT); }
90 
92  inline double getProj_ep(const int i) const {return node[i].proj_ep();}
93 
95  inline double getProj_eq(const int i) const {return node[i].proj_eq();}
96 
98  inline void set_node_u0(const int i, Eigen::Vector3d const &val)
99  { node[i].d[Nodes::CURRENT].u = val; }
100 
102  inline void set_node_zero_v(const int i) { node[i].d[Nodes::NEXT].v.setZero(); }
103 
105  void infos(void) const;
106 
108  inline void setBasis(const double r)
109  {
110  std::for_each(EXEC_POL, node.begin(), node.end(),
111  [&r](Nodes::Node &nod) { nod.setBasis(r); });
112  }
113 
115  void updateNodes(Eigen::Ref<Eigen::VectorXd> X, const double dt);
116 
118  inline void evolution(void)
119  {
120  std::for_each(EXEC_POL, node.begin(), node.end(),
121  [](Nodes::Node &nod) { nod.evolution(); });
122  }
123 
125  Eigen::Vector3d c;
126 
128  Eigen::Vector3d l;
129 
131  double vol;
132 
134  std::vector<Facette::Fac> fac;
135 
137  std::vector<Tetra::Tet> tet;
138 
142  double readSol(bool VERBOSE ,
143  const std::string fileName );
144 
147  inline void init_distrib(Settings const &mySets )
148  {
149  std::for_each(node.begin(),node.end(),[&mySets](Nodes::Node &n)
150  {
151  n.d[Nodes::CURRENT].u = mySets.getMagnetization(n.p);
152  n.d[Nodes::NEXT].u = n.d[Nodes::CURRENT].u;
153  n.d[Nodes::NEXT].phi = 0.;
154  n.d[Nodes::NEXT].phiv = 0.;
155  } );
156  }
157 
161  double avg(std::function<double(Nodes::Node, Nodes::index)> getter ,
162  Nodes::index d ) const;
163 
165  void savesol(const int precision ,
166  const std::string fileName ,
167  std::string const &metadata ) const;
168 
171  bool savesol(const int precision ,
172  const std::string fileName ,
173  std::string const &metadata ,
174  std::vector<double> const &val ) const;
175 
178  inline void set(const int i ,
179  std::function<void(Nodes::Node &, const double)> what_to_set ,
180  const double val )
181  { what_to_set(node[i], val); }
182 
183 private:
186  std::vector<Nodes::Node> node;
187 
193  std::vector<int> node_index;
194 
196  void checkMeshFile(Settings const &mySets );
197 
199  void readNodes(Settings const &mySets );
200 
202  void readTetraedrons(Settings const &mySets );
203 
205  void readTriangles(Settings const &mySets );
206 
208  void readMesh(Settings const &mySets );
209 
211  double doOnNodes(const double init_val ,
212  const Nodes::index coord ,
213  std::function<bool(double, double)> whatToDo ) const;
214 
216  inline double minNodes(const Nodes::index coord ) const
217  {
218  return doOnNodes(__DBL_MAX__, coord, [](double a, double b) { return a < b; });
219  }
220 
222  inline double maxNodes(const Nodes::index coord ) const
223  {
224  return doOnNodes(__DBL_MIN__, coord, [](double a, double b) { return a > b; });
225  }
226 
250  void indexReorder(std::vector<Tetra::prm> const &prmTetra);
251 
254  void sortNodes(Nodes::index long_axis );
255 
256  }; // end class mesh
257 
258  } // end namespace Mesh
259 #endif
Definition: mesh.h:27
const Eigen::Vector3d getNode_p(const int i) const
Definition: mesh.h:83
Eigen::Vector3d l
Definition: mesh.h:128
void checkMeshFile(Settings const &mySets)
Definition: read.cpp:35
void readNodes(Settings const &mySets)
Definition: read.cpp:60
const Eigen::Vector3d getNode_u(const int i) const
Definition: mesh.h:86
void readMesh(Settings const &mySets)
Definition: read.cpp:12
void indexReorder(std::vector< Tetra::prm > const &prmTetra)
Definition: mesh.cpp:48
int getNbFacs(void) const
Definition: mesh.h:77
void infos(void) const
Definition: mesh.cpp:5
Eigen::Vector3d c
Definition: mesh.h:125
void set_node_zero_v(const int i)
Definition: mesh.h:102
void init_distrib(Settings const &mySets)
Definition: mesh.h:147
int getNbNodes(void) const
Definition: mesh.h:74
std::vector< Nodes::Node > node
Definition: mesh.h:186
double minNodes(const Nodes::index coord) const
Definition: mesh.h:216
double doOnNodes(const double init_val, const Nodes::index coord, std::function< bool(double, double)> whatToDo) const
Definition: mesh.cpp:35
double getProj_ep(const int i) const
Definition: mesh.h:92
void savesol(const int precision, const std::string fileName, std::string const &metadata) const
Definition: save.cpp:127
std::vector< Tetra::Tet > tet
Definition: mesh.h:137
double maxNodes(const Nodes::index coord) const
Definition: mesh.h:222
double avg(std::function< double(Nodes::Node, Nodes::index)> getter, Nodes::index d) const
Definition: mesh.cpp:22
int getNbTets(void) const
Definition: mesh.h:80
void set_node_u0(const int i, Eigen::Vector3d const &val)
Definition: mesh.h:98
void sortNodes(Nodes::index long_axis)
Definition: mesh.cpp:97
double readSol(bool VERBOSE, const std::string fileName)
Definition: read.cpp:174
std::vector< Facette::Fac > fac
Definition: mesh.h:134
void setBasis(const double r)
Definition: mesh.h:108
void readTetraedrons(Settings const &mySets)
Definition: read.cpp:82
void evolution(void)
Definition: mesh.h:118
const Eigen::Vector3d getNode_v(const int i) const
Definition: mesh.h:89
void readTriangles(Settings const &mySets)
Definition: read.cpp:130
void updateNodes(Eigen::Ref< Eigen::VectorXd > X, const double dt)
Definition: mesh.cpp:14
std::vector< int > node_index
Definition: mesh.h:193
double getProj_eq(const int i) const
Definition: mesh.h:95
double vol
Definition: mesh.h:131
mesh(Settings const &mySets)
Definition: mesh.h:31
void set(const int i, std::function< void(Nodes::Node &, const double)> what_to_set, const double val)
Definition: mesh.h:178
Container for all the settings provided by the user, with conversions to/from YAML.
Definition: feellgoodSettings.h:63
int verbose
Definition: feellgoodSettings.h:125
std::vector< Tetra::prm > paramTetra
Definition: feellgoodSettings.h:210
Definition: tetra.h:124
contains namespace Facette header containing Fac class, and some constants and a less_than operator t...
many settings to give some parameters to the solver, boundary conditions for the problem,...
constexpr double a[N][NPI]
Definition: facette.h:28
index
Definition: node.h:34
header to define struct Node
Definition: node.h:61
namespace Tetra header containing Tet class, some constants, and integrales