PSCF v1.1
List of all members
Util::Tensor Class Reference

A Tensor represents a Cartesian tensor. More...

#include <Tensor.h>

Public Member Functions

Constructors
 Tensor ()
 Default constructor. More...
 
 Tensor (const Tensor &t)
 Copy constructor. More...
 
 Tensor (double scalar)
 Constructor, initialize all elements to a scalar value. More...
 
 Tensor (const double a[][Dimension])
 Construct Tensor from double [][Dimension] 2D C array. More...
 
Assignment
Tensoroperator= (const Tensor &t)
 Copy assignment. More...
 
Tensoroperator= (const double a[][Dimension])
 Assignment from C double [Dimension][Dimension] 2D array. More...
 
Arithmetic Assignment
void operator+= (const Tensor &dt)
 Add tensor dt to this tensor. More...
 
void operator-= (const Tensor &dt)
 Subtract tensor dt from this tensor. More...
 
void operator*= (double s)
 Multiply this tensor by scalar s. More...
 
void operator/= (double s)
 Divide this tensor by scalar s. More...
 
Array Subscript
const double & operator() (int i, int j) const
 Return one element by value. More...
 
double & operator() (int i, int j)
 Return one element by non-const reference. More...
 
Tensor valued functions (result assigned to invoking object)
Tensorzero ()
 Set all elements of this tensor to zero. More...
 
Tensoridentity ()
 Set this to the identity (unity) tensor. More...
 
TensorsetRow (int i, const Vector &r)
 Set row i of this Tensor to elements of Vector r. More...
 
TensorsetColumn (int i, const Vector &r)
 Set column i of this Tensor to elements of Vector r. More...
 
Tensoradd (const Tensor &t1, const Tensor &t2)
 Add tensors t1 and t2. More...
 
Tensorsubtract (const Tensor &t1, const Tensor &t2)
 Subtract tensor t2 from t1. More...
 
Tensormultiply (const Tensor &t, double s)
 Multiply a tensor t by a scalar s. More...
 
Tensordivide (const Tensor &t, double s)
 Divide a Tensor t by a scalar s. More...
 
Tensortranspose (const Tensor &t)
 Compute transpose of a tensor. More...
 
Tensortranspose ()
 Transpose this tensor. More...
 
Tensorsymmetrize (const Tensor &t)
 Compute symmetric part of a tensor t. More...
 
Tensorsymmetrize ()
 Symmetrize this tensor. More...
 
Tensordyad (const Vector &v1, const Vector &v2)
 Create dyad of two vectors. More...
 
Miscellaneous
double trace () const
 Return the trace of this tensor. More...
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize this to/from an archive. More...
 

Static Members

static const Tensor Zero = Tensor(0.0)
 Constant Tensor with all zero elements. More...
 
static const Tensor Identity = Tensor().identity()
 Constant idenity Tensor (diagonal diagonal elements all 1). More...
 
static void initStatic ()
 Call to guarantee initialization of Zero and Identity tensors. More...
 
static void commitMpiType ()
 Commit MPI datatype MpiTraits<Tensor>::type. More...
 
bool operator== (const Tensor &t1, const Tensor &t2)
 Equality for Tensors. More...
 
bool operator== (const Tensor &t1, const double t2[][Dimension])
 Equality of Tensor and 2D C array. More...
 
std::istream & operator>> (std::istream &in, Tensor &tensor)
 istream extractor for a Tensor. More...
 
std::ostream & operator<< (std::ostream &out, const Tensor &tensor)
 ostream inserter for a Tensor. More...
 

Detailed Description

A Tensor represents a Cartesian tensor.

Definition at line 32 of file Tensor.h.

Constructor & Destructor Documentation

◆ Tensor() [1/4]

Util::Tensor::Tensor ( )
inline

Default constructor.

Definition at line 399 of file Tensor.h.

◆ Tensor() [2/4]

Util::Tensor::Tensor ( const Tensor t)
inline

Copy constructor.

Definition at line 406 of file Tensor.h.

References Util::DimensionSq.

◆ Tensor() [3/4]

Util::Tensor::Tensor ( double  scalar)
inlineexplicit

Constructor, initialize all elements to a scalar value.

Parameters
scalarinitial value for all elements.

Definition at line 417 of file Tensor.h.

References Util::DimensionSq.

◆ Tensor() [4/4]

