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
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]] HYPRE_IJMatrix A() { return m_mat; }
73
75 [[nodiscard]] HYPRE_IJVector b() { return m_rhs; }
76
78 [[nodiscard]] HYPRE_IJVector x() { return m_sln; }
79
81 [[nodiscard]] HypreIntType getNumIters() const { return m_num_iterations; }
82
84 [[nodiscard]] HypreRealType getFinalResidualNorm() const { return m_final_res_norm; }
85
86 [[nodiscard]] bool adjustSingularMatrix() const { return m_adjust_singular_matrix; }
88 [[nodiscard]] HypreIntType ilower() const { return m_ilower; }
89
90private:
91 void init_preconditioner(const std::string& prefix, const std::string& name);
92 void init_solver(const std::string& prefix, const std::string& name);
93
95 void run_hypre_setup();
96 void run_hypre_solve();
97
98 // Preconditioners
99 void boomeramg_precond_configure(const std::string& prefix);
100 void euclid_precond_configure(const std::string& prefix);
101 void ilu_precond_configure(const std::string& prefix);
102
103 // Solvers
104 void boomeramg_solver_configure(const std::string& prefix);
105 void gmres_solver_configure(const std::string& prefix);
106 void cogmres_solver_configure(const std::string& prefix);
107 void lgmres_solver_configure(const std::string& prefix);
108 void flex_gmres_solver_configure(const std::string& prefix);
109 void bicgstab_solver_configure(const std::string& prefix);
110 void pcg_solver_configure(const std::string& prefix);
111 void hybrid_solver_configure(const std::string& prefix);
112
113
114 MPI_Comm m_comm{MPI_COMM_NULL};
115
116 HYPRE_IJMatrix m_mat{nullptr};
117 HYPRE_IJVector m_rhs{nullptr};
118 HYPRE_IJVector m_sln{nullptr};
119
120 HYPRE_ParCSRMatrix m_parA{nullptr};
121 HYPRE_ParVector m_parRhs{nullptr};
122 HYPRE_ParVector m_parSln{nullptr};
123
124 HYPRE_Solver m_solver{nullptr};
125 HYPRE_Solver m_precond{nullptr};
126
127 HypreIntType (*m_solverDestroyPtr)(HYPRE_Solver){nullptr};
128 HypreIntType (*m_solverSetupPtr)(
129 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
130 HypreIntType (*m_solverSolvePtr)(
131 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
132 HypreIntType (*m_solverPrecondPtr)(
133 HYPRE_Solver,
134 HYPRE_PtrToParSolverFcn,
135 HYPRE_PtrToParSolverFcn,
136 HYPRE_Solver){nullptr};
137
138 HypreIntType (*m_precondDestroyPtr)(HYPRE_Solver){nullptr};
139 HypreIntType (*m_precondSetupPtr)(
140 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
141 HypreIntType (*m_precondSolvePtr)(
142 HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
143
144 HypreIntType (*m_solverSetTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
145 HypreIntType (*m_solverSetAbsTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
146 HypreIntType (*m_solverSetMaxIterPtr)(HYPRE_Solver, HypreIntType){nullptr};
147 HypreIntType (*m_solverNumItersPtr)(HYPRE_Solver, HypreIntType*){nullptr};
148 HypreIntType (*m_solverFinalResidualNormPtr)(HYPRE_Solver, amrex::Real*){nullptr};
149
150 HypreIntType m_ilower{0};
151 HypreIntType m_iupper{0};
152
153 HypreRealType m_final_res_norm;
154 HypreIntType m_num_iterations;
155
156 std::string m_solver_name{"BoomerAMG"};
157 std::string m_preconditioner_name{"none"};
158 std::string m_file_prefix{"IJ"};
160 std::string m_euclid_file;
161
163 int m_verbose{0};
164
165 unsigned int m_write_counter{0};
166
168 bool m_has_preconditioner{false};
169
171 bool m_need_setup{true};
172
175 bool m_recompute_preconditioner{true};
176
178 bool m_adjust_singular_matrix{false};
179
181 bool m_write_files{false};
182
184 bool m_overwrite_files{true};
185};
186
187} // namespace amrex
188
189#endif /* AMREX_HYPREIJIFACE_H */
Convenience interface for configuring and invoking HYPRE IJ solvers.
Definition AMReX_HypreIJIface.H:25
void parse_inputs(const std::string &prefix="hypre")
Parse runtime options (solver, preconditioner, tolerances).
Definition AMReX_HypreIJIface.cpp:248
~HypreIJIface()
Definition AMReX_HypreIJIface.cpp:157
HYPRE_IJMatrix A()
IJ matrix instance.
Definition AMReX_HypreIJIface.H:72
HYPRE_IJVector b()
Right hand side IJ vector instance.
Definition AMReX_HypreIJIface.H:75
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:81
HYPRE_Int HypreIntType
Definition AMReX_HypreIJIface.H:27
HypreIJIface(HypreIJIface &&)=delete
HypreIJIface & operator=(HypreIJIface const &)=delete
bool adjustSingularMatrix() const
Definition AMReX_HypreIJIface.H:86
HypreRealType getFinalResidualNorm() const
Final residual norm after a linear solve.
Definition AMReX_HypreIJIface.H:84
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:88
HYPRE_IJVector x()
Solution IJ vector instance.
Definition AMReX_HypreIJIface.H:78
void solve(HypreRealType rel_tol, HypreRealType abs_tol, HypreIntType max_iter)
Solve the linear system using the configured solver/preconditioner.
Definition AMReX_HypreIJIface.cpp:197
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