CEPS  24.01
Cardiac ElectroPhysiology Simulator
LinearSystem.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
32 #include "common/CepsCommon.hpp"
33 
36 
37 // #include "linearAlgebra/SolverType.hpp"
38 
39 // Implementation depends on compilation options
40 #ifdef CEPS_USE_PETSC
41 #include "petscksp.h"
42 typedef KSP CepsSolver;
43 #endif
44 
52 class
53 
54  LinearSystem : public CepsObject
55 {
56  public:
58  LinearSystem ();
59 
61  explicit LinearSystem (InputParameters *params);
62 
64  ~LinearSystem () override;
65 
67  void
68  setupWithParameters(InputParameters* params);
69 
81  virtual void
82  solve(DVecPtr solution);
83 
85  void
86  setLhsMatrix(DMatPtr lhs);
87 
89  void
90  setPreconditioningMatrix(DMatPtr preconditioningMatrix);
91 
93  void
94  setRhsVector(DVecPtr rhs);
95 
97  void
98  setType(const CepsString &type);
99 
101  CepsSolver&
102  getSolver();
103 
105  DMatPtr
106  getLhsMatrix();
107 
109  DVecPtr
110  getRhsVector();
111 
118  void
119  setTolerances(CepsReal rTol, CepsReal aTol, CepsReal dTol, CepsUInt iter);
120 
122  void
123  setMaxNbIterations(CepsUInt nbIterations);
124 
126  void
127  setRelativeTolerance(CepsReal rTol);
128 
130  void
131  setAbsoluteTolerance(CepsReal aTol);
132 
134  void
135  setDivergenceTolerance(CepsReal dTol);
136 
138  CepsReal
139  getRelativeTolerance() const;
140 
142  CepsReal
143  getAbsoluteTolerance() const;
144 
146  CepsReal
147  getDivergenceTolerance() const;
148 
150  CepsUInt
151  getMaxNbIterations() const;
152 
153  private:
155  void
156  initialize();
157 
159  void
160  setUp();
161 
162  protected:
163  CepsSolver m_solver;
167 
172 
174 
177 };
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
std::shared_ptr< DistributedVector > DVecPtr
Short typedef for pointer on distributed vector.
Base class for other (big) CEPS classes. All classes can get a pointer to this base class and also co...
Definition: CepsObject.hpp:40
Reads and stores simulation configuration.
Linear system Ax=b to be solved.
CepsReal m_relativeTolerance
Stopping criterion for iterative methods (rel diff between iterations)
CepsUInt m_avIterNb
average number of iterations
DVecPtr m_rhsVector
Right Hand Side (B)
DMatPtr m_lhsMatrix
Left Hand Side (A)
CepsUInt m_nSolv
number of calls of the solvers
DMatPtr m_precondMatrix
Preconditioning matrix.
CepsReal m_divergenceTolerance
Stopping criterion for iterative methods (too large diff between iterations)
CepsBool m_isSetUp
Is the solver ready to solve ?
CepsUInt m_maxIterations
Maximum of iterations for iterative methods.
CepsReal m_absoluteTolerance
Stopping criterion for iterative methods (abs diff between iterations)
CepsSolver m_solver
Underlying solver.
CepsUInt initialize(int argc, char *argv[])
Initializes parallel environment.