`tensor`

d-dimensional physical tensor

# Description

The `tensor` class defines a `d*d` matrix with floating coefficients. This class is suitable for defining tensors, i.e. `field` with `d*d` matrix values at each physical position.

It is represented as a bidimensional array of coordinates. The coordinate indexes start at zero and finishes at `d-1`, e.g. `a(0,0)`, `a(0,1)`, ..., `a(2,2)`.

The default constructor set all components to zero:

        tensor a;

and this default could be overridden:

        tensor a = {{1, 2, 3.14},
                    {2, 6, 6.2 },
                    {5, 8, 9.0 }};

The standard linear algebra with scalars, vectors of R^3 (see the `point` class) and `tensor` is supported.

The computation of eigenvalues and eigenvectors, together with the SVD decomposition are also provided for convenience.

# Implementation

This documentation has been generated from file fem/geo_element/tensor.h

The `tensor` class is simply an alias to the `tensor_basic` class

typedef tensor_basic<Float> tensor;

The `tensor_basic` class is a template class with the floating type as parameter:

template<class T>
class tensor_basic {
public:
typedef size_t size_type;
typedef T element_type;
typedef T float_type;
// allocators:
tensor_basic (const T& init_val = 0);
tensor_basic (T x[3][3]);
tensor_basic (const tensor_basic<T>& a);
static tensor_basic<T> eye (size_type d = 3);
tensor_basic (const std::initializer_list<std::initializer_list<T> >& il);
// affectation:
tensor_basic<T>& operator= (const tensor_basic<T>& a);
tensor_basic<T>& operator= (const T& val);
// modifiers:
void fill (const T& init_val);
void reset ();
void set_row (const point_basic<T>& r, size_t i, size_t d = 3);
void set_column (const point_basic<T>& c, size_t j, size_t d = 3);
// accessors:
T& operator()(size_type i, size_type j);
const T& operator()(size_type i, size_type j) const;
point_basic<T> row(size_type i) const;
point_basic<T> col(size_type i) const;
size_t nrow() const; // = 3, for template matrix compatibility
size_t ncol() const;
// inputs/outputs:
std::ostream& put (std::ostream& s, size_type d = 3) const;
std::istream& get (std::istream&);
// algebra:
bool operator== (const tensor_basic<T>&) const;
bool operator!= (const tensor_basic<T>& b) const { return ! operator== (b); }
const tensor_basic<T>& operator+ () const { return *this; }
tensor_basic<T> operator- () const;
tensor_basic<T> operator+ (const tensor_basic<T>& b) const;
tensor_basic<T> operator- (const tensor_basic<T>& b) const;
tensor_basic<T> operator* (const tensor_basic<T>& b) const;
tensor_basic<T> operator* (const T& k) const;
tensor_basic<T> operator/ (const T& k) const;
point_basic<T> operator* (const point_basic<T>&) const;
point_basic<T> trans_mult (const point_basic<T>& x) const;
tensor_basic<T>& operator+= (const tensor_basic<T>&);
tensor_basic<T>& operator-= (const tensor_basic<T>&);
tensor_basic<T>& operator*= (const T& k);
tensor_basic<T>& operator/= (const T& k);
T determinant (size_type d = 3) const;
bool is_symmetric (size_type d = 3) const;
// eigenvalues & eigenvectors:
// a = q*d*q^T
// a may be symmetric
// where q=(q1,q2,q3) are eigenvectors in rows (othonormal matrix)
// and d=(d1,d2,d3) are eigenvalues, sorted in decreasing order d1 >= d2 >= d3
// return d
point_basic<T> eig (tensor_basic<T>& q, size_t dim = 3) const;
point_basic<T> eig (size_t dim = 3) const;
// singular value decomposition:
// a = u*s*v^T
// a can be unsymmetric
// where u=(u1,u2,u3) are left pseudo-eigenvectors in rows (othonormal matrix)
// v=(v1,v2,v3) are right pseudo-eigenvectors in rows (othonormal matrix)
// and s=(s1,s2,s3) are eigenvalues, sorted in decreasing order s1 >= s2 >= s3
// return s
point_basic<T> svd (tensor_basic<T>& u, tensor_basic<T>& v, size_t dim = 3) const;
};

