PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
linsolver.cpp
Go to the documentation of this file.
1
8// PetIBM
9#include <petibm/linsolver.h>
10#include <petibm/linsolverksp.h>
11
12#ifdef HAVE_AMGX
14#endif
15
16namespace petibm
17{
18namespace linsolver
19{
20// implement LinSolverBase::destroy
21PetscErrorCode LinSolverBase::destroy()
22{
23 PetscFunctionBeginUser;
24 name = config = type = "";
25 PetscFunctionReturn(0);
26} // destroy
27
28// implement LinSolverBase::printInfo
29PetscErrorCode LinSolverBase::printInfo() const
30{
31 PetscFunctionBeginUser;
32
33 PetscErrorCode ierr;
34
35 std::string info = "";
36 info += (std::string(80, '=') + "\n");
37 info += ("Linear Solver " + name + ":\n");
38 info += (std::string(80, '=') + "\n");
39
40 info += ("\tType: " + type + "\n\n");
41 info += ("\tConfig file: " + config + "\n\n");
42
43 ierr = PetscPrintf(PETSC_COMM_WORLD, "%s", info.c_str()); CHKERRQ(ierr);
44
45 PetscFunctionReturn(0);
46} // printInfo
47
48// implement LinSolverBase::getType
49PetscErrorCode LinSolverBase::getType(std::string &_type) const
50{
51 PetscFunctionBeginUser;
52 _type = type;
53 PetscFunctionReturn(0);
54} // getType
55
56// implement petibm::linsolver::createLinSolver
57PetscErrorCode createLinSolver(const std::string &solverName,
58 const YAML::Node &node, type::LinSolver &solver)
59{
60 PetscFunctionBeginUser;
61
62 std::string key, config, type;
63
64 key = solverName + "Solver";
65
66 // set up type
67 type = node["parameters"][key]["type"].as<std::string>("CPU");
68
69 // set up the path to config file
70 config = node["parameters"][key]["config"].as<std::string>("None");
71 if (config[0] != '/' && config != "None")
72 config = node["directory"].as<std::string>() + "/" + config;
73
74 // factory
75 if (type == "CPU")
76 solver = std::make_shared<LinSolverKSP>(solverName, config);
77 else if (type == "GPU")
78#ifdef HAVE_AMGX
79 solver = std::make_shared<LinSolverAmgX>(solverName, config);
80#else
81 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
82 "AmgX solver is used, while PetIBM is not compiled with AmgX.");
83#endif
84 else
85 SETERRQ2(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
86 "Unrecognized value \"%s\" of the type of the linear solver "
87 "\"%s\"\n",
88 type.c_str(), solverName.c_str());
89
90 PetscFunctionReturn(0);
91} // createLinSolver
92
93} // end of namespace linsolver
94} // end of namespace petibm
PetscErrorCode printInfo() const
Print information to standard output.
Definition: linsolver.cpp:29
std::string config
Path of the solver configuration file to read.
Definition: linsolver.h:132
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
std::string type
Type of the linear solver.
Definition: linsolver.h:135
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
Def. of LinSolverBase, LinSolver, and factory function.
Def. of LinSolverAmgX.
Def. of LinSolverKSP.
A toolbox for building flow solvers.
Definition: bodypack.h:52