Mesh

StructuredBase.h

template<typename TReal, size_t DIM>
class Cubism::Mesh::StructuredBase

Structured mesh base class.

Defines the (pure virtual) interface for a structured mesh.

Template Parameters
  • TReal: Float type for mesh entities

  • DIM: Mesh dimension

Subclassed by Cubism::Mesh::StructuredUniform< TReal, DIM >

Public Types

using RangeType = Core::Range<TReal, DIM>

Range that spans the rectangular domain.

using RealType = typename RangeType::DataType

Float type to describe mesh entities.

using PointType = typename RangeType::PointType

Point type in mesh.

using IndexRangeType = Core::IndexRange<DIM>

Index range used to address discrete mesh entities.

using MultiIndex = typename IndexRangeType::MultiIndex

Multi-dimensional index.

using EntityType = Cubism::EntityType

Mesh entity type.

using MeshIntegrity = Cubism::MeshIntegrity

Mesh integrity.

using iterator = typename EntityIterator::iterator

Mesh entity iterator.

Public Functions

inline StructuredBase(const PointType &begin, const PointType &end, const MultiIndex &cells, const MeshIntegrity type)

Standard mesh constructor.

Parameters
  • begin: Lower left point of physical domain

  • end: Upper right point of physical domain

  • cells: Number of cells in mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredBase(const PointType &end, const MultiIndex &cells, const MeshIntegrity type)

Standard mesh constructor.

Physical begin at 0

Parameters
  • end: Upper right point of physical domain

  • cells: Number of cells in mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredBase(const MultiIndex &cells)

Standard mesh constructor.

Physical domain [0, 1], always a full mesh type

Parameters
  • cells: Number of cells in mesh

inline StructuredBase(const RangeType &grange, const RangeType &range, const IndexRangeType &crange, const MeshIntegrity type)

Standard mesh constructor.

Used for MPI subdomains

Parameters
  • grange: Global domain range spanned by this mesh

  • range: Domain range spanned by this mesh

  • crange: Cell range spanned by this mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredBase(const RangeType &grange, const RangeType &range, const IndexRangeType &crange, const IndexRangeType &nrange, const std::vector<IndexRangeType> &frange, const MeshIntegrity type)

Low-level mesh constructor.

Used for grid topology classes and sub-meshes

Parameters
  • grange: Global domain range spanned by this mesh

  • range: Domain range spanned by this mesh

  • crange: Cell range spanned by this mesh

  • nrange: Node range spanned by this mesh

  • frange: Face range spanned by this mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline EntityIterator getIterator(const EntityType t, const size_t d = 0)

Get iterator for a mesh entity.

Return

Entity iterator class

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline EntityIterator getIterator(const EntityType t, const Dir d)

Get iterator for a mesh entity.

Can be used with Cubism::Dir::X for example.

Return

Entity iterator class

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline Entity operator[](const EntityType t) const

Iterable mesh entities.

Assume m is a mesh instance. The access operator can be used in the following manner:

for (auto c : m[EntityType::Cell]) {} // c is a cell index

auto faces = m[EntityType::Face]; // iterators for faces
for (auto fx : faces) {}         // fx is a X-face index
for (auto fx : faces[Dir::X]) {} // fx is a X-face index
for (auto fy : faces[Dir::Y]) {} // fy is a Y-face index
for (auto fz : faces[Dir::Z]) {} // fz is a Z-face index

Return

Entity iterator container

Parameters
  • t: Entity type

inline size_t size(const EntityType t, const size_t d = 0) const

Total size of mesh entities.

Return

Number of entities

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline size_t size(const EntityType t, const Dir d) const

Total size of mesh entities.

Return

Number of entities

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline MultiIndex getSize(const EntityType t, const size_t d = 0) const

Size of mesh entities.

Return

Number of entities along all directions

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline MultiIndex getSize(const EntityType t, const Dir d) const

Size of mesh entities.

Return

Number of entities along all directions

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline IndexRangeType getIndexRange(const EntityType t, const size_t d = 0) const

Index range for an entity type.

Return

Index range

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline IndexRangeType getIndexRange(const EntityType t, const Dir d) const

Index range for an entity type.

Return

