Excercise

After we have mananged to solve for 2-D cavity flow, it’s time to try 3-D. And parralel proccessing!

3-D cavity flow

First, try to make a 3-D simulations. Start by copying the case to a new folder and to clean the case

cp -r cavity2D cavity3D
./clean.sh

Now these things have to happen

  • make the mesh 3-D by having cells in the z-direction

  • make sure the the front and back sides are not set to “empty” anymore

  • set proper boundary conditions for front and back

  • run it and hope for the best!

Getting fancy - let’s make a parallel run

Three-dimensional simulations need a lot of computing resources and thankfully OpenFoam is fully parallelized and very efficient in making parallel runs. The standard parallelization technique in OpenFoam is called “domain decompositon”. This means that the compuational domain is split into sub-domains and each sub-domain is send to one of the computional cores. As always, all of this is controlled via a dictionary file. This file is called system/decomposeParDict .

To get started we make a copy of our 3-D case.

cp -r cavity3D cavity3D_par
./clean.sh

Unfortunately, theree is no file system/decomposeParDict in our example case… Fortunately, there is probably an example file somewhere in all the provided tutorials. A simple way to find and copy one is this:

cd
find  . -name "decomposeParDict"
./hydrothermalfoam-master/cookbooks/parallel_serial/fixedTfixedFluxPressure/2d_par/system/decomposeParDict
./hydrothermalfoam-master/cookbooks/parallel_serial/fixedTnoFlux/2d_par/system/decomposeParDict
./hydrothermalfoam-master/cookbooks/3Dbox_par/system/decomposeParDict
./hydrothermalfoam-master/cookbooks/helloworld_par/system/decomposeParDict
cp ./hydrothermalfoam-master/cookbooks/helloworld_par/system/decomposeParDict $HOME/HydrothermalFoam_runs/cavity3D_par

Now open this file and edit it; it should look like this

Listing 9 Domain decomposition and parallel processing.
 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      decomposeParDict;
15}
16// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
17
18numberOfSubdomains 4;
19
20method          scotch;
21
22simpleCoeffs
23{
24    n               (2 1 2);
25    delta           0.001;
26}
27// ************************************************************************* //

The domain is split into four equally sized blocks. Again details on this can be found in the OpenFoam User Guide.

../../_images/decomposed_mesh.png

Next you need to modify the run.sh script to invoke a parallel run.

cp run.sh run_par.sh

It should look like this:

Listing 10 The run_par.sh file.
 1#!/bin/sh
 2cd ${0%/*} || exit 1    # Run from this directory
 3
 4# Source tutorial run functions
 5. $WM_PROJECT_DIR/bin/tools/RunFunctions
 6
 7application=`getApplication`
 8
 9./clean.sh
10runApplication blockMesh
11runApplication decomposePar
12runParallel $application
13reconstructPar

Now it’s time to run the case. Results should look like this:

../../_images/3dcavity.png

Fig. 10 Results of the 3-D parallel cavity flow simulation.