Feellgood
solver.h
Go to the documentation of this file.
1 #ifndef solver_h
2 #define solver_h
3 
10 #include <eigen3/Eigen/Dense>
11 #include "mesh.h"
12 #include "algebra/algebra.h"
13 
19 template <int DIM_PROBLEM>
20 class solver
21  {
22  public:
24  explicit solver(Mesh::mesh & _msh ,
25  std::vector<Tetra::prm> & _pTetra ,
26  std::vector<Facette::prm> & _pFac ,
27  const std::string name ,
28  const double _tol ,
29  const bool v ,
30  const int max_iter ,
31  std::function<bool(Mesh::Edge)> edge_filter = [](Mesh::Edge){ return true; }):
33  msh(&_msh), NOD(_msh.getNbNodes()), paramTet(_pTetra),
34  paramFac(_pFac), verbose(v), iter(name,_tol,v,max_iter),
35  K(build_shape(edge_filter)), L_rhs(DIM_PROBLEM*NOD) {}
36 
38  virtual void checkBoundaryConditions(void) const = 0;
39 
40  protected:
42  static const int DIM_PB = DIM_PROBLEM;
43 
46 
48  const int NOD;
49 
51  const std::vector<Tetra::prm> &paramTet;
52 
54  const std::vector<Facette::prm> &paramFac;
55 
57  const bool verbose;
58 
61 
64 
66  std::vector<double> L_rhs;
67 
69  algebra::MatrixShape build_shape(std::function<bool(Mesh::Edge)> edge_filter)
70  {
71  algebra::MatrixShape shape(DIM_PROBLEM * NOD);
72 
73  // Add a DIM_PROBLEM × DIM_PROBLEM block connecting nodes i and j.
74  auto add_block = [this, &shape](int i, int j)
75  {
76  for (int k = 0; k < DIM_PROBLEM; ++k)
77  {
78  for (int l = 0; l < DIM_PROBLEM; ++l)
79  { shape[DIM_PROBLEM*i+k].insert(DIM_PROBLEM*j+l); }
80  }
81  };
82 
83  // Add a diagonal block for each node.
84  for (int i = 0; i < NOD; ++i)
85  { add_block(i, i); }
86 
87  // Add two off-diagonal blocks for each edge relevant to the current problem.
88  for (auto edge: msh->edges)
89  {
90  if (edge_filter(edge))
91  {
92  add_block(edge.first, edge.second);
93  add_block(edge.second, edge.first);
94  }
95  }
96 
97  return shape;
98  }
99 
103  template <int N>
104  void buildMat(std::vector<int> &ind, Eigen::Matrix<double,DIM_PROBLEM*N,DIM_PROBLEM*N> &Ke)
105  {
106  for (int ie=0; ie<N; ie++)
107  {
108  int i_ = ind[ie];
109  for (int je=0; je<N; je++)
110  {
111  int j_ = ind[je];
112  for (int di=0; di<DIM_PROBLEM; di++)
113  for (int dj=0; dj<DIM_PROBLEM; dj++)
114  K.add(DIM_PROBLEM*i_ + di, DIM_PROBLEM*j_ + dj, Ke(di*N+ie,dj*N+je));
115  }
116  }
117  }
118 
122  template <int N>
123  void buildVect(std::vector<int> &ind, std::vector<double> &Le)
124  {
125  for (int ie=0; ie<N; ie++)
126  {
127  int i_ = ind[ie];
128  for (int di=0; di<DIM_PROBLEM; di++)
129  { L_rhs[DIM_PROBLEM*i_ + di] += Le[di*N+ie]; }
130  }
131  }
132  }; // end template class solver
133 
134 #endif
set of class to handle sparse matrix operations for gradient conjugate algorithms a sparse vector cla...
Definition: mesh.h:30
std::vector< Edge > edges
Definition: mesh.h:331
int getNbNodes(void) const
Definition: mesh.h:141
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:21
Mesh::mesh * msh
Definition: solver.h:45
void buildMat(std::vector< int > &ind, Eigen::Matrix< double, DIM_PROBLEM *N, DIM_PROBLEM *N > &Ke)
Definition: solver.h:104
virtual void checkBoundaryConditions(void) const =0
algebra::SparseMatrix K
Definition: solver.h:63
const int NOD
Definition: solver.h:48
const bool verbose
Definition: solver.h:57
algebra::iteration< double > iter
Definition: solver.h:60
const std::vector< Tetra::prm > & paramTet
Definition: solver.h:51
void buildVect(std::vector< int > &ind, std::vector< double > &Le)
Definition: solver.h:123
algebra::MatrixShape build_shape(std::function< bool(Mesh::Edge)> edge_filter)
Definition: solver.h:69
static const int DIM_PB
Definition: solver.h:42
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:24
const std::vector< Facette::prm > & paramFac
Definition: solver.h:54
std::vector< double > L_rhs
Definition: solver.h:66
class mesh, readMesh is expecting a mesh file in gmsh format either text or binary,...
std::pair< int, int > Edge
Definition: mesh.h:23
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