Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/run-openfoam-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: OpenFOAM-CI
on:
push:

pull_request:
branches: [ main ]

workflow_dispatch:

env:
CACHE_NUMBER: 1 # increase to reset cache manually

jobs:
openfoam:
runs-on: ubuntu-latest

steps:
- name: checkout repo content
uses: actions/checkout@v2

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
activate-environment: model-validation
use-mamba: true

- name: Set strict channel priority
run: conda config --set channel_priority strict

- name: Setup Apptainer
uses: eWaterCycle/setup-apptainer@v2
with:
apptainer-version: 1.4.5

- name: Update environment
run: mamba env update -n model-validation -f environment_benchmarks.yml

- name: Simulate rotating cylinders using OpenFOAM
shell: bash -l {0}
run: |
cd $GITHUB_WORKSPACE/benchmarks/rotating-cylinders/openfoam
python3 run_benchmark.py

- name: Upload OpenFOAM results
uses: actions/upload-artifact@v4
with:
name: openfoam-results
path: benchmarks/rotating-cylinders/openfoam/results
retention-days: 5
39 changes: 39 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/0/U
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2412 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0 0 0);

boundaryField
{
innerWall
{
type noSlip;
}

outerWall
{
type noSlip;
}

frontAndBack
{
type empty;
}
}

// ************************************************************************* //
34 changes: 34 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/0/p
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2412 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 0;

boundaryField
{
"innerWall|outerWall"
{
type zeroGradient;
}

frontAndBack
{
type empty;
}
}

// ************************************************************************* //
10 changes: 10 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/Allclean
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------

cleanCase

rm -f *.png

#------------------------------------------------------------------------------
12 changes: 12 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/Allrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------

runApplication blockMesh || exit 1
runApplication $(getApplication) || exit 1

echo "Simulation completed. You could now post-process (e.g. visualize) the results."
# ./plot # disabled for benchmark/snakemake-setup

#------------------------------------------------------------------------------
47 changes: 47 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
from pathlib import Path

with open("parameters.json") as f:
config = json.load(f)

rule all:
input: "postProcessing/done"


rule run_simulation_container:
input:
template="system/blockMeshDict.template"
output:
directory("10000"),
touch("postProcessing/done")
params:
r0=config["domain"]["r1"],
r1=config["domain"]["r2"],
nr=config["grid"]["cells_radial"],
ntheta=config["grid"]["cells_angular"] // 4,
g=config["grid"]["grading"],
omega=config["problem"]["omega1"]
resources:
serial_run=1
container: "docker://opencfd/openfoam-run:2412"
shell:
"""
set -euo pipefail

sed -e "s/{{r0}}/{params.r0}/g" \
-e "s/{{r1}}/{params.r1}/g" \
-e "s/{{nr}}/{params.nr}/g" \
-e "s/{{ntheta}}/{params.ntheta}/g" \
-e "s/{{g}}/{params.g}/g" \
{input.template} > system/blockMeshDict
sed -i "s/{{omega}}/{params.omega}/g" constant/MRFProperties

set +u && source /usr/lib/openfoam/openfoam2412/etc/bashrc && set -u
chmod +x Allrun
./Allrun

ls -la
tail log.simpleFoam

touch postProcessing/done
"""
30 changes: 30 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/constant/MRFProperties
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2412 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object MRFProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

MRF1
{
cellZone all;
active yes;

nonRotatingPatches (outerWall);

origin (0 0 0);
axis (0 0 1);
omega {omega};
}

// ************************************************************************* //
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2412 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

transportModel Newtonian;

nu 1;

// ************************************************************************* //
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2412 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object turbulenceProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType laminar;

// ************************************************************************* //
46 changes: 46 additions & 0 deletions benchmarks/rotating-cylinders/openfoam/plot
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
# Require gnuplot
command -v gnuplot >/dev/null || {
echo "FOAM FATAL ERROR: gnuplot not found - skipping graph creation" 1>&2
exit 1
}


gnuplot<<EOF
set terminal pngcairo font "helvetica,16" size 800,600
set output "p.png"
set xlabel "Radius, r"
set xrange [1:2]
set grid

Omega1 = 100.
Omega2 = 0.
R1 = 1.
R2 = 2.

mu = Omega2/Omega1

A = Omega1*(1. - R2*R2*mu/R1/R1)/(1. - R2*R2/R1/R1)
B = R1*R1*Omega1*(1. - mu)/(1. - R1*R1/R2/R2)

analytical_utheta(r) = A*r + B/r
C = 0.5*A*A*R1*R1 + 2.*A*B*log(R1) - 0.5*B*B/R1/R1
analytical_p(r) = 0.5*A*A*r*r + 2.*A*B*log(r) - 0.5*B*B/r/r - C

samples="postProcessing/sample1/10000/centreLine_p_U.xy"

set ylabel "Pressure, p"
set samples 20
set key bottom right
plot samples u 1:2 w lines lw 2 lc "black" t "OpenFOAM", \
analytical_p(x) w p ps 2 pt 6 lw 2 lc rgb "red" t "analytical"

set ylabel "U_{/Symbol q}, rad/s"
set output "Utheta.png"
set samples 20
set key top right
plot samples u 1:4 w lines lw 2 lc "black" t "OpenFOAM", \
analytical_utheta(x) w p ps 2 pt 6 lw 2 lc rgb "red" t "analytical"
set output
EOF
Loading
Loading