-
OpenFOAM
-
OpenFOAM is a C++ based open source library for the analysis of problems in structural and fluid mechanics.
- Contact Person:
- Services:
- Links:penFOAM PageKitware PageSourceForge PageParaView Page
Introduction to OpenFOAM
OpenFOAM(Open Source Field Operation and Manipulation) is an open source CFD toolbox consisting of C++ libraries and executables or also calledapplications. A more detailed description can be found in the documentation.
The model is stored in a so-called case directory, which consists of further subdirectories and files and in which, among other things, the mesh and model descriptions are defined by so-called dictionaries. The meshes can be entered directly via editor in blockMeshDict, the blockmesh directory, but there are also a number of conversion programs that can generate OpenFOAM formats from the mesh formats of other commercial programs, e.g.
- from Fluent.msh files
- from STAR-CD/ProStar mesh files
- from Gambit.neu-File
The pre/post processors HyperMesh and ANSYS ICEM_CFD itself can directly generate meshes for OpenFOAM .
The standard postprocessor for OpenFOAM is Paraview. But there are also tools to convert the results into
- a Fluent format
- a Fieldview format
- an EnSight format
can be converted. In addition, a VTK format can also be generated, which in turn can be displayed with Paraview .
There are a lot of standard solvers for all possible flow models, like
- incompressible, compressible
- multiphase flow
- Direct Numerical Simulation (DNS)
- Heat propagation and buoyancy flow
- Particle transport
- Molecular dynamic methods
- Monte Carlo methods
- Electrostatic and magnetohydrodynamic flows
- Stress-strain analysis of solids
- Black-Scholes equation in finance
and many turbulence models that will not be enumerated in detail here.
OpenFOAM is installed in the SCC on the bwUniCluster. Parallel processing can be done very easily by partitioning the network. For each processor a separate directory is created, where the results of the processed domain are written. Afterwards the results from the partitions are merged again.
Quick guide
Introduction
Control
Geometry and meshing
Initial and boundary conditions
Physical properties
Discretization and Solver
Start of the solver
Postprocessing
Parallel processing
Documentation
Introduction
Using the example of a small problem, Lid-Driven Cavity Flow, i.e. the flow in a box at a given velocity at the lid surface, the principle of OpenFOAM will be presented. In OpenFOAM, calculations are basically performed in three-dimensional geometry. If a problem is to be calculated as a two-dimensional model, an element layer should be created as a thickness in the third direction and appropriate boundary conditions should be set at the boundary surfaces (see below).
First a new case structure must be created.
where case can have a name, e.g. cavity in this demonstration. The case structure consists of three subdirectories
system contains |
controlDict |
in which start/end time and time steps or input/output intervals for the results are defined |
fvSchemes | in which the differential equations are formulated | |
fvSolution | in which the solver is specified. | |
constant contains | polyMesh | in which the geometry and the boundaries are described |
Properties | these are dictionaries in which the physical properties are described | |
Time Directories | 0, ... | The directory 0 contains the initial conditions at the start time (=0). In the controlDict as time increment deltaT is specified and a writeInterval, so that all deltaT*writeInterval time units, the results are written out into a new directory. |
In addition, there may be other directories and files.
Control
First the OpenFOAM environment is created. On the bwUniCluster one enters
source $FOAM_INIT
(or simply: foamInit)
The control is used to set the start and end time and time step size, as well as the output interval for the results. For this purpose a controlDict is created in the subdirectory system with the following content:
FoamFile application icoFoam; |
Most of the parameters are self-explanatory, otherwise you can find a more detailed description in the OpenFOAM User's Guide.
Geometry and meshing
The simple geometry allows to create a structured mesh. For this purpose there is the blockMesh tool. For more complicated geometry, unstructured meshes can be generated using other preprocessors such as HyperMesh or ANSYS ICEM_CFD.
A blockMeshDict is placed in the polyMesh subdirectory. In this the geometry and the mesh is described, as well as the boundary surfaces.
FoamFile convertToMeters 0.1; vertices blocks edges patches ( mergePatchPairs |
Header
all length units are multiplied by 0.1
Definitions of margins for later boundary conditions |
Based on this, the mesh is created using
blockMesh -case<path>/cavity
or if you are in the cavity subdirectory, it is sufficient to enter
blockMesh
is sufficient.
Initial and boundary conditions
The boundary conditions for the velocity U and the pressure p are defined in the two files U and p in the subdirectory 0.
FoamFile dimensions [0 1 -1 0 0 0]; fixedWalls frontAndBack |
FoamFile dimensions [0 2 -2 0 0 0]; internalField uniform 0; boundaryField fixedWalls fixedWalls frontAndBack |
The header contains the name and type of the variable (scalar or vector). The dimension assignment is done according to the following scheme:
the vector positions stand for the SI units
[kg m s K mol A cd]
and the numbers mean the powers of these units, which make up the whole unit. For the velocity in m/sec the vector is then [0 1 -1 0 0 0], for the (kinematic) pressurem2/sec2 correspondingly [0 2 -2 0 0 0].
Inside the box both fields are zero, on the boundary surfaces the velocity is 0 or has the components (1 0 0) on the lid, the pressure has the value "zeroGradient", which means that the normal component of the pressure gradient disappears there. From the side surfaces "frontAndBack "no boundary conditions are given.
Physical properties
For incompressible laminar flow of Newtonian fluids, only the kinematic viscosity is to be specified as physical properties and this is defined via the file transportProperties in the directory constant:
FoamFile nu nu [ 0 2 -1 0 0 ] 0.01; |
nu has the value 0.01m2/s.
Discretization and Solver
The discretization of the differential equations are specified in the file fvSchemes and the solver parameters are specified in the file fvSolution, located in the system subdirectory. Details can also be found in the User's Guide.
FoamFile ddtSchemes gradSchemes divSchemes laplacianSchemes interpolationSchemes interpolate(HbyA) linear; snGradSchemes fluxRequired |
FoamFile solvers U preconditioner DILU; PISO |
Starting the solver
The job can be started in an interactive way and also in batch. The easiest way is to call the solver directly. In our example it is the icoFoam solver:
icoFoam -case<path>/cavity
or if you are in the cavity directory, it is sufficient to simply enter
icoFoam.
On the bwUniCluster (see also Wiki.bwhpc.de: OpenFoam) a start script has to be created to send the job to the Job Management Systems. Here is an example "openfoam.sh":
#!/bin/bash -l
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --partition=single
#SBATCH --time=0:10:00
#SBATCH --mem=6gb
module load cae/openfoam/v2212
foamInit
blockMesh
icoFoam
The start script is submitted as follows:
sbatch openfoam.sh
For parallel processing the grid must be partitioned before (see below).
Postprocessing
The result is a number of directories named after the output time, as described above for the time directories of the case structure. In our example these are the directories 0, 0.1, 0.2, .....,0.5 which contain the results at these times.
The default postprocessor is Paraview, which is embedded in OpenFOAM. In the case subdirectory simply enter the command
paraFoam
in the case subdirectory and select OpenFOAM as reader. More details can be found in the OpenFOAM User Guide.
You can also use Paraview as a standalone postprocessor with
paraview
and read in a variety of other formats, e.g. VTK, EnSight, FLUENT and many more.
OpenFOAM itself offers some converters that generate these formats. For this purpose, the subdirectory cavity calls the different data converters that generate the input data for various other postprocessors:
- foamDataToFluent
- foamToVTK
- foamToEnsight
- and others.
For example, a VTK format is generated by calling
foamToVTK
whereupon a subdirectory VTK is created, in which the files cavity_0.vtk, cavity_20.vtk, ... cavity_100.vtk are located. The numbers here do not mean the result at time points, but after the number of time steps. The handling of Paraview is described in the ParaFOAM User's Guide, ParaView Tutorial and other documentations.
Formats for EnSight, FLUENT and others are generated in an analogous way.
With foamCalc further derived quantities can be calculated from the results. Another useful tool is the sample library. It can be used to collect data along a line or on a surface and output it in a format that allows it to be plotted with plotting programs like gnuplot, Matlab or others. The prerequisite is that a sampleDict is created in the system subdirectory. An example is
FoamFile setFormat raw; sets start (0.02 0.051 0.005); surfaces (); fields (U.component(1)); |
Here, along a line with endpoints (0.02 0.051 0.005) and (0.06 0.051 0.005) at 10 points, the y-component of the velocity is evaluated. A subdirectory sets is created and the values for the XY plot are placed in the subdirectories 0, 0.1 , ... , 0.5. An area plot is not requested.
Parallel processing
First, the computational domain must be decomposed into domains. For this purpose, a Dictionary decomposeParDict is again placed in the subdirectory system. With the call
decomposePar
the partitioning takes place. An example for a decomposition into 8 domains is the following file:
FoamFile numberOfSubdomains 8; method simple; simpleCoeffs hierarchicalCoeffs metisCoeffs manualCoeffs distributed no; roots ( ); |
With the method simple the allocation is given by the number of partitions in each direction by the triple n=(nx,ny,nz). More information about the different methods and the meaning of the coefficients methodeCoeffscan be found in the User's Guide.
After the decomposition the calculation can be started on the bwUniCluster can be started as described on the websiteWiki.bwhpc.de OpenFoam.
If the calculation starts, in case 8 subdirectories processor0, .... , processor7 are created, each with the results of a domain at the times described above. With the call
reconstructPar
the results of the individual domains are merged again.
The line
distributed no;
in decomposeParDict states that the same file system is accessed by all processors. This can lead to performance losses with large problems and also with high parallelization degree. In these cases it is better that each processor writes its data to a local file system. To do this, change the line to
distributed yes;
In addition further information must be in decomposeParDict, which is however only known at run time of the job, the names of the temporary local directories.
Documentation
The following link leads to the online documentation of OpenFOAM: https://www.openfoam.com/documentation/