Block-Structured AMR Software Framework
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 
13 namespace amrex {
14 
16 {
17 public:
18  using HypreIntType = HYPRE_Int;
19  using HypreRealType = HYPRE_Real;
20 
21  HypreIJIface(MPI_Comm comm, HypreIntType ilower, HypreIntType iupper,
22  int verbose);
23 
24  ~HypreIJIface();
25 
26  HypreIJIface (HypreIJIface const&) = delete;
27  HypreIJIface (HypreIJIface &&) = delete;
30 
31  void parse_inputs(const std::string& prefix = "hypre");
32 
33  void solve(HypreRealType rel_tol, HypreRealType abs_tol, HypreIntType max_iter);
34 
36  [[nodiscard]] HYPRE_IJMatrix A() { return m_mat; }
37 
39  [[nodiscard]] HYPRE_IJVector b() { return m_rhs; }
40 
42  [[nodiscard]] HYPRE_IJVector x() { return m_sln; }
43 
45  [[nodiscard]] HypreIntType getNumIters() const { return m_num_iterations; }
46 
48  [[nodiscard]] HypreRealType getFinalResidualNorm() const { return m_final_res_norm; }
49 
50  [[nodiscard]] bool adjustSingularMatrix() const { return m_adjust_singular_matrix; }
51 
52 private:
53  void init_preconditioner(const std::string& prefix, const std::string& name);
54  void init_solver(const std::string& prefix, const std::string& name);
55 
57  void run_hypre_setup();
58  void run_hypre_solve();
59 
60  // Preconditioners
61  void boomeramg_precond_configure(const std::string& prefix);
62  void euclid_precond_configure(const std::string& prefix);
63 
64  // Solvers
65  void boomeramg_solver_configure(const std::string& prefix);
66  void gmres_solver_configure(const std::string& prefix);
67  void cogmres_solver_configure(const std::string& prefix);
68  void lgmres_solver_configure(const std::string& prefix);
69  void flex_gmres_solver_configure(const std::string& prefix);
70  void bicgstab_solver_configure(const std::string& prefix);
71  void pcg_solver_configure(const std::string& prefix);
72  void hybrid_solver_configure(const std::string& prefix);
73 
74 
76 
77  HYPRE_IJMatrix m_mat{nullptr};
78  HYPRE_IJVector m_rhs{nullptr};
79  HYPRE_IJVector m_sln{nullptr};
80 
81  HYPRE_ParCSRMatrix m_parA{nullptr};
82  HYPRE_ParVector m_parRhs{nullptr};
83  HYPRE_ParVector m_parSln{nullptr};
84 
85  HYPRE_Solver m_solver{nullptr};
86  HYPRE_Solver m_precond{nullptr};
87 
88  HypreIntType (*m_solverDestroyPtr)(HYPRE_Solver){nullptr};
90  HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
92  HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
94  HYPRE_Solver,
95  HYPRE_PtrToParSolverFcn,
96  HYPRE_PtrToParSolverFcn,
97  HYPRE_Solver){nullptr};
98 
99  HypreIntType (*m_precondDestroyPtr)(HYPRE_Solver){nullptr};
101  HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
103  HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector){nullptr};
104 
105  HypreIntType (*m_solverSetTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
106  HypreIntType (*m_solverSetAbsTolPtr)(HYPRE_Solver, amrex::Real){nullptr};
107  HypreIntType (*m_solverSetMaxIterPtr)(HYPRE_Solver, HypreIntType){nullptr};
108  HypreIntType (*m_solverNumItersPtr)(HYPRE_Solver, HypreIntType*){nullptr};
109  HypreIntType (*m_solverFinalResidualNormPtr)(HYPRE_Solver, amrex::Real*){nullptr};
110 
113 
116 
117  std::string m_solver_name{"BoomerAMG"};
118  std::string m_preconditioner_name{"none"};
119  std::string m_file_prefix{"IJ"};
120 
122  int m_verbose{0};
123 
124  unsigned int m_write_counter{0};
125 
127  bool m_has_preconditioner{false};
128 
130  bool m_need_setup{true};
131 
134 
137 
139  bool m_write_files{false};
140 
142  bool m_overwrite_files{true};
143 };
144 
145 } // namespace amrex
146 
147 #endif /* AMREX_HYPREIJIFACE_H */
int MPI_Comm
Definition: AMReX_ccse-mpi.H:47
static constexpr int MPI_COMM_NULL
Definition: AMReX_ccse-mpi.H:55
Definition: AMReX_HypreIJIface.H:16
bool m_write_files
Flag indicating whether to dump matrix files.
Definition: AMReX_HypreIJIface.H:139
MPI_Comm m_comm
Definition: AMReX_HypreIJIface.H:75
HypreIntType(* m_solverSetupPtr)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Definition: AMReX_HypreIJIface.H:89
HypreIJIface & operator=(HypreIJIface const &)=delete
std::string m_solver_name
Definition: AMReX_HypreIJIface.H:117
void pcg_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:575
void gmres_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:433
void bicgstab_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:548
void boomeramg_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:376
void parse_inputs(const std::string &prefix="hypre")
Definition: AMReX_HypreIJIface.cpp:172
void lgmres_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:492
void flex_gmres_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:520
~HypreIJIface()
Definition: AMReX_HypreIJIface.cpp:81
void hybrid_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:601
HYPRE_ParVector m_parRhs
Definition: AMReX_HypreIJIface.H:82
HypreIntType(* m_precondSetupPtr)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Definition: AMReX_HypreIJIface.H:100
HYPRE_IJVector m_sln
Definition: AMReX_HypreIJIface.H:79
HYPRE_IJMatrix A()
IJ matrix instance.
Definition: AMReX_HypreIJIface.H:36
int m_verbose
Verbosity of the HYPRE solvers.
Definition: AMReX_HypreIJIface.H:122
HYPRE_IJVector b()
Right hand side IJ vector instance.
Definition: AMReX_HypreIJIface.H:39
HypreIntType(* m_solverFinalResidualNormPtr)(HYPRE_Solver, amrex::Real *)
Definition: AMReX_HypreIJIface.H:109
HypreIJIface(HypreIJIface const &)=delete
HypreRealType m_final_res_norm
Definition: AMReX_HypreIJIface.H:114
std::string m_file_prefix
Definition: AMReX_HypreIJIface.H:119
HypreIntType(* m_precondSolvePtr)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Definition: AMReX_HypreIJIface.H:102
HYPRE_Solver m_solver
Definition: AMReX_HypreIJIface.H:85
HypreIntType getNumIters() const
Number of iterations taken by the solver to reach the desired tolerance.
Definition: AMReX_HypreIJIface.H:45
void boomeramg_precond_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:235
HypreIntType(* m_solverSetMaxIterPtr)(HYPRE_Solver, HypreIntType)
Definition: AMReX_HypreIJIface.H:107
void cogmres_solver_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:464
HypreIntType(* m_solverSolvePtr)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Definition: AMReX_HypreIJIface.H:91
bool m_overwrite_files
Flag indicating whether the files are overwritten on subsequent writes.
Definition: AMReX_HypreIJIface.H:142
HYPRE_Int HypreIntType
Definition: AMReX_HypreIJIface.H:18
std::string m_preconditioner_name
Definition: AMReX_HypreIJIface.H:118
HypreIJIface(HypreIJIface &&)=delete
HYPRE_ParCSRMatrix m_parA
Definition: AMReX_HypreIJIface.H:81
HypreIntType m_ilower
Definition: AMReX_HypreIJIface.H:111
HypreIntType m_iupper
Definition: AMReX_HypreIJIface.H:112
bool adjustSingularMatrix() const
Definition: AMReX_HypreIJIface.H:50
HypreRealType getFinalResidualNorm() const
Final residual norm after a linear solve.
Definition: AMReX_HypreIJIface.H:48
void run_hypre_setup()
run_setup
Definition: AMReX_HypreIJIface.cpp:101
unsigned int m_write_counter
Definition: AMReX_HypreIJIface.H:124
HYPRE_Real HypreRealType
Definition: AMReX_HypreIJIface.H:19
HYPRE_IJVector m_rhs
Definition: AMReX_HypreIJIface.H:78
HypreIntType(* m_solverDestroyPtr)(HYPRE_Solver)
Definition: AMReX_HypreIJIface.H:88
HYPRE_ParVector m_parSln
Definition: AMReX_HypreIJIface.H:83
HYPRE_IJMatrix m_mat
Definition: AMReX_HypreIJIface.H:77
HypreIntType m_num_iterations
Definition: AMReX_HypreIJIface.H:115
HypreIntType(* m_solverSetAbsTolPtr)(HYPRE_Solver, amrex::Real)
Definition: AMReX_HypreIJIface.H:106
HYPRE_Solver m_precond
Definition: AMReX_HypreIJIface.H:86
bool m_recompute_preconditioner
Flag indicating whether user has requested recomputation of preconditioner.
Definition: AMReX_HypreIJIface.H:133
bool m_has_preconditioner
Flag indicating whether a preconditioner has been set.
Definition: AMReX_HypreIJIface.H:127
void init_solver(const std::string &prefix, const std::string &name)
Definition: AMReX_HypreIJIface.cpp:211
HypreIntType(* m_precondDestroyPtr)(HYPRE_Solver)
Definition: AMReX_HypreIJIface.H:99
HYPRE_IJVector x()
Solution IJ vector instance.
Definition: AMReX_HypreIJIface.H:42
void solve(HypreRealType rel_tol, HypreRealType abs_tol, HypreIntType max_iter)
Definition: AMReX_HypreIJIface.cpp:121
bool m_need_setup
Flag indicating whether the solver/preconditioner has been setup.
Definition: AMReX_HypreIJIface.H:130
void run_hypre_solve()
Definition: AMReX_HypreIJIface.cpp:115
bool m_adjust_singular_matrix
Should singular matrix be adjusted to fix solution on a node/cell?
Definition: AMReX_HypreIJIface.H:136
HypreIntType(* m_solverPrecondPtr)(HYPRE_Solver, HYPRE_PtrToParSolverFcn, HYPRE_PtrToParSolverFcn, HYPRE_Solver)
Definition: AMReX_HypreIJIface.H:93
void euclid_precond_configure(const std::string &prefix)
Definition: AMReX_HypreIJIface.cpp:356
HypreIntType(* m_solverSetTolPtr)(HYPRE_Solver, amrex::Real)
Definition: AMReX_HypreIJIface.H:105
HypreIJIface(MPI_Comm comm, HypreIntType ilower, HypreIntType iupper, int verbose)
Definition: AMReX_HypreIJIface.cpp:63
HypreIntType(* m_solverNumItersPtr)(HYPRE_Solver, HypreIntType *)
Definition: AMReX_HypreIJIface.H:108
void init_preconditioner(const std::string &prefix, const std::string &name)
Definition: AMReX_HypreIJIface.cpp:199
Definition: AMReX_Amr.cpp:49
int verbose
Definition: AMReX_DistributionMapping.cpp:36