Util::Tensor::Tensor ( const double  a[][Dimension])
inlineexplicit

Construct Tensor from double [][Dimension] 2D C array.

Parameters
a2D array a[Dimension][Dimension]

Definition at line 428 of file Tensor.h.

References Util::Dimension.

Member Function Documentation

◆ operator=() [1/2]

Tensor & Util::Tensor::operator= ( const Tensor t)
inline

Copy assignment.

Parameters
tTensor to assign.

Definition at line 468 of file Tensor.h.

References Util::DimensionSq.

◆ operator=() [2/2]

Tensor & Util::Tensor::operator= ( const double  a[][Dimension])
inline

Assignment from C double [Dimension][Dimension] 2D array.

Parameters
a2D array a[Dimension][Dimension]

Definition at line 480 of file Tensor.h.

References Util::Dimension.

◆ operator+=()

void Util::Tensor::operator+= ( const Tensor dt)
inline

Add tensor dt to this tensor.

Upon return, *this = *this + dt.

Parameters
dttensor increment (input)

Definition at line 495 of file Tensor.h.

References Util::DimensionSq.

◆ operator-=()

void Util::Tensor::operator-= ( const Tensor dt)
inline

Subtract tensor dt from this tensor.

Upon return, *this = *this - dt.

Parameters
dttensor increment (input)

Definition at line 506 of file Tensor.h.

References Util::DimensionSq.

◆ operator*=()

void Util::Tensor::operator*= ( double  s)
inline

Multiply this tensor by scalar s.

Upon return, *this = (*this)*s.

Parameters
sscalar multiplier

Definition at line 517 of file Tensor.h.

References Util::DimensionSq.

◆ operator/=()

void Util::Tensor::operator/= ( double  s)
inline

Divide this tensor by scalar s.

Upon return, *this = (*this)/s.

Parameters
sscalar divisor (input)

Definition at line 528 of file Tensor.h.

References Util::DimensionSq.

◆ operator()() [1/2]

const double & Util::Tensor::operator() ( int  i,
int  j 
) const
inline

Return one element by value.

Parameters
irow element index
jcolumn element index
Returns
element (i, j) of the tensor

Definition at line 539 of file Tensor.h.

References Util::Dimension.

◆ operator()() [2/2]

double & Util::Tensor::operator() ( int  i,
int  j 
)
inline

Return one element by non-const reference.

Parameters
irow element index
jcolumn element index
Returns
element i of the tensor

Definition at line 552 of file Tensor.h.

References Util::Dimension.

◆ zero()

Tensor & Util::Tensor::zero ( )
inline

Set all elements of this tensor to zero.

Returns
reference to this tensor

Definition at line 441 of file Tensor.h.

References Util::DimensionSq.

Referenced by Util::setToZero().

◆ identity()

Tensor & Util::Tensor::identity ( )
inline

Set this to the identity (unity) tensor.

Returns
reference to this tensor

Definition at line 453 of file Tensor.h.

References Util::Dimension, and Util::DimensionSq.

◆ setRow()

Tensor & Util::Tensor::setRow ( int  i,
const Vector r 
)
inline

Set row i of this Tensor to elements of Vector r.

Returns
reference to this tensor

Definition at line 737 of file Tensor.h.

References Util::Dimension.

◆ setColumn()

Tensor & Util::Tensor::setColumn ( int  i,
const Vector r 
)
inline

Set column i of this Tensor to elements of Vector r.

Returns
reference to this tensor

Definition at line 749 of file Tensor.h.

References Util::Dimension.

◆ add()

Tensor & Util::Tensor::add ( const Tensor t1,
const Tensor t2 
)
inline

Add tensors t1 and t2.

Upon return, *this = t1 + t2.

Parameters
t1tensor
t2tensor
Returns
reference to this tensor

Definition at line 567 of file Tensor.h.

References Util::DimensionSq.

◆ subtract()

Tensor & Util::Tensor::subtract ( const Tensor t1,
const Tensor t2 
)
inline

Subtract tensor t2 from t1.

Upon return, *this == t1 - t2.

Parameters
t1tensor (input)
t2tensor (input)
Returns
reference to this tensor

Definition at line 581 of file Tensor.h.

References Util::DimensionSq.

◆ multiply()

Tensor & Util::Tensor::multiply ( const Tensor t,
double  s 
)
inline

Multiply a tensor t by a scalar s.

