Skip to content

Commit

Permalink
Comments on FAB-related classes and methods (AMReX-Codes#3636)
Browse files Browse the repository at this point in the history
New or updated comments for various FAB-related classes and methods.
Descriptions are tweaked to match standard comment conventions and make
IntelliSense happy. For example, some descriptions get moved to be just
before their respective class declarations.
  • Loading branch information
eebasso authored Nov 29, 2023
1 parent 4b64003 commit 4b8dd03
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 222 deletions.
96 changes: 48 additions & 48 deletions Src/Base/AMReX_BaseFab.H
Original file line number Diff line number Diff line change
Expand Up @@ -90,54 +90,6 @@ makeArray4 (T* p, Box const& bx, int ncomp) noexcept
return Array4<T>{p, amrex::begin(bx), amrex::end(bx), ncomp};
}

/**
* \brief A Fortran Array-like Object
* BaseFab emulates the Fortran array concept.
* Useful operations can be performed upon
* BaseFabs in C++, and they provide a convenient interface to
* Fortran when it is necessary to retreat into that language.
* BaseFab is a template class. Through use of the
* template, a BaseFab may be based upon any class. So far at least,
* most applications have been based upon simple types like integers,
* real*4s, or real*8s. Most applications do not use BaseFabs
* directly, but utilize specialized classes derived from BaseFab.
* Classes derived from BaseFab include FArrayBox, IArrayBox, TagBox,
* Mask, EBFArrayBox, EBCellFlag and CutFab.
* BaseFab objects depend on the dimensionality of space
* (indirectly through the DOMAIN Box member). It is
* typical to define the macro SPACEDIM to be 1, 2, or 3 to indicate
* the dimension of space. See the discussion of class Box for more
* information. A BaseFab contains a Box DOMAIN, which indicates the
* integer indexing space over which the array is defined. A BaseFab
* also has NVAR components. By components, we mean that for each
* point in the rectangular indexing space, there are NVAR values
* associated with that point. A Fortran array corresponding to a
* BaseFab would have (SPACEDIM+1) dimensions.
* By design, the array layout in a BaseFab mirrors that of a
* Fortran array. The first index (x direction for example) varies
* most rapidly, the next index (y direction), if any, varies next
* fastest. The component index varies last, after all the spatial
* indices.
* It is sometimes convenient to be able to treat a sub-array within an
* existing BaseFab as a BaseFab in its own right. This is often
* referred to as aliasing the BaseFab. Note that when aliasing is
* used, the BaseFabs domain will not, in general, be the same as the
* parent BaseFabs domain, nor will the number of components.
* BaseFab is a dimension dependent class, so SPACEDIM must be
* defined as either 1, 2, or 3 when compiling.
* This is NOT a polymorphic class.
* It does NOT provide a copy constructor or assignment operator.
* T MUST have a default constructor and an assignment operator.
*/

template <typename T>
typename std::enable_if<std::is_arithmetic<T>::value>::type
placementNew (T* const /*ptr*/, Long /*n*/)
Expand Down Expand Up @@ -178,6 +130,54 @@ placementDelete (T* const ptr, Long n)
});
}

