Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLTensorOp.H
Go to the documentation of this file.
1#ifndef AMREX_ML_TENSOR_OP_H_
2#define AMREX_ML_TENSOR_OP_H_
3#include <AMReX_Config.H>
4
6#include <AMReX_Array.H>
7
8// Feature macro: when defined, MLTensorOp::setMappingFactors exists and the
9// cross-term (transpose and bulk) fluxes honour a diagonal mesh mapping.
10#define AMREX_MLTENSOROP_HAS_MAPPING_FACTORS 1
11
12namespace amrex {
13
20// Tensor solver for high Reynolds flows with small gradient in viscosity.
21// The system it solves is
22//
23// alpha a v - beta div dot tau = rhs
24//
25// where tau = eta [grad v + (grad v)^T] + (kappa-(2/3)eta) (div v) I.
26// Here eta and kappa are shear and bulk viscosity, and I is identity tensor.
27//
28// The user needs to provide `a` by `setACoeffs`, eta by `setShearViscosity`,
29// and kappa by `setBulkViscosity`. If `setBulkViscosity` is not called,
30// kappa is set to zero.
31//
32// The scalars alpha and beta can be set with `setScalars(Real, Real)`. If
33// they are not set, their default value is 1.
34
37 : public MLABecLaplacian
38{
39public:
40
42 MLTensorOp ();
48 MLTensorOp (const Vector<Geometry>& a_geom,
49 const Vector<BoxArray>& a_grids,
50 const Vector<DistributionMapping>& a_dmap,
51 const LPInfo& a_info = LPInfo(),
52 const Vector<FabFactory<FArrayBox> const*>& a_factory = {});
56 MLTensorOp (const Vector<Geometry>& a_geom,
57 const Vector<BoxArray>& a_grids,
58 const Vector<DistributionMapping>& a_dmap,
59 const Vector<iMultiFab const*>& a_overset_mask, // 1: unknown, 0: known
60 const LPInfo& a_info = LPInfo(),
61 const Vector<FabFactory<FArrayBox> const*>& a_factory = {});
62 ~MLTensorOp () override = default;
63
64 MLTensorOp (const MLTensorOp&) = delete;
65 MLTensorOp (MLTensorOp&&) = delete;
66 MLTensorOp& operator= (const MLTensorOp&) = delete;
68
78 void define (const Vector<Geometry>& a_geom,
79 const Vector<BoxArray>& a_grids,
80 const Vector<DistributionMapping>& a_dmap,
81 const LPInfo& a_info = LPInfo(),
82 const Vector<FabFactory<FArrayBox> const*>& a_factory = {});
83
94 void define (const Vector<Geometry>& a_geom,
95 const Vector<BoxArray>& a_grids,
96 const Vector<DistributionMapping>& a_dmap,
97 const Vector<iMultiFab const*>& a_overset_mask,
98 const LPInfo& a_info = LPInfo(),
99 const Vector<FabFactory<FArrayBox> const*>& a_factory = {});
100
107 void setShearViscosity (int amrlev, const Array<MultiFab const*,AMREX_SPACEDIM>& eta);
114 void setShearViscosity (int amrlev, Real eta);
121 void setBulkViscosity (int amrlev, const Array<MultiFab const*,AMREX_SPACEDIM>& kappa);
128 void setBulkViscosity (int amrlev, Real kappa);
129
130 [[nodiscard]] int getNComp () const final { return AMREX_SPACEDIM; }
131
132 [[nodiscard]] bool isCrossStencil () const final { return false; }
133 [[nodiscard]] bool isTensorOp () const final { return true; }
134
141 [[nodiscard]] bool needsUpdate () const final {
142 return (m_needs_update || MLABecLaplacian::needsUpdate());
143 }
150 void update () final {
151 amrex::Abort("MLTensorOp: update TODO");
152 }
153
155 void prepareForSolve () final;
156 [[nodiscard]] bool isSingular (int /*armlev*/) const final { return false; }
157 [[nodiscard]] bool isBottomSingular () const final { return false; }
158
170 void apply (int amrlev, int mglev, MultiFab& out, MultiFab& in, BCMode bc_mode,
171 StateMode s_mode, const MLMGBndry* bndry=nullptr) const final;
172
181 void compFlux (int amrlev, const Array<MultiFab*,AMREX_SPACEDIM>& fluxes,
182 MultiFab& sol, Location loc) const override;
183
196 void compVelGrad (int amrlev, const Array<MultiFab*,AMREX_SPACEDIM>& fluxes,
197 MultiFab& sol, Location loc) const;
198
199 void setBCoeffs (int amrlev, const Array<MultiFab const*,AMREX_SPACEDIM>& beta) = delete;
200
223 void setMappingFactors (int amrlev, const Array<MultiFab const*,AMREX_SPACEDIM>& fac);
224
226 [[nodiscard]] bool isMapped () const noexcept { return m_use_mapped; }
227
230 [[nodiscard]] bool hasMappingFactors (int amrlev) const noexcept {
231 return m_use_mapped && amrlev < static_cast<int>(m_mapfac.size())
232 && m_mapfac[amrlev][0].isDefined();
233 }
234
235protected:
236
237 bool m_has_kappa = false;
239
240 bool m_use_mapped = false;
241 Vector<Array<MultiFab,AMREX_SPACEDIM> > m_mapfac; // per AMR level, MG level 0
242
243private:
244
245 bool m_needs_update = true;
246
247public: // for cuda
248
259 void applyBCTensor (int amrlev, int mglev, MultiFab& vel,
260 BCMode bc_mode, StateMode s_mode, const MLMGBndry* bndry
261 ) const;
262};
263
264}
265
266#endif
Fixed-size array types for use on GPU and CPU.
GpuArray< Real, 3 > beta
Definition AMReX_MLEBNodeFDLaplacian.cpp:1099
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
Definition AMReX_MLABecLaplacian.H:22
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLABecLaplacian.H:29
bool needsUpdate() const override
True if coefficients need to be averaged down before the next apply().
Definition AMReX_MLABecLaplacian.H:170
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLCellLinOp.H:38
typename MLLinOpT< MF >::StateMode StateMode
Definition AMReX_MLCellLinOp.H:39
Boundary helper for MLMG that manages coarse/fine and physical BC metadata.
Definition AMReX_MLMGBndry.H:20
Tensor solver with shear/bulk viscosity inputs for high-Reynolds flows.
Definition AMReX_MLTensorOp.H:38
bool isMapped() const noexcept
True if setMappingFactors has been called for any AMR level.
Definition AMReX_MLTensorOp.H:226
bool isTensorOp() const final
Whether this operator is a tensor solve.
Definition AMReX_MLTensorOp.H:133
void update() final
Not implemented for tensor operators.
Definition AMReX_MLTensorOp.H:150
bool m_has_kappa
Definition AMReX_MLTensorOp.H:237
MLTensorOp(MLTensorOp &&)=delete
void setMappingFactors(int amrlev, const Array< MultiFab const *, 3 > &fac)
Declare a diagonal mesh mapping and supply its face factors.
Definition AMReX_MLTensorOp.cpp:132
bool isBottomSingular() const final
Convenience helper for the coarsest level singularity flag.
Definition AMReX_MLTensorOp.H:157
bool hasMappingFactors(int amrlev) const noexcept
Definition AMReX_MLTensorOp.H:230
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FArrayBox > const * > &a_factory={})
Define the hierarchy for standard tensor solves.
Definition AMReX_MLTensorOp.cpp:39
bool m_use_mapped
Definition AMReX_MLTensorOp.H:240
MLTensorOp(const MLTensorOp &)=delete
void setShearViscosity(int amrlev, const Array< MultiFab const *, 3 > &eta)
Provide shear viscosity eta as face-centered MultiFabs.
Definition AMReX_MLTensorOp.cpp:100
~MLTensorOp() override=default
Vector< Array< MultiFab, 3 > > m_mapfac
Definition AMReX_MLTensorOp.H:241
void setBCoeffs(int amrlev, const Array< MultiFab const *, 3 > &beta)=delete
bool needsUpdate() const final
True if coefficients have changed since the last prepareForSolve().
Definition AMReX_MLTensorOp.H:141
bool isSingular(int) const final
Query whether AMR level amrlev is singular (null space present).
Definition AMReX_MLTensorOp.H:156
void prepareForSolve() final
Assemble viscosity data/BC caches before solving.
Definition AMReX_MLTensorOp.cpp:149
Vector< Vector< Array< MultiFab, 3 > > > m_kappa
Definition AMReX_MLTensorOp.H:238
void compVelGrad(int amrlev, const Array< MultiFab *, 3 > &fluxes, MultiFab &sol, Location loc) const
Compute velocity gradients (symmetrized) at the requested location.
Definition AMReX_MLTensorOp_grad.cpp:135
void setBulkViscosity(int amrlev, const Array< MultiFab const *, 3 > &kappa)
Provide bulk viscosity kappa as face-centered MultiFabs.
Definition AMReX_MLTensorOp.cpp:112
bool isCrossStencil() const final
Whether the stencil is the cross shape.
Definition AMReX_MLTensorOp.H:132
MLTensorOp & operator=(const MLTensorOp &)=delete
void apply(int amrlev, int mglev, MultiFab &out, MultiFab &in, BCMode bc_mode, StateMode s_mode, const MLMGBndry *bndry=nullptr) const final
Apply the tensor operator on AMR level amrlev / MG level mglev.
Definition AMReX_MLTensorOp.cpp:231
int getNComp() const final
Return number of components.
Definition AMReX_MLTensorOp.H:130
MLTensorOp()
Construct an empty tensor operator; call define() before solving.
Definition AMReX_MLTensorOp.cpp:12
void compFlux(int amrlev, const Array< MultiFab *, 3 > &fluxes, MultiFab &sol, Location loc) const override
Assemble viscous fluxes on AMR level amrlev.
Definition AMReX_MLTensorOp_grad.cpp:7
void applyBCTensor(int amrlev, int mglev, MultiFab &vel, BCMode bc_mode, StateMode s_mode, const MLMGBndry *bndry) const
Apply tensor-specific boundary conditions on (amrlev,mglev).
Definition AMReX_MLTensorOp.cpp:369
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
std::array< T, N > Array
Definition AMReX_Array.H:31
Definition AMReX_Amr.cpp:50
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:242
Configuration knobs for multilevel linear operators (grid agglomeration, metrics, etc....
Definition AMReX_MLLinOp.H:51