Skip to content

Commit 24f07b7

Browse files
authored
Curl Curl: Add support for variable alpha (#5276)
Add support for solving `∇ × α ∇ × E + β E = f`, where `α` can be a nodal MultiFab. Close #5241
1 parent d10a21a commit 24f07b7

12 files changed

Lines changed: 1282 additions & 54 deletions

File tree

Docs/sphinx_documentation/source/LinearSolvers.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,16 @@ discretized form of
863863

864864
.. math:: \nabla \times (\alpha \nabla \times \vec{E}) + \beta \vec{E} = \vec{f},
865865

866-
where :math:`\vec{E}` and :math:`\vec{f}` are defined on cell edges,
867-
:math:`\alpha` is a positive scalar, and :math:`\beta` is a non-negative
868-
scalar (either a constant or a field). An :cpp:`Array` of three
869-
:cpp:`MultiFab`\ s is used to store the components of :math:`\vec{E}` and
870-
:math:`\vec{f}`. It is the user's responsibility to ensure that the
871-
right-hand-side data are consistent on edges shared by multiple
872-
:cpp:`Box`\ es. If needed, you can call :cpp:`MLCurlCurl::prepareRHS` to
873-
perform this synchronization.
866+
where :math:`\vec{E}` and :math:`\vec{f}` are defined on cell edges. The
867+
coefficient :math:`\alpha` may be supplied either as a single positive
868+
scalar through :cpp:`MLCurlCurl::setScalars`, or as a nodal :cpp:`MultiFab`
869+
by calling :cpp:`MLCurlCurl::setAlpha` with one entry per AMR level. The
870+
:math:`\beta` term can be a non-negative scalar or an edge-centered field
871+
set via :cpp:`setBeta`. An :cpp:`Array` of three :cpp:`MultiFab`\ s is used
872+
to store the components of :math:`\vec{E}` and :math:`\vec{f}`. It is the
873+
user's responsibility to ensure that the right-hand-side data are consistent
874+
on edges shared by multiple :cpp:`Box`\ es. If needed, you can call
875+
:cpp:`MLCurlCurl::prepareRHS` to perform this synchronization.
874876

875877
The solver supports 1D, 2D and 3D. Note that even in the 1D and 2D cases,
876878
:math:`\vec{E}` still has three components, one for each spatial

Src/LinearSolvers/MLMG/AMReX_MLCurlCurl.H

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ namespace amrex {
1010
/**
1111
* \brief curl (alpha curl E) + beta E = rhs
1212
*
13-
* Here E is an Array of 3 MultiFabs on staggered grid, alpha is a positive
14-
* scalar, and beta is either a non-negative scalar or a MultiFab.
13+
* Here E is an Array of 3 MultiFabs on the staggered grid. The coefficient
14+
* \f$\alpha\f$ can be supplied either as a positive scalar (via setScalars)
15+
* or as a nodal MultiFab (via setAlpha), and \f$\beta\f$ can be either a
16+
* non-negative scalar or an edge-centered MultiFab (via setBeta).
1517
*
1618
* It's the caller's responsibility to make sure rhs has consistent nodal
1719
* data. If needed, one could call prepareRHS for this.
@@ -45,11 +47,21 @@ public:
4547
const LPInfo& a_info = LPInfo(),
4648
int a_coord = 0);
4749

50+
//! Set scalar coefficients. This clears any previously supplied nodal alpha
51+
//! or edge-centered beta MultiFabs, so call setAlpha/setBeta afterwards if
52+
//! you still need spatially varying coefficients.
4853
void setScalars (RT a_alpha, RT a_beta) noexcept;
4954

50-
//! This is needed only if there is variable beta coefficient.
55+
//! This is needed only if there is variable beta coefficient. Call this
56+
//! after setScalars if both APIs are used, because setScalars clears the
57+
//! cached beta MultiFabs.
5158
void setBeta (const Vector<Array<MultiFab const*,3>>& a_bcoefs);
5259

60+
//! Set variable alpha defined on nodal MultiFab. Call this after
61+
//! setScalars if both APIs are used, because setScalars clears the cached
62+
//! nodal alpha fields.
63+
void setAlpha (const Vector<MultiFab const*>& a_acoeffs);
64+
5365
//! Synchronize RHS on nodal points. If the user can guarantee it, this
5466
//! function does not need to be called.
5567
void prepareRHS (Vector<MF*> const& rhs) const;
@@ -140,6 +152,8 @@ private:
140152
void update_lusolver ();
141153

142154
void set_curvilinear_domain_bc ();
155+
void clearAlphaMultiFab ();
156+
void clearBetaMultiFab ();
143157

144158
int m_coord = 0;
145159

@@ -160,6 +174,7 @@ private:
160174
Vector<Vector<std::unique_ptr<Gpu::DeviceScalar
161175
<LUSolver<AMREX_SPACEDIM*2,RT>>>>> m_lusolver;
162176
Vector<Vector<Array<std::unique_ptr<MultiFab>,3>>> m_bcoefs;
177+
Vector<Vector<Array<std::unique_ptr<MultiFab>,3>>> m_acoefs;
163178
bool m_use_pcg = false;
164179
bool m_needs_update = true;
165180
};

0 commit comments

Comments
 (0)