SOFA API  1df67014
Open source framework for multi-physics simuation
sofa::type::MatSym< D, real > Class Template Reference

#include <MatSym.h>

Inheritance diagram for sofa::type::MatSym< D, real >:

Detailed Description

template<sofa::Size D, class real = SReal>
class sofa::type::MatSym< D, real >

Dense symmetric matrix of size DxD storing only D*(D+1)/2 values

Template Parameters
DSize of the matrix
realType of scalar

Static Public Attributes

static constexpr auto NumberStoredValues = D * (D + 1) / 2
 
- Static Public Attributes inherited from sofa::type::Vec< N, ValueType >
static constexpr sofa::Size static_size = N
 
static constexpr Size total_size = N
 Compile-time constant specifying the number of scalars within this vector (equivalent to static_size and size() method) More...
 
static constexpr Size spatial_dimensions = N
 Compile-time constant specifying the number of dimensions of space (equivalent to total_size here) More...
 

Public Member Functions

constexpr MatSym () noexcept
 
constexpr MatSym (NoInit) noexcept
 
template<sofa::Size TD = D, typename = std::enable_if_t<TD == 3>>
constexpr MatSym (const real &v1, const real &v2, const real &v3, const real &v4, const real &v5, const real &v6)
 Constructor from 6 elements. More...
 
constexpr MatSym (const sofa::Size sizeM, const real &v)
 Constructor from an element. More...
 
template<typename real2 >
 MatSym (const MatSym< D, real2 > &m)
 Constructor from another matrix. More...
 
template<typename real2 >
void operator= (const MatSym< D, real2 > &m)
 Assignment from another matrix. More...
 
void clear ()
 Sets each element to 0. More...
 
void fill (real r)
 Sets each element to r. More...
 
real & operator() (const int i, const int j)
 Write access to element (i,j). More...
 
const real & operator() (const int i, const int j) const
 Read-only access to element (i,j). More...
 
template<sofa::Size TD = D, typename = std::enable_if_t<TD == 3 || TD == 2>>
Vec< NumberStoredValues, real > getVoigt () const
 convert to Voigt notation (supported only for D == 2 and D == 3) More...
 
constexpr void identity ()
 Set matrix to identity. More...
 
Mat< D, D, real > SymSymMultiply (const MatSym< D, real > &m) const
 Matrix multiplication operator: product of two symmetric matrices. More...
 
Mat< D, D, real > operator* (const MatSym< D, real > &m) const
 
Mat< D, D, real > SymMatMultiply (const Mat< D, D, real > &m) const
 
Mat< D, D, real > operator* (const Mat< D, D, real > &m) const
 
Mat< D, D, real > MatSymMultiply (const Mat< D, D, real > &m) const
 
MatSym< D, real > operator+ (const MatSym< D, real > &m) const
 Matrix addition operator with a symmetric matrix. More...
 
Mat< D, D, real > operator+ (const Mat< D, D, real > &m) const
 Matrix addition operator with a non-symmetric matrix. More...
 
MatSym< D, real > operator- (const MatSym< D, real > &m) const
 Matrix substractor operator with a symmetric matrix. More...
 
Mat< D, D, real > operator- (const Mat< D, D, real > &m) const
 Matrix substractor operator with a non-symmetric matrix. More...
 
Coord operator* (const Coord &v) const
 Multiplication operator Matrix * Vector. More...
 
MatSym< D, real > operator* (real f) const
 Scalar multiplication operator. More...
 
MatSym< D, real > operator/ (real f) const
 Scalar division operator. More...
 
void operator*= (real r)
 Scalar multiplication assignment operator. More...
 
void operator/= (real r)
 Scalar division assignment operator. More...
 
void operator+= (const MatSym< D, real > &m)
 Addition assignment operator. More...
 
void operator-= (const MatSym< D, real > &m)
 Substraction assignment operator. More...
 
bool invert (const MatSym< D, real > &m)
 Invert matrix m. More...
 
Tests operators
bool operator== (const MatSym< D, real > &b) const
 
