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  {
17 const int N = 3;
18 const int NPI = 4;
20 constexpr double u[NPI] = {1 / 3., 1 / 5., 3 / 5.,
21  1 / 5.};
22 constexpr double v[NPI] = {1 / 3., 1 / 5., 1 / 5.,
23  3 / 5.};
24 constexpr double pds[NPI] = {-27 / 96., 25 / 96., 25 / 96.,
25  25 / 96.};
28 constexpr double a[N][NPI] = {
29  {1. - u[0] - v[0], 1. - u[1] - v[1], 1. - u[2] - v[2], 1. - u[3] - v[3]},
30  {u[0], u[1], u[2], u[3]},
31  {v[0], v[1], v[2], v[3]}};
32 
33 static const Eigen::Matrix<double,N,NPI> eigen_a = [] {
34  Eigen::Matrix<double,N,NPI> tmp; tmp << a[0][0], a[0][1], a[0][2], a[0][3],
35  a[1][0], a[1][1], a[1][2], a[1][3],
36  a[2][0], a[2][1], a[2][2], a[2][3];
37  return tmp; }();
38 
42 struct prm
43  {
44  std::string regName;
46  double Ks;
47  Eigen::Vector3d uk;
50  inline void infos()
51  {
52  std::cout << "surface region name = " << regName
53  << " ; suppress charges = " << suppress_charges << std::endl;
54 
55  if (Ks != 0)
56  {
57  std::cout << "Ks*a = " << Ks << "*[ " << uk << "]" << std::endl;
58  }
59  else
60  std::cout << "no surface anisotropy" << std::endl;
61  };
62  };
63 
68 class Fac : public element<N,NPI>
69  {
70 public:
72  inline Fac(const std::vector<Nodes::Node> &_p_node ,
73  const int _NOD ,
74  const int _idx ,
75  std::initializer_list<int> _i )
76  : element<N,NPI>(_p_node,_idx,_i),dMs(0)
77  {
78  if (_NOD > 0)
79  {
80  zeroBasing();
81  surf = calc_surf();
82  n = calc_norm();
83  }
84  else
85  {
86  surf = 0.0;
87  n = Eigen::Vector3d(0,0,0);
88  } // no index shift here if NOD == 0 : usefull while reordering face indices
89 
90  for(int i=0;i<NPI;i++)
91  { weight[i] = 2.0 * surf * Facette::pds[i]; }
92  }
93 
95  double surf;
96 
98  double dMs;
99 
101  Eigen::Vector3d n;
102 
106  void interpolation(std::function<Eigen::Vector3d(Nodes::Node)> getter ,
107  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result ) const
108  {
109  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
110  for (int i = 0; i < N; i++) vec_nod.col(i) = getter(getNode(i));
111 
112  result = vec_nod * eigen_a;
113  }
114 
118  void interpolation(std::function<double(Nodes::Node)> getter ,
119  Eigen::Ref<Eigen::Matrix<double,NPI,1>> result ) const
120  {
121  Eigen::Matrix<double,N,1> scalar_nod;
122  for (int i = 0; i < N; i++) scalar_nod(i) = getter(getNode(i));
123 
124  result = scalar_nod.transpose() * eigen_a;
125  }
126 
128  void integrales(Facette::prm const &params );
129 
131  double anisotropyEnergy(Facette::prm const &param ,
132  Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> const u ) const;
133 
135  void charges(Facette::prm const &param ,
136  std::function<Eigen::Vector3d(Nodes::Node)> getter ,
137  std::vector<double> &srcDen ,
138  int &nsrc ,
139  std::vector<double> &corr ) const;
140 
142  double demagEnergy(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> u ,
143  Eigen::Ref<Eigen::Matrix<double,NPI,1>> phi ) const;
144 
146  double potential(std::function<Eigen::Vector3d(Nodes::Node)> getter, int i) const;
147 
149  inline bool operator<(const Fac &f) const
150  {
151  return (this->ind[0] < f.ind[0])
152  || ((this->ind[0] == f.ind[0])
153  && ((this->ind[1] < f.ind[1])
154  || ((this->ind[1] == f.ind[1]) && (this->ind[2] < f.ind[2]))));
155  }
156 
158  inline Eigen::Vector3d calc_norm(void) const
159  {
160  Eigen::Vector3d _n = normal_vect();
161  _n.normalize();
162  return _n;
163  }
164 
166  void getPtGauss(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result) const
167  {
168  Eigen::Matrix<double,Nodes::DIM,N> vec_nod;
169  for (int i = 0; i < N; i++)
170  {
171  vec_nod.col(i) << getNode(i).p;
172  }
173  result = vec_nod * eigen_a;
174  }
175 
176 private:
177  void orientate(void) {}// orientation is done in mesh::indexReorder
178 
180  inline double calc_surf(void) const { return 0.5 * normal_vect().norm(); }
181 
183  inline Eigen::Vector3d normal_vect() const
184  {
185  Eigen::Vector3d p0p1 = getNode(1).p - getNode(0).p;
186  Eigen::Vector3d p0p2 = getNode(2).p - getNode(0).p;
187 
188  return p0p1.cross(p0p2);
189  }
190  }; // end class Fac
191 
192  } // namespace Facette
193 
194 #endif /* facette_h */
Definition: facette.h:69
double surf
Definition: facette.h:95
bool operator<(const Fac &f) const
Definition: facette.h:149
void orientate(void)
Definition: facette.h:177
void interpolation(std::function< Eigen::Vector3d(Nodes::Node)> getter, Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const
Definition: facette.h:106
double potential(std::function< Eigen::Vector3d(Nodes::Node)> getter, int i) const
Definition: facette.cpp:88
double dMs
Definition: facette.h:98
Eigen::Vector3d normal_vect() const
Definition: facette.h:183
double demagEnergy(Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> u, Eigen::Ref< Eigen::Matrix< double, NPI, 1 >> phi) const
Definition: facette.cpp:82
void interpolation(std::function< double(Nodes::Node)> getter, Eigen::Ref< Eigen::Matrix< double, NPI, 1 >> result) const
Definition: facette.h:118
void charges(Facette::prm const &param, std::function< Eigen::Vector3d(Nodes::Node)> getter, std::vector< double > &srcDen, int &nsrc, std::vector< double > &corr) const
Definition: facette.cpp:49
Eigen::Vector3d n
Definition: facette.h:101
double calc_surf(void) const
Definition: facette.h:180
Fac(const std::vector< Nodes::Node > &_p_node, const int _NOD, const int _idx, std::initializer_list< int > _i)
Definition: facette.h:72
void integrales(Facette::prm const &params)
Definition: facette.cpp:6
Eigen::Vector3d calc_norm(void) const
Definition: facette.h:158
double anisotropyEnergy(Facette::prm const &param, Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> const u) const
Definition: facette.cpp:42
void getPtGauss(Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const
Definition: facette.h:166
Template abstract class, mother class for tetraedrons and facettes.
Definition: element.h:24
void zeroBasing(void)
Definition: element.h:140
Eigen::Matrix< double, NPI, 1 > weight
Definition: element.h:48
std::vector< int > ind
Definition: element.h:42
const Nodes::Node & getNode(const int i) const
Definition: element.h:133
const int N
Definition: facette.h:17
constexpr double pds[NPI]
Definition: facette.h:24
constexpr double u[NPI]
Definition: facette.h:20
constexpr double v[NPI]
Definition: facette.h:22
const int NPI
Definition: facette.h:18
constexpr double a[N][NPI]
Definition: facette.h:28
Definition: facette.h:43
Eigen::Vector3d uk
Definition: facette.h:47
void infos()
Definition: facette.h:50
bool suppress_charges
Definition: facette.h:45
double Ks
Definition: facette.h:46
std::string regName
Definition: facette.h:44
Definition: node.h:61
Eigen::Vector3d p
Definition: node.h:62