48 diag =
Vector(v0[0], v1[1], v2[2]);
49 off =
Vector(v0[1], v0[2], v1[2]);
63 return Vector(diag[0], off[0], off[1]);
65 return Vector(off[0], diag[1], off[2]);
67 return Vector(off[1], off[2], diag[2]);
75 if (rowIdx == colIdx) {
78 return off[rowIdx + colIdx - 1];
84 if (rowIdx == colIdx) {
87 return off[rowIdx + colIdx - 1];
104 return Vector(diag[0] * v[0] + off[0] * v[1] + off[1] * v[2],
105 off[0] * v[0] + diag[1] * v[1] + off[2] * v[2],
106 off[1] * v[0] + off[2] * v[1] + diag[2] * v[2]);
175 return diag == other.diag && off == other.off;
179 return diag != other.diag || off != other.off;
194 return diag[0] * diag[1] * diag[2] + 2 * off[0] * off[1] * off[2] -
211 return getSqrLength(off) - (diag[1] * diag[2] + diag[2] * diag[0] + diag[0] * diag[1]);
224 invDiag[0] = diag[1] * diag[2] -
sqr(off[2]);
225 invDiag[1] = diag[2] * diag[0] -
sqr(off[1]);
226 invDiag[2] = diag[0] * diag[1] -
sqr(off[0]);
227 invOff[0] = off[1] * off[2] - diag[2] * off[0];
228 invOff[1] = off[2] * off[0] - diag[1] * off[1];
229 invOff[2] = off[0] * off[1] - diag[0] * off[2];
248 0.5_f *
Vector(transformed(0, 1) + transformed(1, 0),
249 transformed(0, 2) + transformed(2, 0),
250 transformed(1, 2) + transformed(2, 1)));
253 template <
typename T1,
typename T2>
259 almostEqual(matrix(0, 2), matrix(2, 0), 1.e-6_f) &&
262 Vector(matrix(0, 0), matrix(1, 1), matrix(2, 2)),
Vector(matrix(0, 1), matrix(0, 2), matrix(1, 2)));
350 return { t(0, 0), t(1, 1), t(2, 2), t(0, 1), t(0, 2), t(1, 2) };
364 0.5_f *
Vector(v1[0] * v2[1] + v1[1] * v2[0],
365 v1[0] * v2[2] + v1[2] * v2[0],
366 v1[1] * v2[2] + v1[2] * v2[1]));
373 return { 0._f, 0._f, 0._f };
379 const Float a = q - p * p / 3._f;
380 const Float b = (2._f *
pow<3>(p) - 9._f * p * q + 27._f * r) / 27._f;
382 if (0.25_f * b * b + aCub >= 0._f) {
383 return { 0._f, 0._f, 0._f };
388 const Vector v(phi / 3._f, (phi + 2 *
PI) / 3._f, (phi + 4 *
PI) / 3._f);
390 return { sig[0] * n, sig[1] * n, sig[2] * n };
Three-dimensional affine matrix.
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
constexpr INLINE T sqr(const T &f) noexcept
Return a squared value.
INLINE T sqrt(const T f)
Return a squared root of a value.
constexpr INLINE Float pow< 3 >(const Float v)
constexpr Float PI
Mathematical constants.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
INLINE SymmetricTensor symmetricOuter(const Vector &v1, const Vector &v2)
SYMMETRIZED outer product of two vectors.
Eigen eigenDecomposition(const SymmetricTensor &t)
Computes eigenvectors and corresponding eigenvalues of symmetric matrix.
INLINE auto less(const SymmetricTensor &t1, const SymmetricTensor &t2)
INLINE SymmetricTensor max(const SymmetricTensor &t1, const SymmetricTensor &t2)
Component-wise maximum of two tensors.
INLINE SymmetricTensor clamp(const SymmetricTensor &t, const Interval &range)
Clamping all components by range.
INLINE bool isReal(const SymmetricTensor &t)
INLINE SymmetricTensor transform(const SymmetricTensor &t, const AffineMatrix &transform)
INLINE StaticArray< Float, 6 > getComponents(const SymmetricTensor &t)
INLINE Float norm(const SymmetricTensor &t)
INLINE Float minElement(const SymmetricTensor &t)
Returns the minimal element of the tensor.
T1 convert(const T2 &matrix)
INLINE auto abs(const SymmetricTensor &t)
Returns the tensor of absolute values.
INLINE bool almostEqual(const SymmetricTensor &t1, const SymmetricTensor &t2, const Float eps=EPS)
Tensor utils.
INLINE Float normSqr(const SymmetricTensor &t)
Arbitrary squared norm of the tensor.
INLINE StaticArray< Float, 3 > findEigenvalues(const SymmetricTensor &t)
Returns three eigenvalue of symmetric matrix.
INLINE Float maxElement(const SymmetricTensor &t)
Returns the maximal element of the tensor.
Svd singularValueDecomposition(const SymmetricTensor &t)
Computes the singular value decomposition of symmetric matrix.
INLINE Float ddot(const SymmetricTensor &t1, const SymmetricTensor &t2)
Double-dot product t1 : t2 = sum_ij t1_ij t2_ij.
INLINE SymmetricTensor min(const SymmetricTensor &t1, const SymmetricTensor &t2)
Component-wise minimum of two tensors.
INLINE Float getSqrLength(const Vector &v)
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.
Array with fixed number of allocated elements.
Symmetric tensor of 2nd order.
INLINE SymmetricTensor & operator-=(const SymmetricTensor &other)
INLINE Float & operator()(const Size rowIdx, const Size colIdx)
Returns a given element of the matrix.
INLINE const Vector & offDiagonal() const
Returns the off-diagonal elements of the tensor.
INLINE Float operator()(const Size rowIdx, const Size colIdx) const
Returns a given element of the matrix, const version.
INLINE SymmetricTensor(const Vector &v0, const Vector &v1, const Vector &v2)
Construct tensor given three vectors as rows.
INLINE friend SymmetricTensor operator-(const SymmetricTensor &t1, const SymmetricTensor &t2)
INLINE Vector operator*(const Vector &v) const
Applies the tensor on given vector.
INLINE bool operator==(const SymmetricTensor &other) const
SymmetricTensor pseudoInverse(const Float eps) const
INLINE SymmetricTensor operator-() const
INLINE friend SymmetricTensor operator/(const SymmetricTensor &t, const Float v)
Divides a tensor by a scalar.
INLINE SymmetricTensor & operator=(const SymmetricTensor &other)
INLINE SymmetricTensor(const Float value)
Initialize all components of the tensor to given value.
INLINE Float invariant() const
Returns n-th invariant of the tensor (1<=n<=3)
friend std::ostream & operator<<(std::ostream &stream, const SymmetricTensor &t)
INLINE friend SymmetricTensor operator*(const SymmetricTensor &t1, const SymmetricTensor &t2)
Multiplies a tensor by another tensor, element-wise. Not a matrix multiplication!
INLINE SymmetricTensor(const Vector &diag, const Vector &off)
Construct tensor given its diagonal vector and a vector of off-diagonal elements (sorted top-bottom a...
INLINE bool operator!=(const SymmetricTensor &other) const
INLINE SymmetricTensor(const SymmetricTensor &other)
INLINE Float trace() const
Return the trace of the tensor.
INLINE friend SymmetricTensor operator*(const Float v, const SymmetricTensor &t)
INLINE SymmetricTensor inverse() const
INLINE friend SymmetricTensor operator*(const SymmetricTensor &t, const Float v)
Multiplies a tensor by a scalar.
INLINE Vector row(const Size idx) const
Returns a row of the matrix.
static INLINE SymmetricTensor identity()
Returns an identity tensor.
INLINE friend SymmetricTensor operator+(const SymmetricTensor &t1, const SymmetricTensor &t2)
Sums up two tensors.
SymmetricTensor()=default
INLINE friend SymmetricTensor operator/(const SymmetricTensor &t1, const SymmetricTensor &t2)
Divides a tensor by another tensor, element-wise.
INLINE Float determinant() const
Returns the determinant of the tensor.
INLINE SymmetricTensor & operator+=(const SymmetricTensor &other)
INLINE SymmetricTensor & operator/=(const Float value)
INLINE SymmetricTensor & operator*=(const Float value)
INLINE const Vector & diagonal() const
Returns the diagonal part of the tensor.
AffineMatrix vectors
Matrix of eigenvectors, stored as rows.
Vector values
Eigenvalues.