SOFA API  f82e2e00
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 sofa::Size N = D * D
 
static constexpr Size nbLines = D
 
static constexpr Size nbCols = D
 
static constexpr auto NumberStoredValues = NumberOfIndependentElements<D>
 
static constexpr fixed_array< sofa::Index, 3 *3 > toVoigt = {0, 1, 3, 1, 2, 4, 3, 4, 5}
 
static constexpr fixed_array< std::tuple< sofa::Index, sofa::Index >, 6 > fromVoigt
 
- 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...
 
Mat< D, D, real > toMat () const
 
template<Size D2>
constexpr void getsub (Size a, MatSym< D2, real > &m) const requires(D2<
 
- Public Member Functions inherited from sofa::type::VecNoInit< NumberOfIndependentElements< D >, 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
 
template<std::size_t I>
constexpr reference get () &noexcept requires(I< N)
 
template<std::size_t I>
constexpr const_reference get () const &noexcept requires(I< N)
 
template<std::size_t I>
constexpr ValueType && get () &&noexcept requires(I< N)
 
template<std::size_t I>
constexpr const ValueType && get () const &&noexcept requires(I< N)
 
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 () noexcept
 
constexpr const_reference front () const noexcept
 
constexpr reference back () noexcept
 
constexpr const_reference back () const noexcept
 

Static Public Member Functions

static constexpr sofa::Index voigtID (sofa::Index i, sofa::Index j=0)
 
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 ()
 

Additional Inherited Members

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

Attribute details

◆ fromVoigt

template<sofa::Size D, class real = SReal>
constexpr fixed_array<std::tuple<sofa::Index, sofa::Index>, 6> sofa::type::MatSym< D, real >::fromVoigt
staticconstexpr
Initial value:
=
{
std::make_tuple(0,0),
std::make_tuple(0,1),
std::make_tuple(1,1),
std::make_tuple(0,2),
std::make_tuple(1,2),
std::make_tuple(2,2)
}

◆ N

template<sofa::Size D, class real = SReal>
constexpr sofa::Size sofa::type::MatSym< D, real >::N = D * D
staticconstexpr

◆ nbCols

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

◆ nbLines

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

◆ NumberStoredValues

template<sofa::Size D, class real = SReal>
constexpr auto sofa::type::MatSym< D, real >::NumberStoredValues = NumberOfIndependentElements<D>
staticconstexpr

◆ toVoigt

template<sofa::Size D, class real = SReal>
constexpr fixed_array<sofa::Index, 3*3> sofa::type::MatSym< D, real >::toVoigt = {0, 1, 3, 1, 2, 4, 3, 4, 5}
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.

◆ getsub()

template<sofa::Size D, class real = SReal>
template<Size D2>
constexpr void sofa::type::MatSym< D, real >::getsub ( Size  a,
MatSym< D2, real > &  m 
) const
constexpr

◆ 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

◆ 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=()

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.

◆ toMat()

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

◆ voigtID()

template<sofa::Size D, class real = SReal>
static constexpr sofa::Index sofa::type::MatSym< D, real >::voigtID ( sofa::Index  i,
sofa::Index  j = 0 
)
inlinestaticconstexpr