Core¶
Index.h¶
-
template<size_t
DIM>
classCubism::Core::IndexRange: public Cubism::Core::Range<Index, DIM> Rectangular index range.
Defines a simple consecutive index space.
- Template Parameters
DIM: Dimension of the index space
Public Functions
-
inline
IndexRange() Default constructor (NULL range)
-
inline explicit
IndexRange(const DataType e) Construct index range.
Constructs equal extent in all
DIMdimensions.- Parameters
e: End point (top right) of index space. Begin is0.
-
inline explicit
IndexRange(const PointType &e) Construct index range.
Constructs an extent specified the
DIM-dimensionale.- Parameters
e: End point (top right) of index space. Begin is0.
-
inline
IndexRange(const DataType b, const DataType e) Construct index range.
Constructs equal extent in all
DIMdimensions.- Parameters
b: Begin point (lower left) of index space.e: End point (top right) of index space.
-
inline
IndexRange(const PointType &b, const PointType &e) Construct index range.
Constructs an extent specified the
DIM-dimensional difference ofeandb.- Parameters
b: Begin point (lower left) of index space.e: End point (top right) of index space.
-
inline IndexRange
getIntersection(const IndexRange &o) const Get intersection subspace.
- Return
New range for intersection
- Parameters
o: Other index range
-
inline bool
isIndex(const MultiIndex &p) const Check if index is valid local in this range.
- Return
True if
pis a valid index (exclusive; C-style indexing)- Parameters
p: Local multi-dimensional index
-
inline bool
isGlobalIndex(const MultiIndex &p) const Check if index is valid global in this range.
- Return
True if
pis a valid index (exclusive; C-style indexing)- Parameters
p: Global multi-dimensional index
-
inline size_t
size() const Size of index space.
- Return
Total number of indices in the index range
-
inline size_t
sizeDim(const size_t i) const Size of index space.
- Return
Number of indices along dimension
i- Parameters
i: Dimension
-
inline size_t
getFlatIndex(const MultiIndex &p) const Convert a local multi-dimensional index to a local one-dimensional index.
Computes a local* flat index from a local multi-dimensional index relative to the index space spanned by this range.
- Return
Local flattened index
- Parameters
p: Local multi-dimensional index
-
inline size_t
getFlatIndexFromGlobal(const MultiIndex &p) const Convert a global multi-dimensional index to a local one-dimensional index.
Computes a local* flat index from a global multi-dimensional index relative to the index space spanned by this range.
- Return
Local flattened index
- Parameters
p: Global multi-dimensional index
-
inline MultiIndex
getMultiIndex(size_t i) const Convert a local one-dimensional index to a local multi-dimensional index.
Computes a local* multi-dimensional index from a local one-dimensional index relative to the index space spanned by this range.
- Return
Local multi-dimensional index
- Parameters
i: Local one-dimensional index
Range.h¶
-
template<typename
T, size_tDIM>
classCubism::Core::Range Rectangular range.
- Template Parameters
T: Data type that describes coordinates in the rangeDIM: Dimension
Public Functions
-
inline
Range() Default constructor (NULL range)
-
inline explicit
Range(const DataType e) Construct range.
Constructs equal extent in all
DIMdimensions.- Parameters
e: End point (top right) of rectangle. Begin is0.
-
inline explicit
Range(const PointType &e) Construct range.
Constructs an extent specified the
DIM-dimensionale.- Parameters
e: End point (top right) of rectangle. Begin is0.
-
inline
Range(const DataType b, const DataType e) Construct range.
Constructs equal extent in all
DIMdimensions.- Parameters
b: Begin point (lower left) of rectangle.e: End point (top right) of rectangle.
-
inline
Range(const PointType &b, const PointType &e) Construct range.
Constructs an extent specified the
DIM-dimensional difference ofeandb.- Parameters
b: Begin point (lower left) of rectangle.e: End point (top right) of rectangle.
-
inline void
setBegin(const PointType &b) Set range begin.
- Parameters
b: New begin point
-
inline void
setEnd(const PointType &e) Set range end.
- Parameters
e: New end point
-
inline PointType
getBegin() const Get range begin.
- Return
Begin point
-
inline PointType
getEnd() const Get range end.
- Return
End point
-
inline PointType
getExtent() const Get range extent.
Note
If
getNullSpace().size() > 0then the extent for the corresponding null space dimension is equal to the identity. This allows for arithmetic operations if the range spans a lower dimensional space. Use thegetNullSpace()method to obtain the null space components.- Return
Range extent
-
inline DataType
getVolume() const Get range volume.
- Return
Range volume
-
inline std::vector<size_t>
getNullSpace() const Get the null space.
The range has a reduced basis if
null.size()>0, wherenullis the return value.- Return
Vector of indices corresponding to the dimensions that span a null space
-
inline bool
isContained(const Range &o) const Check if other range is contained in this range.
- Return
True if
ois contained in this range (inclusive)- Parameters
o: Other range
-
inline bool
isContained(const PointType &p) const Check if point is contained in this range.
- Return
True if
pis contained in this range (inclusive)- Parameters
p: Point
-
inline bool
isIntersecting(const Range &o) const Check if other range intersects this range.
- Return
True if
ointersects this range- Parameters
o: Other range
-
inline Range
getIntersection(const Range &o) const Get intersection subspace.
- Return
New range for intersection
- Parameters
o: Other range
-
inline bool
operator==(const Range &o) const Check if other range is equal to this range.
- Parameters
o: Other range
-
inline bool
operator!=(const Range &o) const Check if other range is not equal to this range.
- Parameters
o: Other range
Stencil.h¶
-
template<size_t
DIM>
classCubism::Core::Stencil Describes a stencil.
- Template Parameters
DIM: Stencil dimensionality
Public Functions
-
inline
Stencil() Default constructor.
-
inline
Stencil(const DataType b, const DataType e, const bool tensorial = false) Main constructor.
A symmetric stencil from -1 to +1 is constructed by
Stencil(-1,2). The stencil end is exclusive.- Parameters
b: Begin of stencile: End of stenciltensorial: Flag for tensorial stencil type
-
inline
Stencil(const PointType &b, const PointType &e, const bool tensorial = false) Main constructor.
An arbitrary stencil in 2D may be constructed as follows
Stencil<2>({-1, -2}, {1, 3}). The stencil end is exclusive.- Parameters
b: Begin of stencile: End of stenciltensorial: Flag for tensorial stencil type
-
inline MultiIndex
getBegin() const Get stencil begin.
The stencil begin is inclusive.
- Return
Multi-dimensional index of stencil begin
-
inline MultiIndex
getEnd() const Get stencil end.
The stencil end is exclusive.
- Return
Multi-dimensional index of stencil end
-
inline bool
isTensorial() const Check if stencil is tensorial.
Tensorial stencils take into account edge and corner ghosts. A non-tensorial stencil accounts for face ghosts only.
- Return
True if tensorial
Vector.h¶
-
template<typename
T, size_tDIM>
classCubism::Core::Vector Vector class with support for common operations.
Wraps around
std::array. The data typeTmust follow the rules of aggregate initialization. The vector dimensionDIMshould be low-dimensional when used for automatic variables on the stack.- Template Parameters
T: Data typeDIM: Dimension
Public Functions
-
inline
Vector() Default constructor.
All elements are initialized to
0.
-
inline
Vector(const Vector &c) noexcept Default copy constructor.
-
inline
Vector(Vector &&c) noexcept Default move constructor (linear complexity)
-
inline
Vector(const ArrayType &ary) Copy constructor.
Initialize data from
std::arrayof same type
-
inline
Vector(ArrayType &&ary) noexcept Move constructor.
Initialize data from
std::arrayof same type (linear complexity)
-
template<typename
U, size_tDIMU>
inlineVector(const Vector<U, DIMU> &c) Constructor for arbitrary Vector types.
The type
Umust define a cast toDataType.- Template Parameters
U: Scalar typeDIMU: Vector dimension
- Parameters
c: Initial values
-
template<typename
U>
inline explicitVector(const U scalar) Constructor for any scalar type
U.The type
Umust define a cast toDataType.- Template Parameters
U: Scalar type
- Parameters
scalar: Initialization value
-
template<typename
U>
inlineVector(std::initializer_list<U> ilist) Constructor for arbitrary list initialization.
The type
Umust define a cast toDataType.- Template Parameters
U: Scalar type
- Parameters
ilist: Initializer list
-
template<typename
U>
inlineVector(const std::vector<U> &vec) Constructor to initialize data from
std::vectorThe type
Umust define a cast toDataType.- Template Parameters
U: Scalar type
- Parameters
vec: Initializer vector
-
template<typename
U, size_tDIMU>
inlineVector(const std::array<U, DIMU> &ary) Constructor to initialize data from arbitrary
std::arrayThe type
Umust define a cast toDataType. IfDIMU > DIMonly the firstDIMelements will be copied. IfDIMU < DIMthe missing elements will be initialized to zero.- Template Parameters
U: Scalar typeDIMU: Array dimension
- Parameters
ary: Initializer array
-
template<typename
U>
inline explicitVector(const U *ptr, size_t n) Constructor to initialize data from arbitrary pointer.
The type
Umust define a cast toDataType. Ifn > DIMonly the firstDIMelements will be copied. Ifn < DIMthe missing elements will be initialized to zero.- Template Parameters
U: Scalar type
- Parameters
ptr: Pointer to first elementn: Number of elements to copy
-
~Vector() = default Default destructor.
-
inline Vector &
operator=(const ArrayType &ary) Copy assignment operator.
-
inline Vector &
operator=(ArrayType &&ary) Move assignment operator (linear complexity)
-
inline Vector &
operator=(const DataType c) Copy assignment operator for scalar c.
-
template<typename
U, size_tDIMU>
inline Vector &operator=(const Vector<U, DIMU> &c) Copy assignment operator for any other Vector type.
The type
Umust define a cast toDataType. IfDIMU > DIMonly the firstDIMelements will be copied. IfDIMU < DIMthe missing elements in this vector will not be modified.- Template Parameters
U: Scalar typeDIMU: Vector dimension
- Parameters
c: Source vector
-
inline void
swap(Vector &other) noexcept Swap this vector with other vector.
-
inline size_t
size() const Size of vector.
- Return
Size of vector (static)
-
inline DataType *
data() Get pointer to raw data.
- Return
Pointer to first element
-
inline const DataType *
data() const Get pointer to raw data.
- Return
constpointer to first element
-
inline ArrayType &
getArray() Get underlying array.
- Return
std::array
-
inline const ArrayType &
getArray() const Get underlying array.
- Return
const std::array
-
inline DataType &
operator[](const size_t i) Data access interface.
- Return
Reference to element
- Parameters
i: Vector element
-
inline const DataType &
operator[](const size_t i) const Data access interface.
- Return
constreference to element- Parameters
i: Vector element
-
inline explicit
operator ArrayType() const Cast operator.
Cast to
std::array
-
inline explicit
operator DataType*() Cast operator.
Cast to pointer pointing to the first array element
-
inline bool
operator==(const Vector &other) const Equality operator.
A Vector is equal to another if they are equal component-wise.
-
inline bool
operator<(const Vector &other) const Less than operator.
A Vector is smaller than another if all components are less than the corresponding components of the other Vector.
-
inline bool
operator>(const Vector &other) const Greater than operator.
A Vector is larger than another if all components are greater than the corresponding components of the other Vector.
-
inline bool
operator<=(const Vector &other) const Less-equal than operator.
A Vector is smaller or equal than another if all components are less or equal than the corresponding components of the other Vector.
-
inline bool
operator>=(const Vector &other) const Greater-equal than operator.
A Vector is larger or equal than another if all components are greater or equal than the corresponding components of the other Vector.
-
inline bool
lexLT(const Vector &other) const Lexicographic less-than.
Identical to
std::array
-
inline bool
lexLE(const Vector &other) const Lexicographic less-equal.
Identical to
std::array
-
inline bool
lexGT(const Vector &other) const Lexicographic greater-than.
Identical to
std::array
-
inline bool
lexGE(const Vector &other) const Lexicographic greater-equal.
Identical to
std::array
-
inline DataType
normsq() const Squared Euclidean vector norm.
-
inline DataType
norm() const Euclidean vector norm (L2)
-
inline DataType
normL2() const Vector L2 norm (alias for
norm())
-
inline DataType
normL1() const Vector L1 norm.
-
inline DataType
normLinf() const Vector maximum norm.
-
inline Vector
unit() const Unit vector.
-
inline DataType
dot(const Vector &other) const Vector dot product.
-
inline DataType
getCrossThird(const Vector &other) const Third component of vector cross-product.
-
inline DataType
distsq(Vector other) const Squared distance between this and other vector.
-
inline DataType
dist(Vector other) const Distance between this and other vector.
-
inline DataType
sum() const Sum of vector components.
-
inline DataType
prod() const Product of vector components.
-
inline DataType
min() const Minimum vector component.
-
inline DataType
max() const Maximum vector component.
-
inline size_t
argmin() const Index of minimum component.
-
inline size_t
argmax() const Index of maximum component.
-
inline Vector
abs() const Absolute value.
- Return
Absolute copy of this vector