Nabla Logo programmer
  Advanced Search
  
  Send us a comment/query
 
  Back to main web site
 
  OpenFOAM guides
  - User guide
  - Programmer’s guide
 
  Index
 
  Changes from OpenFOAM 2.2 to 2.3
 
  Trademarks in the guides
  ©2000-2007 Nabla Ltd.

1.4 OpenFOAM tensor classes

OpenFOAM contains a C++ class library primitive that contains the classes for the tensor mathematics described so far. The basic tensor classes that are available as standard in OpenFOAM are listed in Table  1.1. The Table also lists the functions that allow the user to access individual components of a tensor, known as access functions.


Rank Common name Basic class Access functions




0 Scalar scalar
1 Vector vector x(), y(), z()
2 Tensor tensor xx(), xy(), xz(). . .





Table 1.1: Basic tensor classes in OpenFOAM

We can declare the tensor

     (          )
        1  2  3
T  =    4  5  6
        7  8  9
\special {t4ht=
(1.44)

in OpenFOAM by the line:


    tensor T(1, 2, 3, 4, 5, 6, 7, 8, 9);

We can then access the component T13   \special {t4ht=, or Txz  \special {t4ht= using the xz() access function. For instance the code


    Info << ``Txz = '' << T.xz() << endl;
outputs to the screen:


    Txz = 3

1.4.1 Algebraic tensor operations in OpenFOAM

The algebraic operations described in Section  1.3 are all available to the OpenFOAM tensor classes using syntax which closely mimics the notation used in written mathematics. Some functions are represented solely by descriptive functions, e.g. symm(), but others can also be executed using symbolic operators, e.g. *. All functions are listed in Table  1.2.

OperationComment Mathematical

Description

Description

in OpenFOAM





Addition a + b  \special {t4ht=

a + b

Subtraction a - b  \special {t4ht=

a - b

Scalar multiplication sa  \special {t4ht=

s * a

Scalar division a/s  \special {t4ht=

a / s

Outer product rank a, b >=  1  \special {t4ht= ab  \special {t4ht=

a * b

Inner product rank a, b >=  1  \special {t4ht= a •b  \special {t4ht=

a & b

Double inner product rank a, b >=  2  \special {t4ht= a ••b  \special {t4ht=

a && b

Cross product rank a, b = 1  \special {t4ht= a  b  \special {t4ht=

a ^ b

Square a2   \special {t4ht=

sqr(a)

Magnitude squared    2
|a|   \special {t4ht=

magSqr(a)

Magnitude |a| \special {t4ht=

mag(a)

Power n =  0,1,...,4  \special {t4ht=  n
a  \special {t4ht=

pow(a,n)

Component average i = 1,...,N  \special {t4ht= --
ai  \special {t4ht=

cmptAv(a)

Component maximum i = 1,...,N  \special {t4ht= max(a  )
       i  \special {t4ht=

max(a)

Component minimum i = 1,...,N  \special {t4ht= min(ai)  \special {t4ht=

min(a)

Scale scale(a  \special {t4ht=,b  \special {t4ht=)

scale(a,b)

Geometric transformation
transforms a  \special {t4ht= using tensor T  \special {t4ht=

transform(T,a)

Operations exclusive to tensors of rank 2




Transpose   T
T   \special {t4ht=

T.T()

Diagonal diagT  \special {t4ht=

diag(T)

Trace trT  \special {t4ht=

tr(T)

Deviatoric component dev T  \special {t4ht=

dev(T)

Symmetric component symm  T  \special {t4ht=

symm(T)

Skew-symmetric component skew T  \special {t4ht=

skew(T)

Determinant det T  \special {t4ht=

det(T)

Cofactors cofT  \special {t4ht=

cof(T)

Inverse inv T  \special {t4ht=

inv(T)

Hodge dual *T  \special {t4ht=

*T

Operations exclusive to scalars




Sign (boolean) sgn(s)  \special {t4ht=

sign(s)

Positive (boolean) s >=  0  \special {t4ht=

pos(s)

Negative (boolean) s <=  0  \special {t4ht=

neg(s)

Limit n  \special {t4ht= scalar limit(s,n)  \special {t4ht=

limit(s,n)

Square root   --
 V~  s  \special {t4ht=

sqrt(s)

Exponential exp s  \special {t4ht=

exp(s)

Natural logarithm lns  \special {t4ht=

log(s)

Base 10 logarithm log  s
   10  \special {t4ht=

log10(s)

Sine sins  \special {t4ht=

sin(s)

Cosine cos s  \special {t4ht=

cos(s)

Tangent tan s  \special {t4ht=

tan(s)

Arc sine asins  \special {t4ht=

asin(s)

Arc cosine acos s  \special {t4ht=

acos(s)

Arc tangent atan s  \special {t4ht=

atan(s)

Hyperbolic sine sinhs  \special {t4ht=

sinh(s)

Hyperbolic cosine cosh s  \special {t4ht=

cosh(s)

Hyperbolic tangent tanh s  \special {t4ht=

tanh(s)

Hyperbolic arc sine asinh s  \special {t4ht=

asinh(s)

Hyperbolic arc cosine acosh s  \special {t4ht=

acosh(s)

Hyperbolic arc tangent atanh s  \special {t4ht=

atanh(s)

Error function erfs  \special {t4ht=

erf(s)

Complement error function erfcs  \special {t4ht=

erfc(s)

Logarithm gamma function lnGs  \special {t4ht=

lgamma(s)

Type 1 Bessel function of order 0 J0s  \special {t4ht=

j0(s)

Type 1 Bessel function of order 1 J1s  \special {t4ht=

j1(s)

Type 2 Bessel function of order 0 Y  s
  0  \special {t4ht=

y0(s)

Type 2 Bessel function of order 1 Y1 s  \special {t4ht=

y1(s)





a,b  \special {t4ht= are tensors of arbitrary rank unless otherwise stated
s  \special {t4ht= is a scalar, N  \special {t4ht= is the number of tensor components
Table 1.2: Algebraic tensor operations in OpenFOAM