Feellgood
solver.h
Go to the documentation of this file.
1 #ifndef solver_h
2 #define solver_h
3 
14 #include <eigen3/Eigen/Dense>
15 #include "mesh.h"
16 #include "algebra/algebra.h"
17 
23 template <int DIM_PROBLEM>
24 class solver
25  {
26  public:
28  explicit solver(Mesh::mesh & _msh ,
29  std::vector<Tetra::prm> & _pTetra ,
31  std::vector<Facette::prm> & _pFac ,
33  const std::string name ,
34  const double _tol ,
35  const bool v ,
36  const int max_iter ,
37  std::function<bool(Mesh::Edge)> edge_filter = [](Mesh::Edge){ return true; }):
39  msh(&_msh), NOD(_msh.getNbNodes()), paramTet(_pTetra),
40  paramFac(_pFac), verbose(v), iter(name,_tol,v,max_iter),
41  K(build_shape(edge_filter)), L_rhs(DIM_PROBLEM*NOD) {}
42 
44  virtual void checkBoundaryConditions(void) const = 0;
45 
46  protected:
48  static const int DIM_PB = DIM_PROBLEM;
49 
52 
54  const int NOD;
55 
58  const std::vector<Tetra::prm> &paramTet;
59 
62  const std::vector<Facette::prm> &paramFac;
63 
65  const bool verbose;
66 
69 
72 
74  std::vector<double> L_rhs;
75 
77  algebra::MatrixShape build_shape(std::function<bool(Mesh::Edge)> edge_filter)
78  {
79  algebra::MatrixShape shape(DIM_PROBLEM * NOD);
80 
81  // Add a DIM_PROBLEM × DIM_PROBLEM block connecting nodes i and j.
82  auto add_block = [this, &shape](int i, int j)
83  {
84  for (int k = 0; k < DIM_PROBLEM; ++k)
85  {
86  for (int l = 0; l < DIM_PROBLEM; ++l)
87  { shape[DIM_PROBLEM*i+k].insert(DIM_PROBLEM*j+l); }
88  }
89  };
90 
91  // Add a diagonal block for each node.
92  for (int i = 0; i < NOD; ++i)
93  { add_block(i, i); }
94 
95  // Add two off-diagonal blocks for each edge relevant to the current problem.
96  for (auto edge: msh->edges)
97  {
98  if (edge_filter(edge))
99  {
100  add_block(edge.first, edge.second);
101  add_block(edge.second, edge.first);
102  }
103  }
104 
105  return shape;
106  }
107 
111  template <int N>
112  void buildMat(std::vector<int> &ind, Eigen::Matrix<double,DIM_PROBLEM*N,DIM_PROBLEM*N> &Ke)
113  {
114  for (int ie=0; ie<N; ie++)
115  {
116  int i_ = ind[ie];
117  for (int je=0; je<N; je++)
118  {
119  int j_ = ind[je];
120  for (int di=0; di<DIM_PROBLEM; di++)
121  for (int dj=0; dj<DIM_PROBLEM; dj++)
122  K.add(DIM_PROBLEM*i_ + di, DIM_PROBLEM*j_ + dj, Ke(di*N+ie,dj*N+je));
123  }
124  }
125  }
126 
130  template <int N>
131  void buildVect(std::vector<int> &ind, std::vector<double> &Le)
132  {
133  for (int ie=0; ie<N; ie++)
134  {
135  int i_ = ind[ie];
136  for (int di=0; di<DIM_PROBLEM; di++)
137  { L_rhs[DIM_PROBLEM*i_ + di] += Le[di*N+ie]; }
138  }
139  }
140  }; // end template class solver
141 
142 #endif
set of class to handle sparse matrix operations for gradient conjugate algorithms a sparse vector cla...
Definition: mesh.h:32
std::vector< Edge > edges
Definition: mesh.h:329
int getNbNodes(void) const
Definition: mesh.h:139
Square sparse matrix.
Definition: sparseMat.h:46
void add(int i, int j, double val)
Definition: sparseMat.h:114
template class for the different solvers template parameter DIM_PROBLEM: dimensionnality of the probl...
Definition: solver.h:25
Mesh::mesh * msh
Definition: solver.h:51
void buildMat(std::vector< int > &ind, Eigen::Matrix< double, DIM_PROBLEM *N, DIM_PROBLEM *N > &Ke)
Definition: solver.h:112
virtual void checkBoundaryConditions(void) const =0
algebra::SparseMatrix K
Definition: solver.h:71
const int NOD
Definition: solver.h:54
const bool verbose
Definition: solver.h:65
algebra::iteration< double > iter
Definition: solver.h:68
const std::vector< Tetra::prm > & paramTet
Definition: solver.h:58
void buildVect(std::vector< int > &ind, std::vector< double > &Le)
Definition: solver.h:131
algebra::MatrixShape build_shape(std::function< bool(Mesh::Edge)> edge_filter)
Definition: solver.h:77
static const int DIM_PB
Definition: solver.h:48
solver(Mesh::mesh &_msh, std::vector< Tetra::prm > &_pTetra, std::vector< Facette::prm > &_pFac, const std::string name, const double _tol, const bool v, const int max_iter, std::function< bool(Mesh::Edge)> edge_filter=[](Mesh::Edge){ return true;})
Definition: solver.h:28
const std::vector< Facette::prm > & paramFac
Definition: solver.h:62
std::vector< double > L_rhs
Definition: solver.h:74
class mesh, readMesh is expecting a mesh file in gmsh format either text or binary,...
std::pair< int, int > Edge
Definition: mesh.h:25
const int N
Definition: facette.h:18
constexpr double v[NPI]
Definition: facette.h:49
std::vector< std::set< int > > MatrixShape
Definition: sparseMat.h:38