IFEM  90A354
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
Tensor Class Reference

Simple class for representing a non-symmetric second-order tensor. More...

#include <Tensor.h>

Inheritance diagram for Tensor:
Inheritance graph
[legend]
Collaboration diagram for Tensor:
Collaboration graph
[legend]

Public Member Functions

 Tensor (const t_ind nsd, bool identity=false)
 Constructor creating a zero or identity tesnor.
 
 Tensor (const Vec3 &vn, bool vnIsX=false)
 Constructor creating a transformation from a face normal vector. More...
 
 Tensor (const Vec3 &t1, const Vec3 &t2, bool t1isZ=false, bool t2isXZ=false)
 Constructor creating a transformation from two tangent vectors. More...
 
 Tensor (const Vec3 &v1, const Vec3 &v2, const Vec3 &v3)
 Constructor creating a transformation from three unit vectors. More...
 
 Tensor (Real a1, Real a2, Real a3)
 Constructor creating a transformation from three rotation angles. More...
 
 Tensor (const Tensor &T, bool transpose=false)
 Copy constructor, optionally creating the transpose of T.
 
 Tensor (const std::vector< Real > &a, bool transpose=false)
 Constructor copying its content from a one-dimensional array.
 
virtual ~Tensor ()
 Empty destructor.
 
void zero ()
 Sets *this to the 0-tensor.
 
void diag (Real value=Real(1))
 Sets *this to a diagonal tensor with value on the diagonal.
 
void diag (const Vec3 &diagonal)
 Sets *this to a diagonal tensor with given vector as diagonal.
 
 operator const std::vector< Real > & () const
 Type casting to a one-dimensional vector, for referencing.
 
 operator std::vector< Real > & ()
 Type casting to a one-dimensional vector, for assignment.
 
const Realptr () const
 Reference through a pointer.
 
const Realoperator() (t_ind i, t_ind j) const
 Index-1 based component reference.
 
Realoperator() (t_ind i, t_ind j)
 Index-1 based component access.
 
Vec3 operator[] (t_ind i) const
 Index-0 based column reference.
 
Tensoroperator= (const Tensor &T)
 Assignment operator.
 
Tensoroperator= (const std::vector< Real > &val)
 Overloaded assignment operator.
 
Tensoroperator= (Real val)
 Overloaded assignment operator.
 
Tensoroperator+= (const Tensor &T)
 Incrementation operator.
 
Tensoroperator+= (Real val)
 Incrementation operator.
 
Tensoroperator-= (const Tensor &T)
 Decrementation operator.
 
Tensoroperator-= (Real val)
 Decrementation operator.
 
Tensoroperator*= (Real val)
 Scaling operator.
 
Tensoroperator*= (const Tensor &B)
 Post-multiplication with another Tensor.
 
TensorpostMult (const Tensor &B)
 Post-multiplication with another Tensor.
 
TensorpreMult (const Tensor &A)
 Pre-multiplication with another Tensor.
 
Tensorrotate (Real alpha, t_ind axis)
 Rotates the tensor about given coordinate axis.
 
TensorouterProd (const Vec3 &a, const Vec3 &b)
 Dyadic (outer) product between two vectors.
 
Real innerProd (const Tensor &T) const
 Returns the inner-product of *this and the given tensor.
 
t_ind dim () const
 Returns the dimension of this tensor.
 
size_t size () const
 Returns the size of this tensor.
 
virtual bool symmetric () const
 Query whether this tensor is symmetric or not.
 
bool equal (const Tensor &T, Real tol=Real(1.0e-6)) const
 Query whether this tensor equals another within given tolerance.
 
bool isZero (Real tol=Real(1.0e-6)) const
 Query whether this tensor is zero within given tolerance.
 
virtual Tensortranspose ()
 Transposes the tensor.
 
virtual Tensorsymmetrize ()
 Makes the tensor symmetric.
 
Tensorshift (short int idx=1)
 Performs a cyclic permutation of the tensor columns.
 
virtual Real trace () const
 Returns the trace of the tensor.
 
virtual Real det () const
 Returns the determinant of the tensor.
 
