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 =
62  (Eigen::MatrixXd(N,NPI) << a[0][0], a[0][1], a[0][2], a[0][3],
63  a[1][0], a[1][1], a[1][2], a[1][3],
64  a[2][0], a[2][1], a[2][2], a[2][3] ).finished();
65 #endif
69 struct prm
70  {
71  std::string regName;
73  double Ks;
74  Eigen::Vector3d uk;
75  double V;
77  double jn;
79  Eigen::Vector3d uP;
81  Eigen::Vector3d s;
84  inline void infos(const bool spinAcc = false)
85  {
86  std::cout << "surface region name = " << regName
87  << " ; suppress charges = " << suppress_charges << std::endl;
88 
89  if (Ks != 0)
90  {
91  std::cout << "Ks*a = " << Ks << "*[ " << uk << "]" << std::endl;
92  }
93  else
94  std::cout << "no surface anisotropy" << std::endl;
95 
96  if (spinAcc)
97  {
98  std::cout<< "V= " << V << "; jn= " << jn << "; uP= " << uP << "; s= " << s << std::endl;
99  }
100  };
101  };
102 
108 class Fac : public element<N,NPI>
109  {
110 public:
112  inline Fac(const std::vector<Nodes::Node> &_p_node ,
113  const int _NOD ,
114  const int _idx ,
115  std::initializer_list<int> _i )
116  : element<N,NPI>(_p_node,_idx,_i),dMs(0)
117  {
118  if (_NOD > 0)
119  {
120  zeroBasing();
121  surf = calc_surf();
122  n = calc_norm();
123  }
124  else
125  {
126  surf = 0.0;
127  n = Eigen::Vector3d(0,0,0);
128  } // no index shift here if NOD == 0 : usefull while reordering face indices
129 
130  for(int i=0;i<NPI;i++)
131  { weight[i] = 2.0 * surf * Facette::pds[i]; }
132  }
133 
135  double surf;
136 
139  double dMs;
140 
142  Eigen::Vector3d n;
143 
147  void interpolation(std::function<Eigen::Vector3d(Nodes::Node)> getter ,
148  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result ) const
149  {
150  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
151  for (int i = 0; i < N; i++) vec_nod.col(i) = getter(getNode(i));
152 
153  result = vec_nod * eigen_a;
154  }
155 
159  void interpolation(std::function<double(Nodes::Node)> getter ,
160  Eigen::Ref<Eigen::Matrix<double,NPI,1>> result ) const
161  {
162  Eigen::Matrix<double,N,1> scalar_nod;
163  for (int i = 0; i < N; i++) scalar_nod(i) = getter(getNode(i));
164 
165  result = scalar_nod.transpose() * eigen_a;
166  }
167 
170  void integrales(Facette::prm const &params );
171 
173  double anisotropyEnergy(Facette::prm const &param ,
174  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> const u ) const;
175 
177  Eigen::Matrix<double,NPI,1> charges(const double &dMs ,
178  std::function<Eigen::Vector3d(const Nodes::Node&)> getter ) const;
179 
182  void correctionCharges(std::function<Eigen::Vector3d(Nodes::Node)> getter ,
183  Eigen::Matrix<double,Facette::NPI,1> &localCharges ,
184  std::vector<double> &corr );
185 
187  double demagEnergy(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> u ,
188  Eigen::Ref<Eigen::Matrix<double,NPI,1>> phi ) const;
189 
191  double potential(std::function<Eigen::Vector3d(Nodes::Node)> getter, int i) const;
192 
194  inline bool operator<(const Fac &f) const
195  {
196  return (this->ind[0] < f.ind[0])
197  || ((this->ind[0] == f.ind[0])
198  && ((this->ind[1] < f.ind[1])
199  || ((this->ind[1] == f.ind[1]) && (this->ind[2] < f.ind[2]))));
200  }
201 
204  bool operator==(const Fac &f) const
205  {
206  const int a= this->ind[0];
207  const int b= this->ind[1];
208  const int c= this->ind[2];
209  const int i= f.ind[0];
210  const int j= f.ind[1];
211  const int k= f.ind[2];
212  return ((a==i)&&(b==j)&&(c==k))||((a==j)&&(b==i)&&(c==k))
213  ||((a==i)&&(b==k)&&(c==j))||((a==k)&&(b==i)&&(c==j))
214  ||((a==j)&&(b==k)&&(c==i))||((a==k)&&(b==j)&&(c==i));
215  }
216 
218  inline Eigen::Vector3d calc_norm(void) const
219  {
220  Eigen::Vector3d _n = normal_vect();
221  _n.normalize();
222  return _n;
223  }
224 
226  void getPtGauss(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result) const
227  {
228  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
229  for (int i = 0; i < N; i++)
230  {
231  vec_nod.col(i) << getNode(i).p;
232  }
233  result = vec_nod * eigen_a;
234  }
235 
237  inline double calc_surf(void) const { return 0.5 * normal_vect().norm(); }
238 
239 private:
241  void orientate(void) {}
242 
244  inline Eigen::Vector3d normal_vect() const
245  {
246  Eigen::Vector3d p0p1 = getNode(1).p - getNode(0).p;
247  Eigen::Vector3d p0p2 = getNode(2).p - getNode(0).p;
248 
249  return p0p1.cross(p0p2);
250  }
251  }; // end class Fac
252 
253  } // namespace Facette
254 
255 #endif /* facette_h */
Definition: facette.h:109
double surf
Definition: facette.h:135
bool operator<(const Fac &f) const
Definition: facette.h:194
void orientate(void)
Definition: facette.h:241
void interpolation(std::function< Eigen::Vector3d(Nodes::Node)> getter, Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const
Definition: facette.h:147
double potential(std::function< Eigen::Vector3d(Nodes::Node)> getter, int i) const
Definition: facette.cpp:88
double dMs
Definition: facette.h:139
Eigen::Vector3d normal_vect() const
Definition: facette.h:244
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:204
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:159
Eigen::Vector3d n
Definition: facette.h:142
double calc_surf(void) const
Definition: facette.h:237
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:112
void integrales(Facette::prm const &params)
Definition: facette.cpp:6
Eigen::Vector3d calc_norm(void) const
Definition: facette.h:218
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:226
Template abstract class, mother class for tetraedrons and facettes.
Definition: element.h:31
void zeroBasing(void)
Definition: element.h:120
Eigen::Matrix< double, NPI, 1 > weight
Definition: element.h:56
std::vector< int > ind
Definition: element.h:50
const Nodes::Node & getNode(const int i) const
Definition: element.h:114
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:70
Eigen::Vector3d uk
Definition: facette.h:74
void infos(const bool spinAcc=false)
Definition: facette.h:84
Eigen::Vector3d s
Definition: facette.h:81
Eigen::Vector3d uP
Definition: facette.h:79
bool suppress_charges
Definition: facette.h:72
double Ks
Definition: facette.h:73
double jn
Definition: facette.h:77
double V
Definition: facette.h:75
std::string regName
Definition: facette.h:71
Definition: node.h:61
Eigen::Vector3d p
Definition: node.h:62