Index range

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getExtent() const

Mesh extent.

Return

Extent of mesh in all directions

inline RealType getVolume() const

Mesh volume.

Return

Total mesh volume

inline PointType getBegin() const

Get mesh begin.

Return

Local begin of mesh

inline PointType getEnd() const

Get mesh end.

Return

Local end of mesh

inline PointType getGlobalBegin() const

Get mesh begin.

Return

Global begin of mesh

inline PointType getGlobalEnd() const

Get mesh end.

Return

Global end of mesh

inline RangeType getRange() const

Get mesh range.

Return

Mesh range

inline RangeType getGlobalRange() const

Get mesh range.

Return

Global mesh range

inline bool isSubMesh() const

Test if this is a sub-mesh.

Return

True if this is a sub-mesh of some full mesh

inline MultiIndex getMultiIndex(const size_t i, const EntityType t, const size_t d = 0) const

Convert local flat index to multi-dimensional index.

Return

Local multi-dimensional index

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline MultiIndex getMultiIndex(const size_t i, const EntityType t, const Dir d) const

Convert local flat index to multi-dimensional index.

Return

Local multi-dimensional index

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline MultiIndex getGlobalIndex(const size_t i, const EntityType t, const size_t d = 0) const

Convert local flat index to global multi-dimensional index.

Return

Global multi-dimensional index

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline MultiIndex getGlobalIndex(const size_t i, const EntityType t, const Dir d) const

Convert local flat index to global multi-dimensional index.

Return

Global multi-dimensional index

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline MultiIndex getGlobalIndex(const MultiIndex &p, const EntityType t, const size_t d = 0) const

Convert local multi-dimensional index to global multi-dimensional index.

Return

Global multi-dimensional index

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline MultiIndex getGlobalIndex(const MultiIndex &p, const EntityType t, const Dir d) const

Convert local multi-dimensional index to global multi-dimensional index.

Return

Global multi-dimensional index

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getGlobalCoords(const size_t i, const EntityType t, const size_t d = 0) const

Convert local flat index to global coordinates.

Return

Global coordinates

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline PointType getGlobalCoords(const size_t i, const EntityType t, const Dir d) const

Convert local flat index to global coordinates.

Return

Global coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getGlobalCoords(const MultiIndex &p, const EntityType t, const size_t d = 0) const

Convert local multi-dimensional index to global coordinates.

Return

Global coordinates

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline PointType getGlobalCoords(const MultiIndex &p, const EntityType t, const Dir d) const

Convert local multi-dimensional index to global coordinates.

Return

Global coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getGlobalCoords(const iterator &it) const

Convert entity iterator to global coordinates.

Return

Global coordinates

Parameters
  • it: Entity iterator

inline PointType getCoords(const size_t i, const EntityType t, const size_t d = 0) const

Convert local flat index to local coordinates.

Return

Local coordinates

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline PointType getCoords(const size_t i, const EntityType t, const Dir d) const

Convert local flat index to local coordinates.

Return

Local coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getCoords(const MultiIndex &p, const EntityType t, const size_t d = 0) const

Convert local multi-dimensional index to local coordinates.

Return

Local coordinates

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

template<typename Dir>
inline PointType getCoords(const MultiIndex &p, const EntityType t, const Dir d) const

Convert local multi-dimensional index to local coordinates.

Return

Local coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional index

  • t: Entity type

  • d: Direction indicator (for Face entities only)

inline PointType getCoords(const iterator &it) const

Convert entity iterator to local coordinates.

Return

Local coordinates

Parameters
  • it: Entity iterator

inline PointType getGlobalCoordsCell(const MultiIndex &p) const

Get global cell coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Global cell coordinates

Parameters
  • p: Local multi-dimensional cell index

inline PointType getGlobalCoordsNode(const MultiIndex &p) const

Get global node coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Global node coordinates

Parameters
  • p: Local multi-dimensional node index

template<typename Dir = size_t>
inline PointType getGlobalCoordsFace(const MultiIndex &p, const Dir dir) const

Get global face coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Global face coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • dir: Face direction identifier

inline PointType getCoordsCell(const MultiIndex &p) const

Get local cell coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Local cell coordinates

