Feellgood
linear_algebra.h
Go to the documentation of this file.
1 #ifndef linear_algebra_h
2 #define linear_algebra_h
3 
9 #include <random>
10 #pragma GCC diagnostic push
11 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
12 #include <execution>
13 #pragma GCC diagnostic pop
14 
15 #include "config.h"
16 
17 #include "facette.h"
18 #include "feellgoodSettings.h"
19 #include "solver.h"
20 #include "meshUtils.h"
21 #include "node.h"
22 #include "tetra.h"
23 
24 #include "algebra/algebra.h"
25 
27 const int DIM_PB_MAG = 2;
28 
37 class LinAlgebra : public solver<DIM_PB_MAG>
38  {
39 public:
44  : solver<DIM_PB_MAG>(my_msh, s.paramTetra, s.paramFacette, "bicg_dir", s.TOL, s.verbose, s.MAXITER),
46  {
47  L_rhs.resize(2*NOD);
48  Xw.resize(2*NOD);
50  if (!s.recenter)
51  { idx_dir = Nodes::IDX_UNDEF; }
52  else
54 
55  if(s.getFieldType() == R4toR3)
56  { setExtSpaceField(s); }
57 
58  for (int i=0;i<NOD;i++)
59  {
60  if(!my_msh.magNode[i])
61  {
62  lvd.push_back(2*i);
63  lvd.push_back(2*i+1);
64  }
65  }
66  lvd.shrink_to_fit();
67  }
68 
71  {
72  algebra::MatrixShape shape(2 * NOD);
73  auto insert_pair = [this, &shape](int i, int j)
74  {
75  shape[2*i].insert(2*j);
76  shape[2*i].insert(2*j+1);
77  shape[2*i+1].insert(2*j);
78  shape[2*i+1].insert(2*j+1);
79  };
80  for (int i = 0; i < NOD; ++i)
81  { insert_pair(i, i); }
82  for (auto edge: msh->edges)
83  {
84  insert_pair(edge.first, edge.second);
85  insert_pair(edge.second, edge.first);
86  }
87  return shape;
88  }
89 
93  void prepareElements(Eigen::Vector3d const &Hext , timing const &t_prm );
94 
98  void prepareElements(double const A_Hext , timing const &t_prm );
99 
101  void buildInitGuess(std::vector<double> &G) const;
102 
105  bool solve(timing const &t_prm );
106 
108  inline void set_DW_vz(double vz ) { DW_vz = vz; }
109 
111  inline double get_v_max(void) { return v_max; }
112 
114  void setExtSpaceField(Settings &s );
115 
117  void base_projection();
118 
119 private:
122 
125 
127  std::vector<double> L_rhs;
128 
130  std::vector<double> Xw;
131 
133  const int verbose;
134 
136  double DW_vz;
137 
139  double v_max;
140 
142  std::vector< Eigen::Matrix<double,Nodes::DIM,Tetra::NPI> > extSpaceField;
143 
145  std::vector<int> lvd;
146  };// end class linAlgebra
147 #endif
set of class to handle sparse matrix operations for gradient conjugate algorithms a sparse vector cla...
Definition: linear_algebra.h:38
LinAlgebra(Settings &s, Mesh::mesh &my_msh)
Definition: linear_algebra.h:43
double DW_vz
Definition: linear_algebra.h:136
double get_v_max(void)
Definition: linear_algebra.h:111
void setExtSpaceField(Settings &s)
Definition: linear_algebra.cpp:83
Nodes::index idx_dir
Definition: linear_algebra.h:121
double v_max
Definition: linear_algebra.h:139
void prepareElements(Eigen::Vector3d const &Hext, timing const &t_prm)
Definition: linear_algebra.cpp:26
algebra::MatrixShape build_shape()
Definition: linear_algebra.h:70
void set_DW_vz(double vz)
Definition: linear_algebra.h:108
void buildInitGuess(std::vector< double > &G) const
Definition: linear_algebra.cpp:13
std::vector< int > lvd
Definition: linear_algebra.h:145
std::vector< double > Xw
Definition: linear_algebra.h:130
algebra::r_sparseMat K
Definition: linear_algebra.h:124
void base_projection()
Definition: linear_algebra.cpp:3
std::vector< double > L_rhs
Definition: linear_algebra.h:127
bool solve(timing const &t_prm)
Definition: solver.cpp:6
std::vector< Eigen::Matrix< double, Nodes::DIM, Tetra::NPI > > extSpaceField
Definition: linear_algebra.h:142
const int verbose
Definition: linear_algebra.h:133
Definition: mesh.h:27
std::vector< bool > magNode
Definition: mesh.h:331
std::vector< std::pair< int, int > > edges
Definition: mesh.h:326
Container for all the settings provided by the user, with conversions to/from YAML.
Definition: feellgoodSettings.h:73
Nodes::index recentering_direction
Definition: feellgoodSettings.h:147
field_exprType getFieldType(void) const
Definition: feellgoodSettings.h:309
bool recenter
Definition: feellgoodSettings.h:144
Read-mode square sparse matrix.
Definition: sparseMat.h:89
template class for the different solvers template parameter DIM_PROBLEM: dimensionnality of the probl...
Definition: solver.h:20
Mesh::mesh * msh
Definition: solver.h:37
const int NOD
Definition: solver.h:40
Definition: time_integration.h:6
contains namespace Facette header containing Fac class, and some constants and a less_than operator t...
many settings to give some parameters to the solver, boundary conditions for the problem,...
@ R4toR3
Definition: feellgoodSettings.h:46
const int DIM_PB_MAG
Definition: linear_algebra.h:27
index
Definition: node.h:34
std::vector< std::set< int > > MatrixShape
Definition: sparseMat.h:42
header to define struct Node
two templates to fill matrix and vectors in various dimensionnality situations. DIM_PROBLEM = 1 is us...
namespace Tetra header containing Tet class, some constants, and integrales