Class ModelArray

Nested Relationships

Nested Types

Class Documentation

class ModelArray

A class that holds the array data for the model.

This class holds n-dimensional data for the model. It is designed to be a light (not transparent) wrapper around Eigen::Array. The underlying Array is two dimensional, with the first dimension acting like the one dimensional vector backing an n-dimensional array type. All of the n dimensional indexing is collapsed onto the first dimension. Any access to components for Discontinuous Galerkin variables is done through the second dimension. For finite volume variables, there is one component in the second dimension.

Sizes and dimensionality as calculated by the static and member functions only pertain to the grid, with the DG components being ignored. For a degree-2 DG variable the size in memory would be 6 times that reported by the size() function.

Public Types

using Slice = ArraySlicer::Slice
using TypeDimensions = std::map<Type, std::vector<Dimension>>
using DataType = Eigen::Array<FloatType, Eigen::Dynamic, Eigen::Dynamic, majority>
using Components = DataType::RowXpr
using ConstComponents = DataType::ConstRowXpr
using Component = DataType::ColXpr
using ConstComponent = DataType::ConstColXpr
using MultiDim = std::vector<size_t>
using TypeMap = std::map<ModelArray::Type, ModelArray::Type>

Public Functions

ModelArray()

Construct an unnamed ModelArray of Type::H

ModelArray(const Type type, const std::pair<FloatType, FloatType> &bounds = {-std::numeric_limits<FloatType>::max(), std::numeric_limits<FloatType>::max()})

Construct a ModelArray of the given type.

Parameters:
  • t – The ModelArray::Type for the new object.

  • bounds – The physical lower and upper bounds for the new object. See lowerPhysicalLimit and upperPhysicalLimit.

ModelArray(const ModelArray&)

Copy constructor.

inline virtual ~ModelArray()
ModelArray &operator=(const ModelArray&)

Copy assignment operator.

ModelArray &operator=(const FloatType &val)

Assigns a FloatType value to all elements of the object.

Parameters:

val – The value to be assigned.

ModelArray &operator=(const ModelArraySlice&)

Assigns an entire ModelArray from the data contained in a ModelArraySlice.

Given a ModelArraySlice, copy all of the data from that slice into all of the model array. For only copying to some of a ModelArray, please see ModelArraySlice::operator=(ModelArray&). The shape of the slice must match, up to any number of trailing length 1 dimensions.

inline ModelArray &operator=(const DataType &src)

Assign a DataType to an existing ModelArray.

Parameters:

src – The DataType object to be assigned.

inline operator DataType&()

Casts the data to a DataType reference.

inline operator const DataType&() const

Casts the data to a const DataType reference

ModelArraySlice operator[](const Slice&)

Creates a ModelArraySlice.

ConstModelArraySlice operator[](const Slice&) const
inline ModelArray &operator+=(const ModelArray &b)

In place addition of another ModelArray.

inline ModelArray &operator-=(const ModelArray &b)

In place subtraction of another ModelArray.

inline ModelArray &operator*=(const ModelArray &b)

In place multiplication by another ModelArray.

inline ModelArray &operator/=(const ModelArray &b)

In place division by another ModelArray.

inline ModelArray &operator+=(FloatType b)

In place addition of a FloatType.

inline ModelArray &operator-=(FloatType b)

In place subtraction of a FloatType.

inline ModelArray &operator*=(FloatType b)

In place multiplication by a FloatType.

inline ModelArray &operator/=(FloatType b)

In place division by a FloatType.

ModelArray operator+(const ModelArray&) const

Returns a ModelArray containing the per-element sum of the object and the provided ModelArray.

ModelArray operator-(const ModelArray&) const

Returns a ModelArray containing the per-element difference between the object and the provided ModelArray.

ModelArray operator*(const ModelArray&) const

Returns a ModelArray containing the per-element product of the object and the provided ModelArray.

ModelArray operator/(const ModelArray&) const

Returns a ModelArray containing the per-element ratio between the object and the provided ModelArray.

