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
72 [[nodiscard]] bool setupPending () const noexcept
73 { return m_need_setup || m_recompute_preconditioner; }
74
77 void setThrowException (bool t) noexcept { m_throw_exception = t; }
78
80 [[nodiscard]] HYPRE_IJMatrix A() { return m_mat; }
81
83 [[nodiscard]] HYPRE_IJVector b() { return m_rhs; }
84
86 [[nodiscard]] HYPRE_IJVector x() { return m_sln; }
87
89 [[nodiscard]] HypreIntType getNumIters() const { return m_num_iterations; }
90
92 [[nodiscard]] HypreRealType getFinalResidualNorm() const { return m_final_res_norm; }
93
94 [[nodiscard]] bool adjustSingularMatrix() const { return m_adjust_singular_matrix; }
96 [[nodiscard]] HypreIntType ilower() const { return m_ilower; }
97
98private:
99 void init_preconditioner(const std::string& prefix, const std::string& name);
100 void init_solver(const std::string& prefix, const std::string& name);
101
103 void run_hypre_setup();
104 void run_hypre_solve();
106 void report_failure (const std::string& msg) const;
107
108 // Preconditioners
109 void boomeramg_precond_configure(const std::string& prefix);
110 void euclid_precond_configure(const std::string& prefix);
111 void ilu_precond_configure(const std::string& prefix);
112
113 // Solvers
114 void boomeramg_solver_configure(const std::string& prefix);
115 void gmres_solver_configure(const std::string& prefix);
116 void cogmres_solver_configure(const std::string& prefix);
117 void lgmres_solver_configure(const std::string& prefix);
118 void flex_gmres_solver_configure(const std::string& prefix);
119 void bicgstab_solver_configure(const std::string& prefix);
120 void pcg_solver_configure(const std::string& prefix);
121 void hybrid_solver_configure(const std::string& prefix);
122
123
124 MPI_Comm m_comm{MPI_COMM_NULL};
125
126 HYPRE_IJMatrix m_mat{nullptr};
127 HYPRE_IJVector m_rhs{nullptr};
128 HYPRE_IJVector m_sln{nullptr};
129
130 HYPRE_ParCSRMatrix m_parA{nullptr};
131 HYPRE_ParVector m_parRhs{nullptr};
132 HYPRE_ParVector m_parSln{nullptr};
133
134 HYPRE_Solver m_solver{nullptr};
135 HYPRE_Solver m_precond{nullptr};
136
137 HypreIntType (*m_solverDestroyPtr)(HYPRE_Solver){nullptr};
138 HypreIntType (*m_solverSetupPtr)(
139 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
140 HypreIntType (*m_solverSolvePtr)(
141 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
142 HypreIntType (*m_solverPrecondPtr)(
143 HYPRE_Solver,
144 HYPRE_PtrToParSolverFcn,
145 HYPRE_PtrToParSolverFcn,
146 HYPRE_Solver){nullptr};
147
148 HypreIntType (*m_precondDestroyPtr)(HYPRE_Solver){nullptr};
149 HypreIntType (*m_precondSetupPtr)(
150 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
151 HypreIntType (*m_precondSolvePtr)(
152 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
153
154 HypreIntType (*m_solverSetTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
155 HypreIntType (*m_solverSetAbsTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
156 HypreIntType (*m_solverSetMaxIterPtr)(HYPRE_Solver, HypreIntType){nullptr};
157 HypreIntType (*m_solverNumItersPtr)(HYPRE_Solver, HypreIntType*){nullptr};
158 HypreIntType (*m_solverFinalResidualNormPtr)(HYPRE_Solver, amrex::Real*){nullptr};
159
160 HypreIntType m_ilower{0};
161 HypreIntType m_iupper{0};
162
163 HypreRealType m_final_res_norm;
164 HypreIntType m_num_iterations;
165
166 std::string m_solver_name{"BoomerAMG"};
167 std::string m_preconditioner_name{"none"};
168 std::string m_file_prefix{"IJ"};
170 std::string m_euclid_file;
171
173 int m_verbose{0};
174
175 unsigned int m_write_counter{0};
176
178 bool m_has_preconditioner{false};
179
181 bool m_need_setup{true};
182
185 bool m_recompute_preconditioner{true};
186
188 bool m_adjust_singular_matrix{false};
189
191 bool m_abort_on_hypre_error{true};
192
194 bool m_throw_exception{false};
195
197 bool m_write_files{false};
198
200 bool m_overwrite_files{true};
201};
202
205std::string hypreErrorMessage (const std::string& where);
206
207} // namespace amrex
208
209#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
bool setupPending() const noexcept
Will the next solve do the solver/preconditioner setup?
Definition AMReX_HypreIJIface.H:72
HYPRE_IJMatrix A()
IJ matrix instance.
Definition AMReX_HypreIJIface.H:80
HYPRE_IJVector b()
Right hand side IJ vector instance.
Definition AMReX_HypreIJIface.H:83
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:89
HYPRE_Int HypreIntType
Definition AMReX_HypreIJIface.H:27
HypreIJIface(HypreIJIface &&)=delete
HypreIJIface & operator=(HypreIJIface const &)=delete
bool adjustSingularMatrix() const
Definition AMReX_HypreIJIface.H:94
HypreRealType getFinalResidualNorm() const
Final residual norm after a linear solve.
Definition AMReX_HypreIJIface.H:92
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:96
HYPRE_IJVector x()
Solution IJ vector instance.
Definition AMReX_HypreIJIface.H:86
void setThrowException(bool t) noexcept
Definition AMReX_HypreIJIface.H:77
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