High Level Programming For OpenFOAM
High Level Programming For OpenFOAM
Example:
11 12 13
A tensor T = 21 22 23 is defined line-by-line:
31 32 33
tensor T( 11, 12, 13, 21, 22, 23, 31, 32, 33);
Info << "Txz = " << T.xz() << endl;
Outputs to the screen:
Txz = 13
Comment
Mathematical
description
Addition
a+b
Outer product
Rank a, b 1 ab
Inner product
Rank a, b 1 a b
Cross product
Rank a, b = 1 a b
Operations exclusive to tensors of rank 2
Transpose
TT
Determinant
detT
Operations exclusive to scalars
Positive (boolean)
s0
Hyperbolic arc sine
asinh s
Description
in OpenFOAM
a+b
a*b
a&b
ab
T.T()
det(T)
pos(s)
asinh(s)
10
Examine an fvMesh
Let us examine an fvMesh:
run
rm -rf cavity
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
sed -i s/"20 20 1"/"2 2 1"/g constant/polyMesh/blockMeshDict
blockMesh
Run Test-mesh (first compile it: wmake $FOAM_RUN/test/mesh)
C() gives the center of all cells and boundary faces.
V() gives the volume of all the cells.
Cf() gives the center of all the faces.
Try also adding in Test-mesh.C, before return(0):
Info<< mesh.C().internalField()[1][1] << endl;
Info<< mesh.boundaryMesh()[0].name() << endl;
See $FOAM_SRC/finiteVolume/fvMesh
11
Examine a volScalarField
Read a volScalarField that corresponds to the mesh. Add in Test-mesh.C,
before return(0):
volScalarField p
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
Info<< p << endl;
Info<< p.boundaryField()[0] << endl;
12
fvm::/fvc:: functions
laplacian(Gamma,phi)
ddt(phi)
ddt(rho, phi)
div(psi, scheme)
div(psi, phi, word)
div(psi, phi)
Source
Sp(rho, phi)
SuSp(rho, phi)
: vol<type>Field, : scalar, volScalarField, : surfaceScalarField
13
Example
A call for solving the equation
~
U
~ U
~ = p
+ U
t
has the OpenFOAM representation
solve
(
fvm::ddt(rho, U)
+ fvm::div(phi, U)
- fvm::laplacian(mu, U)
==
- fvc::grad(p)
)
14
15
none;
Gauss linear corrected;
Boundary conditions:
Part of class volScalarField object T, read from file:
boundaryField{
patch1{ type zeroGradient;}
patch2{ type fixedValue; value uniform 273;}}
16