bool operator!= (const MatSym< D, real > &b) const
 
- Public Member Functions inherited from sofa::type::VecNoInit< D *(D+1)/2, SReal >
constexpr VecNoInit () noexcept
 
constexpr VecNoInit (const Vec< N, SReal > &v) noexcept
 
constexpr VecNoInit (Vec< N, SReal > &&v) noexcept
 
- Public Member Functions inherited from sofa::type::Vec< N, ValueType >
constexpr Vec ()=default
 Default constructor: sets all values to 0. More...
 
constexpr Vec (NoInit)
 Fast constructor: no initialization. More...
 
template<Size NN = N, typename std::enable_if< NN==1, int >::type = 0>
constexpr Vec (const ValueType r1) noexcept
 Specific constructor for 1-element vectors. More...
 
template<typename... ArgsT, typename = std::enable_if_t< (std::is_convertible_v<ArgsT, ValueType> && ...) >, typename = std::enable_if_t< (sizeof...(ArgsT) == N && sizeof...(ArgsT) > 1) >>
constexpr Vec (ArgsT &&... r) noexcept
 
template<typename R , typename T , Size NN = N, typename std::enable_if< NN==6, int >::type = 0>
 Vec (const Vec< 3, R > &a, const Vec< 3, T > &b)
 Specific constructor for 6-elements vectors, taking two 3-elements vectors. More...
 
template<Size NN = N, typename std::enable_if< NN==1, int >::type = 0>
constexpr void set (const ValueType r1) noexcept
 Specific set function for 1-element vectors. More...
 
template<typename... ArgsT, typename = std::enable_if_t< (std::is_convertible_v<ArgsT, ValueType> && ...) >, typename = std::enable_if_t< (sizeof...(ArgsT) == N && sizeof...(ArgsT) > 1) >>
constexpr void set (const ArgsT... r) noexcept
 
template<Size N2, class real2 >
constexpr void set (const Vec< N2, real2 > &v, ValueType defaultvalue=0) noexcept
 Specific set from a different size vector (given default value and ignored outside entries) More...
 
template<Size NN = N, typename std::enable_if<(NN >1), int >::type = 0>
constexpr Vec (const Vec< N-1, ValueType > &v, ValueType r1) noexcept
 Constructor from an N-1 elements vector and an additional value (added at the end). More...
 
constexpr Vec (const sofa::type::fixed_array< ValueType, N > &p) noexcept
 
template<Size N2, typename real2 >
constexpr Vec (const Vec< N2, real2 > &v) noexcept
 Constructor from a different size vector (null default value and ignoring outside entries) More...
 
template<typename real2 >
constexpr Vec (const Vec< N, real2 > &p) noexcept
 
template<typename real2 >
constexpr Vec (const real2 *p) noexcept
 Constructor from an array of values. More...
 
template<Size NN = N, typename std::enable_if<(NN >=1), int >::type = 0>
constexpr ValueType & x () noexcept
 Special access to first element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=2), int >::type = 0>
constexpr ValueType & y () noexcept
 Special access to second element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=3), int >::type = 0>
constexpr ValueType & z () noexcept
 Special access to third element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=4), int >::type = 0>
constexpr ValueType & w () noexcept
 Special access to fourth element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=1), int >::type = 0>
constexpr const ValueType & x () const noexcept
 Special const access to first element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=2), int >::type = 0>
constexpr const ValueType & y () const noexcept
 Special const access to second element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=3), int >::type = 0>
constexpr const ValueType & z () const noexcept
 Special const access to third element. More...
 
template<Size NN = N, typename std::enable_if<(NN >=4), int >::type = 0>
constexpr const ValueType & w () const noexcept
 Special const access to fourth element. More...
 
template<Size NN = N, typename std::enable_if< NN==1, int >::type = 0>
constexpr void operator= (const ValueType r1) noexcept
 Specific Assignment operator for 1-element vectors. More...
 
template<typename real2 >
constexpr void operator= (const real2 *p) noexcept
 Assignment operator from an array of values. More...
 
