AMReX-Hydro
AMReX-based hydro routines for low Mach number flows
Loading...
Searching...
No Matches
hydro_MacProjector.H
Go to the documentation of this file.
1#ifndef AMREX_MAC_PROJECTOR_H_
2#define AMREX_MAC_PROJECTOR_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_MLMG.H>
6#include <AMReX_MLPoisson.H>
8
9#if defined(AMREX_USE_EB) && !defined(HYDRO_NO_EB)
10#include <AMReX_MLEBABecLap.H>
11#endif
12
13#ifdef AMREX_USE_HYPRE
15#endif
16
17namespace Hydro {
18
20{
21public:
24#if !defined(AMREX_USE_EB) || defined(HYDRO_NO_EB)
25 amrex::MLMG::Location a_umac_loc = amrex::MLMG::Location::FaceCenter,
26 amrex::MLMG::Location a_beta_loc = amrex::MLMG::Location::FaceCenter,
27 amrex::MLMG::Location a_phi_loc = amrex::MLMG::Location::CellCenter,
28 amrex::MLMG::Location a_divu_loc = amrex::MLMG::Location::CellCenter
29#else
30 amrex::MLMG::Location a_umac_loc,
31 amrex::MLMG::Location a_beta_loc,
32 amrex::MLMG::Location a_phi_loc,
33 amrex::MLMG::Location a_divu_loc = amrex::MLMG::Location::CellCenter
34#endif
35 );
36
37 //
38 // Constructors
39 //
41 amrex::MLMG::Location a_umac_loc,
43 amrex::MLMG::Location a_beta_loc,
44 amrex::MLMG::Location a_phi_loc,
46 const amrex::LPInfo& a_lpinfo,
48 amrex::MLMG::Location a_divu_loc,
49 const amrex::Vector<amrex::iMultiFab const*>& a_overset_mask = {});
50
52 amrex::MLMG::Location a_umac_loc,
54 amrex::MLMG::Location a_beta_loc,
55 amrex::MLMG::Location a_phi_loc,
57 const amrex::LPInfo& a_lpinfo,
59 : MacProjector(a_umac, a_umac_loc, a_beta, a_beta_loc, a_phi_loc,
60 a_geom, a_lpinfo, a_divu, amrex::MLMG::Location::CellCenter) {}
61
62#if !defined(AMREX_USE_EB) || defined(HYDRO_NO_EB)
66 const amrex::LPInfo& a_lpinfo,
68 : MacProjector(a_umac, amrex::MLMG::Location::FaceCenter,
69 a_beta, amrex::MLMG::Location::FaceCenter, amrex::MLMG::Location::CellCenter,
70 a_geom, a_lpinfo, a_divu, amrex::MLMG::Location::CellCenter) {}
71
73 const amrex::Vector<amrex::Array<amrex::MultiFab const*,AMREX_SPACEDIM> >& a_beta,
74 const amrex::Vector<amrex::Geometry>& a_geom,
75 const amrex::Vector<amrex::MultiFab const*>& a_divu = {})
76 : MacProjector(a_umac, amrex::MLMG::Location::FaceCenter,
77 a_beta, amrex::MLMG::Location::FaceCenter, amrex::MLMG::Location::CellCenter,
78 a_geom, amrex::LPInfo(), a_divu, amrex::MLMG::Location::CellCenter) {}
79
81 amrex::Real a_const_beta,
82 const amrex::Vector<amrex::Geometry>& a_geom,
83 const amrex::LPInfo& a_lpinfo,
84 const amrex::Vector<amrex::iMultiFab const*>& a_overset_mask = {},
85 const amrex::Vector<amrex::MultiFab const*>& a_divu = {});
86#endif
87
88 /** Initialize the underlying linear operator and MLMG instances
89 */
90 void initProjector (
91 amrex::LPInfo a_lpinfo,
92 const amrex::Vector<amrex::Array<amrex::MultiFab const*,AMREX_SPACEDIM> >& a_beta,
93 const amrex::Vector<amrex::iMultiFab const*>& a_overset_mask = {});
94
95 //! Update Bcoeffs for the linear operator
97 //! Update Bcoeff and if Robin BC also reset scalars in order to reuse the linear operator
99
100#if !defined(AMREX_USE_EB) || defined(HYDRO_NO_EB)
101 void initProjector (amrex::Vector<amrex::BoxArray> const& a_grids,
102 amrex::Vector<amrex::DistributionMapping> const& a_dmap,
103 amrex::LPInfo a_lpinfo, amrex::Real a_const_beta,
104 const amrex::Vector<amrex::iMultiFab const*>& a_overset_mask = {});
105
106 void updateBeta (amrex::Real a_const_beta);
107#endif
108
109 //! Set Umac before calling the projection step
110 void setUMAC(const amrex::Vector<amrex::Array<amrex::MultiFab*, AMREX_SPACEDIM> >&);
111
112 //! Set div(U)
113 //!
114 //! The source term S is copied into internal storage and persists until it
115 //! is overwritten by another call. Passing an empty vector, or a vector
116 //! whose entry for a level is a nullptr, resets S to zero on the levels not
117 //! supplied. This matters when one MacProjector object is reused across
118 //! time steps.
119 void setDivU(const amrex::Vector<amrex::MultiFab const*>&);
120
121#if defined(AMREX_USE_EB) && !defined(HYDRO_NO_EB)
122 void setEBInflowVelocity (int amrlev, const amrex::MultiFab& eb_vel);
123#endif
124
125 //
126 // Methods to set BCs and coarse/fine values
127 //
128 // These methods are wrappers of the linop methods of the same name
129 // However, use of these is preferred to make sure operations
130 // are performed in the correct order
131 //
134
135 void setLevelBC (int amrlev, const amrex::MultiFab* levelbcdata,
136 const amrex::MultiFab* robin_a = nullptr,
137 const amrex::MultiFab* robin_b = nullptr,
138 const amrex::MultiFab* robin_f = nullptr);
139
140 void setCoarseFineBC (const amrex::MultiFab* crse, int crse_ratio)
142 "MacProjector::setCoarseFineBC: initProjector must be called before calling this method");
143 m_linop->setCoarseFineBC(crse, crse_ratio);}
144
145 //
146 // Methods to perform projection
147 //
148 void project (const amrex::Vector<amrex::MultiFab*>& phi_in, amrex::Real reltol, amrex::Real atol);
149 void project (amrex::Real reltol, amrex::Real atol);
150 void project_doit (amrex::Real reltol, amrex::Real atol);
151
152 //
153 // Get Fluxes. DO NOT USE LinOp to get fluxes!!!
154 //
157
158 //
159 // Setters and getters
160 //
161 void setVerbose (int v) noexcept
162 { m_verbose = v;
163 // m_mlmg does not exist yet if the geometry-only constructor was used
164 // and initProjector has not been called. The value set here is passed
165 // on to MLMG by setOptions when the projector is initialized.
166 if (m_mlmg) { m_mlmg->setVerbose(m_verbose); } }
167
168 //! Throw std::runtime_error instead of aborting when the solve fails
169 void setThrowException (bool t)
170 { m_throw_exception = t;
171 if (m_mlmg) { m_mlmg->setThrowException(t); }
172#ifdef AMREX_USE_HYPRE
173 if (m_hypremlabeclap) { m_hypremlabeclap->setThrowException(t); }
174#endif
175 }
176
177 //! Iterations of the last projection: MLMG's, or with use_mlhypre
178 //! hypre's (HypreMLABecLap's IJ mode only)
179 [[nodiscard]] int getNumIters () const noexcept { return m_num_iters; }
180
181 // Methods to get underlying objects
182 // Use these to modify properties of MLMG and linear operator
185 "MacProjector::getLinOp: initProjector must be called before calling this method");
186 return *m_linop; }
187 amrex::MLMG& getMLMG () noexcept
189 "MacProjector::getMLMG: initProjector must be called before calling this method");
190 return *m_mlmg; }
191
192 [[nodiscard]] bool needInitialization() const noexcept { return m_needs_init; }
193
194 // Methods to get phi and rhs for debugging
195 [[nodiscard]] const amrex::Vector<amrex::MultiFab>& getPhi() const noexcept { return m_phi; }
196 [[nodiscard]] const amrex::Vector<amrex::MultiFab>& getRHS() const noexcept { return m_rhs; }
197private:
198 void setOptions ();
199 void queryMLHypre ();
200
201 void averageDownVelocity ();
202
203 std::unique_ptr<amrex::MLPoisson> m_poisson;
204 std::unique_ptr<amrex::MLABecLaplacian> m_abeclap;
205#if defined(AMREX_USE_EB) && !defined(HYDRO_NO_EB)
206 std::unique_ptr<amrex::MLEBABecLap> m_eb_abeclap;
209#endif
211
213
214 std::unique_ptr<amrex::MLMG> m_mlmg;
215
221
223
224 int m_verbose = 0;
225 int m_maxiter = 200;
226 int m_num_iters = 0;
227 bool m_throw_exception = false;
228
229 // Opt-in GMRES (right-preconditioned by MLMG V-cycles) for the projection solve.
230 // mac_proj.use_gmres = 1 : always solve with GMRES+MLMG
231 // mac_proj.gmres_fallback = 1 : solve with MLMG as usual; if MLMG fails to
232 // converge, finish the solve with GMRES+MLMG
233 // (warm-started from the partial MLMG solution)
234 // instead of aborting
235 // mac_proj.gmres_maxiter : GMRES iteration cap (default 200)
236 int m_use_gmres = 0;
239
242 bool m_has_robin = false;
243
246
247 // Location of umac -- face center vs face centroid
249
251
253
254 // Location of divu (RHS -- optional) -- cell center vs cell centroid.
255 //
256 // NOTE: this flag is currently not acted upon. The divergence that S is
257 // combined with is computed by EB_computeDivergence, which returns the
258 // cut-cell volume average, i.e. the centroid value to O(h^2). S is
259 // therefore always interpreted as the cut-cell average (centroid) value,
260 // whatever a_divu_loc says. In non-EB builds all locations coincide.
262
263 bool m_needs_init = true;
264
265 bool m_use_mlhypre = false;
266#ifdef AMREX_USE_HYPRE
267 std::unique_ptr<amrex::HypreMLABecLap> m_hypremlabeclap;
268 std::string m_mlhypre_prefix = "hypre_mlabeclap";
269 // Keep the object and its solver setup when the coefficients change
270 bool m_mlhypre_reuse_setup = false;
271 bool m_hypre_needs_setup = false;
272#endif
273};
274
275}
276
277#endif
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition hydro_MacProjector.H:20
void setVerbose(int v) noexcept
Definition hydro_MacProjector.H:161
amrex::MLMG::Location m_divu_loc
Definition hydro_MacProjector.H:261
void setOptions()
Definition hydro_MacProjector.cpp:612
int m_maxiter
Definition hydro_MacProjector.H:225
void project(const amrex::Vector< amrex::MultiFab * > &phi_in, amrex::Real reltol, amrex::Real atol)
Definition hydro_MacProjector.cpp:336
void setLevelBC(int amrlev, const amrex::MultiFab *levelbcdata, const amrex::MultiFab *robin_a=nullptr, const amrex::MultiFab *robin_b=nullptr, const amrex::MultiFab *robin_f=nullptr)
Definition hydro_MacProjector.cpp:306
int getNumIters() const noexcept
Definition hydro_MacProjector.H:179
const amrex::Vector< amrex::MultiFab > & getRHS() const noexcept
Definition hydro_MacProjector.H:196
void updateBeta(const amrex::Vector< amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > > &)
Update Bcoeffs for the linear operator.
Definition hydro_MacProjector.cpp:190
std::unique_ptr< amrex::MLMG > m_mlmg
Definition hydro_MacProjector.H:214
bool m_has_robin
Definition hydro_MacProjector.H:242
bool m_use_mlhypre
Definition hydro_MacProjector.H:265
amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > m_umac
Definition hydro_MacProjector.H:216
void project_doit(amrex::Real reltol, amrex::Real atol)
Definition hydro_MacProjector.cpp:351
amrex::Vector< amrex::MultiFab > m_phi
Definition hydro_MacProjector.H:218
std::unique_ptr< amrex::MLABecLaplacian > m_abeclap
Definition hydro_MacProjector.H:204
amrex::MLLinOp * m_linop
Definition hydro_MacProjector.H:210
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_eb_vel
Definition hydro_MacProjector.H:208
void updateCoeffs(const amrex::Vector< amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > > &)
Update Bcoeff and if Robin BC also reset scalars in order to reuse the linear operator.
Definition hydro_MacProjector.cpp:208
amrex::Vector< amrex::MultiFab > m_divu
Definition hydro_MacProjector.H:219
int m_gmres_fallback
Definition hydro_MacProjector.H:237
bool m_needs_domain_bcs
Definition hydro_MacProjector.H:240
MacProjector(const amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > &a_umac, amrex::MLMG::Location a_umac_loc, const amrex::Vector< amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > > &a_beta, amrex::MLMG::Location a_beta_loc, amrex::MLMG::Location a_phi_loc, const amrex::Vector< amrex::Geometry > &a_geom, const amrex::LPInfo &a_lpinfo, const amrex::Vector< amrex::MultiFab const * > &a_divu, amrex::MLMG::Location a_divu_loc, const amrex::Vector< amrex::iMultiFab const * > &a_overset_mask={})
void setThrowException(bool t)
Throw std::runtime_error instead of aborting when the solve fails.
Definition hydro_MacProjector.H:169
void setDomainBC(const amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > &lobc, const amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > &hibc)
Definition hydro_MacProjector.cpp:289
amrex::MLMG & getMLMG() noexcept
Definition hydro_MacProjector.H:187
amrex::Vector< amrex::Array< amrex::MultiFab, AMREX_SPACEDIM > > m_fluxes
Definition hydro_MacProjector.H:220
amrex::MLLinOp & getLinOp() noexcept
Definition hydro_MacProjector.H:183
void getFluxes(const amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > &a_flux, const amrex::Vector< amrex::MultiFab * > &a_sol, amrex::MLMG::Location a_loc) const
Definition hydro_MacProjector.cpp:575
std::unique_ptr< amrex::MLEBABecLap > m_eb_abeclap
Definition hydro_MacProjector.H:206
int m_use_gmres
Definition hydro_MacProjector.H:236
amrex::Vector< amrex::Geometry > m_geom
Definition hydro_MacProjector.H:222
int m_num_iters
Definition hydro_MacProjector.H:226
amrex::Vector< amrex::EBFArrayBoxFactory const * > m_eb_factory
Definition hydro_MacProjector.H:207
bool m_needs_init
Definition hydro_MacProjector.H:263
MacProjector(const amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > &a_umac, amrex::MLMG::Location a_umac_loc, const amrex::Vector< amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > > &a_beta, amrex::MLMG::Location a_beta_loc, amrex::MLMG::Location a_phi_loc, const amrex::Vector< amrex::Geometry > &a_geom, const amrex::LPInfo &a_lpinfo, const amrex::Vector< amrex::MultiFab const * > &a_divu={})
Definition hydro_MacProjector.H:51
amrex::Real m_const_beta
Definition hydro_MacProjector.H:212
amrex::MLMG::Location m_beta_loc
Definition hydro_MacProjector.H:250
bool needInitialization() const noexcept
Definition hydro_MacProjector.H:192
void averageDownVelocity()
Definition hydro_MacProjector.cpp:701
void queryMLHypre()
Definition hydro_MacProjector.cpp:169
MacProjector(const amrex::Vector< amrex::Geometry > &a_geom, amrex::MLMG::Location a_umac_loc, amrex::MLMG::Location a_beta_loc, amrex::MLMG::Location a_phi_loc, amrex::MLMG::Location a_divu_loc=amrex::MLMG::Location::CellCenter)
void setEBInflowVelocity(int amrlev, const amrex::MultiFab &eb_vel)
Definition hydro_MacProjector.cpp:830
void setCoarseFineBC(const amrex::MultiFab *crse, int crse_ratio)
Definition hydro_MacProjector.H:140
bool m_throw_exception
Definition hydro_MacProjector.H:227
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > m_hibc
Definition hydro_MacProjector.H:245
void setDivU(const amrex::Vector< amrex::MultiFab const * > &)
Definition hydro_MacProjector.cpp:253
void initProjector(amrex::LPInfo a_lpinfo, const amrex::Vector< amrex::Array< amrex::MultiFab const *, AMREX_SPACEDIM > > &a_beta, const amrex::Vector< amrex::iMultiFab const * > &a_overset_mask={})
Definition hydro_MacProjector.cpp:54
int m_gmres_maxiter
Definition hydro_MacProjector.H:238
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > m_lobc
Definition hydro_MacProjector.H:244
std::unique_ptr< amrex::MLPoisson > m_poisson
Definition hydro_MacProjector.H:203
amrex::MLMG::Location m_phi_loc
Definition hydro_MacProjector.H:252
int m_verbose
Definition hydro_MacProjector.H:224
amrex::MLMG::Location m_umac_loc
Definition hydro_MacProjector.H:248
const amrex::Vector< amrex::MultiFab > & getPhi() const noexcept
Definition hydro_MacProjector.H:195
void setUMAC(const amrex::Vector< amrex::Array< amrex::MultiFab *, AMREX_SPACEDIM > > &)
Set Umac before calling the projection step.
Definition hydro_MacProjector.cpp:247
amrex::Vector< amrex::MultiFab > m_rhs
Definition hydro_MacProjector.H:217
amrex::Vector< int > m_needs_level_bcs
Definition hydro_MacProjector.H:241
typename MLLinOpT< MF >::Location Location
amrex_real Real
std::array< T, N > Array
MLMGT< MultiFab > MLMG
MLLinOpT< MultiFab > MLLinOp
Definition hydro_FFTMacProjector.cpp:6