22 friend auto abs(
const T& t);
26 friend constexpr T
min(
const T& t1,
const T& t2);
28 friend constexpr T
max(
const T& t1,
const T& t2);
32 friend constexpr
auto less(
const T& t1,
const T& t2);
90 m =
Vector(v0[0], v1[1], v0[1], v0[2]);
115 return Vector(m[M00], m[M01], m[M02]);
117 return Vector(m[M01], m[M11], m12);
119 return Vector(m[M02], m12, -m[M00] - m[M11]);
127 return Vector(m[M00], m[M11], -m[M00] - m[M11]);
132 return Vector(m[M01], m[M02], m12);
140 if (rowIdx == colIdx) {
149 const int sum = rowIdx + colIdx;
160 return Vector(m[M00] * v[0] + m[M01] * v[1] + m[M02] * v[2],
161 m[M01] * v[0] + m[M11] * v[1] + m12 * v[2],
162 m[M02] * v[0] + m12 * v[1] + (-m[M00] - m[M11]) * v[2]);
219 return m == other.m && m12 == other.m12;
231 return m != other.m || m12 != other.m12;
248 stream << std::setprecision(6) << std::setw(20) << t(0, 0) << std::setw(20) << t(1, 1)
249 << std::setw(20) << t(0, 1) << std::setw(20) << t(0, 2) << std::setw(20) << t(1, 2);
299 const Float vectorMin =
min(
min(t.m[0], t.m[1]),
min(t.m[2], t.m[3]));
300 const Float result =
min(vectorMin, t.m12, -t.m[0] - t.m[1]);
309 const Float vectorMax =
max(
max(t.m[0], t.m[1]),
max(t.m[2], t.m[3]));
310 const Float result =
max(vectorMax, t.m12, -t.m[0] - t.m[1]);
389 return { t(0, 0), t(1, 1), t(2, 2), t(0, 1), t(0, 2), t(1, 2) };
#define SPH_ASSERT(x,...)
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Basic algebra for symmetric 2nd order tensors.
INLINE Pair< TracelessTensor > clampWithDerivative(const TracelessTensor &v, const TracelessTensor &dv, const Interval &range)
INLINE bool isReal(const TracelessTensor &t)
INLINE TracelessTensor sqrtInv(const TracelessTensor &)
INLINE TracelessTensor clamp(const TracelessTensor &t, const Interval &range)
Clamps components of the traceless tensor.
INLINE TracelessTensor convert(const AffineMatrix &m)
INLINE Float maxElement(const TracelessTensor &t)
Returns the maximal component of the traceless tensor.
INLINE Float norm(const TracelessTensor &t)
Arbitrary norm of the tensor.
INLINE Float normSqr(const TracelessTensor &t)
Arbitrary squared norm of the tensor.
INLINE Float ddot(const TracelessTensor &t1, const SymmetricTensor &t2)
Double-dot product t1 : t2 = sum_ij t1_ij t2_ij.
INLINE auto abs(const TracelessTensor &t)
Returns the tensor of absolute values form traceless tensor elements.
INLINE TracelessTensor max(const TracelessTensor &t1, const TracelessTensor &t2)
Component-wise maximum of two tensors.
INLINE Float minElement(const TracelessTensor &t)
Returns the minimal component of the traceless tensor.
INLINE auto less(const TracelessTensor &t1, const TracelessTensor &t2)
INLINE StaticArray< Float, 6 > getComponents(const TracelessTensor &t)
INLINE bool almostEqual(const TracelessTensor &t1, const TracelessTensor &t2, const Float eps=EPS)
Checks if two tensors are equal to some given accuracy.
INLINE TracelessTensor min(const TracelessTensor &t1, const TracelessTensor &t2)
Component-wise minimum of two tensors.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
BasicVector< Float > Vector
INLINE float dot(const BasicVector< float > &v1, const BasicVector< float > &v2)
Make sure the vector is trivially constructible and destructible, needed for fast initialization of a...
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float upper() const
Returns upper bound of the interval.
Array with fixed number of allocated elements.
Symmetric tensor of 2nd order.
INLINE const Vector & offDiagonal() const
Returns the off-diagonal elements of the tensor.
INLINE Float trace() const
Return the trace of the tensor.
static INLINE SymmetricTensor identity()
Returns an identity tensor.
INLINE const Vector & diagonal() const
Returns the diagonal part of the tensor.
Symmetric traceless 2nd order tensor.
INLINE TracelessTensor & operator=(const SymmetricTensor &other)
constexpr friend T min(const T &t1, const T &t2)
Minimum & Maximum value.
constexpr friend T max(const T &t1, const T &t2)
INLINE Vector row(const int idx) const
Returns a row of the matrix.
friend Float maxElement(const T &t)
Returns maximum element, simply the value iself by default.
friend std::ostream & operator<<(std::ostream &stream, const TracelessTensor &t)
INLINE TracelessTensor operator-() const
INLINE TracelessTensor & operator/=(const Float value)
INLINE TracelessTensor & operator=(const TracelessTensor &other)
friend T sqrtInv(const T &t)
INLINE Float operator()(const int rowIdx, const int colIdx) const
Returns a given element of the matrix.
INLINE TracelessTensor(const Float xx, const Float yy, const Float xy, const Float xz, const Float yz)
Initialize tensor given 5 independent components.
INLINE TracelessTensor & operator-=(const TracelessTensor &other)
INLINE friend bool operator==(const SymmetricTensor &t1, const TracelessTensor &t2)
INLINE friend bool operator!=(const SymmetricTensor &t1, const TracelessTensor &t2)
friend auto abs(const T &t)
INLINE friend TracelessTensor operator-(const TracelessTensor &t1, const TracelessTensor &t2)
INLINE TracelessTensor & operator*=(const Float value)
INLINE friend TracelessTensor operator*(const Float v, const TracelessTensor &t)
INLINE Vector operator*(const Vector &v) const
Applies the tensor on given vector.
INLINE TracelessTensor(const TracelessTensor &other)=default
INLINE friend TracelessTensor operator*(const TracelessTensor &t, const Float v)
Multiplies the tensor by a scalar.
INLINE TracelessTensor(const SymmetricTensor &other)
Construct traceless tensor using other tensor (not traceless in general).
INLINE Vector offDiagonal() const
Returns off-diagonal elements of the matrix.
INLINE Vector diagonal() const
Returns diagonal of the matrix.
INLINE TracelessTensor(const Float value)
Initialize all components of the tensor to given value, excluding last element of the diagonal,...
friend Float minElement(const T &t)
Returns minimum element, simply the value iself by default.
INLINE friend bool operator!=(const TracelessTensor &t1, const SymmetricTensor &t2)
INLINE bool operator!=(const TracelessTensor &other) const
INLINE friend TracelessTensor operator/(const TracelessTensor &t, const Float v)
Divides a tensor by a scalar.
INLINE friend TracelessTensor operator+(const TracelessTensor &t1, const TracelessTensor &t2)
INLINE TracelessTensor & operator+=(const TracelessTensor &other)
INLINE TracelessTensor(const Vector &v0, const Vector &v1, const Vector &v2)
Construct tensor given three vectors as rows.
INLINE friend bool operator==(const TracelessTensor &t1, const SymmetricTensor &t2)
constexpr friend auto less(const T &t1, const T &t2)
Compares two objects of the same time component-wise.
friend T clamp(const T &t, const Interval &range)
INLINE TracelessTensor()=default
INLINE bool operator==(const TracelessTensor &other) const