Module OpenFOAM

Module OpenFOAM

Interactive

Open an interactive session to a compute node. Adjust the number of CPUs (--cpus-per-task 1) and the amount of memory (--mem 4G) needed for your job. Increase the number of --cpus-per-task only when using code that can run in parallel.

srun --cpus-per-task 1 --mem 4G --pty bash

Load the OpenFOAM module. Versions installed are 11.0, 10.0, 9.0, 8.0, and 5.0:

module load openFOAM/11.0

Change the directory to the location in which OpenFOAM should run; in this case, one of the provided tutorials will be used.  This should be the directory that contains the directory of settings, such as "0", "constant", "system", and so on.

cd icoFoam/cavity

Run the "Allrun" script to set things up to run the "case", and then it runs blockMesh to create the mesh, and runs the solver (icoFoam):

./Allrun

When the job finishes, you can check the output, and leave the compute node if you're ready:

[user@athena1 ~]$ srun --cpus-per-task 1 --mem 4G --pty bash ## start on the head node [user@athena150 ~]$ module load openFOAM ## now on a compute node [user@athena150 ~]$ cd icoFoam/cavity/ [user@athena150 ~/icoFoam/cavity]$ ./Allrun Running blockMesh on /lustre/home/user/icoFoam/cavity/cavity Running icoFoam on /lustre/home/user/icoFoam/cavity/cavity Cloning cavityFine case from cavity Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityFine Running mapFields from cavity to cavityFine Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityFine Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityGrade Running mapFields from cavityFine to cavityGrade Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityGrade Cloning cavityHighRe case from cavity Setting cavityHighRe to generate a secondary vortex Copying cavity/0* directory to cavityHighRe Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityHighRe Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityHighRe Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityClipped Running mapFields from cavity to cavityClipped Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityClipped [user@athena150 ~/icoFoam/cavity]$ cd cavity [user@athena150 ~/icoFoam/cavity/cavity]$ tail log.blockMesh nInternalFaces: 760 ---------------- Patches ---------------- patch 0 (start: 760 size: 20) name: movingWall patch 1 (start: 780 size: 60) name: fixedWalls patch 2 (start: 840 size: 800) name: frontAndBack End [user@athena150 ~/icoFoam/cavity/cavity]$ tail log.icoFoam smoothSolver: Solving for Ux, Initial residual = 2.3091e-07, Final residual = 2.3091e-07, No Iterations 0 smoothSolver: Solving for Uy, Initial residual = 5.0684e-07, Final residual = 5.0684e-07, No Iterations 0 DICPCG: Solving for p, Initial residual = 8.63844e-07, Final residual = 8.63844e-07, No Iterations 0 time step continuity errors : sum local = 8.8828e-09, global = 5.49744e-19, cumulative = 3.84189e-19 DICPCG: Solving for p, Initial residual = 9.59103e-07, Final residual = 9.59103e-07, No Iterations 0 time step continuity errors : sum local = 9.66354e-09, global = -1.28048e-19, cumulative = 2.56141e-19 ExecutionTime = 0.094039 s ClockTime = 0 s End [user@athena150 ~/icoFoam/cavity/cavity]$ cd .. [user@athena150 ~/icoFoam/cavity]$ ./Allclean Cleaning /lustre/home/user/icoFoam/cavity/cavity case Cleaning /lustre/home/user/icoFoam/cavity/cavityGrade case Cleaning /lustre/home/user/icoFoam/cavity/cavityClipped case Removing cavityFine case Removing cavityHighRe case [user@athena150 ~icoFoam/cavity]$ exit ## leave the compute node exit [user@athena1 ~]$ ## now back on the head node

Batch job

Prepare the inputs for the job.  In this case, one of the tutorials included in the OpenFOAM installation will be used. 

cp -r /opt/OpenFOAM/OpenFOAM-11/tutorials/legacy/incompressible/icoFoam/ .

Change to the directory where your OpenFOAM "case" is located; here, the tutorial example is used:

cd icoFoam

Create the Slurm job script file.  Adjust the number of CPUs (--cpus-per-task 1) and the amount of memory (--mem 4G) needed for your job. Increase the number of --cpus-per-task only when using code that can run in parallel.

