chombo-discharge
Loading...
Searching...
No Matches
EBGradient Class Reference

Class for computing gradients in an EBAMR context. More...

#include <CD_EBGradient.H>

Public Types

using CellLocation = Location::Cell
 Specification of cell-center or cell-centroid type of interpolation.

Public Member Functions

 EBGradient ()=delete
 Disallowed constructor.
 EBGradient (const EBGradient &a_other)=delete
 Disallowed copy constructor.
 EBGradient (const EBLevelGrid &a_eblg, const EBLevelGrid &a_eblgFine, const EBLevelGrid &a_eblgFiCo, const bool a_hasFine, const Real a_dx, const int a_refRat, const int a_order, const int a_weighting, const IntVect a_ghostVector) noexcept
 Full constructor. Calsl the define function.
virtual ~EBGradient () noexcept
 Destructor (does nothing).
virtual void define (const EBLevelGrid &a_eblg, const EBLevelGrid &a_eblgFine, const EBLevelGrid &a_eblgFiCo, const bool a_hasFine, const Real a_dx, const int a_refRat, const int a_order, const int a_weighting, const IntVect a_ghostVector) noexcept
 Define function.
virtual void computeLevelGradient (LevelData< EBCellFAB > &a_gradient, const LevelData< EBCellFAB > &a_phi) const noexcept
 Compute gradient using data on the input level only.
virtual void computeNormalDerivative (LevelData< EBFluxFAB > &a_gradient, const LevelData< EBCellFAB > &a_phi) const noexcept
 Compute the gradient component which is normal to the face, using centered differencing.
virtual void computeAMRGradient (LevelData< EBCellFAB > &a_gradient, const LevelData< EBCellFAB > &a_phi, const LevelData< EBCellFAB > &a_phiFine) const noexcept
 Compute gradient using two-level stencils (matching at EBCF).

Protected Member Functions

virtual void defineLevelStencils () noexcept
 Define level stencils.
virtual void defineMasks (LevelData< FArrayBox > &a_coarMaskCF, LevelData< FArrayBox > &a_coarMaskInvalid) noexcept
 Make masks.
virtual void defineIteratorsEBCF (const LevelData< FArrayBox > &a_coarMaskCF, const LevelData< FArrayBox > &a_coarMaskInvalid) noexcept
 Define iterators and cells that need modified stencils.
virtual void defineStencilsEBCF (const LevelData< FArrayBox > &a_coarMaskInvalid) noexcept
 Define stencils for interpolation across the EBCF refinement boundary.
virtual void defineBuffers () noexcept
 Define buffer data.
virtual bool getFiniteDifferenceStencil (VoFStencil &a_stencil, const VolIndex &a_vof, const EBISBox &a_ebisBox, IntVectSet *a_invalidCells) const noexcept
 Get the finite difference stencil for the gradient in a cell, assuming that the data is cell-centered.
virtual bool getLeastSquaresStencil (VoFStencil &a_stencilCoar, VoFStencil &a_stencilFine, const VolIndex &a_vofCoar, const CellLocation &a_dataLocation, const EBISLayout &a_ebislCoar, const EBISLayout &a_ebislFine, const DataIndex &a_dit, const DenseIntVectSet &a_validCellsCoar, const DenseIntVectSet &a_validCellsFine, const Real &a_dxCoar, const Real &a_dxFine, const int &a_order, const int &a_weight) const noexcept
 Build a gradient stencil using least squares.
virtual bool isFiniteDifferenceStencilValid (const IntVect &a_ivCoar, const EBISBox &a_ebisBox, const FArrayBox &a_invalidRegion) const noexcept
 Check if the level finite difference stencils in a cell only reach into valid cells.
virtual void makeAggStencils () noexcept
 Turn raw stencils into optimized AggStencils.

Protected Attributes

CellLocation m_dataLocation
 How to interpret data locations.
EBLevelGrid m_eblg
 Grids.
EBLevelGrid m_eblgFine
 Fine grids.
EBLevelGrid m_eblgFiCo
 Refined coarse grids.
bool m_isDefined
 Is defined or not.
bool m_hasFine
 True if we have a finer level (m_eblgFine is defined).
bool m_hasEBCF
 True if we have EBCF crossings that require special stencils.
