ACES Instructions For OpenFOAM 2024 Spring
ACES Instructions For OpenFOAM 2024 Spring
1. Prepare
1.1. Start VNC session
We are going to use a VNC session to run OpenFOAM and ParaView in this tutorial.
OpenFOAM itself can also be run in the portal shell or using ssh. But ParaView requires
rendering, so we’ll use VNC here.
Once the VNC is started, open it and you will get a terminal. Commands can be pasted
into the VNC clipboard and then to the terminal with Shift + Insert.
In Chrome, you often get a popup to allow access to the clipboard. By doing so, you can
Shift + Insert directly without pasting to the VNC clipboard first.
A set of functions have been prepared for this course that will reduce the amount of
typing needed. To load them:
source /scratch/training/openfoam/of_fcns
The of_fcns script simplifies some of the commands in the course. When the simplified
commands are used, general ones are shown (grayed out) below for reference.
loadOF10
module purge
module load GCC/11.3.0 OpenMPI/4.1.4 OpenFOAM/10 NEdit/5.7.7
source $FOAM_BASH
Note that the script also loads the NEdit module so we can look at and edit text files.
mkdir $SCRATCH/FOAM_RUN
cd $SCRATCH/FOAM_RUN
1.4. Prepare a separate terminal for running ParaView
Again, right click the background and click “xterm” to open a new terminal to load
ParaView in. This will open a new terminal window.
source /scratch/training/openfoam/of_fcns
loadPV11
module purge
module load ParaView/5.11.1-MPI-Linux64
Keep this terminal open in the background for now, let’s go back to the OpenFOAM
terminal.
copyFoamTutorial windAroundBuildings
cd windAroundBuildings
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/windAroundBuildings .
chmod --recursive +w windAroundBuildings
cd windAroundBuildings
The following are the basic steps outlined in the Allrun script of the tutorial. Each
OpenFOAM tutorial has an Allrun script that gives you an idea what tools are involved.
You can simply run the Allrun script as bash Allrun. But we’ll do it step by step here so
we have time to talk about what is going on.
blockMesh
2.3. Extract surface features/edges (optional)
snappyHexMesh can detect edges and refine around them, as well as snap the mesh to
wrap nicely around corners. There seems to be a problem with the surfaceFeatures
utility on ACES so we’ll have to disable it for now. We’ll do this by removing the line that
picks out the edges in system/snappyHexMeshDict.
surfaceFeatures
disableSF_10
snappyHexMesh -overwrite
simpleFoam
cd $SCRATCH/FOAM_RUN/windAroundBuildings
Normally, ParaView can be launched using the paraFoam script. But we will load it
manually here. ParaView has a built-in reader for OpenFOAM cases. It reads the case
directly from the constant, system and [0-9] folders.
But the ParaView file reader interface requires a single file to be read. So we create a
dummy (empty) file in the case directory with the file ending .foam. This will allow
ParaView to read the whole case.
PV11_loadcase
touch buildings.foam
paraview --data=”buildings.foam”
In ParaView
When ParaView Loads, if not already selected, select patch/buildings under “Mesh
Regions” (Scroll down from green “Apply” button”) Then click “Apply”.
Extract building geometry
● In the top menu, Filters -> Alphabetical -> Extract block
● Select “buildings” patch
● Click “Apply”
● Advance time to last time step (400) by clicking ▶| in the case menu
● Color by pressure by clicking “Solid Color” in the display menu and change to p
● Return to top view by clicking -z in the display menu. This button may be hidden
if your window is too small. If so, click the indicated “>>” button in the example
below to show it.
Make a slice to view velocity profile
● Click windAroundBuildings.OpenFOAM in the left pipeline browser and click
“Slice” in the filters menu
● Click “Z-Normal” in the properties of the slice and change origin z to 30m (x and y
do not matter). Click Apply.
● Find the tutorial that is closest to your problem. Meaning it has the key features you are
looking for. Not necessarily the closest geometry. Geometry is “easy” to change.
● Modify the geometry, boundary conditions and/or solver settings to suit your needs.
● Success?
In this example, we will add a new building to the existing geometry from the tutorial and
measure forces on it. The new building will be a cylindrical tower with a height of 225m and
diameter of 50m.
cd $SCRATCH/FOAM_RUN
copyFoamTutorial windAroundBuildings windAroundNewBuilding
cd windAroundNewBuilding
cd $SCRATCH/FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/windAroundBuildings
./windAroundNewBuilding
In snappyHexMeshDict:
Add in geometry
newBuilding
{
type searchableCylinder;
point1 ( 150 30 0);
point2 (150 30 225);
radius 25;
}
Add in refinementSurfaces
newBuilding
{
level (3 3); //Specify refinement level 3 on new bldg.
patchInfo { type wall; } //Specify boundary type “wall”
}
In blockMeshDict
Modify:
zMax 300;
In controlDict
Add in functions
forceCoeffs1
{
type forceCoeffs;
libs ("libforces.so");
writeControl timeStep;
timeInterval 1; //Write forces every time step
log yes;
blockMesh
disableSF_10
snappyHexMesh -overwrite
simpleFoam
gnuplot
plot "postProcessing/forceCoeffs1/0/forceCoeffs.dat" using 1:2 with lines
exit
3.7. Look at the results with ParaView
Follow the same steps as in the tutorial. But when loading the case and applying the
“Extract Block” filter, select both buildings and newBuilding blocks.
4. Running in parallel
4.1. Decompose the mesh
The windAroundBuildings tutorial doesn’t have a dictionary for decomposing the mesh,
so we’ll copy one from another tutorial.
getDCPD
chmod +w system/decomposeParDict
In decomposeParDict
Modify:
numberOfSubdomains 3;
n (3 1 1);
Then we can decompose the mesh for parallel processing using the decomposePar
command.
rm -r [1-9]*
decomposePar
Running in serial took about 180 seconds and this took about 60 seconds (180/3). So it
scales pretty ideally in this case!
5. Modify solver
5.1. Prepare a directory for custom applications
mkdir $SCRATCH/FOAM_APPS
cd $SCRATCH/FOAM_APPS
5.2. Copy an existing application
cp -r $WM_PROJECT_DIR/applications/solvers/incompressible/icoFoam
my_icoFoam
cd my_icoFoam
mv icoFoam.C my_icoFoam.C
The last two commands are very important not to skip! Or you may overwrite the
default solver.
5.3. Define the new field and make the solver read/write it.
In createFields.H
#include “createPhi.H”
label pRefCell = 0;
∂𝐹
∂𝑡
+ ∇· (𝑈𝐹 ) − ∇ · (ν∇𝐹 ) = 0
Let’s put the equation in its own file for better readability.
touch myFieldEqn.H
In myFieldEqn.H
Add :
solve
(
fvm::ddt(myField)
+ fvm::div(phi, myField)
- fvm::laplacian(nu, myField)
);
In my_icoFoam.C
while(piso.correct())
{
#include "myFieldEqn.H"
volScalarField rAU(1.0/UEqn.A())
Note: If you are compiling a library rather than an executable, the command is wmake
libso
5.6. Test the new solver
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .
chmod --recursive +w cavity
cd cavity
blockMesh
cp 0/p 0/myField
In 0/myField
Modify :
movingWall
{
type fixedValue;
value uniform 1;
}
fixedWalls
{
type fixedValue;
value uniform 0;
}
Define matrix solvers for myField
Now we need to define solvers and schemes for myField
In system/fvSolution
myField
{
solver PBiCG;
preconditioner DILU;
tolerance 1e-5;
relTol 0;
}
myFieldFinal {$myField;}
In system/fvSchemes
my_icoFoam