OpenFOAM_slurm_script.sh
#!/bin/bash #SBATCH --job-name OpenFOAM_ico_cavity_job #SBATCH --output OpenFOAM_job_output.log #SBATCH --error OpenFOAM_job_error.log #SBATCH --cpus-per-task=1 #SBATCH --mem 4G module load openFOAM/11.0 cd ./cavity ./Allrun

Submit the job to Slurm:

sbatch OpenFOAM_slurm_script.sh

Monitor the execution of your job in the Slurm queue:

squeue -u $USER

The job may show up in the queue as running (R) or pending (PD). When the job completes, it will disappear from the queue and you can check the output.

[user@athena1 ~icoFoam/cavity]$ sbatch OpenFOAM_slurm_script.sh Submitted batch job 443 [user@athena1 ~icoFoam/cavity]$ squeue -u $USER JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) ## Job is running with JOBID 443 443 cpu OpenFOAM user R 0:02 1 athena150 [user@athena1 ~icoFoam/cavity]$ squeue -u $USER JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) ## JOBID 443 completed and exited the queue [user@athena1 ~icoFoam/cavity]$ cat OpenFOAM_job_error.log [user@athena1 ~icoFoam/cavity]$ cat OpenFOAM_job_output.log Cleaning /lustre/home/user/icoFoam/cavity/cavity case Cleaning /lustre/home/user/icoFoam/cavity/cavityGrade case Cleaning /lustre/home/user/icoFoam/cavity/cavityClipped case Removing cavityFine case Removing cavityHighRe case Running blockMesh on /lustre/home/user/icoFoam/cavity/cavity Running icoFoam on /lustre/home/user/icoFoam/cavity/cavity Cloning cavityFine case from cavity Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityFine Running mapFields from cavity to cavityFine Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityFine Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityGrade Running mapFields from cavityFine to cavityGrade Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityGrade Cloning cavityHighRe case from cavity Setting cavityHighRe to generate a secondary vortex Copying cavity/0* directory to cavityHighRe Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityHighRe Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityHighRe Running blockMesh on /lustre/home/user/icoFoam/cavity/cavityClipped Running mapFields from cavity to cavityClipped Running icoFoam on /lustre/home/user/icoFoam/cavity/cavityClipped [user@athena1 ~icoFoam/cavity]$ tail cavity/cavity/log.blockMesh nInternalFaces: 760 ---------------- Patches ---------------- patch 0 (start: 760 size: 20) name: movingWall patch 1 (start: 780 size: 60) name: fixedWalls patch 2 (start: 840 size: 800) name: frontAndBack End [user@athena1 ~icoFoam/cavity]$ tail cavity/cavity/log.icoFoam smoothSolver: Solving for Ux, Initial residual = 2.3091e-07, Final residual = 2.3091e-07, No Iterations 0 smoothSolver: Solving for Uy, Initial residual = 5.0684e-07, Final residual = 5.0684e-07, No Iterations 0 DICPCG: Solving for p, Initial residual = 8.63844e-07, Final residual = 8.63844e-07, No Iterations 0 time step continuity errors : sum local = 8.8828e-09, global = 5.49744e-19, cumulative = 3.84189e-19 DICPCG: Solving for p, Initial residual = 9.59103e-07, Final residual = 9.59103e-07, No Iterations 0 time step continuity errors : sum local = 9.66354e-09, global = -1.28048e-19, cumulative = 2.56141e-19 ExecutionTime = 0.084884 s ClockTime = 0 s End

Parallel job

Prepare the inputs for the job.  In this case, one of the tutorials included in the OpenFOAM installation will be used again.

cp -r /opt/OpenFOAM/OpenFOAM-11/tutorials/legacy/incompressible/icoFoam/ .

Change the directory to the "case" directory in which to run the parallel job:

cd icoFoam/cavity/cavity

Create the Slurm job script file.  Adjust the number of CPUs (--cpus-per-task 1) and the amount of memory per cpu (--mem-per-cpu 4G) needed for your job. Increase the number of --cpus-per-task only when using code that can run in parallel. 