ModelArray operator-() const
ModelArray operator+(const FloatType&) const

Returns a ModelArray with a constant added to every element of the object.

ModelArray operator-(const FloatType&) const

Returns a ModelArray with a constant subtracted from every element of the object.

ModelArray operator*(const FloatType&) const

Returns a ModelArray with every element of the object multiplied by a constant.

ModelArray operator/(const FloatType&) const

Returns a ModelArray with every element of the object divided by a constant.

ModelArray max(FloatType max) const

Calculates element-wise maximum of the data and the given scalar value.

Parameters:

max – the maximum value of the resultant array.

ModelArray min(FloatType min) const

Calculates element-wise minimum of the data and the given scalar value.

Parameters:

min – the minimum value of the resultant array.

ModelArray max(const ModelArray &maxArr) const

Calculates element-wise maximum of the data and the given second array.

Parameters:

maxArr – the array containing the maximum values.

ModelArray min(const ModelArray &minArr) const

Calculates element-wise minimum of the data and the given second array.

Parameters:

minArr – the array containing the minimum values.

ModelArray &clampAbove(FloatType max)

Clamps the values in the array to the given maximum.

Parameters:

max – the maximum value of the final array.

ModelArray &clampBelow(FloatType min)

Clamps the values in the array to the given minimum.

Parameters:

min – the minimum value of the final array.

ModelArray &clampAbove(const ModelArray &maxArr)

Clamps the values in the array to maximum values in the given array.

Parameters:

maxArr – the array of clamp maximum target values.

ModelArray &clampBelow(const ModelArray &minArr)

Clamps the values in the array to minimum values in the given array.

Parameters:

minArr – the array of clamp minimum target values.

inline size_t nDimensions() const

Returns the number of dimensions of this type of ModelArray.

inline const MultiDim &dimensions() const

Returns a vector<size_t> of the size of each dimension of this type of ModelArray.

inline size_t size() const

Returns the total number of elements of this type of ModelArray.

inline size_t trueSize() const

Returns the size of the data array of this object.

inline const FloatType *getData() const

Returns a read-only pointer to the underlying data buffer.

inline ModelArray::DataType &getDataRef()

Returns a reference to the underlying ModelArray::DataType object.

inline const DataType &data() const

Returns a const reference to the Eigen data.

inline Type getType() const

Returns the (enum of) the ModelArray::Type of this.

inline void setDimensions(const MultiDim &dims)

Sets the number and size of the dimensions of this type of ModelArray.

Sets the number and size of the dimensions of this type of ModelArray. The data buffer of this object is then resized to match the new definition.

Parameters:

dim – The per-dimension size to be set.

inline void reinitialize()

Updates the size of the object data buffer to match the class specification and sets every element to 0.

void setData(FloatType value)

Sets the value of every element in the object to the provided value.

Parameters:

value – The new value for every element.

void setData(const FloatType *pData)

Reads and sets data from a raw buffer of FloatType data.

The given pointer is the address of the first element read. Subsequent doubles in memory are read until every element in the object has been read. Ensure the provided buffer contains sufficient data to fill every element of the object, as no further bounds checking is performed.

Parameters:

pData – The pointer to the data buffer to be read.

void setData(const DataType &data)

Reads and sets data from an instance of the underlying data class (Eigen::Array).

Parameters:

data – The data object to be copied from.

void setData(const ModelArray &source)

Reads and sets data from another ModelArray.

This function reads the data buffer only, and performs no bounds checking on the ModelArray argument. Unlike the assignment operator or copy constructor, it does not change the size or type of the object.

Parameters:

source – The object to be copied from.

void assignData(const ModelArray &source)

Sets data from another ModelArray, respecting the type of this.

This function copies the data from the source but keeps the the type and size of this. In case the number of components does not match, only the 0th component is copied.

Parameters:

source – The object to be copied from.

void assignData(ModelArray &&source)
inline const FloatType &operator[](size_t i) const

Returns the data at the specified one dimensional index.

