Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_HypreIJIface.H
Go to the documentation of this file.
1#ifndef AMREX_HYPREIJIFACE_H
2#define AMREX_HYPREIJIFACE_H
3#include <AMReX_Config.H>
4
5#include <AMReX_MultiFab.H>
6
7#include <HYPRE.h>
8#include <HYPRE_parcsr_ls.h>
9#include <HYPRE_parcsr_mv.h>
10
11#include <memory>
12
18
19namespace amrex {
20
25{
26public:
27 using HypreIntType = HYPRE_Int;
28 using HypreRealType = HYPRE_Real;
29
39 int verbose);
40
42
43 HypreIJIface (HypreIJIface const&) = delete;
47
53 void parse_inputs(const std::string& prefix = "hypre");
54
62 void solve(HypreRealType rel_tol, HypreRealType abs_tol, HypreIntType max_iter);
63
65 void setNeedSetup () noexcept { m_need_setup = true; }
66
69 void setRecomputePreconditioner (bool b) noexcept { m_recompute_preconditioner = b; }
70
73 void setThrowException (bool t) noexcept { m_throw_exception = t; }
74
76 [[nodiscard]] HYPRE_IJMatrix A() { return m_mat; }
77
79 [[nodiscard]] HYPRE_IJVector b() { return m_rhs; }
80
82 [[nodiscard]] HYPRE_IJVector x() { return m_sln; }
83
85 [[nodiscard]] HypreIntType getNumIters() const { return m_num_iterations; }
86
88 [[nodiscard]] HypreRealType getFinalResidualNorm() const { return m_final_res_norm; }
89
90 [[nodiscard]] bool adjustSingularMatrix() const { return m_adjust_singular_matrix; }
92 [[nodiscard]] HypreIntType ilower() const { return m_ilower; }
93
94private:
95 void init_preconditioner(const std::string& prefix, const std::string& name);
96 void init_solver(const std::string& prefix, const std::string& name);
97
99 void run_hypre_setup();
100 void run_hypre_solve();
102 void report_failure (const std::string& msg) const;
103
104 // Preconditioners
105 void boomeramg_precond_configure(const std::string& prefix);
106 void euclid_precond_configure(const std::string& prefix);
107 void ilu_precond_configure(const std::string& prefix);
108
109 // Solvers
110 void boomeramg_solver_configure(const std::string& prefix);
111 void gmres_solver_configure(const std::string& prefix);
112 void cogmres_solver_configure(const std::string& prefix);
113 void lgmres_solver_configure(const std::string& prefix);
114 void flex_gmres_solver_configure(const std::string& prefix);
115 void bicgstab_solver_configure(const std::string& prefix);
116 void pcg_solver_configure(const std::string& prefix);
117 void hybrid_solver_configure(const std::string& prefix);
118
119
120 MPI_Comm m_comm{MPI_COMM_NULL};
121
122 HYPRE_IJMatrix m_mat{nullptr};
123 HYPRE_IJVector m_rhs{nullptr};
124 HYPRE_IJVector m_sln{nullptr};
125
126 HYPRE_ParCSRMatrix m_parA{nullptr};
127 HYPRE_ParVector m_parRhs{nullptr};
128 HYPRE_ParVector m_parSln{nullptr};
129
130 HYPRE_Solver m_solver{nullptr};
131 HYPRE_Solver m_precond{nullptr};
132
133 HypreIntType (*m_solverDestroyPtr)(HYPRE_Solver){nullptr};
134 HypreIntType (*m_solverSetupPtr)(
135 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
136 HypreIntType (*m_solverSolvePtr)(
137 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
138 HypreIntType (*m_solverPrecondPtr)(
139 HYPRE_Solver,
140 HYPRE_PtrToParSolverFcn,
141 HYPRE_PtrToParSolverFcn,
142 HYPRE_Solver){nullptr};
143
144 HypreIntType (*m_precondDestroyPtr)(HYPRE_Solver){nullptr};
145 HypreIntType (*m_precondSetupPtr)(
146 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
147 HypreIntType (*m_precondSolvePtr)(
148 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
149
150 HypreIntType (*m_solverSetTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
151 HypreIntType (*m_solverSetAbsTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
152 HypreIntType (*m_solverSetMaxIterPtr)(HYPRE_Solver, HypreIntType){nullptr};
153 HypreIntType (*m_solverNumItersPtr)(HYPRE_Solver, HypreIntType*){nullptr};
154 HypreIntType (*m_solverFinalResidualNormPtr)(HYPRE_Solver, amrex::Real*){nullptr};
155
156 HypreIntType m_ilower{0};
157 HypreIntType m_iupper{0};
158
159 HypreRealType m_final_res_norm;
160 HypreIntType m_num_iterations;
161
162 std::string m_solver_name{"BoomerAMG"};
163 std::string m_preconditioner_name{"none"};
164 std::string m_file_prefix{"IJ"};
166 std::string m_euclid_file;
167
169 int m_verbose{0};
170
171 unsigned int m_write_counter{0};
172
174 bool m_has_preconditioner{false};
175
177 bool m_need_setup{true};
178
181 bool m_recompute_preconditioner{true};
182
184 bool m_adjust_singular_matrix{false};
185
187 bool m_abort_on_hypre_error{true};
188
190 bool m_throw_exception{false};
191
193 bool m_write_files{false};
194
196 bool m_overwrite_files{true};
197};
198
201std::string hypreErrorMessage (const std::string& where);
202
203} // namespace amrex
204
205#endif /* AMREX_HYPREIJIFACE_H */
void parse_inputs(const std::string &prefix="hypre")
Parse runtime options (solver, preconditioner, tolerances).
Definition AMReX_HypreIJIface.cpp:310
~HypreIJIface()
Definition AMReX_HypreIJIface.cpp:195
HYPRE_IJMatrix A()
IJ matrix instance.
Definition AMReX_HypreIJIface.H:76
HYPRE_IJVector b()
Right hand side IJ vector instance.
Definition AMReX_HypreIJIface.H:79
HypreIJIface(HypreIJIface const &)=delete
void setRecomputePreconditioner(bool b) noexcept
Definition AMReX_HypreIJIface.H:69
HypreIntType getNumIters() const
Number of iterations taken by the solver to reach the desired tolerance.
Definition AMReX_HypreIJIface.H:85
HYPRE_Int HypreIntType
Definition AMReX_HypreIJIface.H:27
HypreIJIface(HypreIJIface &&)=delete
HypreIJIface & operator=(HypreIJIface const &)=delete
bool adjustSingularMatrix() const
Definition AMReX_HypreIJIface.H:90
HypreRealType getFinalResidualNorm() const
Final residual norm after a linear solve.
Definition AMReX_HypreIJIface.H:88
HYPRE_Real HypreRealType
Definition AMReX_HypreIJIface.H:28
void setNeedSetup() noexcept
Call after changing the matrix so the next solve redoes the setup.
Definition AMReX_HypreIJIface.H:65
HypreIntType ilower() const
Lowest global row id owned by this rank.
Definition AMReX_HypreIJIface.H:92
HYPRE_IJVector x()
Solution IJ vector instance.
Definition AMReX_HypreIJIface.H:82
void setThrowException(bool t) noexcept
Definition AMReX_HypreIJIface.H:73
void solve(HypreRealType rel_tol, HypreRealType abs_tol, HypreIntType max_iter)
Solve the linear system using the configured solver/preconditioner.
Definition AMReX_HypreIJIface.cpp:250
HypreIJIface(MPI_Comm comm, HypreIntType ilower, HypreIntType iupper, int verbose)
Construct an IJ interface spanning rows [ilower, iupper].
Definition AMReX_HypreIJIface.cpp:177
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
static constexpr int MPI_COMM_NULL
Definition AMReX_ccse-mpi.H:59
Definition AMReX_Amr.cpp:50
std::string hypreErrorMessage(const std::string &where)
Definition AMReX_HypreIJIface.cpp:158