Note that --nodes, --ntasks-per-node, --cpus-per-node, all will need to agree with the value set for "Subdomains" in the system/decomposeParDict file for this "case".  For example, in this job script, the number of subdomains value in the system/decomposeParDIct file is 8; 2 nodes * 4 ntasks-per-node * 1 cpus-per-task = 8.

OpenFOAM_slurm_parallel_script.sh
#!/bin/bash #SBATCH --job-name OpenFOAM_ico_cavity_job #SBATCH --output OpenFOAM_job_output.log #SBATCH --error OpenFOAM_job_error.log #SBATCH --nodes=2 #SBATCH --ntasks-per-node=4 #SBATCH --cpus-per-task=1 #SBATCH --mem-per-cpu=4G module load mpi/openmpi-4.1.6 openFOAM/11.0 srun icoFoam -parallel

Create the system/decomposeParDict file:

foamGet decomposeParDict Multiple files with "decomposeParDict" prefix found: 1) /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/annotated/decomposeParDict 2) /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/preProcessing/decomposeParDict ** Note: it is easier to use files NOT in the "annotated" directory Enter file number (1-2) to obtain description (suggest 2) : 2 Copying /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/preProcessing/decomposeParDict to system

Finish setting up the case directory for the parallel job.  You may be familiar with creating the mesh and so on, decomposePar will read the system/decomposeParDict file, and create the processor<N> subdirectories to be used for each section the case is to be broken into to be worked on by N processors.

blockMesh ## create the mesh checkMesh ## optional, check the mesh if you like setFields decomposePar ## create the subdirectories used by each processor involved in the job

Submit the job to Slurm:

sbatch OpenFOAM_slurm_parallel_script.sh

Monitor the execution of your job in the Slurm queue:

squeue -u $USER

The job may show up in the queue as running (R) or pending (PD). When the job completes, it will disappear from the queue and you can check the output.

[user@athena1 ~]$ cp -r /opt/OpenFOAM/OpenFOAM-11/tutorials/legacy/incompressible/icoFoam/ . [user@athena1 ~]$ cd icoFoam/cavity/cavity [user@athena1 ~/icoFoam/cavity/cavity]$ foamGet decomposeParDict Multiple files with "decomposeParDict" prefix found: 1) /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/annotated/decomposeParDict 2) /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/preProcessing/decomposeParDict ** Note: it is easier to use files NOT in the "annotated" directory Enter file number (1-2) to obtain description (suggest 2) : 2 Copying /opt/OpenFOAM/OpenFOAM-11/etc/caseDicts/preProcessing/decomposeParDict to system [user@athena1 ~/icoFoam/cavity/cavity]$ blockMesh [user@athena1 ~/icoFoam/cavity/cavity]$ checkMesh [user@athena1 ~/icoFoam/cavity/cavity]$ setFields [user@athena1 ~/icoFoam/cavity/cavity]$ decomposePar [user@athena1 ~/icoFoam/cavity/cavity]$ sbatch OpenFOAM_slurm_parallel_script.sh Submitted batch job 576 [user@athena1 ~/icoFoam/cavity/cavity]$ squeue -u $USER JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) ## Job is running with JOBID 576 576 cpu OpenFOAM user R 0:13 2 athena[101,150] [user@athena1 ~/icoFoam/cavity/cavity]$ squeue -u $USER JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) ## JOBID 576 completed and exited the queue [user@athena1 ~/icoFoam/cavity/cavity]$ tail OpenFOAM_job_error.log [user@athena1 ~/icoFoam/cavity/cavity]$ tail OpenFOAM_job_output.log smoothSolver: Solving for Uy, Initial residual = 5.00134e-07, Final residual = 5.00134e-07, No Iterations 0 DICPCG: Solving for p, Initial residual = 1.14959e-06, Final residual = 5.62255e-07, No Iterations 1 time step continuity errors : sum local = 6.39729e-09, global = 2.79339e-19, cumulative = 5.05375e-17 DICPCG: Solving for p, Initial residual = 5.43989e-07, Final residual = 5.43989e-07, No Iterations 0 time step continuity errors : sum local = 6.24756e-09, global = -9.20652e-20, cumulative = 5.04454e-17 ExecutionTime = 0.462801 s ClockTime = 0 s End Finalising parallel run