Example: Lid-driven cavity
To test that everything works, we copy all the tutorial cases and choose the basic Lid-driven cavity case.
[test03@prelog OpenFOAM]$ mkdir -p $FOAM_RUN
[test03@prelog OpenFOAM]$ cp -r $FOAM_TUTORIALS $FOAM_RUN

Figure 2.1: |
Geometry of the lid driven cavity case. |
We move to the case directory, create the mesh and run the simulation
[test03@prelog OpenFOAM]$ cd $FOAM_RUN/tutorials/incompressible/icoFoam/cavity
[test03@prelog cavity]$ blockMesh
[test03@prelog cavity]$ icoFoam
Let us increase the mesh density by editing the file constant/polyMesh/blockMeshDict so that the 20x20x1 mesh is increased to 500x500x1
blocks
(
hex (0 1 2 3 4 5 6 7) (500 500 1) simpleGrading (1 1 1)
);
This reduces the cell size by a factor of 25 and increases the number of cells 625 times. Since we want to keep the basic case as untouched as possible, the number of steps must also be adjusted to satisfy the Courant criterion. We do this by editing the file system/controlDict, changing the number of steps from 20 to 1000 and the write frequency to
deltaT 0.0001;
writeControl timeStep;
writeInterval 1000;
We repeat the meshing and run the simulation
[test03@prelog cavity]$ blockMesh
[test03@prelog cavity]$ icoFoam > log &
The run time now increases substantially and takes more than a day, whereas the original case took less than a second. The execution in the background can be followed with
[test03@prelog cavity]$ tail -f log
To shorten the time, we parallelise the problem by decomposing the domain into connected subdomains, which are then run on separate processors. For the decomposition into subdomains we use the file from the dam break case, which decomposes the mesh into four subdomains.
[test03@prelog cavity]$ cp $FOAM_RUN/tutorials/multiphase/interFoam/ras/damBreak/system/decomposeParDict system/
To decompose into subdomains we use the command
[test03@prelog cavity]$ decomposePar
This creates the subdirectories processor[0-3], which are the basis for the computation of the individual processes. The parallel simulation is run with the command:
[test03@prelog cavity]$ sbatch --partition=rome --ntasks=4 --ntasks-per-core=1 --wrap="mpirun icoFoam -parallel"
To increase the number of processes, the domain must be decomposed into even more subdomains. For automatic decomposition of more complex domains, tools such as metis or scotsh can also be used. In the cavity case the decomposition is simple. To change to 12 processors, the file system/decomposeParDict must be changed to
numberOfSubdomains 12;
method simple;
simpleCoeffs
{
n ( 3 4 1 );
delta 0.001;
}
Before decomposing into subdomains again, the processor directories must be deleted and the case run with the new number of processes
[test03@prelog cavity]$ rm -rf processor*
[test03@prelog cavity]$ decomposePar
[test03@prelog cavity]$ sbatch --partition=rome --ntasks=12 --ntasks-per-core=1 --wrap="mpirun icoFoam -parallel"
Primer: Lid-driven cavity
Za test delovanja kopiramo vse primere iz navodil in izberemo osnovni primer Lid-driven cavity.
[test03@prelog OpenFOAM]$ mkdir -p $FOAM_RUN
[test03@prelog OpenFOAM]$ cp -r $FOAM_TUTORIALS $FOAM_RUN

Figure 2.1: |
Geometrija za primer lid driven cavity. |
Premaknemo se v imenik s primerom, naredimo mrežo in poženemo simulacijo
[test03@prelog OpenFOAM]$ cd $FOAM_RUN/tutorials/incompressible/icoFoam/cavity
[test03@prelog cavity]$ blockMesh
[test03@prelog cavity]$ icoFoam
Povečajmo gostoto mreže popravkom datoteke constant/polyMesh/blockMeshDict tako, da mrežo 20x20x1 povečamo na 500x500x1
blocks
(
hex (0 1 2 3 4 5 6 7) (500 500 1) simpleGrading (1 1 1)
);
S tem se je velikost celice zmanjšala za 25 krat in tudi 625 krat večje število celic. Ker želimo ohraniti osnovni primer kar najbolj nedotaknjen, je potrebno prilagoditi še število korakov, da zadostimo Courantovem kriteriju. To naredimo tako, da popravimo datoteko system/controlDict in popravimo števio korakov z 20 na 1000 ter pogostost zapisov na
deltaT 0.0001;
writeControl timeStep;
writeInterval 1000;
Ponovimo mreženje in poženemo simulacijo
[test03@prelog cavity]$ blockMesh
[test03@prelog cavity]$ icoFoam > log &
Čas se sedaj bistveno poveča in je zanj potrebno več kote en dan medtem ko je bilo za izhodiščni primer potrebno manj kot sekunda. Izvajanju v ozadju lahko sledimo z
[test03@prelog cavity]$ tail -f log
Za skrajšanje časa problem paraleliziramo z razdelitvijo območja na povezana podobmočja, ki se potem izvajajo na ločenih procesorjih. Za razdelitev na podobmočja uporabimo datoteko primera razlitja jezu, ki razdeli mrežo na štiri podombočja.
[test03@prelog cavity]$ cp $FOAM_RUN/tutorials/multiphase/interFoam/ras/damBreak/system/decomposeParDict system/
Za razdelitev na podobmočja uporabimo ukaz
[test03@prelog cavity]$ decomposePar
Pri tem se izdelajo podimeniki processor[0-3], ki so osnova za računanje posameznih procesov. Paralelno simulacijo poženemo z ukazom:
[test03@prelog cavity]$ sbatch --partition=rome --ntasks=4 --ntasks-per-core=1 --wrap="mpirun icoFoam -parallel"
Za povečanje števila procesov, je potrebno razdeliti na še več poddomen. Za avtomatsko razdelitev zahtevnejših območij se lahko uporabijo tudi orodja kot je metis ali scotsh. V primeru kavitacije je razdeljevanje enostavno. Za spremembo na 12 procesorjev je potrebno popraviti datoteko system/decomposeParDict na
numberOfSubdomains 12;
method simple;
simpleCoeffs
{
n ( 3 4 1 );
delta 0.001;
}
Pred ponovno razdelitvijo na podobmočja je potrebno pobrisati datoteko procesorjev in zagnati z novim številom procesov
[test03@prelog cavity]$ rm -rf processor*
[test03@prelog cavity]$ decomposePar
[test03@prelog cavity]$ sbatch --partition=rome --ntasks=12 --ntasks-per-core=1 --wrap="mpirun icoFoam -parallel"