/**
* \brief A FortranArrayBox(FAB)-like object
*
* BaseFab emulates the Fortran array concept.
* Useful operations can be performed upon
* BaseFabs in C++, and they provide a convenient interface to
* Fortran when it is necessary to retreat into that language.
*
* BaseFab is a template class. Through use of the
* template, a BaseFab may be based upon any class. So far at least,
* most applications have been based upon simple types like integers,
* real*4s, or real*8s. Most applications do not use BaseFabs
* directly, but utilize specialized classes derived from BaseFab.
*
* Classes derived from BaseFab include FArrayBox, IArrayBox, TagBox,
* Mask, EBFArrayBox, EBCellFlag and CutFab.
*
* BaseFab objects depend on the dimensionality of space
* (indirectly through the DOMAIN Box member). It is
* typical to define the macro SPACEDIM to be 1, 2, or 3 to indicate
* the dimension of space. See the discussion of class Box for more
* information. A BaseFab contains a Box DOMAIN, which indicates the
* integer indexing space over which the array is defined. A BaseFab
* also has NVAR components. By components, we mean that for each
* point in the rectangular indexing space, there are NVAR values
* associated with that point. A Fortran array corresponding to a
* BaseFab would have (SPACEDIM+1) dimensions.
*
* By design, the array layout in a BaseFab mirrors that of a
* Fortran array. The first index (x direction for example) varies
* most rapidly, the next index (y direction), if any, varies next
* fastest. The component index varies last, after all the spatial
* indices.
*
* It is sometimes convenient to be able to treat a sub-array within an
* existing BaseFab as a BaseFab in its own right. This is often
* referred to as aliasing the BaseFab. Note that when aliasing is
* used, the BaseFabs domain will not, in general, be the same as the
* parent BaseFabs domain, nor will the number of components.
* BaseFab is a dimension dependent class, so SPACEDIM must be
* defined as either 1, 2, or 3 when compiling.
*
* This is NOT a polymorphic class.
*
* It does NOT provide a copy constructor or assignment operator.
*
* \tparam T MUST have a default constructor and an assignment operator.
*/
template <class T>
class BaseFab
: public DataAllocator
Expand Down
12 changes: 6 additions & 6 deletions Src/Base/AMReX_BoxArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -515,16 +515,16 @@ struct BATransformer
// for backward compatibility
using BndryBATransformer = BATransformer;

/**
* \brief A collection of Boxes stored in an Array. It is a
* reference-counted concrete class, not a polymorphic one; i.e. you
* cannot use any of the List member functions with a BoxList.
*/

class MFIter;
class AmrMesh;
class FabArrayBase;

