Jasak2 Slides
Jasak2 Slides
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 1
Outline
Objective
• Present a narrative on numerical simulation software development
Topics
• Design and limitations of contemporary CFD software
• Model representation through equation mimicking
• Object orientation, generic programming and library design
• Top-level solvers and utilities: interactivity
• Five Basic Classes in OpenFOAM
◦ Space and time: polyMesh, fvMesh, Time
◦ Field algebra: Field, DimensionedField and GeometricField
◦ Boundary conditions: fvPatchField and derived classes
◦ Sparse matrices: lduMatrix, fvMatrix and linear solvers
◦ Finite Volume discretisation: fvc and fvm namespace
• Summary
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 2
Background
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 3
Design of Modern Solvers
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 4
Object Orientation
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 5
Object-Oriented Numerics for CCM
» –2
∂k 1 ǫo
+ ∇•(uk) − ∇•[(ν + νt )∇k] = νt (∇u + ∇uT ) − k
∂t 2 ko
solve
(
fvm::ddt(k)
+ fvm::div(phi, k)
- fvm::laplacian(nu() + nut, k)
== nut*magSqr(symm(fvc::grad(U)))
- fvm::Sp(epsilon/k, k)
);
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 6
Object Orientation
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 7
Object Orientation
Main Objects
• Computational domain
Object Software representation C++ Class
Tensor (List of) numbers + algebra vector, tensor
Mesh primitives Point, face, cell point, face, cell
Space Computational mesh polyMesh
Time Time steps (database) time
• Field algebra
Object Software representation C++ Class
Field List of values Field
Boundary condition Values + condition patchField
Dimensions Dimension set dimensionSet
Geometric field Field + mesh + boundary conditions geometricField
Field algebra + − ∗ / tr(), sin(), exp() . . . field operators
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 8
Object Orientation
Main Objects
• Linear equation systems and linear solvers
Object Software representation C++ Class
Linear equation matrix Matrix coefficients lduMatrix
Solvers Iterative solvers lduMatrix::solver
• Numerics: discretisation methods
Object Software representation C++ Class
Interpolation Differencing schemes interpolation
Differentiation ddt, div, grad, curl fvc, fec
Discretisation ddt, d2dt2, div, laplacian fvm, fem, fam
• Top-level code organisation
Object Software representation C++ Class
Model library Library eg. turbulenceModel
Application main() –
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 9
Generic Programming
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 10
Model-to-Model Interaction
class turbulenceModel
{
virtual volSymmTensorField R() const = 0;
virtual fvVectorMatrix divR
(
volVectorField& U
) const = 0;
virtual void correct() = 0;
};
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 11
Model-to-Model Interaction
autoPtr<turbulenceModel> turbulence =
turbulenceModel::New(U, phi, laminarTransport);
fvVectorMatrix UEqn
(
fvm::ddt(rho, U)
+ fvm::div(phi, U)
+ turbulence->divR(U)
==
- fvc::grad(p)
);
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 12
Run-Time Selection
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 13
Layered Development
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 14
Five Basic Classes
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 15
Space and Time
Representation of Time
• Main functions of Time class
◦ Follow simulation in terms of time-steps: start and end time, delta t
◦ Time is associated with I/O functionality: what and when to write
◦ objectRegistry: all IOobjects, including mesh, fields and dictionaries
registered with time class
◦ Main simulation control dictionary: controlDict
◦ Holding paths to <case> and associated data
• Associated class: regIOobject: database holds a list of objects, with
functionality held under virtual functions
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 16
Space and Time
Representation of Space
• Computational mesh consists of
◦ List of points. Point index is determined from its position in the list
◦ List of faces. A face is an ordered list of points (defines face normal)
◦ List of cells OR owner-neighbour addressing (defines left and right cell for
each face, saving some storage and mesh analysis time)
◦ List of boundary patches, grouping external faces
• polyMesh class holds mesh definition objects
• primitiveMesh: some parts of mesh analysis extracted out (topo changes)
• polyBoundaryMesh is a list of polyPatches
Finite Volume Mesh
• polyMesh class provides mesh data in generic manner: it is used by multiple
applications and discretisation methods
• For convenience, each discretisation wraps up primitive mesh functionality to suit
its needs: mesh metrics, addressing etc.
• fvMesh: mesh-related support for the Finite Volume Method
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 17
Space and Time
Representation of Space
• Further mesh functionality is generally independent of discretisation
◦ Mesh motion (automatic mesh motion)
◦ Topological changes
◦ Problem-specific mesh templates: mixer vessels, moving boxes, pumps,
valves, internal combustion engines etc.
• Implementation is separated into derived classes and mesh modifier objects
(changing topology)
• Functionality located in the dynamicMesh library
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 18
Field Algebra
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 19
Field Algebra
Field
• Simply, a list with algebra, templated on element type
• Assign unary and binary operators from the element, mapping functionality etc.
Dimensioned Field
• A field associated with a mesh, with a name and mesh reference
• Derived from IOobject for input-output and database registration
Geometric Field
• Consists of an internal field (derivation) and a GeometricBoundaryField
• Boundary field is a field of fields or boundary patches
• Geometric field can be defined on various mesh entities
◦ Points, edges, faces, cells
• . . . with various element types
◦ scalar, vector, tensor, symmetric tensor etc
• . . . on various mesh support classes
◦ Finite Volume, Finite Area, Finite Element
• Implementation involves a LOT of templating!
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 20
Boundary Conditions
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 21
Sparse Matrix and Solver
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 22
Sparse Matrix and Solver
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 23
Sparse Matrix and Solver
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 24
Finite Volume Method
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 25
Finite Volume Method
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 26
Finite Volume Method
template<class Type>
class gradScheme
:
public refCount
{
//- Calculate and return the grad of the given field
virtual tmp
<
GeometricField
<outerProduct<vector, Type>::type, fvPatchField, volMesh>
> grad
(
const GeometricField<Type, fvPatchField, volMesh>&
) const = 0;
};
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 27
Finite Volume Method
igGrad /= mesh.V();
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 28
Summary
Sixth OpenFOAM Workshop, Penn State University, 13-16 June 2011. Five Basic Classes in OpenFOAM – p. 29