virtual Real inverse (Real tol=Real(0))
 Inverts the tensor. More...
 
Vec3 rotVec () const
 Returns the rotation angles corresponding to the tensor.
 
virtual std::ostream & print (std::ostream &os, int prec=0) const
 Prints out the tensor to an output stream.
 

Protected Types

using t_ind = unsigned short int
 Tensor index type (for convenience)
 

Protected Member Functions

virtual t_ind index (t_ind i, t_ind j) const
 Returns a 0-based array index for the given tensor indices. More...
 

Protected Attributes

const t_ind n
 Number of spatial dimensions for the tensor.
 
std::vector< Realv
 The actual tensor component values.
 

Private Member Functions

void define3Dtransform (const Vec3 &v1, const Vec3 &v2, const Vec3 &v3)
 Creates a 3D transformation from three unit vectors.
 

Friends

Vec3 operator* (const Tensor &T, const Vec3 &v)
 Multiplication between a tensor and a point vector.
 
Vec3 operator* (const Vec3 &v, const Tensor &T)
 Multiplication between a point vector and transpose of a tensor.
 
Tensor operator* (const Tensor &A, const Tensor &B)
 Multiplication between two tensors.
 
Tensor operator* (Real a, const Tensor &T)
 Multiplication between a scalar and a tensor.
 
std::ostream & operator<< (std::ostream &os, const Tensor &T)
 Output stream operator.
 

Detailed Description

Simple class for representing a non-symmetric second-order tensor.

Constructor & Destructor Documentation

◆ Tensor() [1/4]

Tensor::Tensor ( const Vec3 vn,
bool  vnIsX = false 
)
explicit

Constructor creating a transformation from a face normal vector.

The provided vector vn is taken as the local Z-axis. The local X- and Y-axes are then defined by projecting either the global X- or Y-axis onto the normal plane, depending on whether vn points mostly in the global Y- or X-direction, respectively.

If vnIsX is true, vn is taken as the local X-axis instead and the other two axes are shifted accordingly.

References Vec3::cross(), define3Dtransform(), Vec3::normalize(), Vec3::x, Vec3::y, and Vec3::z.

◆ Tensor() [2/4]

Tensor::Tensor ( const Vec3 t1,
const Vec3 t2,
bool  t1isZ = false,
bool  t2isXZ = false 
)

Constructor creating a transformation from two tangent vectors.

The first tangent vector t1 is taken as the local X-axis (or Z-axis, if t1isZ is true). The local Z-axis (X-axis) is then defined as the cross product between t1 and t2. If t2isXZ is true, the local Y-axis is instead defined as the cross product between t2 and t1.

References Vec3::cross(), define3Dtransform(), and Vec3::normalize().

◆ Tensor() [3/4]

Tensor::Tensor ( const Vec3 v1,
const Vec3 v2,
const Vec3 v3 
)

Constructor creating a transformation from three unit vectors.

This constructor assumes the three vectors provided form an orthonormal basis.

References define3Dtransform().

◆ Tensor() [4/4]

Tensor::Tensor ( Real  a1,
Real  a2,
Real  a3 
)

Constructor creating a transformation from three rotation angles.

This constructor computes an incremental rotation tensor from the given rotation angles via a quaternion representation of the rotation. The angles provided are those related to a Rodrigues parameterization.

References epsZ, Vec3::length(), Real, v, Vec3::x, Vec3::y, and Vec3::z.

Member Function Documentation

◆ index()

virtual t_ind Tensor::index ( t_ind  i,
t_ind  j 
) const
inlineprotectedvirtual

Returns a 0-based array index for the given tensor indices.

Assuming column-wise storage for non-symmetric tensors.

Reimplemented in SymmTensor.

References n.

Referenced by operator()(), and rotVec().

◆ inverse()

Real Tensor::inverse ( Real  tol = Real(0))
virtual

Inverts the tensor.

Parameters
[in]tolDivision by zero tolerance
Returns
Determinant of the tensor

Reimplemented in SymmTensor.

References det(), n, Real, and v.


The documentation for this class was generated from the following files: