28const static Eigen::StorageOptions majority = Eigen::RowMajor;
53#include "include/ModelArrayDetails.hpp"
55 static const int N_DEFINED_DIMENSIONS =
static_cast<int>(Dimension::COUNT);
61 typedef std::map<Type, std::vector<Dimension>> TypeDimensions;
70 static const std::map<Type, Dimension> componentMap;
72 typedef Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic, majority> DataType;
74 typedef DataType::RowXpr Component;
75 typedef DataType::ConstRowXpr ConstComponent;
218 typedef std::vector<size_t> MultiDim;
223 static size_t nDimensions(Type type) {
return m_dims.at(type).size(); }
227 static const MultiDim&
dimensions(Type type) {
return m_dims.at(type); }
231 static size_t size(Type type) {
return m_sz.at(type); }
236 const double*
getData()
const {
return m_data.data(); }
239 const DataType&
data()
const {
return m_data; }
281 m_data.resize(m_sz.at(type),
definedDimensions.at(componentMap.at(type)).length);
283 m_data.resize(m_sz.at(type), Eigen::NoChange);
304 void setData(
const double* pData);
326 template <
typename T,
typename I>
static inline T indexr(
const T* dims, I first)
328 return static_cast<T
>(first);
332 template <
typename T,
typename I>
static inline T indexr(
const T* dims, I first, I second)
334 return first + second * dims[0];
338 template <
typename T,
typename I,
typename... Args>
339 static inline T indexr(
const T* dims, I first, Args... args)
341 std::initializer_list<I> loc { first, args... };
342 return indexrHelper(dims, loc);
346 template <
typename T>
static T indexr(
const T* dims,
const ModelArray::MultiDim& loc)
348 return indexrHelper(dims, loc);
352 template <
typename T,
typename C>
static T indexrHelper(
const T* dims,
const C& loc)
354 size_t ndims = loc.size();
357 auto iloc = begin(loc);
358 for (
size_t dim = 0; dim < ndims; ++dim) {
359 ii += stride * (*iloc++);
375 const double&
operator[](
size_t i)
const {
return m_data(i, 0); }
387 const double&
operator[](
const MultiDim& dims)
const;
392 template <
typename... Args>
const double&
operator()(Args... args)
const
407 double&
operator[](
size_t i) {
return const_cast<double&
>(std::as_const(*
this)(i)); }
425 return const_cast<double&
>(std::as_const(*
this)(args...));
463 const ConstComponent
components(
size_t i)
const {
return m_data.row(i); }
471 const ConstComponent
components(
const MultiDim& loc)
const;
544 static bool hasDoF(
const Type type);
564 static bool areMapsInvalid;
565 static void validateMaps();
569 size_t& at(
const Type& type) {
return m_sizes.at(type); }
570 const size_t& at(
const Type& type)
const {
return m_sizes.at(type); }
572 size_t& operator[](
const Type& type) {
return m_sizes[type]; }
573 size_t& operator[](Type&& type) {
return m_sizes[type]; }
575 size_t size() const noexcept {
return m_sizes.size(); }
580 std::map<Type, size_t> m_sizes;
587 MultiDim& at(
const Type& type) {
return m_dimensions.at(type); }
588 const MultiDim& at(
const Type& type)
const {
return m_dimensions.at(type); }
590 MultiDim& operator[](
const Type& type) {
return m_dimensions[type]; }
591 MultiDim& operator[](Type&& type) {
return m_dimensions[type]; }
593 size_t size() const noexcept {
return m_dimensions.size(); }
598 std::map<Type, MultiDim> m_dimensions;
600 static DimensionMap m_dims;
604#include "include/ModelArrayTypedefs.hpp"
607ModelArray operator+(
const double&,
const ModelArray&);
608ModelArray operator-(
const double&,
const ModelArray&);
609ModelArray operator*(
const double&,
const ModelArray&);
610ModelArray operator/(
const double&,
const ModelArray&);
A class that holds the array data for the model.
const double & operator[](size_t i) const
Returns the data at the specified one dimensional index.
Component components(size_t i)
Accesses the full Discontinuous Galerkin coefficient vector at the indexed location.
double & operator[](size_t i)
Returns the data at the specified one dimensional index.
ModelArray & operator+=(double b)
In place addition of a double.
size_t trueSize() const
Returns the size of the data array of this object.
static TypeDimensions typeDimensions
The dimensions that make up each defined type. Defined in ModelArrayDetails.cpp.
static size_t size(Type type)
Returns the total number of elements of the specified type of ModelArray.
ModelArray & operator+=(const ModelArray &b)
In place addition of another ModelArray.
bool hasDoF() const
Returns whether this type of ModelArray has additional discontinuous Galerkin components.
size_t indexFromLocation(const MultiDim &loc) const
Returns the index for a given set of multi-dimensional location for this array's type.
static const MultiDim & dimensions(Type type)
Returns a vector<size_t> of the size of each dimension of the specified type of ModelArray.
double & zIndexAndLayer(size_t hIndex, size_t layer)
Special access function for ZFields.
const MultiDim & dimensions() const
Returns a vector<size_t> of the size of each dimension of this type of ModelArray.
ModelArray & clampBelow(double min)
Clamps the values in the array to the given minimum.
double & operator()(Args... args)
Returns the specified point from a ModelArray.
ModelArray & operator/=(double b)
In place division by a double.
ModelArray operator*(const ModelArray &) const
Returns a ModelArray containing the per-element product of the object and the provided ModelArray.
static void setNComponents(Type type, size_t nComp)
Sets the number of components for a single D/CG array type.
ModelArray & operator*=(double b)
In place multiplication by a double.
ModelArray min(double min) const
Calculates element-wise minimum of the data and the given scalar value.
ModelArray & operator-=(const ModelArray &b)
In place subtraction of another ModelArray.
ModelArray & operator/=(const ModelArray &b)
In place division by another ModelArray.
ModelArray & operator=(const ModelArray &)
Copy assignment operator.
ModelArray operator+(const ModelArray &) const
Returns a ModelArray containing the per-element sum of the object and the provided ModelArray.
const double & zIndexAndLayer(size_t hIndex, size_t layer) const
Special access function for ZFields, const version.
static size_t nDimensions(Type type)
Returns the number of dimensions of the specified type of ModelArray.
ModelArray & clampAbove(double max)
Clamps the values in the array to the given maximum.
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.
static void setDimension(Dimension dim, size_t length)
Sets the length of an individual dimension before propagating it to the defined array types.
Type getType() const
Returns the (enum of) the ModelArray::Type of this.
void setData(double value)
Sets the value of every element in the object to the provided value.
void setDimensions(const MultiDim &dims)
Sets the number and size of the dimensions of this type of ModelArray.
void resize()
Conditionally updates the size of the object data buffer to match the class specification.
ModelArray operator/(const ModelArray &) const
Returns a ModelArray containing the per-element ratio between the object and the provided ModelArray.
const DataType & data() const
Returns a const reference to the Eigen data.
size_t nComponents() const
Returns the number of discontinuous Galerkin components held in this type of ModelArray.
size_t nDimensions() const
Returns the number of dimensions of this type of ModelArray.
const double & operator()(Args... args) const
Returns the data at the given set of indices.
size_t zLayerIndex(size_t hIndex, size_t layer) const
Special access function for ZFields, common implementation version.
ModelArray & operator*=(const ModelArray &b)
In place multiplication by another ModelArray.
const double * getData() const
Returns a read-only pointer to the underlying data buffer.
void setNComponents(size_t nComp)
Sets the number of components for this array's type.
MultiDim locationFromIndex(size_t index) const
Returns the multi-dimensional location for a given index for this array's type.
ModelArray max(double max) const
Calculates element-wise maximum of the data and the given scalar value.
size_t size() const
Returns the total number of elements of this type of ModelArray.
static size_t nComponents(const Type type)
Returns the number of discontinuous Galerkin components held in the specified type of ModelArray.
static std::map< Dimension, DimensionSpec > definedDimensions
The name and length of each dimension that is defined.
static const std::map< Type, std::string > typeNames
The name of each type of ModelArray.
static void setNComponents(std::map< Type, size_t > cMap)
Sets the number of components for DG & CG array types.
ModelArray & operator-=(double b)
In place subtraction of a double.