Feellgood
element.h
1 #ifndef element_h
2 #define element_h
3 
4 #pragma GCC diagnostic push
5 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
6 #include <execution>
7 #pragma GCC diagnostic pop
8 
9 #include <eigen3/Eigen/Sparse>
10 #include <eigen3/Eigen/Dense>
11 
12 #include "node.h"
13 #include "algebra/algebra.h"
14 
23 template <int N,int NPI>
24 class element
25  {
27  public:
28  explicit element(const std::vector<Nodes::Node> &_p_node ,
29  const int _idx ,
30  std::initializer_list<int> & _i
31  ) : idxPrm(_idx), refNode(_p_node)
32  {
33  if(_i.size() == N)
34  { ind.assign(_i); }
35  else
36  {
37  std::cout<<"Warning: element constructor is given an init list with size() != N\n";
38  }
39  Kp.setZero();
40  Lp.setZero();
41  }
42 
44  std::vector<int> ind;
45 
47  int idxPrm;
48 
50  Eigen::Matrix<double,NPI,1> weight;
51 
53  Eigen::Matrix<double,2*N,2*N> Kp;
54 
56  Eigen::Matrix<double,2*N,1> Lp;
57 
59  inline constexpr int getN(void) const { return N; }
60 
62  inline constexpr int getNPI(void) const { return NPI; }
63 
71  void buildMatP(Eigen::Ref<Eigen::Matrix<double,2*N,3*N>> P )
72  {
73  P.setZero();
74  Eigen::Matrix<double,Nodes::DIM,N,Eigen::RowMajor> tempo;
75  for (int i = 0; i < N; i++) { tempo.col(i) = getNode(i).ep; }
76 
77  P.template block<N,N>(0,0).diagonal() = tempo.row(Nodes::IDX_X);
78  P.template block<N,N>(0,N).diagonal() = tempo.row(Nodes::IDX_Y);
79  P.template block<N,N>(0,2*N).diagonal() = tempo.row(Nodes::IDX_Z);
80 
81  for (int i = 0; i < N; i++) { tempo.col(i) = getNode(i).eq; }
82 
83  P.template block<N,N>(N,0).diagonal() = tempo.row(Nodes::IDX_X);
84  P.template block<N,N>(N,N).diagonal() = tempo.row(Nodes::IDX_Y);
85  P.template block<N,N>(N,2*N).diagonal() = tempo.row(Nodes::IDX_Z);
86  }
87 
90  {
91  for (int i = 0; i < N; i++)
92  {
93  int i_ = ind[i];
94 
95  for (int j = 0; j < N; j++)
96  {
97  int j_ = ind[j];
98  if (Kp(i, j) != 0) K.add(2*i_+1, 2*j_, Kp(i, j) );
99  if (Kp(i, N+j) != 0) K.add(2*i_+1, 2*j_+1, Kp(i, N+j));
100  if (Kp(N+i, j) != 0) K.add(2*i_, 2*j_, Kp(N+i, j) );
101  if (Kp(N+i, N+j) != 0) K.add(2*i_, 2*j_+1, Kp(N+i, N+j));
102  }
103  }
104  }
105 
107  void assemblage_vect(std::vector<double> &L ) const
108  {
109  for (int i = 0; i < N; i++)
110  {
111  const int i_ = ind[i];
112  if(Lp[i] != 0)
113  { L[2*i_+1] += Lp[i]; }
114  if(Lp[N+i] != 0)
115  { L[2*i_] += Lp[N + i]; }
116  }
117  }
118 
120  void infos() const
121  {
122  std::cout << "idxPrm: " << idxPrm << " ind: {";
123  for(unsigned int i = 0; i < N-1; i++)
124  { std::cout << ind[i] << ": " << refNode[ind[i]].p << std::endl; }
125  std::cout << ind[N-1] <<": " << refNode[ind[N-1]].p << "}\n";
126  };
127 
129  virtual void getPtGauss(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result) const = 0;
130 
131  protected:
133  inline const Nodes::Node & getNode(const int i) const { return refNode[ind[i]]; }
134 
136  inline bool existNodes(void)
137  { return (refNode.size() > 0); }
138 
140  inline void zeroBasing(void)
141  { std::for_each(ind.begin(),ind.end(),[](int & _i){ _i--; } ); }
142 
143  private:
145  const std::vector<Nodes::Node> & refNode;
146 
148  virtual void orientate() = 0;
149  };
150 
151 #endif
set of class to handle sparse matrix operations for gradient conjugate algorithms a sparse vector cla...
Read-mode square sparse matrix.
Definition: sparseMat.h:87
void add(int i, int j, double val)
Definition: sparseMat.h:151
Template abstract class, mother class for tetraedrons and facettes.
Definition: element.h:25
void assemblage_vect(std::vector< double > &L) const
Definition: element.h:107
int idxPrm
Definition: element.h:47
void assemblage_mat(algebra::r_sparseMat &K) const
Definition: element.h:89
void zeroBasing(void)
Definition: element.h:140
Eigen::Matrix< double, 2 *N, 1 > Lp
Definition: element.h:56
bool existNodes(void)
Definition: element.h:136
constexpr int getNPI(void) const
Definition: element.h:62
void buildMatP(Eigen::Ref< Eigen::Matrix< double, 2 *N, 3 *N >> P)
Definition: element.h:71
void infos() const
Definition: element.h:120
virtual void getPtGauss(Eigen::Ref< Eigen::Matrix< double, Nodes::DIM, NPI >> result) const =0
Eigen::Matrix< double, NPI, 1 > weight
Definition: element.h:50
virtual void orientate()=0
std::vector< int > ind
Definition: element.h:44
element(const std::vector< Nodes::Node > &_p_node, const int _idx, std::initializer_list< int > &_i)
Definition: element.h:28
constexpr int getN(void) const
Definition: element.h:59
Eigen::Matrix< double, 2 *N, 2 *N > Kp
Definition: element.h:53
const Nodes::Node & getNode(const int i) const
Definition: element.h:133
const std::vector< Nodes::Node > & refNode
Definition: element.h:145
const int N
Definition: facette.h:17
const int NPI
Definition: facette.h:18
const int P
Definition: fmm_demag.h:25
header to define struct Node
Definition: node.h:61
Eigen::Vector3d eq
Definition: node.h:64
Eigen::Vector3d ep
Definition: node.h:63