PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
linsolveramgx.cpp
Go to the documentation of this file.
1
8#include <cstdio>
9#include <fstream>
10#include <iostream>
11
12// PetIBM
14
15namespace petibm
16{
17namespace linsolver
18{
19// implement LinSolverAmgX::LinSolverAmgX
20LinSolverAmgX::LinSolverAmgX(const std::string &solverName,
21 const std::string &file)
22 : LinSolverBase(solverName, file)
23{
24 init();
25} // LinSolverAmgX
26
27// implement LinSolverAmgX::~LinSolverAmgX
29{
30 PetscFunctionBeginUser;
31 PetscErrorCode ierr;
32 PetscBool finalized;
33
34 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
35 if (finalized) return;
36
37 ierr = amgx.finalize(); CHKERRV(ierr);
38} // ~LinSolverAmgX
39
40// implement LinSolverAmgX::destroy
41PetscErrorCode LinSolverAmgX::destroy()
42{
43 PetscFunctionBeginUser;
44
45 PetscErrorCode ierr;
46
47 ierr = amgx.finalize(); CHKERRQ(ierr);
48 ierr = LinSolverBase::destroy(); CHKERRQ(ierr);
49
50 PetscFunctionReturn(0);
51} // destroy
52
53// implement LinSolverAmgX::init
54PetscErrorCode LinSolverAmgX::init()
55{
56 PetscFunctionBeginUser;
57
58 PetscErrorCode ierr;
59
60 type = "NVIDIA AmgX";
61
62 // create temporary empty file if no configuration file is provided
63 if (config == "None")
64 {
65 config = "solversAmgXOptions-tmp.info";
66 std::fstream file(config.c_str(), std::ios::out);
67 }
68
69 ierr = amgx.initialize(PETSC_COMM_WORLD, "dDDI", config); CHKERRQ(ierr);
70
71 // remove temporary file if necessary
72 if (config == "solversAmgXOptions-tmp.info") std::remove(config.c_str());
73
74 PetscFunctionReturn(0);
75} // init
76
77// implement LinSolverAmgX::setMatrix
78PetscErrorCode LinSolverAmgX::setMatrix(const Mat &A)
79{
80 PetscFunctionBeginUser;
81
82 PetscErrorCode ierr;
83
84 ierr = amgx.setA(A); CHKERRQ(ierr);
85
86 PetscFunctionReturn(0);
87} // setMatrix
88
89// implement LinSolverAmgX::solve
90PetscErrorCode LinSolverAmgX::solve(Vec &x, Vec &b)
91{
92 PetscFunctionBeginUser;
93
94 PetscErrorCode ierr;
95
96 ierr = amgx.solve(x, b); CHKERRQ(ierr);
97
98 PetscFunctionReturn(0);
99} // solve
100
101// implement LinSolverAmgX::getIters
102PetscErrorCode LinSolverAmgX::getIters(PetscInt &iters)
103{
104 PetscFunctionBeginUser;
105
106 PetscErrorCode ierr;
107
108 ierr = amgx.getIters(iters); CHKERRQ(ierr);
109
110 PetscFunctionReturn(0);
111} // getIters
112
113// implement LinSolverAmgX::getResidual
114PetscErrorCode LinSolverAmgX::getResidual(PetscReal &res)
115{
116 PetscFunctionBeginUser;
117
118 PetscErrorCode ierr;
119
120 PetscInt iter;
121
122 ierr = amgx.getIters(iter); CHKERRQ(ierr);
123 ierr = amgx.getResidual(iter, res); CHKERRQ(ierr);
124
125 PetscFunctionReturn(0);
126} // getResidual
127
128} // end of namespace linsolver
129} // end of namespace petibm
virtual PetscErrorCode setMatrix(const Mat &A)
Set the coefficient matrix of the linear system.
virtual ~LinSolverAmgX()
Default destructor.
LinSolverAmgX(const std::string &solverName, const std::string &file)
Constructor.
virtual PetscErrorCode solve(Vec &x, Vec &b)
Solve the linear system.
virtual PetscErrorCode destroy()
Manually destroy the data in the current instance.
virtual PetscErrorCode init()
Private initialization function.
virtual PetscErrorCode getIters(PetscInt &iters)
Get the number of iterations of the solver.
AmgXSolver amgx
the underlying AmgX wrapper solver.
Definition: linsolveramgx.h:54
virtual PetscErrorCode getResidual(PetscReal &res)
Get the final residual of the solver.
The abstract (base) class for different iterative solvers.
Definition: linsolver.h:60
std::string config
Path of the solver configuration file to read.
Definition: linsolver.h:132
virtual PetscErrorCode destroy()
Manually destroy the data in the current instance.
Definition: linsolver.cpp:21
std::string type
Type of the linear solver.
Definition: linsolver.h:135
Def. of LinSolverAmgX.
A toolbox for building flow solvers.
Definition: bodypack.h:52