|
Peano
|
Class to capture all of the PETSc objects needed by some experiements. More...
#include <LinearEquationSystem.h>

Public Types | |
| enum class | PreconditionerType : int { None , LU , JACOBI } |
| Enum class to allow us to customise different different petsc preconditioner types. More... | |
| enum class | KSPSolverType : int { GMRES , CG } |
| Enum class to allow us to customise different different petsc solver types. More... | |
Public Member Functions | |
| LinearEquationSystem () | |
| Trivial constructor. | |
| virtual | ~LinearEquationSystem () |
| void | printMatrix () |
| Overload to print the matrix to terminal. | |
| void | printMatrix (std::string filename) |
| Overload to print the matrix to file. | |
| void | printRhs () |
| Overload to print the rhs to terminal. | |
| void | printRhs (std::string filename) |
| Overload to print the rhs to file. | |
| void | printX () |
| Overload to print the solution to terminal. | |
| void | printX (std::string filename) |
| Overload to print the solution to terminal. | |
| int | getDoFs () const |
| Returns number of DoFs in the system. | |
| void | init (int dofs) |
| method to intialise the matrix and two vectors each we _dofs entries | |
| double | get (int i) const |
| Getter method to inspect the value of the solution vector at a given index. | |
| void | insert (int row, int col, double val) |
| Overload to insert val into the matrix, at given row, column position. | |
| void | increment (int row, int col, double val) |
| Overload to increment existing val in the matrix, at given row, column position. | |
| void | insert (int row, double val) |
| Overload to insert val into the rhs vector, at given row position. | |
| void | increment (int row, double val) |
| Overload to increment existing val in the rhs vector, at given row position. | |
| template<int rows, int columns> | |
| void | insertMatrix (int row, int col, const tarch::la::Matrix< rows, columns, double > &stencil) |
| Method to insert a tarch::la::Matrix into the PETSc matrix. | |
| void | solve (PreconditionerType pctype=PreconditionerType::None, KSPSolverType ksptype=KSPSolverType::GMRES) |
| Method to hand over to petsc and solve. | |
| void | cleanUpPetscObjects () |
| Method to clean up PETSc objects. | |
| PCType | getPreconditionerTypeFromEnum (PreconditionerType type) |
| KSPType | getKSPSolverTypeFromEnum (KSPSolverType type) |
Private Attributes | |
| int | _dofs |
| Mat | _A |
| Vec | _x |
| Vec | _b |
Static Private Attributes | |
| static tarch::logging::Log | _log |
Class to capture all of the PETSc objects needed by some experiements.
The default constructor will set the number of "dofs" to be -1. The initialisation of most of the PETSc objects are deferred until the true number of dofs is known, so as not to interfere with Peano's MPI handing.
This class supports creating a (square) matrix (member variable _A), a RHS vector (_b), and a member variable _x, which will have the solution written into it.
The intended workflow is as follows:
At present, we only support a handful of preconditioners and solvers, each of which can yield quite different results. More info on which preconditioners are supported can be found here and solvers can be found here (see table 6).
Definition at line 46 of file LinearEquationSystem.h.
|
strong |
Enum class to allow us to customise different different petsc solver types.
See documentation of this class for more info on what solvers are supported within petsc.
| Enumerator | |
|---|---|
| GMRES | |
| CG | |
Definition at line 177 of file LinearEquationSystem.h.
|
strong |
Enum class to allow us to customise different different petsc preconditioner types.
See documentation of this class for more info on what preconditioners are supported within petsc.
| Enumerator | |
|---|---|
| None | |
| LU | |
| JACOBI | |
Definition at line 166 of file LinearEquationSystem.h.
| petsc::LinearEquationSystem::LinearEquationSystem | ( | ) |
Trivial constructor.
Sets the dofs to be -1. Modify this in init()
|
virtual |
| void petsc::LinearEquationSystem::cleanUpPetscObjects | ( | ) |
Method to clean up PETSc objects.
Call this in some late stage during the main function. We would ideally put these in the destructor of this class, but the destructor is typically called after Peano has already cleaned up its MPI routines. This causes a (trivial) MPI error at the very end of execution. For now, we put this stuff here so as not to cause any issues.
| double petsc::LinearEquationSystem::get | ( | int | i | ) | const |
Getter method to inspect the value of the solution vector at a given index.
Only call after solve() has completed.
| int | i |
| int petsc::LinearEquationSystem::getDoFs | ( | ) | const |
Returns number of DoFs in the system.
Equivalent to number of rows in the matrix, and number of entries in the solution/rhs vector
| KSPType petsc::LinearEquationSystem::getKSPSolverTypeFromEnum | ( | KSPSolverType | type | ) |
| PCType petsc::LinearEquationSystem::getPreconditionerTypeFromEnum | ( | PreconditionerType | type | ) |
| void petsc::LinearEquationSystem::increment | ( | int | row, |
| double | val | ||
| ) |
Overload to increment existing val in the rhs vector, at given row position.
| int | row - row index of where we insert |
| double | val - value to insert |
| void petsc::LinearEquationSystem::increment | ( | int | row, |
| int | col, | ||
| double | val | ||
| ) |
Overload to increment existing val in the matrix, at given row, column position.
| int | row - row index of where we insert |
| int | col - col index of where we insert |
| double | val - value to insert |
| void petsc::LinearEquationSystem::init | ( | int | dofs | ) |
method to intialise the matrix and two vectors each we _dofs entries
| int | dofs |
| void petsc::LinearEquationSystem::insert | ( | int | row, |
| double | val | ||
| ) |
Overload to insert val into the rhs vector, at given row position.
| int | row - row index of where we insert |
| double | val - value to insert |
| void petsc::LinearEquationSystem::insert | ( | int | row, |
| int | col, | ||
| double | val | ||
| ) |
Overload to insert val into the matrix, at given row, column position.
| int | row - row index of where we insert |
| int | col - col index of where we insert |
| double | val - value to insert |
| void petsc::LinearEquationSystem::insertMatrix | ( | int | row, |
| int | col, | ||
| const tarch::la::Matrix< rows, columns, double > & | stencil | ||
| ) |
Method to insert a tarch::la::Matrix into the PETSc matrix.
The (0,0) entry of the supplied matrix will be placed at (row, col) in the PETSc matrix. We put the implementation in the header so that the templates work.
| int | row - starting row where we wish to insert |
| int | col - starting col where we wish to insert |
| const | tarch::la::Matrix<rows,columns,double>& stencil |
Definition at line 145 of file LinearEquationSystem.h.
References _A.
| void petsc::LinearEquationSystem::printMatrix | ( | ) |
Overload to print the matrix to terminal.
| void petsc::LinearEquationSystem::printMatrix | ( | std::string | filename | ) |
Overload to print the matrix to file.
| std::string | filename |
| void petsc::LinearEquationSystem::printRhs | ( | ) |
Overload to print the rhs to terminal.
| void petsc::LinearEquationSystem::printRhs | ( | std::string | filename | ) |
Overload to print the rhs to file.
| std::string | filename |
| void petsc::LinearEquationSystem::printX | ( | ) |
Overload to print the solution to terminal.
| void petsc::LinearEquationSystem::printX | ( | std::string | filename | ) |
Overload to print the solution to terminal.
| std::string | filename |
| void petsc::LinearEquationSystem::solve | ( | PreconditionerType | pctype = PreconditionerType::None, |
| KSPSolverType | ksptype = KSPSolverType::GMRES |
||
| ) |
Method to hand over to petsc and solve.
|
private |
Definition at line 206 of file LinearEquationSystem.h.
Referenced by insertMatrix().
|
private |
Definition at line 208 of file LinearEquationSystem.h.
|
private |
Definition at line 204 of file LinearEquationSystem.h.
|
staticprivate |
Definition at line 202 of file LinearEquationSystem.h.
|
private |
Definition at line 207 of file LinearEquationSystem.h.