8#include "include/ModelArray.hpp"
19ModelArray::SizeMap ModelArray::m_sz;
20ModelArray::DimensionMap ModelArray::m_dims;
21bool ModelArray::areMapsInvalid =
true;
26 m_data.resize(std::max(std::size_t { 0 }, m_sz.at(type)),
nComponents());
54 return result += addend;
60 return result -= subtrahend;
66 return result *= multiplier;
72 return result /= divisor;
78 copy.m_data = -m_data;
108ModelArray operator-(
const double& x,
const ModelArray& y) {
return -(y - x); }
110ModelArray operator*(
const double& x,
const ModelArray& y) {
return y * x; }
112ModelArray operator/(
const double& x,
const ModelArray& y)
114 ModelArray xArray(y.getType());
122 maxed.m_data.array() = m_data.array().max(
max);
129 mined.m_data.array() = m_data.array().min(
min);
136 maxed.m_data.array() = m_data.array().max(maxArr.m_data);
143 mined.m_data.array() = m_data.array().min(minArr.m_data);
149 m_data = this->
max(max).m_data;
155 m_data = this->
min(min).m_data;
161 m_data = this->
max(maxArr).m_data;
167 m_data = this->
min(minArr).m_data;
180 auto out = std::copy(pData, pData + m_sz.at(type) *
nComponents(), m_data.data());
190 for (
size_t i = 0; i < dimSpecs.size(); ++i) {
198 for (
auto entry : cMap) {
216 return const_cast<double&
>(std::as_const(*
this)[dims]);
237 return indexr(m_dims.at(type).data(), loc);
248 MultiDim& dims = m_dims.at(type);
249 MultiDim loc(dims.size());
250 for (
size_t i = 0; i < loc.size(); ++i) {
251 size_t theDim = dims[i];
252 size_t pos = index % theDim;
259void ModelArray::validateMaps()
263 areMapsInvalid =
false;
266void ModelArray::DimensionMap::validate()
269 Type type = entry.first;
270 std::vector<size_t>& dims = m_dimensions[type];
271 std::vector<Dimension>& typeDims = entry.second;
272 dims.resize(typeDims.size());
273 for (
size_t i = 0; i < typeDims.size(); ++i) {
279void ModelArray::SizeMap::validate()
283 std::vector<Dimension>& typeDims = entry.second;
284 for (
size_t i = 0; i < typeDims.size(); ++i) {
287 m_sizes.at(entry.first) =
size;
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.
static TypeDimensions typeDimensions
The dimensions that make up each defined type. Defined in ModelArrayDetails.cpp.
size_t indexFromLocation(const MultiDim &loc) const
Returns the index for a given set of multi-dimensional location for this array's type.
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.
ModelArray operator*(const ModelArray &) const
Returns a ModelArray containing the per-element product of the object and the provided ModelArray.
ModelArray min(double min) const
Calculates element-wise minimum of the data and the given scalar value.
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.
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.
void setData(double value)
Sets the value of every element in the object to the provided value.
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.
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 std::map< Dimension, DimensionSpec > definedDimensions
The name and length of each dimension that is defined.
static void setNComponents(std::map< Type, size_t > cMap)
Sets the number of components for DG & CG array types.