Utils API
Helper utilities for common operations. The MPI helper is documented separately in Communication API.
Printing
The print functions can print any combination of arguments of different
types, including entire vectors.
print outputs from the root processor only, so it is the usual
choice for program output, while printAll and printAllPlain
output from every processor, prefixed with the processor rank or not.
-
namespace minim
Vector operations
Element-wise arithmetic between vectors and scalars is provided by
operator overloads, e.g. a + b, a * 2 and a += b all work
as expected for vectors.
The vec namespace contains further vector operations in the style
of NumPy, such as vec::dotProduct, vec::sum, vec::norm and
vec::slice.
Functions
-
template<typename T, typename U>
auto operator+(T a, const vector<U> &b) Element-wise addition of a scalar and a vector.
-
template<typename T, typename U>
auto operator+(const vector<T> &a, U b) Element-wise addition of a vector and a scalar.
-
template<typename T, typename U>
auto operator+(const vector<T> &a, const vector<U> &b) Element-wise addition of two vectors.
-
template<typename T, typename U>
auto &operator+=(vector<T> &a, U b) Add a scalar to each element of the vector.
-
template<typename T, typename U>
auto &operator+=(vector<T> &a, const vector<U> &b) Add the elements of another vector to this one.
-
template<typename T, typename U>
auto operator-(T a, const vector<U> &b) Element-wise subtraction of a vector from a scalar.
-
template<typename T, typename U>
auto operator-(const vector<T> &a, U b) Element-wise subtraction of a scalar from a vector.
-
template<typename T, typename U>
auto operator-(const vector<T> &a, const vector<U> &b) Element-wise subtraction of two vectors.
-
template<typename T, typename U>
auto &operator-=(vector<T> &a, U b) Subtract a scalar from each element of the vector.
-
template<typename T, typename U>
auto &operator-=(vector<T> &a, const vector<U> &b) Subtract the elements of another vector from this one.
-
template<typename T, typename U>
auto operator*(T a, const vector<U> &b) Element-wise multiplication of a scalar and a vector.
-
template<typename T, typename U>
auto operator*(const vector<T> &a, U b) Element-wise multiplication of a vector and a scalar.
-
template<typename T, typename U>
auto operator*(const vector<T> &a, const vector<U> &b) Element-wise multiplication of two vectors.
-
template<typename T, typename U>
auto &operator*=(vector<T> &a, U b) Multiply each element of the vector by a scalar.
-
template<typename T, typename U>
auto &operator*=(vector<T> &a, const vector<U> &b) Multiply the elements of this vector by those of another.
-
template<typename T, typename U>
auto operator/(T a, const vector<U> &b) Element-wise division of a scalar by a vector.
-
template<typename T, typename U>
auto operator/(const vector<T> &a, U b) Element-wise division of a vector by a scalar.
-
template<typename T, typename U>
auto operator/(const vector<T> &a, const vector<U> &b) Element-wise division of two vectors.
-
namespace vec
Vector operations and helpers, in the style of NumPy.
Ranges
The range classes provide iterators over a multi-dimensional grid,
optionally with a halo.
RangeX yields the grid indices at each position, while RangeI
yields the flat index, e.g.:
for (auto x : RangeX({nx, ny}, halo)) {
// x is the vector of grid indices, including the halo
}
RangeX
-
class RangeX
A range over a multi-dimensional grid, yielding the grid indices.
Public Functions
-
inline RangeX(std::vector<int> xSize)
Construct a range over a grid of the given size.
-
inline RangeX(std::vector<int> xSize, int halo)
Construct a range over a grid with a halo of the given width.
-
inline RangeX(std::vector<int> xSize, std::vector<int> xHalo)
Construct a range over a grid with the given halo widths.
-
inline RangeX(std::vector<int> xSize)
RangeI
-
class RangeI
A range over a multi-dimensional grid, yielding the flat index.
Public Functions
-
inline RangeI(std::vector<int> xSize)
Construct a range over a grid of the given size.
-
inline RangeI(std::vector<int> xSize, int halo)
Construct a range over a grid with a halo of the given width.
-
inline RangeI(std::vector<int> xSize, std::vector<int> xHalo)
Construct a range over a grid with the given halo widths.
-
inline RangeI(std::vector<int> xSize)