Skip to content

OpenFOAM setup (fluid)

Makis Chourdakis edited this page Nov 28, 2017 · 18 revisions

OpenFOAM reads several configuration files, which are included in a case directory. In our tutorial, for the Fluid participant, we see the following files:

  • 0/: State of the domain at time=0. In other words: the initial and boundary conditions.
    • T: Temperature field
    • U: Velocity
    • alphat: Turbulent thermal diffusivity
    • epsilon, k: Parameters of the k-epsilon turbulence model (disabled by default)
    • nut: Turbulent viscosity
    • p and p_rgh: Pressure
  • constant/: Model properties
    • g: Gravity
    • thermophysicalProperties: Properties of the thermophysical model (thermodynamics, transport, etc.)
    • turbulenceProperties: Properties of the turbulence model. By default it is set to laminar flow.
  • system/: Solver properties
    • blockMeshDict: Mesh properties. The mesh is produced with the command blockMesh.
    • controlDict: Time step length, end time, output settings etc
    • fvSchemes: Finite Volume Schemes - the numerical schemes
    • fvSolution: Finite Volume Solution - the numerical solvers' parameters
  • Fluid.foam: An empty file that serves as a reference to ParaView
  • precice-adapter-config.yml: Our adapter's configuration file

Let's see the most relevant files in more details.

Mesh generation

The mesh for this case is defined in the system/blockMeshDict file. This is one of the ways to define a mesh in OpenFOAM, which does not require a geometry file.

In this file, the section vertices( ... ) specifies geometry points in the form (x y z), where the values are in meters (unless the ration convertToMeters is different than 1). In the blocks( ... ) sections, the vertices are used to create blocks:

blocks
(
    hex (12 0 3 13 15 4 7 14) (81 41 1) simpleGrading (.2 15 1)
    hex (0 1 2 3 4 5 6 7) (161 41 1) simpleGrading (5 15 1)
    hex (1 8 9 2 5 10 11 6) (51 41 1) simpleGrading (1 15 1)
);
  • Each line corresponds to a block.
  • The hex means hexahedral cells.
  • The first set of numbers defines the vertices used for the block and the numbers correspond to the order they were defined in the vertices. When defining blocks, the order of the nodes in each block needs to follow the "right-hand rule".
  • The second set of numbers is the cells per (x y z) direction. Here, we only use one cell in the z (depth) direction.
  • The rest of the line defines the cell grading or mesh stretching. Here, the method simpleGrading is used. The set of numbers define the ratio of the size of the last cell in each direction to the first one.

In this file we also define the boundaries of the geometry in the boundary( ... ) section. For example:

interface
{
    type wall;
    faces
    (
        (4 0 1 5)
    );
}

defines a wall boundary, named interface, that consists of one face. These numbers refer again to the geometry points and need to follow the "right-hand rule". We are going to use this boundary as the coupling interface.

In order to generate the mesh, we run blockMesh. This is done in the run scripts. You may also check the quality of the mesh using checkMesh. The result mesh looks like this:

Mesh overview

Boundary conditions

The boundary conditions are defined in the 0/ directory, in a different file for each field. Note that, if you started the simulation from a later time (e.g. t=500), then you would define them in the 500/ directory.

Let's see what is defined in the 0/T for the temperature, which participates in the coupling:

dimensions      [ 0 0 0 1 0 0 0 ];

internalField   uniform 300;

boundaryField
{
    interface
    {
        type            fixedGradient;
        gradient        uniform 0;
    }
    inlet
    {
        type            fixedValue;
        value           $internalField;
    }
    outlet
    {
        type            zeroGradient;
    }
...
    defaultFaces
    {
        type            empty;
    }
}

The dimensions defines the dimensions of the field (their exponents), in the form [kg m s K mol A cd] for the SI unit system. OpenFOAM also supports other unit systems. Note that most of the fields that OpenFOAM uses are dimensioned and their conformity is checked during computations.

The internalField specifies the values at the cell centers. In this case, we assign the same (uniform) value to all the cells (300 K).

The section boundaryField{ ... } specifies the boundary conditions. Here we list the following types:

  • The interface is set to type fixedGradient. This is done because we are going to read heat fluxes on this boundary. See the adapter's configuration page for more. The gradient value is overwritten by the adapter.
  • The inlet (defined as the left boundary in the blockMeshDict) is set to a Dirichlet boundary condition. The temperature is set to be the same as the value set in the internalField.
  • In the outlet we specify that the temperature does not change anymore. This is equivalent to writing fixedGradient with gradient uniform 0.
  • The defaultFaces covers any faces that have not been defined here. In this case, this matches the front and back boundaries. We are assuming a 2D problem, so we assign the z-boundaries to empty.

Model properties

It is important to remember that OpenFOAM is not one solver, but rather a collection of solvers, which vary in what models they support. In this tutorial, we use the solver buoyantPimpleFoam for the fluid, which supports the full spectrum of thermophysical and turbulence models.

In the constant/thermophysicalProperties file, we are mainly interested in the values of Cp (specific heat), mu (dynamic viscosity) and Pr (Prandtl number). You may recall for the conductivity, the Prandtl number and the dynamic viscosity:

Equations for k, Pr, mu

From these, we see that we only need these three properties to calculate the conductivity:

Equations for k, Pr, mu

Please refer to the OpenFOAM User Guide for more information.