template<Size M, typename real2 >
constexpr void operator= (const Vec< M, real2 > &v) noexcept
 Assignment from a vector with different dimensions. More...
 
constexpr void assign (const ValueType &value) noexcept
 
constexpr void clear () noexcept
 Sets every element to 0. More...
 
constexpr void fill (ValueType r) noexcept
 Sets every element to r. More...
 
constexpr ValueType & operator() (Size i) noexcept
 Access to i-th element. More...
 
constexpr const ValueType & operator() (Size i) const noexcept
 Const access to i-th element. More...
 
constexpr const ValueType * ptr () const noexcept
 Cast into a const array of values. More...
 
constexpr ValueType * ptr () noexcept
 Cast into an array of values. More...
 
template<Size N2, std::enable_if_t<(N2< N), bool > = true>
constexpr void getsub (const Size i, Vec< N2, ValueType > &m) const noexcept
 
constexpr void getsub (const Size i, ValueType &m) const noexcept
 
constexpr Vec< N, ValueType > mulscalar (const ValueType f) const noexcept
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > mulscalar (const real2 f) const noexcept
 Multiplication by a scalar f. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > operator* (const real2 f) const noexcept
 
constexpr void eqmulscalar (const ValueType f) noexcept
 In-place multiplication by a scalar f. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void eqmulscalar (const real2 f) noexcept
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void operator*= (const real2 f) noexcept
 
constexpr Vec< N, ValueType > divscalar (const ValueType f) const noexcept
 Division by a scalar f. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > divscalar (const real2 f) const noexcept
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > operator/ (const real2 f) const noexcept
 
constexpr void eqdivscalar (const ValueType f) noexcept
 In-place division by a scalar f. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void eqdivscalar (const real2 f) noexcept
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void operator/= (const real2 f) noexcept
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr ValueType operator* (const Vec< N, real2 > &v) const noexcept
 Dot product. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > linearProduct (const Vec< N, real2 > &v) const noexcept
 linear product. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > linearDivision (const Vec< N, real2 > &v) const noexcept
 linear division. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > operator+ (const Vec< N, real2 > &v) const noexcept
 Vector addition. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void operator+= (const Vec< N, real2 > &v) noexcept
 In-place vector addition. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr Vec< N, ValueType > operator- (const Vec< N, real2 > &v) const noexcept
 Vector subtraction. More...
 
template<class real2 , std::enable_if_t< std::is_convertible_v< real2, ValueType >, bool > = true>
constexpr void operator-= (const Vec< N, real2 > &v) noexcept
 In-place vector subtraction. More...
 
template<typename T = ValueType, std::enable_if_t< !std::is_unsigned_v< T >, int > = 0>
constexpr Vec< N, ValueType > operator- () const noexcept
 Vector negation. More...
 
constexpr ValueType norm2 () const noexcept
 Squared norm. More...
 
ValueType norm () const noexcept
 Euclidean norm. More...
 
ValueType lNorm (int l) const
 
constexpr bool normalizeWithNorm (ValueType norm, ValueType threshold=std::numeric_limits< ValueType >::epsilon()) noexcept
 
bool normalize (ValueType threshold=std::numeric_limits< ValueType >::epsilon()) noexcept
 
void normalize (Vec< N, ValueType > failsafe, ValueType threshold=std::numeric_limits< ValueType >::epsilon()) noexcept
 
Vec< N, ValueType > normalized () const noexcept
 
bool isNormalized (ValueType threshold=std::numeric_limits< ValueType >::epsilon() *(ValueType) 10) const
 return true if norm()==1 More...
 
template<typename R , Size NN = N, typename std::enable_if<(NN==3), int >::type = 0>
constexpr Vec cross (const Vec< 3, R > &b) const noexcept
 
constexpr ValueType sum () const noexcept
 sum of all elements of the vector More...
 
constexpr bool operator== (const Vec &b) const noexcept
 
constexpr bool operator!= (const Vec &b) const noexcept
 
constexpr reference operator[] (size_type i)
 
constexpr const_reference operator[] (size_type i) const
 