Real m_dx
 Resolution on this level.
Real m_dxFine
 Resolution on finer level.
int m_order
 Desired order for least squares stencils.
int m_weighting
 Weight (for least squares).
int m_refRat
 Refinement factor between fine and coarse level.
IntVect m_ghostVector
 Number of ghost cells in incoming data holders.
int m_stencilWidth
 Reach of the finite difference stencils in cut cells and next to the domain boundary.
Copier m_copier
 Pre-built copier for making copying from m_eblg to m_eblgFiCo go faster.
LayoutData< BaseIVFAB< VoFStencil > > m_levelStencils
 Stencils for boundaries and cut-cells.
LayoutData< BaseIVFAB< VoFStencil > > m_ebcfStencilsCoar
 Part of EBCF gradient stencil which reaches into the coarse level.
LayoutData< BaseIVFAB< VoFStencil > > m_ebcfStencilsFine
 Part of EBCF gradient stencil which reaches into the coarse level.
LayoutData< RefCountedPtr< AggStencil< EBCellFAB, EBCellFAB > > > m_aggLevelStencils [SpaceDim]
 AggStencils for boundaries and cut-cells. Provides faster application of m_levelStencils.
LayoutData< VoFIterator > m_levelIterator
 Iterator for boundary cells (either domain or EB).
LayoutData< VoFIterator > m_ebcfIterator
 Iterator for EBCF cells.
LayoutData< std::array< FaceIterator, SpaceDim > > m_multiCutFaceIter
 Face iterators restricted to multiply-cut faces per direction (valid box, SurroundingNoBoundary).

Static Protected Attributes

static constexpr int m_comp = 0
 Scalar component to reach into.
static constexpr int m_nComp = 1
 Number of components that are supported.

Detailed Description

Class for computing gradients in an EBAMR context.

Although computing the gradient might seem like an easy thing to do, the presence of a coarse-fine boundary together with an EB complicates both the stencil availability and the consistent handling of the gradient on the coarse level. This class introduces a two-level view of such stencil computations. This class uses regular second order finite differencing in regular regions, including those covered by a finer level. Near the EB, however, the stencil might reach into cut-cells that are covered by the finer level. The invalid data might be filled with bogus data, or at the very best coarsened from the fine level. Since there is no consistent way of doing that coarsening (both conserative and averaging make sense), this class switches to a least squares based approach for such cases. In those particular corner cases we only reach into valid regions in the domain. Because of that, the directional derivatives in those cells are in the form

 d(phi)/dx = sum(vofCoar) w(vofCoar)*phi(vofCoar) + sum(vofFine)[w(vofFine)*phi(vofFine)]

i.e., the gradient is a two-level stencil.

In cut cells and next to the domain boundary, the derivative in a direction is a centered difference if the cells on both sides are available, and otherwise a second order one-sided difference that reaches two cells away. Only if the second cell is not available does the stencil drop to a first order one-sided difference. Near the refinement boundary these stencils only use valid cells, i.e. cells that are not covered by the finer level. If that costs order, the cell gets a two-level least squares stencil instead, fitted to the valid coarse cells within the reach of the finite difference stencils and to the fine cells under the covered ones.

Note
This class requires at least one ghost cell. The second order one-sided differences require two ghost cells, both in the data and in the EBISLayout; with fewer, the one-sided differences are first order.
The second order one-sided differences are only as accurate as the data near the EB. With a first order EB boundary condition in the solver that produced the data (e.g. FieldSolverGMG with gmg_bc_order = 1), they can amplify its error; second order boundary conditions give the most accurate gradients.

Constructor & Destructor Documentation

◆ EBGradient()

EBGradient::EBGradient ( const EBLevelGrid & a_eblg,
const EBLevelGrid & a_eblgFine,
const EBLevelGrid & a_eblgFiCo,
const bool a_hasFine,
const Real a_dx,
const int a_refRat,
const int a_order,
const int a_weighting,
const IntVect a_ghostVector )
noexcept

Full constructor. Calsl the define function.

Parameters
[in]a_eblgGrids
[in]a_eblgFineFine grids
[in]a_eblgFiCoRefinement of coarse grids
[in]a_hasFineHas fine level or not
[in]a_dxResolution
[in]a_refRatRefinement ratio
[in]a_orderInterpolation order for modified gradients.
[in]a_weightingWeighting factor least squares.
[in]a_ghostVectorGhost vector

