A first test case - heat diffusion
What do we need?
case files
a mesh
boundary/initial conditions
a solver
simulations controls (time step, run time, etc.)
post-processing
Theory
The first case is the flange case from OpenFOAM tutorials, which illustrates how to solve for 3-D heat conduction in a complex-shaped solid. The equation we will be solving is the transient heat diffusion, a laplacian partial differential equation (PDE) that is here written for the simplfied case of constant properties (Eqn. equation (3)). The equation is based on plugging Fourier’s law (Eqn. equation (1)) into a general energy conservation equation (Eqn. equation (2))
Here \(\rho\) is density, \(C_{cp}\) the specific heat, \(\lambda_r\) the heat conduction coefficient, and \(D=\frac{\lambda_r}{\rho C_{cp}}\) the thermal diffusivity.
Prepare case files
Our first case is the flange case from the OpenFoam tutorials, which illustrates how to solve for 3-D heat conduction in a complex-shaped solid.
Tip
It is good practice to never change the original tutorials, which reside in $FOAM_TUTORIALS but to always make a copy to your working directory.
To get started, just copy the whole case into your shared working directory (probably $HOME/HydrothermalFoam_runs). You need to do this within the docker container (your right-hand shell in Visual Studio Code if you followed the recommended setup). Cd into your shared folder and type this:
cd $HOME/HydrothermalFoam_runs
cp -rf $FOAM_TUTORIALS/basic/laplacianFoam/flange .
An OpenFoam case consist of a certain directory structure, which contains text files that control the case. The tree structure of flange case is shown in Listing 1.
1.
2├── 0
3│ └── T
4├── Allclean
5├── Allrun
6├── constant
7│ └── transportProperties
8├── flange.ans
9└── system
10 ├── controlDict
11 ├── fvSchemes
12 └── fvSolution
The 0 directory contains all initial and boundary conditions, the system folder contains all controlling parameter files, and the constant folder contains constant properties like the mesh - which we will create next.
Mesh generation
The mesh of flange case is prepared as Ansys format (see line 8 of Listing 1), you can use OpenFOAM mesh convert utility of ansysToFoam
to convert the ansys format to OpenFOAM format, the command is shown below,
ansysToFoam flange.ans -scale 0.001
The -scale
option is used to set scale factor of the whole mesh.
Again, you can use command of tree
to explore what changes in the case folder, you can get something like Listing 2, please notice the new files emphasized in the lines 7-13.
1.
2├── 0
3│ └── T
4├── Allclean
5├── Allrun
6├── constant
7│ ├── polyMesh
8│ │ ├── boundary
9│ │ ├── faceZones
10│ │ ├── faces
11│ │ ├── neighbour
12│ │ ├── owner
13│ │ └── points
14│ └── transportProperties
15├── flange.ans
16└── system
17 ├── controlDict
18 ├── fvSchemes
19 └── fvSolution
After converting the mesh, you can use Paraview to visualize the mesh,
touch a.foam
paraview a.foam
Note
touch a.foam
means create a empty file named a.foam
. You might might have the touch
command in windows; then create the empty file inside the docker shell.
Boundary conditions
Next we need to set boundary conditions. Open the file T inside the 0 directory from your local left-hand shell.
code 0/T
1/*--------------------------------*- C++ -*----------------------------------*\
2========= |
3\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration | Website: https://openfoam.org
5 \\ / A nd | Version: 7
6 \\/ M anipulation |
7\*---------------------------------------------------------------------------*/
8FoamFile
9{
10 version 2.0;
11 format ascii;
12 class volScalarField;
13 object T;
14}
15// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
16
17dimensions [0 0 0 1 0 0 0];
18
19internalField uniform 273;
20
21boundaryField
22{
23 patch1
24 {
25 type zeroGradient;
26 }
27
28 patch2
29 {
30 type fixedValue;
31 value uniform 273;
32 }
33
34 patch3
35 {
36 type zeroGradient;
37 }
38
39 patch4
40 {
41 type fixedValue;
42 value uniform 573;
43 }
44}
45
46// ************************************************************************* //
Notice how boundary conditions are set to parts of the mesh that have an identifier like patch2. Those identifiers are defined during the meshing procedure. Here they were defined in the ansys file.
Units are set by the dimensions keyword. The entries refer to the standard SI units [Kg m s K mol A cd]. By having a “1” in the fourth columns, the units of the defined properties has units of Kelvin.
Transport properties
Next we need to set the value of the thermal diffusivity.
code constant/transportProperties
1/*--------------------------------*- C++ -*----------------------------------*\
2========= |
3\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration | Website: https://openfoam.org
5 \\ / A nd | Version: 7
6 \\/ M anipulation |
7\*---------------------------------------------------------------------------*/
8FoamFile
9{
10 version 2.0;
11 format ascii;
12 class dictionary;
13 location "constant";
14 object transportProperties;
15}
16// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
17
18DT DT [0 2 -1 0 0 0 0] 4e-05;
19
20
21// ************************************************************************* //
Again, check that you understand the units, which here add up to m^2/s.
Case control
Finally, we need to set some control parameters like the time step, run time, output writing. These kind of parameters are set in system/controlDict. Open it and explore the values
code system/controlDict
1/*--------------------------------*- C++ -*----------------------------------*\
2========= |
3\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration | Website: https://openfoam.org
5 \\ / A nd | Version: 7
6 \\/ M anipulation |
7\*---------------------------------------------------------------------------*/
8FoamFile
9{
10 version 2.0;
11 format ascii;
12 class dictionary;
13 location "system";
14 object controlDict;
15}
16// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
17
18application laplacianFoam;
19
20startFrom latestTime;
21
22startTime 0;
23
24stopAt endTime;
25
26endTime 3;
27
28deltaT 0.005;
29
30writeControl runTime;
31
32writeInterval 0.1;
33
34purgeWrite 0;
35
36writeFormat ascii;
37
38writePrecision 6;
39
40writeCompression off;
41
42timeFormat general;
43
44timePrecision 6;
45
46runTimeModifiable true;
You can find detailed descriptions of the different parameters in the OpenFoam User Guide. Note that the solver we are using is called laplacianFoam.
Running the case
Now we are finally ready to run our first test case. Just type this into your docker shell:
laplacianFoam
Notice how several directories are appearing, which contain the intermediate results. You can postprocess the case by simply opening the a.foam
file from paraview.