Upon return, *this == v*s.

Parameters
ttensor factor
sscalar factor
Returns
reference to this tensor

Definition at line 595 of file Tensor.h.

References Util::DimensionSq.

◆ divide()

Tensor & Util::Tensor::divide ( const Tensor t,
double  s 
)
inline

Divide a Tensor t by a scalar s.

Upon return, *this = v/s;

Parameters
ttensor input
sscalar denominator
Returns
reference to this tensor

Definition at line 609 of file Tensor.h.

References Util::DimensionSq.

◆ transpose() [1/2]

Tensor & Util::Tensor::transpose ( const Tensor t)
inline

Compute transpose of a tensor.

Upon return, *this is the transpose of t

Parameters
tinput tensor
Returns
reference to this tensor

Definition at line 636 of file Tensor.h.

References Util::Dimension.

◆ transpose() [2/2]

Tensor & Util::Tensor::transpose ( )
inline

Transpose this tensor.

Upon return, *this is transposed.

Returns
reference to this tensor

Definition at line 657 of file Tensor.h.

References Util::Dimension.

◆ symmetrize() [1/2]

Tensor & Util::Tensor::symmetrize ( const Tensor t)
inline

Compute symmetric part of a tensor t.

Upon return, *this = [t + t.transpose()]/2

Parameters
ttensor input
Returns
reference to this tensor

Definition at line 678 of file Tensor.h.

References Util::Dimension.

◆ symmetrize() [2/2]

Tensor & Util::Tensor::symmetrize ( )
inline

Symmetrize this tensor.

Upon return, this is symmetrized, equal to half the sum of the original tensor and its transpose.

Returns
reference to this tensor

Definition at line 701 of file Tensor.h.

References Util::Dimension.

◆ dyad()

Tensor & Util::Tensor::dyad ( const Vector v1,
const Vector v2 
)
inline

Create dyad of two vectors.

Upon return, *this equals the dyad v1 ^ v2. Equivalently: (*this)(i , j) == v1[i]*v2[j]

Parameters
v1vector input
v2vector input
Returns
reference to this tensor

Definition at line 763 of file Tensor.h.

References Util::Dimension.

◆ trace()

double Util::Tensor::trace ( ) const
inline

Return the trace of this tensor.

Definition at line 621 of file Tensor.h.

References Util::Dimension, and trace().

Referenced by trace().

◆ serialize()

template<class Archive >
void Util::Tensor::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Serialize this to/from an archive.

Parameters
ararchive
versionarchive version id

Definition at line 720 of file Tensor.h.

References Util::DimensionSq.

◆ initStatic()

void Util::Tensor::initStatic ( )
static

Call to guarantee initialization of Zero and Identity tensors.

Call this function once to guarantee that this file is linked.

Definition at line 27 of file Tensor.cpp.

References UTIL_THROW.

Referenced by Util::initStatic().

◆ commitMpiType()

void Util::Tensor::commitMpiType ( )
static

Friends And Related Function Documentation

◆ operator== [1/2]

bool operator== ( const Tensor t1,
const Tensor t2 
)
friend

Equality for Tensors.

Definition at line 43 of file Tensor.cpp.

◆ operator== [2/2]

bool operator== ( const Tensor t1,
const double  t2[][Dimension] 
)
friend

Equality of Tensor and 2D C array.

Definition at line 56 of file Tensor.cpp.

◆ operator>>

std::istream & operator>> ( std::istream &  in,
Tensor tensor 
)
friend

istream extractor for a Tensor.

Input elements of a tensor from stream, without line breaks.

Parameters
ininput stream
tensorTensor to be read from stream
Returns
modified input stream

Definition at line 93 of file Tensor.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Tensor tensor 
)
friend

ostream inserter for a Tensor.

Output elements of a tensor to stream, without line breaks.

Parameters
outoutput stream
tensorTensor to be written to stream
Returns
modified output stream

Definition at line 104 of file Tensor.cpp.

Member Data Documentation

◆ Zero

const Tensor Util::Tensor::Zero = Tensor(0.0)
static

Constant Tensor with all zero elements.

Definition at line 297 of file Tensor.h.

◆ Identity

const Tensor Util::Tensor::Identity = Tensor().identity()
static

Constant idenity Tensor (diagonal diagonal elements all 1).

Definition at line 302 of file Tensor.h.


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