Member Function Documentation

◆ computeAMRGradient()

void EBGradient::computeAMRGradient ( LevelData< EBCellFAB > & a_gradient,
const LevelData< EBCellFAB > & a_phi,
const LevelData< EBCellFAB > & a_phiFine ) const
virtualnoexcept

Compute gradient using two-level stencils (matching at EBCF).

Parameters
[out]a_gradientGradient of input scalar
[in]a_phiInput scalar
[in]a_phiFineInput scalar on finer level.

◆ computeLevelGradient()

void EBGradient::computeLevelGradient ( LevelData< EBCellFAB > & a_gradient,
const LevelData< EBCellFAB > & a_phi ) const
virtualnoexcept

Compute gradient using data on the input level only.

Parameters
[out]a_gradientGradient of input scalar
[in]a_phiInput scalar

◆ computeNormalDerivative()

void EBGradient::computeNormalDerivative ( LevelData< EBFluxFAB > & a_gradient,
const LevelData< EBCellFAB > & a_phi ) const
virtualnoexcept

Compute the gradient component which is normal to the face, using centered differencing.

If the face is oriented along dir, this computes the dir-component of the gradient using centered differences on the face. This routine is useful after e.g. averaging a cell-centered gradient to faces (in order to shrink the stencil).

Parameters
[in,out]a_gradientGradient of input scalar
[in]a_phiInput scalar

◆ define()

void EBGradient::define ( const EBLevelGrid & a_eblg,
const EBLevelGrid & a_eblgFine,
const EBLevelGrid & a_eblgFiCo,
const bool a_hasFine,
const Real a_dx,
const int a_refRat,
const int a_order,
const int a_weighting,
const IntVect a_ghostVector )
virtualnoexcept

Define function.

Parameters
[in]a_eblgGrids
[in]a_eblgFineFine grids
[in]a_eblgFiCoRefinement of coarse grids
[in]a_hasFineHas fine level or not
[in]a_dxResolution
[in]a_refRatRefinement ratio
[in]a_orderInterpolation order for modified gradients.
[in]a_weightingWeighting factor least squares.
[in]a_ghostVectorGhost vector

◆ defineIteratorsEBCF()

void EBGradient::defineIteratorsEBCF ( const LevelData< FArrayBox > & a_coarMaskCF,
const LevelData< FArrayBox > & a_coarMaskInvalid )
protectedvirtualnoexcept

Define iterators and cells that need modified stencils.

Parameters
[in]a_coarMaskCFMask for CF region on the coarse layout.
[in]a_coarMaskInvalidMask for invalid regions on the coarse layout.

◆ defineMasks()

void EBGradient::defineMasks ( LevelData< FArrayBox > & a_coarMaskCF,
LevelData< FArrayBox > & a_coarMaskInvalid )
protectedvirtualnoexcept

Make masks.

Parameters
[out]a_coarMaskCFMask holding a value of 1 in coarse cells within m_stencilWidth cells of the refinement boundary, outside the finer level.
[out]a_coarMaskInvalidMask holding a value of 1 in coarse cells that are covered by a finer grid level. It has m_stencilWidth ghost cells.

◆ defineStencilsEBCF()

void EBGradient::defineStencilsEBCF ( const LevelData< FArrayBox > & a_coarMaskInvalid)
protectedvirtualnoexcept

Define stencils for interpolation across the EBCF refinement boundary.

Parameters
[in]a_coarMaskInvalidCoar mask invalid

◆ getFiniteDifferenceStencil()

bool EBGradient::getFiniteDifferenceStencil ( VoFStencil & a_stencil,
const VolIndex & a_vof,
const EBISBox & a_ebisBox,
IntVectSet * a_invalidCells ) const
protectedvirtualnoexcept

Get the finite difference stencil for the gradient in a cell, assuming that the data is cell-centered.

In each direction this is a centered difference if the cells on both sides are available. Otherwise it is a one-sided difference, second order if m_stencilWidth is two and the second cell is available, and first order if not. Cells in a_invalidCells are treated as unavailable.

