PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
linsolver.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <memory>
11#include <string>
12
13#include <petscmat.h>
14#include <petscsys.h>
15#include <petscvec.h>
16#include <yaml-cpp/yaml.h>
17
18#include <petibm/type.h>
19
41namespace petibm
42{
50namespace linsolver
51{
60{
61public:
63 LinSolverBase() = default;
64
71 LinSolverBase(const std::string &solverName, const std::string &file)
72 : name(solverName), config(file){};
73
75 virtual ~LinSolverBase() = default;
76
78 virtual PetscErrorCode destroy();
79
81 PetscErrorCode printInfo() const;
82
90 PetscErrorCode getType(std::string &_type) const;
91
97 virtual PetscErrorCode setMatrix(const Mat &A) = 0;
98
105 virtual PetscErrorCode solve(Vec &x, Vec &b) = 0;
106
112 virtual PetscErrorCode getIters(PetscInt &iters) = 0;
113
119 virtual PetscErrorCode getResidual(PetscReal &res) = 0;
120
121protected:
129 std::string name;
130
132 std::string config;
133
135 std::string type;
136
145 virtual PetscErrorCode init() = 0;
146
147}; // LinSolver
148
149} // end of namespace linsolver
150
151namespace type
152{
174typedef std::shared_ptr<linsolver::LinSolverBase> LinSolver;
175
176} // end of namespace type
177
178namespace linsolver
179{
217PetscErrorCode createLinSolver(const std::string &solverName,
218 const YAML::Node &node, type::LinSolver &solver);
219
220} // end of namespace linsolver
221
222} // end of namespace petibm
The abstract (base) class for different iterative solvers.
Definition: linsolver.h:60
virtual PetscErrorCode setMatrix(const Mat &A)=0
Set the coefficient matrix of the linear system.
PetscErrorCode printInfo() const
Print information to standard output.
Definition: linsolver.cpp:29
LinSolverBase()=default
Default constructor.
LinSolverBase(const std::string &solverName, const std::string &file)
Constructor.
Definition: linsolver.h:71
std::string config
Path of the solver configuration file to read.
Definition: linsolver.h:132
virtual ~LinSolverBase()=default
Default destructor.
std::string name
Name of the linear solver.
Definition: linsolver.h:129
PetscErrorCode getType(std::string &_type) const
Get the type of this instance.
Definition: linsolver.cpp:49
virtual PetscErrorCode destroy()
Manually destroy the data in the current instance.
Definition: linsolver.cpp:21
virtual PetscErrorCode getIters(PetscInt &iters)=0
Get the number of iterations of the solver.
std::string type
Type of the linear solver.
Definition: linsolver.h:135
virtual PetscErrorCode solve(Vec &x, Vec &b)=0
Solve the linear system.
virtual PetscErrorCode getResidual(PetscReal &res)=0
Get the final residual of the solver.
virtual PetscErrorCode init()=0
Private initialization function.
PetscErrorCode createLinSolver(const std::string &solverName, const YAML::Node &node, type::LinSolver &solver)
A factory function for creating a LinSolver.
Definition: linsolver.cpp:57
std::shared_ptr< linsolver::LinSolverBase > LinSolver
Type definition of LinSolver.
Definition: linsolver.h:174
A toolbox for building flow solvers.
Definition: bodypack.h:52
Definition of user-defined types for convenience.