constexpr const ValueType * data () const noexcept
 
constexpr iterator begin () noexcept
 
constexpr const_iterator begin () const noexcept
 
constexpr iterator end () noexcept
 
constexpr const_iterator end () const noexcept
 
constexpr reference front ()
 
constexpr const_reference front () const
 
constexpr reference back ()
 
constexpr const_reference back () const
 

Static Public Member Functions

static void Mat2Sym (const Mat< D, D, real > &M, MatSym< D, real > &W)
 convert matrix to sym More...
 
- Static Public Member Functions inherited from sofa::type::Vec< N, ValueType >
static constexpr sofa::Size size ()
 

Friends

MatSym< D, real > operator* (real r, const MatSym< D, real > &m)
 Scalar matrix multiplication operator. More...
 

Additional Inherited Members

- Public Attributes inherited from sofa::type::Vec< N, ValueType >
ArrayType elems {}
 

Attribute details

◆ NumberStoredValues

template<sofa::Size D, class real = SReal>
constexpr auto sofa::type::MatSym< D, real >::NumberStoredValues = D * (D + 1) / 2
staticconstexpr

Constructor details

◆ MatSym() [1/5]

template<sofa::Size D, class real = SReal>
constexpr sofa::type::MatSym< D, real >::MatSym ( )
inlineconstexprnoexcept

◆ MatSym() [2/5]

template<sofa::Size D, class real = SReal>
constexpr sofa::type::MatSym< D, real >::MatSym ( NoInit  )
inlineexplicitconstexprnoexcept

◆ MatSym() [3/5]

template<sofa::Size D, class real = SReal>
template<sofa::Size TD = D, typename = std::enable_if_t<TD == 3>>
constexpr sofa::type::MatSym< D, real >::MatSym ( const real &  v1,
const real &  v2,
const real &  v3,
const real &  v4,
const real &  v5,
const real &  v6 
)
inlineconstexpr

Constructor from 6 elements.

◆ MatSym() [4/5]

template<sofa::Size D, class real = SReal>
constexpr sofa::type::MatSym< D, real >::MatSym ( const sofa::Size  sizeM,
const real &  v 
)
inlineconstexpr

Constructor from an element.

◆ MatSym() [5/5]

template<sofa::Size D, class real = SReal>
template<typename real2 >
sofa::type::MatSym< D, real >::MatSym ( const MatSym< D, real2 > &  m)
inlineexplicit

Constructor from another matrix.

Function details

◆ clear()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::clear ( )
inline

Sets each element to 0.

◆ fill()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::fill ( real  r)
inline

Sets each element to r.

◆ getVoigt()

template<sofa::Size D, class real = SReal>
template<sofa::Size TD = D, typename = std::enable_if_t<TD == 3 || TD == 2>>
Vec<NumberStoredValues, real> sofa::type::MatSym< D, real >::getVoigt ( ) const
inline

convert to Voigt notation (supported only for D == 2 and D == 3)

◆ identity()

template<sofa::Size D, class real = SReal>
constexpr void sofa::type::MatSym< D, real >::identity ( )
inlineconstexpr

Set matrix to identity.

◆ invert()

template<sofa::Size D, class real = SReal>
bool sofa::type::MatSym< D, real >::invert ( const MatSym< D, real > &  m)
inline

Invert matrix m.

◆ Mat2Sym()

template<sofa::Size D, class real = SReal>
static void sofa::type::MatSym< D, real >::Mat2Sym ( const Mat< D, D, real > &  M,
MatSym< D, real > &  W 
)
inlinestatic

convert matrix to sym

◆ MatSymMultiply()

template<sofa::Size D, class real = SReal>
Mat<D, D, real> sofa::type::MatSym< D, real >::MatSymMultiply ( const Mat< D, D, real > &  m) const
inline

◆ operator!=()

template<sofa::Size D, class real = SReal>
bool sofa::type::MatSym< D, real >::operator!= ( const MatSym< D, real > &  b) const
inline

◆ operator()() [1/2]

