FieldLab.h

template<typename TField>
class Cubism::Block::FieldLab : public Cubism::Block::Data<TField::DataType, TField::EntityType, TField::IndexRangeType::Dim, Cubism::AlignedBlockAllocator<TField::DataType>>

Field laboratory.

A FieldLab is an extended data structure to include ghost cells for a given stencil. Loading a lab takes care of loading the ghost cells from neighboring block fields and applies boundary conditions if present. The default is periodic if no boundary conditions are specified otherwise.

Template Parameters
  • TField: Field type to map to the lab

Public Functions

inline FieldLab()

Main constructor.

inline void allocate(const StencilType &s, const IndexRangeType &max_range, const bool force = false)

Allocate data lab memory block for a given stencil.

The method may be called subsequently.with a different stencil and maximum range. If the new request can be processed using the current allocation no new memory is allocated unless the force flag is true.

Parameters
  • s: Target stencil

  • max_range: Maximum index range to be processed in the lab

  • force: Force a reallocation for subsequent requests

template<typename Functor = STDFunction>
inline void loadData(const MultiIndex &fid, Functor &id2field, const bool apply_bc = true, const BCVector *extern_bc = nullptr)

Lab data loader.

The id2field mapping function takes a multi-dimensional block field index as an argument and returns a reference to the corresponding block field. The function must map indices periodically.

Parameters
  • fid: Multi-dimensional index of target block field

  • id2field: Index mapping function for block fields

  • apply_bc: Flag whether to apply boundary conditions

  • extern_bc: Pointer to external boundary conditions

template<typename Functor = STDFunction>
inline void loadData(const MultiIndex &fid, Functor &id2field, const BCVector &boundaries, const bool apply_bc = true)

Lab data loader.

This loader is a convenience wrapper around the default loader if boundary conditions need to be enforced. This wrapper applies the boundary conditions specified in boundaries instead of the boundary conditions specified in the block field with index fid (if any). The vector boundaries may be empty.

Parameters
  • fid: Multi-dimensional index of target block field

  • id2field: Index mapping function for block fields

  • boundaries: Vector of boundary conditions

  • apply_bc: Flag whether to apply boundary conditions

inline DataType &operator[](const MultiIndex &p)

Linear data access.

The local index p may reference halo cells. For example, p{-1,0} indexes the first halo cell in the x direction that is adjacent to the inner domain.

Return

Reference to data element

Parameters
  • p: Local multi-dimensional index

inline const DataType &operator[](const MultiIndex &p) const

Linear data access.

The local index p may reference halo cells. For example, p{-1,0} indexes the first halo cell in the x direction that is adjacent to the inner domain.

Return

const reference to data element

Parameters
  • p: Local multi-dimensional index

inline DataType &operator()(const Index ix, const Index iy = 0, const Index iz = 0)

Classic data access.

This operator is only supported for dimensions 1, 2 and 3. Accessing data with this operator has less latency than the multi-index sibling.

Return

Reference to data element

Parameters
  • ix: Index for first dimension

  • iy: Index for second dimension

  • iz: Index for third dimension

inline const DataType &operator()(const Index ix, const Index iy = 0, const Index iz = 0) const

Classic data access.

This operator is only supported for dimensions 1, 2 and 3. Accessing data with this operator has less latency than the multi-index sibling.

Return

const reference to data element

Parameters
  • ix: Index for first dimension

  • iy: Index for second dimension

  • iz: Index for third dimension

inline DataType *getInnerData()

Get pointer to inner block data.

The returned pointer points to the first element defined in loader_.curr_range.

Return

Pointer to first data element of base field

inline const DataType *getInnerData() const

Get pointer to inner block data.

The returned pointer points to the first element defined in loader_.curr_range.

Return

Pointer to first data element of base field

inline const StencilType &getActiveStencil() const

Get currently active (loaded) stencil.

Return

const reference to StencilType

inline const IndexRangeType &getActiveRange() const

Get currently active (loaded) index range.

Return

const reference to IndexRangeType

inline FieldType &getActiveField()

Get reference to currently active (loaded) field.

Return

Reference to FieldType

inline const FieldType &getActiveField() const

Get reference to currently active (loaded) field.

Return

const reference to FieldType

inline IndexRangeType getActiveLabRange() const

Get currently active (loaded) lab index range.

The index range begin is identical to the active stencil begin, which is < 0.

Return

Index range including ghost indices

inline IndexRangeType getMaximumRange() const

Get the maximum range that the lab can hold.

Return

Index range of maximum span

inline bool isAllocated() const

Check if lab is allocated.

Return

True if laboratory is allocated

inline virtual BlockBytes getMemoryFootprint() const override

Get byte utilization of block.

Return

Structure of byte usage for this instance