The argument is used to directly index the data buffer. If the object holds discontinuous Galerkin components, only the cell averaged value is returned. Here the data is a const reference.

Parameters:

i – The one dimensional index of the target point.

const FloatType &operator[](const MultiDim &dims) const

Returns the data at the indices.

The argument is a list of dimension indices (actually a std::vector<size_t>). The number of dimensions provided can be lower than that of the ModelArray type. If the object holds discontinuous Galerkin components, only the cell averaged value is returned. Here the data is a const reference.

Parameters:

dims – The indices of the target point.

template<typename ...Args>
inline const FloatType &operator()(Args... args) const

Returns the data at the given set of indices.

inline FloatType &operator[](size_t i)

Returns the data at the specified one dimensional index.

The argument is used to directly index the data buffer. If the object holds discontinuous Galerkin components, only the cell averaged value is returned. Here the data is a reference and so can be used for assignment.

Parameters:

i – The one dimensional index of the target point.

FloatType &operator[](const MultiDim&)

Returns the data at the indices.

The argument is a list of dimension indices (actually a std::vector<size_t>). The number of dimensions provided can be lower than that of the ModelArray type. If the object holds discontinuous Galerkin components, only the cell averaged value is returned. Here the data is a reference and so can be used for assignment.

Parameters:

dims – The indices of the target point.

template<typename ...Args>
inline FloatType &operator()(Args... args)

Returns the specified point from a ModelArray.

If the object holds discontinuous Galerkin components, only the cell averaged value is returned. Non-const version.

inline void setNComponents(size_t nComp)

Sets the number of components for this array’s type.

Parameters:

nComp – the number of components to be set.

inline Components components(size_t i)

Accesses the full Discontinuous Galerkin coefficient vector at the indexed location.

Parameters:

i – one-dimensional index of the target point.

inline const ConstComponents components(size_t i) const
Components components(const MultiDim &loc)

Accesses the full Discontinuous Galerkin coefficient vector at the specified location.

Parameters:

dims – indexing argument of the target point.

const ConstComponents components(const MultiDim &loc) const
inline Component component(size_t compo = 0)

Returns a particular component at all locations.

Parameters:

comp – The index of the component to be returned. Defaults to component 0.

inline const ConstComponent component(size_t compo = 0) const
inline operator Component()

Implicitly converts a ModelArray to a Component, assuming component zero

inline ModelArray &operator=(const Component &src)

Assigns from a component to the ModelArray. Let Eigen handle size, broadcasting, &c.

inline ModelArray &operator=(const ConstComponent &src)

Assigns from a const component to the ModelArray. Let Eigen handle size, broadcasting, &c.

inline size_t indexFromLocation(const MultiDim &loc) const

Returns the index for a given set of multi-dimensional location for this array’s type.

Parameters:

loc – The multi-dimensional location to return the index for.

inline MultiDim locationFromIndex(size_t index) const

Returns the multi-dimensional location for a given index for this array’s type.

Parameters:

index – The index to return the multi-dimensional location for.

inline size_t nComponents() const

Returns the number of discontinuous Galerkin components held in this type of ModelArray.

inline bool hasDoF() const

Returns whether this type of ModelArray has additional discontinuous Galerkin components.

void setLimits(const FloatType lower, const FloatType upper)
void checkLimits(const ModelArray &mask) const

Public Static Functions

static inline size_t nDimensions(Type type)

Returns the number of dimensions of the specified type of ModelArray.

static inline const MultiDim &dimensions(Type type)

Returns a vector<size_t> of the size of each dimension of the specified type of ModelArray.

static inline size_t size(Type type)

Returns the total number of elements of the specified type of ModelArray.

static inline size_t size(Dimension dim)

Returns the local size of a dimension.

static void setDimensions(Type, const MultiDim&)

Sets the number and size of the dimensions of a specified type of ModelArray.

Parameters:
  • type – The type of array the dimensions are to be specified for.

  • dim – The per-dimension size to be set.

static void setDimension(Dimension dim, size_t globalLength)

Sets the length of an individual dimension before propagating it to the defined array types.

