Beruflich Dokumente
Kultur Dokumente
Feature Meaning
typedefs Alias for a possibly complex type name
function Group of statements that perform a task
pointers Data type that holds addresses to refer to values in memory (e.g. for dynamic memory allocation)
data structures Data members grouped under one name (e.g. the nodes in a linked list)
classes Data members and function members grouped under one name
constructor Function member that initialises the instance of it’s class
destructor Function member that destroys the instance of it’s class
friends Allows a function or class access to private or protected members of a class
inheritance Allows a class to be created based on another class (so code can be reused)
virtual member Member function that will be redefined in a derived class
functions
abstract class Class that contains at least one virtual function
template Family of classes (class template), functions (function template), variables (variable template) or alias
of a family of types (alias template)
namespace Prevents name conflicts in large projects
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 1/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
Evaluate spatial derivatives at future timestep
Uses unknown values - generates a matrix equation to be solved
Type Meaning
scalar, e.g. pressure
volScalarField
Three types
volScalarField
volVectorField
volTensorField
Values are stored in named dictionary files in named timestep directories e.g. case/0/p for pressure
scalar
vector
tensor
Class Meaning
Boundary conditions
fvPatchField
Class Meaning
polyMesh
Stands for polyhedral mesh
Most basic mesh class
Contains:
pointField
faceList
cellList
polyPatchList
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 2/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
Class Meaning
fvMesh
Extends polyMesh contains:
Cell volumes (volScalarField)
Cell centres (volVectorField)
Face area vectors (surfaceVectorField)
Face centres (surfaceVectorField)
Face area magnitudes (surfaceScalarField)
Face motion centres (surfaceScalarField)
Time
Class to control time during OpenFOAM
Declared as variable runTime
Provides list of saved times runTime.times()
Timestep = deltaT()
Return current directory name = name()
Time increments = operator++() operator+=(scalar)
Write objects to disk = write()
Start time, end time = startTime(), endTime()
Class Meaning
dimensionedField
geometricField<Type>
Combination of:
Field
GeometricBoundaryField
fvMesh
dimensionSet
Class Meaning
fvc
Stands for finite volume calculus
Explicit derivative evaluation
Input = known geometricField<Type>
Output = geometricField<Type> object
fvm
Stands for finite volume method
Implicit derivative evaluation
Input = unknown geometricField<Type>
Output = fvMatrix<Type> object, which can be inverted in the matrix equation
Mx=y
volField<Type>
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 3/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
surfaceField<Type>
pointField<Type>
Object registry of entities (dictionaries, fields) which are to be read in or written out
Code Meaning
IOdictionary transportProperties
Read in at creation
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ
IOobject::NO_WRITE
)
);
dimensionedScalar nu
Lookup viscosity in dictionary
(
transportProperties.lookup("nu")
);
Code Meaning
volVectorField U
volVectorField read in from disk
( Associated with runTime database
IOobject Must be read
(
"U",
Times[i].name(),
runTime,
IOobject::MUST_READ
),
mesh
)
Code Meaning
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 4/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
Class Meaning
Object created
NO_READ
Object destroyed
NO_WRITE
Class Meaning
Each operator in fvm constructs particular entries in known M and y as a fvMatrix object
fvMatrix is a template class (actual classes are fvScalarMatrix etc)
fvMatrix handles storage via lduMatrix class
fvMatrix class also handles solution
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 5/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
Class Meaning
PtrList<Type>
List of pointers
SLList<Type>
Non-intrusive singly-linked list
Class Meaning
Field<Type>
Array template class, e.g. Field<vector> = vectorField
Arrays
Pointers
References
Code Meaning
Time derivative
Divergence (div)
Spatial derivative
Discretised using the flux at the faces
e.g. ∇ ⋅ (uq) (the advection term)
Gradient (grad)
Spatial derivative
e.g. ∇p in the momentum equation
Laplacian
Spatial derivative
Discretised as ∇ ⋅ μ∇q
interpolation for μ
discretisation for ∇⋅
e.g. 2
μ∇ q in the momentum equation
Function Meaning
fvc::ddt(A)
Time derivative
fvm::ddt(A) ∂ A/∂ t
fvc::ddt(rho,A)
Density weighted time derivative
fvm::ddt(rho,A) ∂ ρA/∂ t
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 6/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
Function Meaning
fvc::d2dt2(rho,A)
Second density weighted time derivative
fvm::d2dt2(rho,A) ∂ /∂ t(ρ∂ A/∂ t)
fvc::grad(A)
Gradient
fvm::grad(A) A can be a scalar or a vector
Result is a volVectorField (from scalar) or a volTensorField (from vector)
fvc::div(A)
Divergence
fvm::div(A) A can be a vector or a tensor
Result is a volScalarField (from vector) or a volVectorField (from tensor)
fvc::laplacian(A)
Laplacian
2
fvm::laplacian(A) ∇ A
fvc::laplacian(mu, A)
Laplacian
fvm::laplacian(mu, A) ∇ ⋅ (μ∇A)
fvc::curl(A)
Curl
fvm::curl(A) ∇ × A
fvm::div(phi,A)
Divergence using flux to evaluate this
A can be a scalar, vector or a tensor
fvm::Sp(rho,A)
Implicit evaulation of source term
fvm::SuSp(rho,A)
Implicit or explicit evaulation of source term (depending on sign of rho
Equation Code
∂q 2
+ ∇ ⋅ qu = μ∇ q fvScalarMatrix transport
∂t
(
fvm::ddt(q)
+ fvm::div(phi,q)
- fvm::laplacian(mu,q)
);
∂T 2
= κ∇ T solve(fvm::ddt(T) == kappa*fvc::laplacian(T))
∂t
∂k T 2
+ ∇ ⋅ ku − ∇ ⋅ [(ν + νt )∇k] = νt [1/2(∇u + ∇u ] − ε/k solve(
∂t
fvm::ddt(k)
+ fvm::div(phi,k)
- fvm::laplacian(nu()+nut,k)
== nut*magSqr(symm(fvc::grad(U)))
- fvm::Sp(epsilon/k,k)
);
The PISO (Pressure Implicit with Splitting of Operators) is an efficient method to solve the Navier-Stokes equations
The implementation:
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
);
Define and solve the pressure equation and repeat for the prescribed number of non-orthogonal corrector steps
fvScalarMatrix pEqn
(
fvm::laplacian(rUA, p) == fvc::div(phi)
);
pEqn.setReference(pRefCell, pRefValue);
pEqn.solve();
if (nonOrth == nNonOrthCorr)
{
phi -= pEqn.flux();
}
# include "continuityErrs.H"
U -= rUA*fvc::grad(p);
U.correctBoundaryConditions();
Sections of code in separate files that are widely used - all function prototypes in a header file
Equation Code
#include "CourantNumber.H"
File containing code for calculating Courant number
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 8/9
9/21/2019 1.1. OpenFOAM Language — The Visual Room
wmake is a make system – directs the compiler to compile specific files in particular ways.
www.thevisualroom.com/24_openfoam_language/openfoam_language.html#what-are-features-of-c 9/9