AMReX-Hydro
AMReX-based hydro routines for low Mach number flows
Loading...
Searching...
No Matches
hydro_NodalProjector.H
Go to the documentation of this file.
1#ifndef NODAL_PROJECTION_H
2#define NODAL_PROJECTION_H
3#include <AMReX_Config.H>
4
5#include <AMReX.H>
6#include <AMReX_Vector.H>
7#include <AMReX_MultiFab.H>
9#include <AMReX_MLMG.H>
10#ifdef AMREX_USE_HYPRE
12#endif
13#include <utility>
14
15//
16//
17// *************************** DEFAULT MODE ***************************
18//
19// Solves
20//
21// div(sigma*grad(phi)) = div(vel) + S_nd + S_cc
22//
23// and performs the projection
24//
25// vel = vel - sigma * grad(phi)
26//
27// vel, sigma, and S_cc are cell-centered variables, while
28// phi and S_nd are nodal-centered variables.
29//
30// *************************** CUSTOM MODE ***************************
31//
32// Solves
33//
34// div(sigma*grad(phi)) = rhs
35//
36// and performs the projection
37//
38// vel = vel - (sigma/alpha) * grad(phi)
39//
40// alpha is a cell-centered variable, while rhs is nodal-centered.
41//
42// In this mode, the user provides rhs and alpha
43//
44// By default alpha is assumed to be 1. Use setAlpha to change the default.
45//
46// Use setCustomRHS to provide a custom RHS, else "div(vel) + S_nd + S_cc"
47// is used.
48//
49// Example: rhs = div(alpha*vel)
50//
51namespace Hydro {
52
54{
55
56public:
57
61 const amrex::LPInfo& a_lpinfo,
64
70
72 amrex::Real a_const_sigma,
74 const amrex::LPInfo& a_lpinfo,
77
78 void project ( amrex::Real a_rtol = amrex::Real(1.0e-11), amrex::Real a_atol = amrex::Real(1.0e-14) );
79 void project ( const amrex::Vector<amrex::MultiFab*>& a_phi, amrex::Real a_rtol = amrex::Real(1.0e-11),
80 amrex::Real a_atol = amrex::Real(1.0e-14) );
81
85 amrex::Vector< const amrex::MultiFab* > getPhiConst () const {return GetVecOfConstPtrs(m_phi);}
87 amrex::Vector< const amrex::MultiFab* > getRHSConst () const {return GetVecOfConstPtrs(m_rhs);}
88
90
93 const amrex::Vector<amrex::MultiFab*>& a_S_cc = {},
94 const amrex::Vector<const amrex::MultiFab*>& a_S_nd = {} );
95
96 //! Set alpha for the custom mode. alpha is stored as raw pointers, so it
97 //! must outlive the projector, and it persists until it is reset. Pass an
98 //! empty vector to go back to the default alpha = 1.
100 {
101 if (a_alpha.empty()) { m_alpha.clear(); m_has_alpha = false; return; }
102 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(a_alpha.size() == m_phi.size(),
103 "NodalProjector::setAlpha: alpha must have one entry per level");
104 for (auto const* a : a_alpha) {
106 "NodalProjector::setAlpha: alpha entries must not be null");
107 }
108 m_alpha=a_alpha;m_has_alpha=true;
109 }
110 //! Set a custom RHS. It persists until it is reset; pass an empty vector to
111 //! go back to computing "div(vel) + S_nd + S_cc" in project().
113
114
115 // Methods to set verbosity
116 void setVerbose (int v) noexcept
117 { m_verbose = v;
118 if (m_mlmg) { m_mlmg->setVerbose(m_verbose); } }
119
120
121 // Set domain BC
122 void setDomainBC ( std::array<amrex::LinOpBCType,AMREX_SPACEDIM> a_bc_lo,
123 std::array<amrex::LinOpBCType,AMREX_SPACEDIM> a_bc_hi );
124
125 //! Throw std::runtime_error instead of aborting when the solve fails
126 void setThrowException (bool t)
127 { m_throw_exception = t;
128 if (m_mlmg) { m_mlmg->setThrowException(t); } }
129
130 //! Iterations of the last projection (MLMG, or hypre with use_mlhypre)
131 [[nodiscard]] int getNumIters () const noexcept { return m_num_iters; }
132
133 // Methods to get underlying objects
134 // Use these to modify properties of MLMG and linear operator
135 amrex::MLNodeLaplacian& getLinOp () noexcept { return *m_linop; }
136 amrex::MLMG& getMLMG () noexcept { return *m_mlmg; }
137
138 // Methods to set MF for sync
139 void setSyncResidualFine (amrex::MultiFab* a_sync_resid_fine) {m_sync_resid_fine=a_sync_resid_fine;}
140 void setSyncResidualCrse (amrex::MultiFab* a_sync_resid_crse, amrex::IntVect a_ref_ratio, amrex::BoxArray a_fine_grids )
141 {m_sync_resid_crse=a_sync_resid_crse; m_ref_ratio=a_ref_ratio; m_fine_grids=std::move(a_fine_grids);}
142
143private:
144
145 void setOptions ();
147 void computeSyncResidual ();
149 void define (amrex::LPInfo const& a_lpinfo);
150
151 bool m_has_rhs = false;
152 bool m_has_alpha = false;
153 bool m_need_bcs = true;
154
155 // Verbosity
156 int m_verbose = 0;
157
158 // amrex::Geometry
160
161 // EB factory if any
162#if defined(AMREX_USE_EB) && !defined(HYDRO_NO_EB)
164#endif
165
166 // Cell-centered data
173
174 // Node-centered data
178
179 // Linear operator
180 std::unique_ptr< amrex::MLNodeLaplacian > m_linop;
181
182 // Solver
183 std::unique_ptr< amrex::MLMG > m_mlmg;
184 int m_maxiter = 100;
185 int m_num_iters = 0;
186
187 bool m_throw_exception = false;
188
189 // Composite (all AMR levels) solve with hypre instead of MLMG
190 bool m_use_mlhypre = false;
191 std::string m_mlhypre_prefix = "hypre_mlnodelap";
192#ifdef AMREX_USE_HYPRE
193 std::unique_ptr< amrex::HypreMLNodeLap > m_hypremlnodelap;
194#endif
195
196 // Boundary conditions
197 std::array<amrex::LinOpBCType,AMREX_SPACEDIM> m_bc_lo;
198 std::array<amrex::LinOpBCType,AMREX_SPACEDIM> m_bc_hi;
199
200 // Members for synchronization
202 amrex::BoxArray m_fine_grids; // Grid at crse level + 1
205
206 void printInfo ();
207};
208
209}
210
211#endif
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
amrex::Vector< const amrex::MultiFab * > m_sigma
Definition hydro_NodalProjector.H:171
std::unique_ptr< amrex::MLMG > m_mlmg
Definition hydro_NodalProjector.H:183
void printInfo()
Definition hydro_NodalProjector.cpp:517
int m_num_iters
Definition hydro_NodalProjector.H:185
void setCustomRHS(amrex::Vector< const amrex::MultiFab * > a_rhs)
Definition hydro_NodalProjector.cpp:293
int m_verbose
Definition hydro_NodalProjector.H:156
void setCoarseBoundaryVelocityForSync()
Definition hydro_NodalProjector.cpp:569
amrex::Vector< const amrex::MultiFab * > m_alpha
Definition hydro_NodalProjector.H:169
NodalProjector(amrex::Vector< amrex::MultiFab * > a_vel, amrex::Vector< const amrex::MultiFab * > a_sigma, amrex::Vector< amrex::Geometry > a_geom, const amrex::LPInfo &a_lpinfo, amrex::Vector< amrex::MultiFab * > a_S_cc={}, amrex::Vector< const amrex::MultiFab * > a_S_nd={})
Definition hydro_NodalProjector.cpp:17
amrex::Vector< amrex::MultiFab * > getGradPhi()
Definition hydro_NodalProjector.H:82
amrex::Vector< amrex::MultiFab > m_phi
Definition hydro_NodalProjector.H:175
void setSyncResidualFine(amrex::MultiFab *a_sync_resid_fine)
Definition hydro_NodalProjector.H:139
amrex::BoxArray m_fine_grids
Definition hydro_NodalProjector.H:202
void define(amrex::LPInfo const &a_lpinfo)
Definition hydro_NodalProjector.cpp:69
amrex::Vector< amrex::MultiFab * > calcGradPhi(const amrex::Vector< amrex::MultiFab * > &a_phi)
Definition hydro_NodalProjector.cpp:446
amrex::Real m_const_sigma
Definition hydro_NodalProjector.H:172
std::array< amrex::LinOpBCType, AMREX_SPACEDIM > m_bc_hi
Definition hydro_NodalProjector.H:198
void computeSyncResidual()
Definition hydro_NodalProjector.cpp:530
amrex::MultiFab * m_sync_resid_fine
Definition hydro_NodalProjector.H:204
int getNumIters() const noexcept
Iterations of the last projection (MLMG, or hypre with use_mlhypre).
Definition hydro_NodalProjector.H:131
amrex::Vector< amrex::MultiFab > m_rhs
Definition hydro_NodalProjector.H:176
amrex::Vector< amrex::MultiFab * > getRHS()
Definition hydro_NodalProjector.H:86
bool m_need_bcs
Definition hydro_NodalProjector.H:153
amrex::Vector< amrex::EBFArrayBoxFactory const * > m_ebfactory
Definition hydro_NodalProjector.H:163
void computeRHS(const amrex::Vector< amrex::MultiFab * > &a_rhs, const amrex::Vector< amrex::MultiFab * > &a_vel, const amrex::Vector< amrex::MultiFab * > &a_S_cc={}, const amrex::Vector< const amrex::MultiFab * > &a_S_nd={})
Definition hydro_NodalProjector.cpp:483
amrex::Vector< const amrex::MultiFab * > m_S_nd
Definition hydro_NodalProjector.H:177
void setVerbose(int v) noexcept
Definition hydro_NodalProjector.H:116
bool m_throw_exception
Definition hydro_NodalProjector.H:187
bool m_has_alpha
Definition hydro_NodalProjector.H:152
int m_maxiter
Definition hydro_NodalProjector.H:184
bool m_has_rhs
Definition hydro_NodalProjector.H:151
void setAlpha(const amrex::Vector< const amrex::MultiFab * > &a_alpha)
Definition hydro_NodalProjector.H:99
void setThrowException(bool t)
Throw std::runtime_error instead of aborting when the solve fails.
Definition hydro_NodalProjector.H:126
amrex::Vector< const amrex::MultiFab * > getRHSConst() const
Definition hydro_NodalProjector.H:87
amrex::Vector< amrex::Geometry > m_geom
Definition hydro_NodalProjector.H:159
bool m_use_mlhypre
Definition hydro_NodalProjector.H:190
amrex::IntVect m_ref_ratio
Definition hydro_NodalProjector.H:201
amrex::Vector< amrex::MultiFab > m_fluxes
Definition hydro_NodalProjector.H:168
void setSyncResidualCrse(amrex::MultiFab *a_sync_resid_crse, amrex::IntVect a_ref_ratio, amrex::BoxArray a_fine_grids)
Definition hydro_NodalProjector.H:140
amrex::Vector< amrex::MultiFab * > m_S_cc
Definition hydro_NodalProjector.H:170
amrex::Vector< const amrex::MultiFab * > getGradPhiConst() const
Definition hydro_NodalProjector.H:83
amrex::MLNodeLaplacian & getLinOp() noexcept
Definition hydro_NodalProjector.H:135
std::unique_ptr< amrex::MLNodeLaplacian > m_linop
Definition hydro_NodalProjector.H:180
amrex::MLMG & getMLMG() noexcept
Definition hydro_NodalProjector.H:136
amrex::Vector< amrex::MultiFab * > m_vel
Definition hydro_NodalProjector.H:167
std::array< amrex::LinOpBCType, AMREX_SPACEDIM > m_bc_lo
Definition hydro_NodalProjector.H:197
amrex::Vector< amrex::MultiFab * > getPhi()
Definition hydro_NodalProjector.H:84
void setOptions()
Definition hydro_NodalProjector.cpp:190
std::string m_mlhypre_prefix
Definition hydro_NodalProjector.H:191
void averageDown(amrex::Vector< amrex::MultiFab * > const &a_var)
Definition hydro_NodalProjector.cpp:626
amrex::MultiFab * m_sync_resid_crse
Definition hydro_NodalProjector.H:203
amrex::Vector< const amrex::MultiFab * > getPhiConst() const
Definition hydro_NodalProjector.H:85
void setDomainBC(std::array< amrex::LinOpBCType, AMREX_SPACEDIM > a_bc_lo, std::array< amrex::LinOpBCType, AMREX_SPACEDIM > a_bc_hi)
Definition hydro_NodalProjector.cpp:283
void project(amrex::Real a_rtol=amrex::Real(1.0e-11), amrex::Real a_atol=amrex::Real(1.0e-14))
Definition hydro_NodalProjector.cpp:313
Long size() const noexcept
amrex_real Real
MLMGT< MultiFab > MLMG
Definition hydro_FFTMacProjector.cpp:6
MLNodeLaplacianT< MultiFab > MLNodeLaplacian
IntVectND< 3 > IntVect