Peano
Loading...
Searching...
No Matches
LinearEquationSystem.h
Go to the documentation of this file.
1// This file is part of the Peano's PETSc extension. For conditions of
2// distribution and use, please see the copyright notice at
3// www.peano-framework.org
4#pragma once
5
6#include "tarch/logging/Log.h"
10#include "tarch/la/Matrix.h"
11
12#include <petscmat.h>
13#include <petscsys.h>
14#include <petscksp.h>
15
16#include <numeric> //for std iota
17
18
19namespace petsc {
21}
22
47 public:
53
62 void printMatrix(std::string filename);
63
67 void printRhs();
72 void printRhs(std::string filename);
73
77 void printX();
82 void printX(std::string filename);
83
88 int getDoFs() const;
89
95 void init( int dofs );
96
102 double get(int i) const;
103
110 void insert(int row, int col, double val);
111
118 void increment(int row, int col, double val);
119
125 void insert(int row, double val);
126
132 void increment(int row, double val);
133
134
144 template <int rows, int columns>
145 void insertMatrix(int row, int col, const tarch::la::Matrix<rows,columns,double>& stencil){
146 // get a array of row indices we want to insert into, beginning
147 // with the argument "row"
148 int rowIndices[ stencil.rows() ];
149 std::iota(rowIndices, rowIndices + stencil.rows(), row);
150
151 // same for columns
152 int colIndices[ stencil.cols() ];
153 std::iota(colIndices, colIndices + stencil.cols(), col);
154
155 // send to petsc
156 MatSetValues( _A, stencil.rows(), rowIndices, stencil.cols(), colIndices, stencil.data(), ADD_VALUES );
157
158 }
159
166 enum class PreconditionerType: int
167 {
168 None, LU, JACOBI
169 };
170
177 enum class KSPSolverType: int
178 {
179 GMRES, CG
180 };
181
186
196
197
200
201 private:
203
204 int _dofs;
205
206 Mat _A;
207 Vec _x;
208 Vec _b;
209
210};
Class to capture all of the PETSc objects needed by some experiements.
PreconditionerType
Enum class to allow us to customise different different petsc preconditioner types.
void printMatrix(std::string filename)
Overload to print the matrix to file.
LinearEquationSystem()
Trivial constructor.
static tarch::logging::Log _log
KSPSolverType
Enum class to allow us to customise different different petsc solver types.
void printRhs()
Overload to print the rhs to terminal.
void printX()
Overload to print the solution to terminal.
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 init(int dofs)
method to intialise the matrix and two vectors each we _dofs entries
void insert(int row, double val)
Overload to insert val into the rhs vector, at given row position.
PCType getPreconditionerTypeFromEnum(PreconditionerType type)
double get(int i) const
Getter method to inspect the value of the solution vector at a given index.
int getDoFs() const
Returns number of DoFs in the system.
void insert(int row, int col, double val)
Overload to insert val into the matrix, at given row, column position.
KSPType getKSPSolverTypeFromEnum(KSPSolverType type)
void increment(int row, double val)
Overload to increment existing val in the rhs vector, at given row position.
void printX(std::string filename)
Overload to print the solution to terminal.
void increment(int row, int col, double val)
Overload to increment existing val in the matrix, at given row, column position.
void cleanUpPetscObjects()
Method to clean up PETSc objects.
void solve(PreconditionerType pctype=PreconditionerType::None, KSPSolverType ksptype=KSPSolverType::GMRES)
Method to hand over to petsc and solve.
void printMatrix()
Overload to print the matrix to terminal.
void printRhs(std::string filename)
Overload to print the rhs to file.
Static (i.e.
Definition Matrix.h:42
Log Device.
Definition Log.h:517