Skip to content

Commit 9469329

Browse files
authored
MLMG interface (AMReX-Codes#2858)
These changes are made to support a generic type (i.e., amrex::Any) in MLMG. This is still work in progress. But it should not break any existing codes.
1 parent 5a3b303 commit 9469329

21 files changed

+1801
-892
lines changed

Src/Base/AMReX_Any.H

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ public:
6060
private:
6161
struct innards_base {
6262
virtual const std::type_info& Type () const = 0;
63+
virtual ~innards_base () = default;
6364
};
6465

6566
template <typename MF>
6667
struct innards : innards_base
6768
{
68-
innards(MF && mf)
69+
innards (MF && mf)
6970
: m_mf(std::forward<MF>(mf))
7071
{}
7172

73+
virtual ~innards () = default;
74+
7275
virtual const std::type_info& Type () const override {
7376
return typeid(MF);
7477
}

Src/Base/AMReX_BaseFab.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public:
260260
*/
261261
void clear () noexcept;
262262

263-
// Release ownership of memory
263+
//! Release ownership of memory
264264
std::unique_ptr<T,DataDeleter> release () noexcept;
265265

266266
//! Returns how many bytes used

Src/Base/AMReX_FabArray.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ FabArray<FAB>::SumBoundary_nowait (int scomp, int ncomp, IntVect const& src_ngho
28482848

28492849
FabArray<FAB>* tmp = new FabArray<FAB>( boxArray(), DistributionMap(), ncomp, src_nghost, MFInfo(), Factory() );
28502850
amrex::Copy(*tmp, *this, scomp, 0, ncomp, src_nghost);
2851-
this->setVal(0.0, scomp, ncomp, dst_nghost);
2851+
this->setVal(typename FAB::value_type(0), scomp, ncomp, dst_nghost);
28522852
this->ParallelCopy_nowait(*tmp,0,scomp,ncomp,src_nghost,dst_nghost,period,FabArrayBase::ADD);
28532853

28542854
// All local. Operation complete.

Src/LinearSolvers/MLMG/AMReX_MLABecLaplacian.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ MLABecLaplacian::applyMetricTermsCoeffs ()
323323
for (int alev = 0; alev < m_num_amr_levels; ++alev)
324324
{
325325
const int mglev = 0;
326-
applyMetricTerm(alev, mglev, m_a_coeffs[alev][mglev]);
326+
applyMetricTermToMF(alev, mglev, m_a_coeffs[alev][mglev]);
327327
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
328328
{
329-
applyMetricTerm(alev, mglev, m_b_coeffs[alev][mglev][idim]);
329+
applyMetricTermToMF(alev, mglev, m_b_coeffs[alev][mglev][idim]);
330330
}
331331
}
332332
#endif

Src/LinearSolvers/MLMG/AMReX_MLCGSolver.H

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public:
4040
Real eps_rel,
4141
Real eps_abs);
4242

43+
int solve (Any& solnL,
44+
const Any& rhsL,
45+
Real eps_rel,
46+
Real eps_abs);
47+
4348
void setVerbose (int _verbose) { verbose = _verbose; }
4449
int getVerbose () const { return verbose; }
4550

Src/LinearSolvers/MLMG/AMReX_MLCGSolver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ MLCGSolver::solve (MultiFab& sol,
7878
}
7979
}
8080

81+
int
82+
MLCGSolver::solve (Any& sol, const Any& rhs, Real eps_rel, Real eps_abs)
83+
{
84+
AMREX_ASSERT(sol.is<MultiFab>()); // xxxxx TODO: MLCGSolver Any
85+
return solve(sol.get<MultiFab>(), rhs.get<MultiFab>(), eps_rel, eps_abs);
86+
}
87+
8188
int
8289
MLCGSolver::solve_bicgstab (MultiFab& sol,
8390
const MultiFab& rhs,

Src/LinearSolvers/MLMG/AMReX_MLCellABecLap.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public:
5959
virtual MultiFab const* getACoeffs (int amrlev, int mglev) const = 0;
6060
virtual Array<MultiFab const*,AMREX_SPACEDIM> getBCoeffs (int amrlev, int mglev) const = 0;
6161

62-
virtual void applyInhomogNeumannTerm (int amrlev, MultiFab& rhs) const final override;
62+
virtual void applyInhomogNeumannTerm (int amrlev, Any& rhs) const final override;
6363

64-
virtual void applyOverset (int amlev, MultiFab& rhs) const override;
64+
virtual void applyOverset (int amlev, Any& rhs) const override;
6565

6666
#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
6767
virtual std::unique_ptr<Hypre> makeHypre (Hypre::Interface hypre_interface) const override;

Src/LinearSolvers/MLMG/AMReX_MLCellABecLap.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ MLCellABecLap::define (const Vector<Geometry>& a_geom,
108108
amrlev = 0;
109109
for (int mglev = 1; mglev < m_num_mg_levels[amrlev]; ++mglev) {
110110
MultiFab foo(m_grids[amrlev][mglev], m_dmap[amrlev][mglev], 1, 0, MFInfo().SetAlloc(false));
111-
if (! isMFIterSafe(*m_overset_mask[amrlev][mglev], foo)) {
111+
if (! amrex::isMFIterSafe(*m_overset_mask[amrlev][mglev], foo)) {
112112
auto osm = std::make_unique<iMultiFab>(m_grids[amrlev][mglev],
113113
m_dmap[amrlev][mglev], 1, 1);
114114
osm->ParallelCopy(*m_overset_mask[amrlev][mglev]);
@@ -193,13 +193,16 @@ MLCellABecLap::getFluxes (const Vector<Array<MultiFab*,AMREX_SPACEDIM> >& a_flux
193193
}
194194

195195
void
196-
MLCellABecLap::applyInhomogNeumannTerm (int amrlev, MultiFab& rhs) const
196+
MLCellABecLap::applyInhomogNeumannTerm (int amrlev, Any& a_rhs) const
197197
{
198198
bool has_inhomog_neumann = hasInhomogNeumannBC();
199199
bool has_robin = hasRobinBC();
200200

201201
if (!has_inhomog_neumann && !has_robin) return;
202202

203+
AMREX_ASSERT(a_rhs.is<MultiFab>());
204+
MultiFab& rhs = a_rhs.get<MultiFab>();
205+
203206
int ncomp = getNComp();
204207
const int mglev = 0;
205208

@@ -414,9 +417,11 @@ MLCellABecLap::applyInhomogNeumannTerm (int amrlev, MultiFab& rhs) const
414417
}
415418

416419
void
417-
MLCellABecLap::applyOverset (int amrlev, MultiFab& rhs) const
420+
MLCellABecLap::applyOverset (int amrlev, Any& a_rhs) const
418421
{
419422
if (m_overset_mask[amrlev][0]) {
423+
AMREX_ASSERT(a_rhs.is<MultiFab>());
424+
auto& rhs = a_rhs.get<MultiFab>();
420425
const int ncomp = getNComp();
421426
#ifdef AMREX_USE_OMP
422427
#pragma omp parallel if (Gpu::notInLaunchRegion())

Src/LinearSolvers/MLMG/AMReX_MLCellLinOp.H

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <AMReX_Config.H>
44

55
#include <AMReX_MLLinOp.H>
6+
#include <AMReX_iMultiFab.H>
67

78
namespace amrex {
89

@@ -109,6 +110,8 @@ public:
109110

110111
virtual void interpolation (int amrlev, int fmglev, MultiFab& fine, const MultiFab& crse) const override;
111112

113+
virtual void interpAssign (int amrlev, int fmglev, MultiFab& fine, MultiFab& crse) const override;
114+
112115
virtual void averageDownSolutionRHS (int camrlev, MultiFab& crse_sol, MultiFab& crse_rhs,
113116
const MultiFab& fine_sol, const MultiFab& fine_rhs) override;
114117

@@ -132,9 +135,12 @@ public:
132135
virtual void compGrad (int amrlev, const Array<MultiFab*,AMREX_SPACEDIM>& grad,
133136
MultiFab& sol, Location loc) const override;
134137

135-
virtual void applyMetricTerm (int amrlev, int mglev, MultiFab& rhs) const final override;
138+
virtual void applyMetricTerm (int amrlev, int mglev, Any& rhs) const final override;
136139
virtual void unapplyMetricTerm (int amrlev, int mglev, MultiFab& rhs) const final override;
137-
virtual void fillSolutionBC (int amrlev, MultiFab& sol, const MultiFab* crse_bcdata=nullptr) final override;
140+
virtual Vector<Real> getSolvabilityOffset (int amrlev, int mglev,
141+
Any const& rhs) const override;
142+
virtual void fixSolvabilityByOffset (int amrlev, int mglev, Any& rhs,
143+
Vector<Real> const& offset) const override;
138144

139145
virtual void prepareForSolve () override;
140146

@@ -146,6 +152,18 @@ public:
146152
const Array<FArrayBox*,AMREX_SPACEDIM>& flux,
147153
const FArrayBox& sol, Location loc, const int face_only=0) const = 0;
148154

155+
// This could be turned into template if needed.
156+
void applyMetricTermToMF (int amrlev, int mglev, MultiFab& rhs) const;
157+
158+
virtual Real AnyNormInfMask (int amrlev, Any const& a, bool local) const override;
159+
160+
virtual void AnyAvgDownResAmr (int clev, Any& cres, Any const& fres) const override;
161+
162+
virtual void AnyInterpolationAmr (int famrlev, Any& fine, const Any& crse,
163+
IntVect const& /*nghost*/) const override;
164+
165+
virtual void AnyAverageDownAndSync (Vector<Any>& sol) const override;
166+
149167
struct BCTL {
150168
BoundCond type;
151169
Real location;
@@ -210,12 +228,17 @@ protected:
210228
// boundary cell flags for covered, not_covered, outside_domain
211229
Vector<Vector<Array<MultiMask,2*AMREX_SPACEDIM> > > m_maskvals;
212230

231+
Vector<std::unique_ptr<iMultiFab> > m_norm_fine_mask;
232+
213233
mutable Vector<YAFluxRegister> m_fluxreg;
214234

215235
private:
216236

217237
void defineAuxData ();
218238
void defineBC ();
239+
240+
void computeVolInv () const;
241+
mutable Vector<Vector<Real> > m_volinv; // used by solvability fix
219242
};
220243

221244
}

0 commit comments

Comments
 (0)