template<sofa::Size D, class real = SReal>
real& sofa::type::MatSym< D, real >::operator() ( const int  i,
const int  j 
)
inline

Write access to element (i,j).

◆ operator()() [2/2]

template<sofa::Size D, class real = SReal>
const real& sofa::type::MatSym< D, real >::operator() ( const int  i,
const int  j 
) const
inline

Read-only access to element (i,j).

◆ operator*() [1/4]

template<sofa::Size D, class real = SReal>
Coord sofa::type::MatSym< D, real >::operator* ( const Coord v) const
inline

Multiplication operator Matrix * Vector.

◆ operator*() [2/4]

template<sofa::Size D, class real = SReal>
Mat<D,D,real> sofa::type::MatSym< D, real >::operator* ( const Mat< D, D, real > &  m) const
inline

◆ operator*() [3/4]

template<sofa::Size D, class real = SReal>
Mat<D, D, real> sofa::type::MatSym< D, real >::operator* ( const MatSym< D, real > &  m) const
inline

◆ operator*() [4/4]

template<sofa::Size D, class real = SReal>
MatSym<D, real> sofa::type::MatSym< D, real >::operator* ( real  f) const
inline

Scalar multiplication operator.

◆ operator*=()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::operator*= ( real  r)
inline

Scalar multiplication assignment operator.

◆ operator+() [1/2]

template<sofa::Size D, class real = SReal>
Mat<D, D, real> sofa::type::MatSym< D, real >::operator+ ( const Mat< D, D, real > &  m) const
inline

Matrix addition operator with a non-symmetric matrix.

◆ operator+() [2/2]

template<sofa::Size D, class real = SReal>
MatSym<D, real> sofa::type::MatSym< D, real >::operator+ ( const MatSym< D, real > &  m) const
inline

Matrix addition operator with a symmetric matrix.

◆ operator+=()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::operator+= ( const MatSym< D, real > &  m)
inline

Addition assignment operator.

◆ operator-() [1/2]

template<sofa::Size D, class real = SReal>
Mat<D, D, real> sofa::type::MatSym< D, real >::operator- ( const Mat< D, D, real > &  m) const
inline

Matrix substractor operator with a non-symmetric matrix.

◆ operator-() [2/2]

template<sofa::Size D, class real = SReal>
MatSym<D, real> sofa::type::MatSym< D, real >::operator- ( const MatSym< D, real > &  m) const
inline

Matrix substractor operator with a symmetric matrix.

◆ operator-=()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::operator-= ( const MatSym< D, real > &  m)
inline

Substraction assignment operator.

◆ operator/()

template<sofa::Size D, class real = SReal>
MatSym<D, real> sofa::type::MatSym< D, real >::operator/ ( real  f) const
inline

Scalar division operator.

◆ operator/=()

template<sofa::Size D, class real = SReal>
void sofa::type::MatSym< D, real >::operator/= ( real  r)
inline

Scalar division assignment operator.

◆ operator=()

template<sofa::Size D, class real = SReal>
template<typename real2 >
void sofa::type::MatSym< D, real >::operator= ( const MatSym< D, real2 > &  m)
inline

Assignment from another matrix.

◆ operator==()

template<sofa::Size D, class real = SReal>
bool sofa::type::MatSym< D, real >::operator== ( const MatSym< D, real > &  b) const
inline

◆ SymMatMultiply()

template<sofa::Size D, class real = SReal>
Mat<D,D,real> sofa::type::MatSym< D, real >::SymMatMultiply ( const Mat< D, D, real > &  m) const
inline

◆ SymSymMultiply()

template<sofa::Size D, class real = SReal>
Mat<D, D, real> sofa::type::MatSym< D, real >::SymSymMultiply ( const MatSym< D, real > &  m) const
inline

Matrix multiplication operator: product of two symmetric matrices.

Related details

◆ operator*

template<sofa::Size D, class real = SReal>
MatSym<D, real> operator* ( real  r,
const MatSym< D, real > &  m 
)
friend

Scalar matrix multiplication operator.