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 
89  virtual void getPtGauss(Eigen::Ref<Eigen::Matrix<double,Nodes::DIM,NPI>> result) const = 0;
90 
92  void infos(void)
93  {
94  std::cout << "idxPrm: " << idxPrm << " ind: {";
95  for(unsigned int i = 0; i < N-1; i++)
96  { std::cout << ind[i] << ": " << refNode[ind[i]].p << std::endl; }
97  std::cout << ind[N-1] <<": " << refNode[ind[N-1]].p << "}\n";
98  }
99 
100  protected:
102  inline const Nodes::Node & getNode(const int i) const { return refNode[ind[i]]; }
103 
105  inline bool existNodes(void) const { return (refNode.size() > 0); }
106 
108  inline void zeroBasing(void)
109  { std::for_each(ind.begin(),ind.end(),[](int & _i){ _i--; } ); }
110 
111  private:
113  const std::vector<Nodes::Node> & refNode;
114 
116  virtual void orientate() = 0;
117  };
118 #endif
set of class to handle sparse matrix operations for gradient conjugate algorithms a sparse vector cla...
Template abstract class, mother class for tetraedrons and facettes.
Definition: element.h:25
int idxPrm
Definition: element.h:47
void zeroBasing(void)
Definition: element.h:108
Eigen::Matrix< double, 2 *N, 1 > Lp
Definition: element.h:56
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
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
void infos(void)
Definition: element.h:92
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
bool existNodes(void) const
Definition: element.h:105
Eigen::Matrix< double, 2 *N, 2 *N > Kp
Definition: element.h:53
const Nodes::Node & getNode(const int i) const
Definition: element.h:102
const std::vector< Nodes::Node > & refNode
Definition: element.h:113
const int N
Definition: facette.h:18
const int NPI
Definition: facette.h:43
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