Feellgood
fem.h
Go to the documentation of this file.
1 #ifndef fem_h
2 #define fem_h
3 
9 #include <cassert>
10 #include <cmath>
11 #include <cstdlib>
12 #include <fstream>
13 #include <functional>
14 #include <iomanip>
15 #include <iostream>
16 #include <list>
17 #include <map>
18 #include <sstream>
19 #include <utility>
20 #include <vector>
21 
22 #include <sys/times.h>
23 #include <time.h>
24 #include <unistd.h>
25 
26 #include "mesh.h"
27 
28 #include "ANN.h"
29 #include "feellgoodSettings.h"
30 
32 const int NB_ENERGY_TERMS = 4;
33 
36  {
37  EXCHANGE = 0,
38  ANISOTROPY = 1,
39  DEMAG = 2,
40  ZEEMAN = 3
41  };
42 
47 class Fem
48  {
49 public:
51  inline Fem(Settings const &mySets, timing &t_prm) : msh(mySets)
52  {
53  vmax = 0.0;
54  std::fill(E.begin(),E.end(),0);
55  Etot0 = INFINITY; // avoid "WARNING: energy increased" on first time step
56  Etot = 0.0;
57 
58  recenter_mem = false;
59  if (mySets.recenter)
60  {
61  if (mySets.verbose)
62  {
63  std::cout << "Approximate nearest neighbors:\n";
64  }
65  pts = annAllocPts(msh.getNbNodes(), Nodes::DIM);
66  if (!pts)
67  {
68  std::cout << "ANN memory error while allocating points" << std::endl;
69  SYSTEM_ERROR;
70  }
71  else if (mySets.verbose)
72  {
73  std::cout << " points allocated\n";
74  }
75 
76  for (int i = 0; i < msh.getNbNodes(); i++)
77  {
78  this->pts[i][0] = msh.getNode_p(i).x();
79  this->pts[i][1] = msh.getNode_p(i).y();
80  this->pts[i][2] = msh.getNode_p(i).z();
81  }
82 
83  if (mySets.verbose)
84  {
85  std::cout << " building kd_tree\n";
86  }
87 
88  kdtree = new ANNkd_tree(pts, msh.getNbNodes(), Nodes::DIM);
89  if (!kdtree)
90  {
91  std::cout << "ANN memory error while allocating kd_tree" << std::endl;
92  SYSTEM_ERROR;
93  }
94  recenter_mem = true;
95 
96  if (mySets.verbose)
97  {
98  std::cout << " kd_tree allocated\n";
99  }
100  }
101  else if (mySets.verbose)
102  {
103  std::cout << "No recentering.\n";
104  }
105 
106  if (mySets.restoreFileName == "")
107  {
108  msh.init_distrib(mySets);
109  }
110  else
111  {
112  t_prm.set_t(msh.readSol(mySets.verbose, mySets.restoreFileName));
113  }
114 
115  /* This potentially overrides the initial time set above by msh.readSol(). */
116  if (!isnan(mySets.initial_time))
117  {
118  t_prm.set_t(mySets.initial_time);
119  }
120 
121  if (mySets.recenter)
122  {
123  direction(Nodes::IDX_Z);
124  } /* DW propagation direction for recentering */
125  }
126 
129  {
130  if (recenter_mem)
131  {
132  annDeallocPts(pts);
133  delete kdtree;
134  }
135  }
136 
138  double vmax;
139 
141  std::array<double,NB_ENERGY_TERMS> E;
142 
144  double DW_dir;
145 
147  double Etot0;
148 
150  double Etot;
151 
154 
156  void energy(double const t
158  ,Settings &settings );
159 
163  inline void evolution(void)
164  {
165  msh.evolution();
166  Etot0 = Etot;
167  }
168 
170  void saver(Settings &settings , timing const &t_prm ,
171  std::ofstream &fout , const int nt ) const;
172 
184  bool recenter(double thres ,
185  char recentering_direction );
186 
187 private:
189  ANNkd_tree *kdtree;
191  ANNpointArray pts;
194  void direction(enum Nodes::index idx_dir );
195  }; // end class
196 
197 #endif
Definition: fem.h:48
double Etot
Definition: fem.h:150
void direction(enum Nodes::index idx_dir)
Definition: recentering.cpp:7
void evolution(void)
Definition: fem.h:163
std::array< double, NB_ENERGY_TERMS > E
Definition: fem.h:141
double Etot0
Definition: fem.h:147
Mesh::mesh msh
Definition: fem.h:153
Fem(Settings const &mySets, timing &t_prm)
Definition: fem.h:51
bool recenter(double thres, char recentering_direction)
Definition: recentering.cpp:47
ANNpointArray pts
Definition: fem.h:191
ANNkd_tree * kdtree
Definition: fem.h:189
~Fem()
Definition: fem.h:128
double DW_dir
Definition: fem.h:144
bool recenter_mem
Definition: fem.h:188
void saver(Settings &settings, timing const &t_prm, std::ofstream &fout, const int nt) const
Definition: save.cpp:15
double vmax
Definition: fem.h:138
void energy(double const t, Settings &settings)
Definition: energy.cpp:5
Definition: mesh.h:27
const Eigen::Vector3d getNode_p(const int i) const
Definition: mesh.h:83
void init_distrib(Settings const &mySets)
Definition: mesh.h:147
int getNbNodes(void) const
Definition: mesh.h:74
double readSol(bool VERBOSE, const std::string fileName)
Definition: read.cpp:174
void evolution(void)
Definition: mesh.h:118
Container for all the settings provided by the user, with conversions to/from YAML.
Definition: feellgoodSettings.h:63
int verbose
Definition: feellgoodSettings.h:125
double initial_time
Definition: feellgoodSettings.h:188
std::string restoreFileName
Definition: feellgoodSettings.h:185
bool recenter
Definition: feellgoodSettings.h:134
Definition: time_integration.h:6
void set_t(double _t)
Definition: time_integration.h:53
many settings to give some parameters to the solver, boundary conditions for the problem,...
const int NB_ENERGY_TERMS
Definition: fem.h:32
ENERGY_TYPE
Definition: fem.h:36
class mesh, readMesh is expecting a mesh file in gmsh format either text or binary,...
index
Definition: node.h:34
const int DIM
Definition: node.h:20