Parameters
  • p: Local multi-dimensional cell index

inline PointType getCoordsNode(const MultiIndex &p) const

Get local node coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Local node coordinates

Parameters
  • p: Local multi-dimensional node index

template<typename Dir = size_t>
inline PointType getCoordsFace(const MultiIndex &p, const Dir dir) const

Get local face coordinates.

Contains one virtual call. This method is overloaded in the derived class without virtual calls. Prefer this method for excessive coordinate lookup in loops.

Return

Local face coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • dir: Face direction identifier

inline RealType getCellVolume(const size_t i) const

Get cell volume.

Return

Cell volume

Parameters
  • i: Local flat cell index

inline RealType getCellVolume(const MultiIndex &p) const

Get cell volume.

Return

Cell volume

Parameters
  • p: Local multi-dimensional cell index

inline RealType getCellVolume(const iterator &it) const

Get cell volume.

Return

Cell volume

Parameters
  • it: Cell entity iterator

inline PointType getCellSize(const size_t i) const

Get cell size.

Return

Cell size

Parameters
  • i: Local flat cell index

inline PointType getCellSize(const MultiIndex &p) const

Get cell size.

Return

Cell size

Parameters
  • p: Local multi-dimensional cell index

inline PointType getCellSize(const iterator &it) const

Get cell size.

Return

Cell size

Parameters
  • it: Cell entity iterator

inline PointType getSurface(const size_t i, const size_t ci, const size_t d) const

Get surface vector for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface vector

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

template<typename Dir>
inline PointType getSurface(const size_t i, const size_t ci, const Dir d) const

Get surface vector for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface vector

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

inline PointType getSurface(const MultiIndex &p, const MultiIndex &ci, const size_t d) const

Get surface vector for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface vector

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

template<typename Dir>
inline PointType getSurface(const MultiIndex &p, const MultiIndex &ci, const Dir d) const

Get surface vector for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface vector

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

inline RealType getSurfaceArea(const size_t i, const size_t ci, const size_t d) const

Get surface area for a face.

Return

Face surface area

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

template<typename Dir>
inline RealType getSurfaceArea(const size_t i, const size_t ci, const Dir d) const

Get surface area for a face.

Return

Face surface area

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

inline RealType getSurfaceArea(const MultiIndex &p, const MultiIndex &ci, const size_t d) const

Get surface area for a face.

Return

Face surface area

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

template<typename Dir>
inline RealType getSurfaceArea(const MultiIndex &p, const MultiIndex &ci, const Dir d) const

Get surface area for a face.

Return

Face surface area

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

inline PointType getSurfaceNormal(const size_t i, const size_t ci, const size_t d) const

Get surface normal for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface normal

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

template<typename Dir>
inline PointType getSurfaceNormal(const size_t i, const size_t ci, const Dir d) const

Get surface normal for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface normal

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • i: Local flat face index

  • ci: Local flat index of reference cell

  • d: Direction of face

inline PointType getSurfaceNormal(const MultiIndex &p, const MultiIndex &ci, const size_t d) const

Get surface normal for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface normal

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

template<typename Dir>
inline PointType getSurfaceNormal(const MultiIndex &p, const MultiIndex ci, const Dir d) const

Get surface normal for a face.

The vector points outward* of the specified reference cell ci.

Return

Face surface normal

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • ci: Local multi-dimensional index of reference cell

  • d: Direction of face

StructuredUniform.h

template<typename TReal, size_t DIM>
class Cubism::Mesh::StructuredUniform : public Cubism::Mesh::StructuredBase<TReal, DIM>

Structured uniform mesh.

Template Parameters
  • TReal: Float type for mesh entities

  • DIM: Mesh dimension

Public Types

using BaseMesh = StructuredBase<TReal, DIM>

Base mesh type.

using EntityType = Cubism::EntityType

Mesh entity type.

using IndexRangeType = Core::IndexRange<DIM>

Index range used to address discrete mesh entities.

using MeshIntegrity = Cubism::MeshIntegrity

Mesh integrity.

using MultiIndex = typename IndexRangeType::MultiIndex

Multi-dimensional index.

using PointType = typename RangeType::PointType

Point type in mesh.