Parameters:
  • dim – The dimension to be altered.

  • length – The new length of the dimension.

static void setNComponents(std::map<Type, size_t> cMap)

Sets the number of components for DG & CG array types.

Parameters:

cMap – a map from ModelArray::Type to the number of components.

static inline void setNComponents(Type type, size_t nComp)

Sets the number of components for a single D/CG array type.

Parameters:
  • type – the DG or CG array type to set the number of components for.

  • nComp – the number of components to be set.

static inline ModelArray::Type component0Type(ModelArray::Type withComponents)
static size_t indexFromLocation(Type type, const MultiDim &loc)

Returns the index for a given set of multi-dimensional location for the given Type.

Parameters:
  • type – The type to act on.

  • loc – The multi-dimensional location to return the index for.

static MultiDim locationFromIndex(Type type, size_t index)

Returns the multi-dimensional location for a given index for the given Type.

Parameters:
  • type – The type to act on.

  • index – The index to return the multi-dimensional location for.

static inline size_t nComponents(const Type type)

Returns the number of discontinuous Galerkin components held in the specified type of ModelArray.

static bool hasDoF(const Type type)

Returns whether the specified type of ModelArray has additional discontinuous Galerkin components.

Public Static Attributes

static const int N_DEFINED_DIMENSIONS = static_cast<int>(Dimension::COUNT)
static TypeDimensions typeDimensions

The dimensions that make up each defined type. Defined in ModelArrayDetails.cpp.

static std::map<Dimension, DimensionSpec> definedDimensions = {{ModelArray::Dimension::X, {"x_dim", "xdim", 0, 0, 0}}, {ModelArray::Dimension::Y, {"y_dim", "ydim", 0, 0, 0}}, {ModelArray::Dimension::XVERTEX, {"x_vertex", "xvertex", 1, 1, 0}}, {ModelArray::Dimension::YVERTEX, {"y_vertex", "yvertex", 1, 1, 0}}, {ModelArray::Dimension::XCG, {"x_cg", "x_cg", 2, 2, 0}}, {ModelArray::Dimension::YCG, {"y_cg", "y_cg", 2, 2, 0}}, {ModelArray::Dimension::DG, {"dg_comp", "dg_comp", 6, 6, 0}}, {ModelArray::Dimension::DGSTRESS, {"dgstress_comp", "dgstress_comp", 8, 8, 0}}, {ModelArray::Dimension::NCOORDS, {"ncoords", "ncoords", 2, 2, 0}},}

The name and length of each dimension that is defined.

static const std::map<Type, std::string> typeNames = {{ModelArray::Type::H, "HField"}, {ModelArray::Type::VERTEX, "VertexField"}, {ModelArray::Type::U, "UField"}, {ModelArray::Type::V, "VField"}, {ModelArray::Type::DG, "DGField"}, {ModelArray::Type::DGSTRESS, "DGSField"}, {ModelArray::Type::CG, "CGField"},}

The name of each type of ModelArray.

static std::map<Type, Base> baseTypes = {{ModelArray::Type::H, ModelArray::Base::Cell}, {ModelArray::Type::VERTEX, ModelArray::Base::Vertex}, {ModelArray::Type::U, ModelArray::Base::Cell}, {ModelArray::Type::V, ModelArray::Base::Cell}, {ModelArray::Type::DG, ModelArray::Base::Cell}, {ModelArray::Type::DGSTRESS, ModelArray::Base::Cell}, {ModelArray::Type::CG, ModelArray::Base::Vertex},}

The base type of each type of ModelArray.

static const std::map<Type, Dimension> componentMap = {{Type::DG, Dimension::DG}, {Type::DGSTRESS, Dimension::DGSTRESS}, {Type::VERTEX, Dimension::NCOORDS},}

Protected Attributes

Type type
struct DimensionSpec

Public Functions

inline void setLengths(size_t length)
inline bool operator==(const DimensionSpec &other)

Public Members

std::string name
std::string altName
size_t globalLength
size_t localLength
size_t start