/**
* \brief A collection of Boxes stored in an Array.
*
* It is a reference-counted concrete class, not a polymorphic one; i.e. you
* cannot use any of the List member functions with a BoxList.
*/
class BoxArray
{
public:
Expand Down
2 changes: 0 additions & 2 deletions Src/Base/AMReX_FArrayBox.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class FArrayBox;
* primarily for FArrayBox implementers; i.e. user's shouldn't
* call any of the member functions in this class directly.
*/

class FABio // NOLINT(cppcoreguidelines-special-member-functions)
{
public:
Expand Down Expand Up @@ -224,7 +223,6 @@ private:
* This class does NOT provide a copy constructor or assignment operator,
* but it has a move constructor.
*/

class FArrayBox
:
public BaseFab<Real>
Expand Down
120 changes: 61 additions & 59 deletions Src/Base/AMReX_FabArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -56,64 +56,11 @@ Long nBytesOwned (T const&) noexcept { return 0; }
template <typename T>
Long nBytesOwned (BaseFab<T> const& fab) noexcept { return fab.nBytesOwned(); }

/*
A Collection of Fortran Array-like Objects
The FabArray<FAB> class implements a collection (stored as an array) of
Fortran array-like objects. The parameterized type FAB is intended to be
any class derived from BaseFab<T>. For example, FAB may be a BaseFab of
integers, so we could write:
FabArray<BaseFab<int> > int_fabs;
Then int_fabs is a FabArray that can hold a collection of BaseFab<int>
objects.
FabArray is not just a general container class for Fortran arrays. It is
intended to hold "grid" data for use in finite difference calculations in
which the data is defined on a union of (usually disjoint) rectangular
regions embedded in a uniform index space. This region, called the valid
region, is represented by a BoxArray. For the purposes of this discussion,
the Kth Box in the BoxArray represents the interior region of the Kth grid.
Since the intent is to be used with finite difference calculations a
FabArray also includes the notion of a boundary region for each grid. The
boundary region is specified by the ngrow parameter which tells the FabArray
to allocate each FAB to be ngrow cells larger in all directions than the
underlying Box. The larger region covered by the union of all the FABs is
called the region of definition. The underlying notion is that the valid
region contains the grid interior data and the region of definition includes
the interior region plus the boundary areas.
Operations are available to copy data from the valid regions into these
boundary areas where the two overlap. The number of components, that is,
the number of values that can be stored in each cell of a FAB, is either
given as an argument to the constructor or is inherent in the definition of
the underlying FAB. Each FAB in the FabArray will have the same number of
components.
In summary, a FabArray is an array of FABs. The Kth element contains a FAB
that holds the data for the Kth grid, a Box that defines the valid region
of the Kth grid.
A typical use for a FabArray would be to hold the solution vector or
right-hand-side when solving a linear system of equations on a union of
rectangular grids. The copy operations would be used to copy data from the
valid regions of neighboring grids into the boundary regions after each
relaxation step of the iterative method. If a multigrid method is used, a
FabArray could be used to hold the data at each level in the multigrid
hierarchy.
This class is a concrete class not a polymorphic one.
This class does NOT provide a copy constructor or assignment operator.
*/

//
// alloc: allocate memory or not
//
/**
* \brief FabArray memory allocation information
*/
struct MFInfo {
// alloc: allocate memory or not
bool alloc = true;
Arena* arena = nullptr;
Vector<std::string> tags;
Expand Down Expand Up @@ -314,6 +261,60 @@ Add (FabArray<FAB>& dst, FabArray<FAB> const& src, int srccomp, int dstcomp, int
}
}

/**
* \brief An Array of FortranArrayBox(FAB)-like Objects
*
* The FabArray<FAB> class implements a collection (stored as an array) of
* Fortran array box-like ( \p FAB ) objects. The parameterized type \p FAB is intended to be
* any class derived from BaseFab<T>. For example, \p FAB may be a BaseFab of
* integers, so we could write:
*
* FabArray<BaseFab<int> > int_fabs;
*
* Then int_fabs is a FabArray that can hold a collection of BaseFab<int>
* objects.
*
* FabArray is not just a general container class for Fortran arrays. It is
* intended to hold "grid" data for use in finite difference calculations in
* which the data is defined on a union of (usually disjoint) rectangular
* regions embedded in a uniform index space. This region, called the valid
* region, is represented by a BoxArray. For the purposes of this discussion,
* the Kth Box in the BoxArray represents the interior region of the Kth grid.
*
* Since the intent is to be used with finite difference calculations a
* FabArray also includes the notion of a boundary region for each grid. The
* boundary region is specified by the ngrow parameter which tells the FabArray
* to allocate each \p FAB to be ngrow cells larger in all directions than the
* underlying Box. The larger region covered by the union of all the \p FABs is
* called the region of definition. The underlying notion is that the valid
* region contains the grid interior data and the region of definition includes
* the interior region plus the boundary areas.
*
* Operations are available to copy data from the valid regions into these
* boundary areas where the two overlap. The number of components, that is,
* the number of values that can be stored in each cell of a \p FAB, is either
* given as an argument to the constructor or is inherent in the definition of
* the underlying \p FAB. Each \p FAB in the FabArray will have the same number of
* components.
*
* In summary, a FabArray is an array of \p FABs. The Kth element contains a \p FAB
* that holds the data for the Kth grid, a Box that defines the valid region
* of the Kth grid.
*
* A typical use for a FabArray would be to hold the solution vector or
* right-hand-side when solving a linear system of equations on a union of
* rectangular grids. The copy operations would be used to copy data from the
* valid regions of neighboring grids into the boundary regions after each
* relaxation step of the iterative method. If a multigrid method is used, a
* FabArray could be used to hold the data at each level in the multigrid
* hierarchy.
*
* This class is a concrete class not a polymorphic one.
*
* This class does NOT provide a copy constructor or assignment operator.
*
* \tparam FAB FortranArrayBox-like object. Typically a derived class of BaseFab. Not to be confused with FabArrayBase.
*/
template <class FAB>
class FabArray
:
Expand All @@ -338,8 +339,9 @@ public:
FabArray () noexcept;

/**
* \brief Construct an empty FabArray<FAB> that has a default Arena. If
* `define` is called later with a nullptr as MFInfo's arena, the
* \brief Construct an empty FabArray<FAB> that has a default Arena.
*
* If `define` is called later with a nullptr as MFInfo's arena, the
* default Arena `a` will be used. If the arena in MFInfo is not a
* nullptr, the MFInfo's arena will be used.
*/
Expand Down
6 changes: 6 additions & 0 deletions Src/Base/AMReX_FabArrayBase.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ template <typename FAB> class FabArray;

namespace EB2 { class IndexSpace; }

/**
* \brief Base class for FabArray.
*
* Not to be confused with FArrayBox or `FAB` shorthands.
* Can be read as FArrayBox-like Array Base.
*/
class FabArrayBase
{
friend class MFIter;
Expand Down
Loading

0 comments on commit 4b8dd03

Please sign in to comment.