Parameters
[out]a_stencilFinite difference stencil. Component dir holds the derivative in direction dir.
[in]a_vofGrid cell
[in]a_ebisBoxEBISBox
[in]a_invalidCellsCells that the stencil may not use. If nullptr, all cells can be used.
Returns
True if leaving out a_invalidCells did not lower the order of the derivative in any direction, and every direction has a stencil. Always true when a_invalidCells is null.

◆ getLeastSquaresStencil()

bool EBGradient::getLeastSquaresStencil ( VoFStencil & a_stencilCoar,
VoFStencil & a_stencilFine,
const VolIndex & a_vofCoar,
const CellLocation & a_dataLocation,
const EBISLayout & a_ebislCoar,
const EBISLayout & a_ebislFine,
const DataIndex & a_dit,
const DenseIntVectSet & a_validCellsCoar,
const DenseIntVectSet & a_validCellsFine,
const Real & a_dxCoar,
const Real & a_dxFine,
const int & a_order,
const int & a_weight ) const
protectedvirtualnoexcept

Build a gradient stencil using least squares.

Parameters
[out]a_stencilCoarCoarse-grid stencil
[out]a_stencilFineFine-grid stencil
[in]a_vofCoarVoF on the coarse level.
[in]a_dataLocationData location
[in]a_ebislCoarEBISLayout on the coarse level
[in]a_ebislFineEBISLayout on the fine level
[in]a_ditData index
[in]a_validCellsCoarMap of cells that are valid on the coarse domain.
[in]a_validCellsFineMap of cells that are valid on the fine domain.
[in]a_dxCoarGrid resolution on the coarse level
[in]a_dxFineGrid resolution on the fine level
[in]a_orderInterpolation order
[in]a_weightEquation weighting for least squares reconstruction.
Returns
Returns true if a stencil was found, in which case it is defined in a_stencilFine and a_stencilCoar.

◆ isFiniteDifferenceStencilValid()

bool EBGradient::isFiniteDifferenceStencilValid ( const IntVect & a_ivCoar,
const EBISBox & a_ebisBox,
const FArrayBox & a_invalidRegion ) const
protectedvirtualnoexcept

Check if the level finite difference stencils in a cell only reach into valid cells.

This will check the stencils for all vofs in a_ivCoar. Stencils in cut cells may not reach into any covered cell. Stencils in regular cells may reach into covered regular cells, whose data is the average of the finer cells, but not into covered cut cells.

Parameters
[in]a_ivCoarCoarse grid cell.
[in]a_ebisBoxEBISBox
[in]a_invalidRegionMap of cells that are covered by a finer cell.
Returns
True if finite difference stencil valid, false otherwise

Member Data Documentation

◆ m_aggLevelStencils

LayoutData<RefCountedPtr<AggStencil<EBCellFAB, EBCellFAB> > > EBGradient::m_aggLevelStencils[SpaceDim]
protected

AggStencils for boundaries and cut-cells. Provides faster application of m_levelStencils.

Note
Lives on the coarse layout and only has one component.

◆ m_ebcfIterator

LayoutData<VoFIterator> EBGradient::m_ebcfIterator
mutableprotected

Iterator for EBCF cells.

Note
Lives on the coarse layout.

◆ m_levelIterator

LayoutData<VoFIterator> EBGradient::m_levelIterator
mutableprotected

Iterator for boundary cells (either domain or EB).

Note
Lives on the coarse layout.

◆ m_levelStencils

LayoutData<BaseIVFAB<VoFStencil> > EBGradient::m_levelStencils
protected

Stencils for boundaries and cut-cells.

Note
Lives on the coarse layout.

◆ m_multiCutFaceIter

LayoutData<std::array<FaceIterator, SpaceDim> > EBGradient::m_multiCutFaceIter
mutableprotected

Face iterators restricted to multiply-cut faces per direction (valid box, SurroundingNoBoundary).

Used in computeFaceGradient as a second pass after the regular box loop to avoid double-processing singly-cut faces.

◆ m_stencilWidth

int EBGradient::m_stencilWidth
protected

Reach of the finite difference stencils in cut cells and next to the domain boundary.

Two if the data and the EBISLayout have at least two ghost cells, in which case one-sided differences are second order. Otherwise one, in which case one-sided differences are first order.


The documentation for this class was generated from the following files: