Feellgood
facette.h
Go to the documentation of this file.
1 #ifndef facette_h
2 #define facette_h
3 
10 #include "element.h"
11 
15 namespace Facette
16  {
18 const int N = 3;
19 
20 #if ONE_GAUSS_POINT // Single Gauss point at barycenter of triangle
22  const int NPI = 1;
23 
25  constexpr double u[NPI] = {1. / 3.};
26 
28  constexpr double v[NPI] = {1. / 3.};
29 
31  constexpr double pds[NPI] = {1. / 2.};
32 
36  constexpr double a[N][NPI] = { {1. - u[0] - v[0]}, {u[0]}, {v[0]}};
37 
39  const Eigen::Matrix<double,N,NPI> eigen_a =
40  (Eigen::MatrixXd(N,NPI) << a[0][0], a[1][0], a[2][0] ).finished();
41 #else
43  const int NPI = 4;
44 
46  constexpr double u[NPI] = {1 / 3., 1 / 5., 3 / 5., 1 / 5.};
47 
49  constexpr double v[NPI] = {1 / 3., 1 / 5., 1 / 5., 3 / 5.};
50 
52  constexpr double pds[NPI] = {-27 / 96., 25 / 96., 25 / 96., 25 / 96.};
53 
55  constexpr double a[N][NPI] = {
56  {1. - u[0] - v[0], 1. - u[1] - v[1], 1. - u[2] - v[2], 1. - u[3] - v[3]},
57  {u[0], u[1], u[2], u[3]},
58  {v[0], v[1], v[2], v[3]}};
59 
61  const Eigen::Matrix<double,N,NPI> eigen_a = (Eigen::MatrixXd(N,NPI) << a[0][0], a[0][1], a[0][2], a[0][3],
62  a[1][0], a[1][1], a[1][2], a[1][3],
63  a[2][0], a[2][1], a[2][2], a[2][3] ).finished();
64 #endif
68 struct prm
69  {
70  std::string regName;
72  double Ks;
73  Eigen::Vector3d uk;
74  double V;
75  double jn;
77  Eigen::Vector3d uP;
78  Eigen::Vector3d s;
81  inline void infos(const bool spinAcc = false)
82  {
83  std::cout << "surface region name = " << regName
84  << " ; suppress charges = " << suppress_charges << std::endl;
85 
86  if (Ks != 0)
87  {
88  std::cout << "Ks*a = " << Ks << "*[ " << uk << "]" << std::endl;
89  }
90  else
91  std::cout << "no surface anisotropy" << std::endl;
92 
93  if (spinAcc)
94  {
95  std::cout<< "V= " << V << "; jn= " << jn << "; uP= " << uP << "; s= " << s << std::endl;
96  }
97  };
98  };
99 
104 class Fac : public element<N,NPI>
105  {
106 public:
108  inline Fac(const std::vector<Nodes::Node> &_p_node ,
109  const int _NOD ,
110  const int _idx ,
111  std::initializer_list<int> _i )
112  : element<N,NPI>(_p_node,_idx,_i),dMs(0)
113  {
114  if (_NOD > 0)
115  {
116  zeroBasing();
117  surf = calc_surf();
118  n = calc_norm();
119  }
120  else
121  {
122  surf = 0.0;
123  n = Eigen::Vector3d(0,0,0);
124  } // no index shift here if NOD == 0 : usefull while reordering face indices
125 
126  for(int i=0;i<NPI;i++)
127  { weight[i] = 2.0 * surf * Facette::pds[i]; }
128  }
129 
131  double surf;
132 
134  double dMs;
135 
137  Eigen::Vector3d n;
138 
142  void interpolation(std::function<Eigen::Vector3d(Nodes::Node)> getter ,
143  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result ) const
144  {
145  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
146  for (int i = 0; i < N; i++) vec_nod.col(i) = getter(getNode(i));
147 
148  result = vec_nod * eigen_a;
149  }
150 
154  void interpolation(std::function<double(Nodes::Node)> getter ,
155  Eigen::Ref<Eigen::Matrix<double,NPI,1>> result ) const
156  {
157  Eigen::Matrix<double,N,1> scalar_nod;
158  for (int i = 0; i < N; i++) scalar_nod(i) = getter(getNode(i));
159 
160  result = scalar_nod.transpose() * eigen_a;
161  }
162 
164  void integrales(Facette::prm const &params );
165 
167  double anisotropyEnergy(Facette::prm const &param ,
168  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> const u ) const;
169 
171  Eigen::Matrix<double,NPI,1> charges(const double &dMs ,
172  std::function<Eigen::Vector3d(const Nodes::Node&)> getter ) const;
173 
175  void correctionCharges(std::function<Eigen::Vector3d(Nodes::Node)> getter ,
176  Eigen::Matrix<double,Facette::NPI,1> &localCharges ,
177  std::vector<double> &corr );
178 
180  double demagEnergy(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> u ,
181  Eigen::Ref<Eigen::Matrix<double,NPI,1>> phi ) const;
182 
184  double potential(std::function<Eigen::Vector3d(Nodes::Node)> getter, int i) const;
185 
187  inline bool operator<(const Fac &f) const
188  {
189  return (this->ind[0] < f.ind[0])
190  || ((this->ind[0] == f.ind[0])
191  && ((this->ind[1] < f.ind[1])
192  || ((this->ind[1] == f.ind[1]) && (this->ind[2] < f.ind[2]))));
193  }
194 
197  bool operator==(const Fac &f) const
198  {
199  const int a= this->ind[0];
200  const int b= this->ind[1];
201  const int c= this->ind[2];
202  const int i= f.ind[0];
203  const int j= f.ind[1];
204  const int k= f.ind[2];
205  return ((a==i)&&(b==j)&&(c==k))||((a==j)&&(b==i)&&(c==k))
206  ||((a==i)&&(b==k)&&(c==j))||((a==k)&&(b==i)&&(c==j))
207  ||((a==j)&&(b==k)&&(c==i))||((a==k)&&(b==j)&&(c==i));
208  }
209 
211  inline Eigen::Vector3d calc_norm(void) const
212  {
213  Eigen::Vector3d _n = normal_vect();
214  _n.normalize();
215  return _n;
216  }
217 
219  void getPtGauss(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result) const
220  {
221  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
222  for (int i = 0; i < N; i++)
223  {
224  vec_nod.col(i) << getNode(i).p;
225  }
226  result = vec_nod * eigen_a;
227  }
228 
230  inline double calc_surf(void) const { return 0.5 * normal_vect().norm(); }
231 
232 private:
234  void orientate(void) {}
235 
237  inline Eigen::Vector3d normal_vect() const
238  {
239  Eigen::Vector3d p0p1 = getNode(1).p - getNode(0).p;
240  Eigen::Vector3d p0p2 = getNode(2).p - getNode(0).p;
241 
242  return p0p1.cross(p0p2);
243  }
244  }; // end class Fac
245 
246  } // namespace Facette
247 
248 #endif /* facette_h */
Definition: facette.h:105
double surf
Definition: facette.h:131
bool operator<(const Fac &f) const
Definition: facette.h:187
void orientate(void)
Definition: facette.h:234
void interpolation(std::function< Eigen::Vector3d(Nodes::Node)> getter, Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const
Definition: facette.h:142
double potential(std::function< Eigen::Vector3d(Nodes::Node)> getter, int i) const
Definition: facette.cpp:87
double dMs
Definition: facette.h:134
Eigen::Vector3d normal_vect() const
Definition: facette.h:237
double demagEnergy(Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> u, Eigen::Ref< Eigen::Matrix< double, NPI, 1 >> phi) const
Definition: facette.cpp:81
bool operator==(const Fac &f) const
Definition: facette.h:197
void correctionCharges(std::function< Eigen::Vector3d(Nodes::Node)> getter, Eigen::Matrix< double, Facette::NPI, 1 > &localCharges, std::vector< double > &corr)
Definition: facette.cpp:61
void interpolation(std::function< double(Nodes::Node)> getter, Eigen::Ref< Eigen::Matrix< double, NPI, 1 >> result) const
Definition: facette.h:154
Eigen::Vector3d n
Definition: facette.h:137
double calc_surf(void) const
Definition: facette.h:230
Eigen::Matrix< double, NPI, 1 > charges(const double &dMs, std::function< Eigen::Vector3d(const Nodes::Node &)> getter) const
Definition: facette.cpp:45
Fac(const std::vector< Nodes::Node > &_p_node, const int _NOD, const int _idx, std::initializer_list< int > _i)
Definition: facette.h:108
void integrales(Facette::prm const &params)
Definition: facette.cpp:6
Eigen::Vector3d calc_norm(void) const
Definition: facette.h:211
double anisotropyEnergy(Facette::prm const &param, Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> const u) const
Definition: facette.cpp:38
void getPtGauss(Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const
Definition: facette.h:219
Template abstract class, mother class for tetraedrons and facettes.
Definition: element.h:25
void zeroBasing(void)
Definition: element.h:113
Eigen::Matrix< double, NPI, 1 > weight
Definition: element.h:50
std::vector< int > ind
Definition: element.h:44
const Nodes::Node & getNode(const int i) const
Definition: element.h:107
Definition: spinAccumulationSolver.h:23
const int N
Definition: facette.h:18
constexpr double pds[NPI]
Definition: facette.h:52
constexpr double u[NPI]
Definition: facette.h:46
const Eigen::Matrix< double, N, NPI > eigen_a
Definition: facette.h:61
constexpr double v[NPI]
Definition: facette.h:49
const int NPI
Definition: facette.h:43
constexpr double a[N][NPI]
Definition: facette.h:55
Definition: facette.h:69
Eigen::Vector3d uk
Definition: facette.h:73
void infos(const bool spinAcc=false)
Definition: facette.h:81
Eigen::Vector3d s
Definition: facette.h:78
Eigen::Vector3d uP
Definition: facette.h:77
bool suppress_charges
Definition: facette.h:71
double Ks
Definition: facette.h:72
double jn
Definition: facette.h:75
double V
Definition: facette.h:74
std::string regName
Definition: facette.h:70
Definition: node.h:61
Eigen::Vector3d p
Definition: node.h:62