The linear algebra is completed by some classical operators and the matrix exponential:

template <class U>
point_basic<U> operator* (const point_basic<U>& yt, const tensor_basic<U>& a);
template <class U>
tensor_basic<U> trans (const tensor_basic<U>& a, size_t d = 3);
template <class U>
void prod (const tensor_basic<U>& a, const tensor_basic<U>& b, tensor_basic<U>& result,
size_t di=3, size_t dj=3, size_t dk=3);
// tr(a) = a00 + a11 + a22
template <class U>
U tr (const tensor_basic<U>& a, size_t d=3);
template <class U>
U ddot (const tensor_basic<U>&, const tensor_basic<U>&);
// a = u otimes v <==> aij = ui*vj
template <class U>
tensor_basic<U> otimes (const point_basic<U>& u, const point_basic<U>& v, size_t d=3);
template <class U>
tensor_basic<U> inv (const tensor_basic<U>& a, size_t d = 3);
template <class U>
tensor_basic<U> diag (const point_basic<U>& d);
template <class U>
point_basic<U> diag (const tensor_basic<U>& a);
template <class U>
U determinant (const tensor_basic<U>& A, size_t d = 3);
template <class U>
bool invert_3x3 (const tensor_basic<U>& A, tensor_basic<U>& result);
// matrix exponential:
template<class T>
tensor_basic<T> exp (const tensor_basic<T>& a, size_t d = 3);
// inputs/outputs:
template<class T>
inline
std::istream& operator>> (std::istream& in, tensor_basic<T>& a) {
return a.get (in); }
template<class T>
inline
std::ostream& operator<< (std::ostream& out, const tensor_basic<T>& a) {
return a.put (out); }
// t += a otimes b
template<class T>
void cumul_otimes (tensor_basic<T>& t, const point_basic<T>& a, const point_basic<T>& b, size_t na = 3);
template<class T>
void cumul_otimes (tensor_basic<T>& t, const point_basic<T>& a, const point_basic<T>& b, size_t na, size_t nb);
rheolef::tensor_basic::size_type
size_t size_type
Definition: tensor.h:93
rheolef::io::out
@ out
Definition: rheostream.h:167
rheolef::tensor_basic::tensor_basic
tensor_basic(const T &init_val=0)
Definition: tensor.h:266
rheolef::invert_3x3
bool invert_3x3(const tensor_basic< T > &A, tensor_basic< T > &result)
Definition: tensor.cc:333
rheolef::otimes
tensor_basic< U > otimes(const point_basic< U > &u, const point_basic< U > &v, size_t d=3)
rheolef::tensor_basic::operator+=
tensor_basic< T > & operator+=(const tensor_basic< T > &)
Definition: tensor.cc:174
rheolef::tensor_basic::eye
static tensor_basic< T > eye(size_type d=3)
Definition: tensor.h:443
rheolef::tensor_basic::nrow
size_t nrow() const
Definition: tensor.h:321
rheolef::tensor_basic::operator/
tensor_basic< T > operator/(const T &k) const
Definition: tensor.h:360
rheolef::tensor_basic::put
std::ostream & put(std::ostream &s, size_type d=3) const
Definition: tensor.cc:37
rheolef::tensor_basic::eig
point_basic< T > eig(tensor_basic< T > &q, size_t dim=3) const
Definition: tensor.cc:426
rheolef::diag
csr< T, M > diag(const vec< T, M > &d)
Definition: csr.cc:56
rheolef::operator*
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
Definition: csr.h:437
rheolef::tensor_basic::operator==
bool operator==(const tensor_basic< T > &) const
Definition: tensor.cc:101
mkgeo_ball.c
c
Definition: mkgeo_ball.sh:153
rheolef::tensor_basic::trans_mult
point_basic< T > trans_mult(const point_basic< T > &x) const
Definition: tensor.h:367
rheolef::tensor_basic::determinant
T determinant(size_type d=3) const
Definition: tensor.cc:288
rheolef::tensor_basic::operator=
tensor_basic< T > & operator=(const tensor_basic< T > &a)
Definition: tensor.h:303
rheolef::tensor_basic::element_type
T element_type
Definition: tensor.h:94
rheolef::tensor_basic::ncol
size_t ncol() const
Definition: tensor.h:328
rheolef::tensor
tensor_basic< Float > tensor
Definition: tensor.h:181
rheolef::determinant
U determinant(const tensor_basic< U > &A, size_t d=3)
rheolef::tensor_basic::operator+
const tensor_basic< T > & operator+() const
Definition: tensor.h:136
rheolef::ddot
T ddot(const tensor_basic< T > &a, const tensor_basic< T > &b)
ddot(x,y): see the expression page for the full documentation
Definition: tensor.cc:278
a
Definition: diffusion_isotropic.h:25
rheolef::exp
tensor_basic< T > exp(const tensor_basic< T > &a, size_t d)
Definition: tensor-exp.cc:92
rheolef::tensor_basic::operator*
tensor_basic< T > operator*(const tensor_basic< T > &b) const
Definition: tensor.cc:270
rheolef::tensor_basic::operator!=
bool operator!=(const tensor_basic< T > &b) const
Definition: tensor.h:135
rheolef::tensor_basic::operator*=
tensor_basic< T > & operator*=(const T &k)
Definition: tensor.cc:192
rheolef::tensor_basic::svd
point_basic< T > svd(tensor_basic< T > &u, tensor_basic< T > &v, size_t dim=3) const
Definition: tensor.cc:470
rheolef::tensor_basic::float_type
T float_type
Definition: tensor.h:95
rheolef::tensor_basic::is_symmetric
bool is_symmetric(size_type d=3) const
Definition: tensor.cc:351
rheolef::tensor_basic::get
std::istream & get(std::istream &)
Definition: tensor.cc:51
rheolef::operator>>
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:88
rheolef::tensor_basic::reset
void reset()
Definition: tensor.h:260
rheolef::prod
void prod(const tensor_basic< T > &a, const tensor_basic< T > &b, tensor_basic< T > &result, size_t di, size_t dj, size_t dk)
Definition: tensor.cc:256
u
Definition: leveque.h:25
mkgeo_ball.d
d
Definition: mkgeo_ball.sh:154
rheolef::tensor_basic::operator-=
tensor_basic< T > & operator-=(const tensor_basic< T > &)
Definition: tensor.cc:183
rheolef::inv
tensor_basic< T > inv(const tensor_basic< T > &a, size_t d)
Definition: tensor.cc:219
rheolef::point_basic< T >
point_basic< T >
Definition: piola_fem.h:135
mkgeo_ball.b
b
Definition: mkgeo_ball.sh:152
rheolef::tensor_basic::operator-
tensor_basic< T > operator-() const
Definition: tensor.cc:110
rheolef::cumul_otimes
void cumul_otimes(tensor_basic< T > &t, const point_basic< T > &a, const point_basic< T > &b, size_t na, size_t nb)
Definition: tensor.cc:305
size_type
field::size_type size_type
Definition: branch.cc:425
rheolef::tensor_basic::row
point_basic< T > row(size_type i) const
Definition: tensor.cc:313
rheolef::tensor_basic::set_row
void set_row(const point_basic< T > &r, size_t i, size_t d=3)
Definition: tensor.h:435
rheolef::tensor_basic::operator/=
tensor_basic< T > & operator/=(const T &k)
Definition: tensor.cc:201
rheolef::trans
csr< T, sequential > trans(const csr< T, sequential > &a)
trans(a): see the form page for the full documentation
Definition: csr.h:455
rheolef::operator<<
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
mkgeo_ball.dim
dim
Definition: mkgeo_ball.sh:307
rheolef::tensor_basic::fill
void fill(const T &init_val)
Definition: tensor.h:252
rheolef::tensor_basic::col
point_basic< T > col(size_type i) const
Definition: tensor.cc:323
rheolef::tensor_basic::operator()
T & operator()(size_type i, size_type j)
Definition: tensor.h:335
rheolef::tensor_basic::set_column
void set_column(const point_basic< T > &c, size_t j, size_t d=3)
Definition: tensor.h:427
T
Expr1::float_type T
Definition: field_expr.h:218
rheolef::tr
U tr(const tensor_basic< U > &a, size_t d=3)