using RangeType = Core::Range<TReal, DIM>

Range that spans the rectangular domain.

using RealType = typename RangeType::DataType

Float type to describe mesh entities.

Public Functions

inline StructuredUniform(const PointType &begin, const PointType &end, const MultiIndex &cells, const MeshIntegrity type)

Standard mesh constructor.

Parameters
  • begin: Lower left point of physical domain

  • end: Upper right point of physical domain

  • cells: Number of cells in mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredUniform(const PointType &end, const MultiIndex &cells, const MeshIntegrity type)

Standard mesh constructor.

Physical begin at 0

Parameters
  • end: Upper right point of physical domain

  • cells: Number of cells in mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredUniform(const MultiIndex &cells)

Standard mesh constructor.

Physical domain [0, 1], always a full mesh type

Parameters
  • cells: Number of cells in mesh

inline StructuredUniform(const RangeType &grange, const RangeType &range, const IndexRangeType &crange, const MeshIntegrity type)

Standard mesh constructor.

Used for MPI subdomains

Parameters
  • grange: Global domain range spanned by this mesh

  • range: Domain range spanned by this mesh

  • crange: Cell range spanned by this mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline StructuredUniform(const RangeType &grange, const RangeType &range, const IndexRangeType &crange, const IndexRangeType &nrange, const std::vector<IndexRangeType> &frange, const MeshIntegrity type)

Low-level mesh constructor.

Used for grid topology classes and sub-meshes

Parameters
  • grange: Global domain range spanned by this mesh

  • range: Domain range spanned by this mesh

  • crange: Cell range spanned by this mesh

  • nrange: Node range spanned by this mesh

  • frange: Face range spanned by this mesh

  • type: Mesh integrity type (full mesh or sub-mesh)

inline virtual std::unique_ptr<StructuredUniform> getSubMesh(const IndexRangeType &range, const EntityType entity, const size_t d = 0) const

Get sub-mesh instance.

An empty mesh is returned if there is no common intersection. If range is larger it will be clipped to the boundaries of this mesh.

Note

This method is not part of the BaseMesh interface.

Return

New sub-mesh instance

Parameters
  • range: Index range of new mesh

  • entity: Entity type corresponding to range

  • d: Direction indicator (for Face entities only)

inline virtual std::unique_ptr<StructuredUniform> getSubMesh(const PointType &begin, const PointType &end) const

Get sub-mesh instance.

If begin or end is outside of the physical range spanned by this mesh, then they will be adjusted to the begin and/or end points of the range corresponding to this mesh, respectively. The extracted discrete mesh is always guaranteed to include the begin and end points. Therefore, getRange().getBegin() of the extracted sub-mesh may be smaller in any component than begin and vice versa getRange().getEnd() may be larger in any component than end.

Note

This method is not part of the BaseMesh interface.

Return

New sub-mesh instance

Parameters
  • begin: Lower left point of physical domain for sub-mesh

  • end: Upper right point of physical domain for sub-mesh

inline PointType getGlobalCoordsCell(const MultiIndex &p) const

Get global cell coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Global cell coordinates

Parameters
  • p: Local multi-dimensional cell index

inline PointType getGlobalCoordsNode(const MultiIndex &p) const

Get global node coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Global node coordinates

Parameters
  • p: Local multi-dimensional node index

template<typename Dir = size_t>
inline PointType getGlobalCoordsFace(const MultiIndex &p, const Dir dir) const

Get global face coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Global face coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • dir: Face direction identifier

inline PointType getCoordsCell(const MultiIndex &p) const

Get local cell coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Local cell coordinates

Parameters
  • p: Local multi-dimensional cell index

inline PointType getCoordsNode(const MultiIndex &p) const

Get local node coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Local node coordinates

Parameters
  • p: Local multi-dimensional node index

template<typename Dir = size_t>
inline PointType getCoordsFace(const MultiIndex &p, const Dir dir) const

Get local face coordinates.

This is a non-virtual method. Prefer this method for excessive coordinate lookup in loops.

Return

Local face coordinates

Template Parameters
  • Dir: Special type that defines a cast to size_t

Parameters
  • p: Local multi-dimensional face index

  • dir: Face direction identifier