OpenFOAM Boundary Condition Files
1 Initial and Boundary conditions
Since CFD is a numerical integration method, we will need to define initial (IC) and boundary conditions (BC) for the integration in time and space, respectively. Initial and boundary conditions must be provided for all components of the solution vector - in the minimal case pressure p and velocity vector U, haemoFOAM also needs IC and BC for haematocrit concentration H.
Both initial and boundary conditions are set in the files in the time directories, in particular the 0 directory. Please also refer to the official documention for the file structure of OpenFOAM cases, and the Youtube Video - Setting up out First Case.
The 0 directory contains the files H, p, and U, for haematocrit, pressure, and velocity vector, respectively:
~/OpenFOAM/acests3-v1912/run/carotid_steadyState_template ❯ ls 0 H p U
2 Anatomy of IC/BC files
Please also see the official documentation, which is quite brief, so I’ll expand on it here.
The IC/BC files look like this:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v1912 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volVectorField; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; internalField uniform (0 0 0); boundaryField { inlet { type fixedValue; value uniform (10 0 0); } outlet { type zeroGradient; } upperWall { type noSlip; } lowerWall { type fixedValue; value uniform (0 0 0); } frontAndBack { type empty; } } // ************************************************************************* //
The first 7 lines are comments which are mostly decorative (the file will still work without them). The first line has a *- C++ -* in the middle which will tell most editors to use C++ mode - not strictly needed, but useful.
The next 7 lines are important and tell OpenFOAM what the contents are and how to read them:
FoamFile { version 2.0; format ascii; class volVectorField; object U; }
This block is always of the form FoamFile{ }. The version is the configuration file version, not the OpenFOAM version. This is very stable and has not changed for a long time. Most OpenFOAM cases can easily be opened and run on different versions of FOAM, unlike most commercial CFD packages, which tend not to be backward compatible. The file format is usually ascii, i.e. plain text. Keep all file formats in ascii for compatibility and easy of use, since they will always be human readable then.
The next two lines are the important ones. They tell the system that the file contains a vector field stored in the cell volumes, and the name of the “object”, in this case the velocity vector U.
All lines in C++ need to be terminated with a semicolon, forgetting the semicolon is one of the most common mistakes while editing OpenFOAM files!
2.1 Dimensions
The dimensions line tells the code what the dimensions of the object are. The numbers denote the exponent in the SI system in the order of:
[kg m s K mol A cd]
This means that the velocity has:
dimensions [0 1 -1 0 0 0 0];
i.e. \(m^1 s^{-1}\).
2.2 Initial conditions
The next line describes the initial conditions. In most cases it will be enough to initialise with a uniform value as is done here:
internalField uniform (0 0 0);
This initialised the whole field with zero velocity.
2.3 Boundary conditions
The rest of the file contains the boundary conditions, in a nested block:
boundaryField
{
patchName
{
type boundaryConditionType;
value boundaryConditionValues;
}
}
Make sure that you keep track of the opening and closing curly brackets.
We will discuss the different boundary condition types here: OpenFOAM BCs. A full list of all available boundary conditions (most of which will not be of interest in our context) can be found here.