From 30deb03b9e2e440cc815d98a0ce24cd6ae56e46f Mon Sep 17 00:00:00 2001 From: "moritz.schwarzmeier" Date: Wed, 9 Jul 2025 16:24:26 +0200 Subject: [PATCH 1/3] add OpenFOAM test case: rotating cylinder --- .github/workflows/run-benchmark.yml | 41 +++++- benchmarks/rotating-cylinder-OpenFOAM/0/U | 39 ++++++ benchmarks/rotating-cylinder-OpenFOAM/0/p | 34 +++++ .../rotating-cylinder-OpenFOAM/Allclean | 10 ++ benchmarks/rotating-cylinder-OpenFOAM/Allrun | 10 ++ .../rotating-cylinder-OpenFOAM/Snakefile | 8 ++ .../constant/MRFProperties | 30 ++++ .../constant/transportProperties | 22 +++ .../constant/turbulenceProperties | 20 +++ benchmarks/rotating-cylinder-OpenFOAM/plot | 44 ++++++ .../system/blockMeshDict | 130 ++++++++++++++++++ .../system/controlDict | 88 ++++++++++++ .../system/fvSchemes | 51 +++++++ .../system/fvSolution | 57 ++++++++ 14 files changed, 578 insertions(+), 6 deletions(-) create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/0/U create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/0/p create mode 100755 benchmarks/rotating-cylinder-OpenFOAM/Allclean create mode 100755 benchmarks/rotating-cylinder-OpenFOAM/Allrun create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/Snakefile create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/constant/MRFProperties create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/constant/transportProperties create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/constant/turbulenceProperties create mode 100755 benchmarks/rotating-cylinder-OpenFOAM/plot create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/system/controlDict create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/system/fvSchemes create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/system/fvSolution diff --git a/.github/workflows/run-benchmark.yml b/.github/workflows/run-benchmark.yml index a98a3d6..6361d4a 100644 --- a/.github/workflows/run-benchmark.yml +++ b/.github/workflows/run-benchmark.yml @@ -20,8 +20,6 @@ jobs: tests: runs-on: ubuntu-latest - - steps: - name: checkout repo content uses: actions/checkout@v2 @@ -30,19 +28,25 @@ jobs: uses: conda-incubator/setup-miniconda@v3 with: miniforge-version: latest - activate-environment: model-validation + activate-environment: model-validation use-mamba: true - name: Update environment run: mamba env update -n model-validation -f environment_benchmarks.yml if: steps.cache.outputs.cache-hit != 'true' + - name: run-OpenFOAM-benchmarks + shell: bash -l {0} + run: | + cd $GITHUB_WORKSPACE/benchmarks/rotating-cylinder-OpenFOAM/ + snakemake --force --cores 'all' + - name: run-fenics-benchmarks shell: bash -l {0} run: | cd $GITHUB_WORKSPACE/benchmarks/linear-elasticity-plate-with-hole/ snakemake --use-conda --force --cores 'all' - + - name: run-Kratos-benchmarks shell: bash -l {0} run: | @@ -67,11 +71,36 @@ jobs: name: fenics-output path: | benchmarks/linear-elasticity-plate-with-hole/data - + - name: Archive kratos data uses: actions/upload-artifact@v4 with: name: kratos-output path: | benchmarks/linear-elasticity-plate-with-hole-Kratos/data - + + + test_rotCyl_OF: + runs-on: ubuntu-latest + container: + image: opencfd/openfoam-run:2412 + + steps: + - name: Print debug information + run: | + echo "Running on OpenFOAM image" + echo "Current directory: $PWD" + echo "Available files:" + ls -la + + - name: checkout repo content + uses: actions/checkout@v2 + + - name: run-OpenFOAM-benchmarks + shell: bash -l {0} + run: | + cd $GITHUB_WORKSPACE/benchmarks/rotating-cylinder-OpenFOAM/ + sudo apt-get update && sudo apt-get install -y gnuplot + chmod +x ./plot + bash ./Allrun + echo "Finished job" diff --git a/benchmarks/rotating-cylinder-OpenFOAM/0/U b/benchmarks/rotating-cylinder-OpenFOAM/0/U new file mode 100644 index 0000000..ae67c92 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/0/U @@ -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; + } +} + +// ************************************************************************* // diff --git a/benchmarks/rotating-cylinder-OpenFOAM/0/p b/benchmarks/rotating-cylinder-OpenFOAM/0/p new file mode 100644 index 0000000..007b1b9 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/0/p @@ -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; + } +} + +// ************************************************************************* // diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Allclean b/benchmarks/rotating-cylinder-OpenFOAM/Allclean new file mode 100755 index 0000000..ad9bdea --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/Allclean @@ -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 + +#------------------------------------------------------------------------------ diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Allrun b/benchmarks/rotating-cylinder-OpenFOAM/Allrun new file mode 100755 index 0000000..9fcf369 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/Allrun @@ -0,0 +1,10 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +runApplication blockMesh +runApplication $(getApplication) +./plot + +#------------------------------------------------------------------------------ diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Snakefile b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile new file mode 100644 index 0000000..1eb6662 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile @@ -0,0 +1,8 @@ + +rule run_simulation_container: + input: + ".", + output: + directory("."), + container: "docker://opencfd/openfoam-run:2412" + shell: "./Allrun" diff --git a/benchmarks/rotating-cylinder-OpenFOAM/constant/MRFProperties b/benchmarks/rotating-cylinder-OpenFOAM/constant/MRFProperties new file mode 100644 index 0000000..98414d4 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/constant/MRFProperties @@ -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 100; +} + +// ************************************************************************* // diff --git a/benchmarks/rotating-cylinder-OpenFOAM/constant/transportProperties b/benchmarks/rotating-cylinder-OpenFOAM/constant/transportProperties new file mode 100644 index 0000000..607db27 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/constant/transportProperties @@ -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; + +// ************************************************************************* // diff --git a/benchmarks/rotating-cylinder-OpenFOAM/constant/turbulenceProperties b/benchmarks/rotating-cylinder-OpenFOAM/constant/turbulenceProperties new file mode 100644 index 0000000..52a7d3b --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/constant/turbulenceProperties @@ -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; + +// ************************************************************************* // diff --git a/benchmarks/rotating-cylinder-OpenFOAM/plot b/benchmarks/rotating-cylinder-OpenFOAM/plot new file mode 100755 index 0000000..2fb9f14 --- /dev/null +++ b/benchmarks/rotating-cylinder-OpenFOAM/plot @@ -0,0 +1,44 @@ +#!/bin/sh +# Require gnuplot +command -v gnuplot >/dev/null || { + echo "FOAM FATAL ERROR: gnuplot not found - skipping graph creation" 1>&2 + exit 1 +} + + +gnuplot< Date: Mon, 21 Jul 2025 12:05:58 +0000 Subject: [PATCH 2/3] run OpenFOAM with snakemake --- .github/workflows/run-benchmark.yml | 13 +++++++++++-- benchmarks/rotating-cylinder-OpenFOAM/Allrun | 4 +++- benchmarks/rotating-cylinder-OpenFOAM/Snakefile | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-benchmark.yml b/.github/workflows/run-benchmark.yml index 6361d4a..78cbe60 100644 --- a/.github/workflows/run-benchmark.yml +++ b/.github/workflows/run-benchmark.yml @@ -19,6 +19,8 @@ env: jobs: tests: runs-on: ubuntu-latest + container: + image: opencfd/openfoam-run:2412 steps: - name: checkout repo content @@ -35,11 +37,18 @@ jobs: run: mamba env update -n model-validation -f environment_benchmarks.yml if: steps.cache.outputs.cache-hit != 'true' + - name: Ensure log directory exists + run: mkdir -p benchmarks/rotating-cylinder-OpenFOAM/.snakemake/log + - name: run-OpenFOAM-benchmarks shell: bash -l {0} run: | cd $GITHUB_WORKSPACE/benchmarks/rotating-cylinder-OpenFOAM/ - snakemake --force --cores 'all' + mkdir -p ./.snakemake/log || true # bc. snakemake is not able to create this directory itself + chmod +x Allrun + echo "Starting snakemake" + snakemake --cores 1 + echo "Finished job." - name: run-fenics-benchmarks shell: bash -l {0} @@ -100,7 +109,7 @@ jobs: shell: bash -l {0} run: | cd $GITHUB_WORKSPACE/benchmarks/rotating-cylinder-OpenFOAM/ - sudo apt-get update && sudo apt-get install -y gnuplot + # sudo apt-get update && sudo apt-get install -y gnuplot chmod +x ./plot bash ./Allrun echo "Finished job" diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Allrun b/benchmarks/rotating-cylinder-OpenFOAM/Allrun index 9fcf369..b2a0cbe 100755 --- a/benchmarks/rotating-cylinder-OpenFOAM/Allrun +++ b/benchmarks/rotating-cylinder-OpenFOAM/Allrun @@ -5,6 +5,8 @@ cd "${0%/*}" || exit # Run from this directory runApplication blockMesh runApplication $(getApplication) -./plot + +echo "Simulation completed. You could now post-process (e.g. visualize) the results." +# ./plot # disabled for benchmark/snakemake-setup #------------------------------------------------------------------------------ diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Snakefile b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile index 1eb6662..2c4a984 100644 --- a/benchmarks/rotating-cylinder-OpenFOAM/Snakefile +++ b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile @@ -1,8 +1,17 @@ rule run_simulation_container: input: - ".", - output: - directory("."), + mesh="system/blockMeshDict", + config="system/controlDict", + initial_conditions="0/", + scripts="Allrun" + output: + directory("1000"), container: "docker://opencfd/openfoam-run:2412" - shell: "./Allrun" + shell: + """ + set -euo pipefail + echo "Starting simulation." + ./Allrun + ls -la + """ From 6b1c5551d6c9727a59b35c3d0eaf38d36f4d0c83 Mon Sep 17 00:00:00 2001 From: mschwarzmeier <89848589+mschwarzmeier@users.noreply.github.com> Date: Mon, 22 Sep 2025 16:38:26 +0000 Subject: [PATCH 3/3] set up OpenFOAM case as parameter study --- .gitignore | 3 ++- .../rotating-cylinder-OpenFOAM/Snakefile | 27 ++++++++++++++++--- .../rotating-cylinder-OpenFOAM/cases/.gitkeep | 0 .../{blockMeshDict => blockMeshDict.template} | 4 +-- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 benchmarks/rotating-cylinder-OpenFOAM/cases/.gitkeep rename benchmarks/rotating-cylinder-OpenFOAM/system/{blockMeshDict => blockMeshDict.template} (97%) diff --git a/.gitignore b/.gitignore index f684468..72025d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .snakemake -site \ No newline at end of file +site +venv/ diff --git a/benchmarks/rotating-cylinder-OpenFOAM/Snakefile b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile index 2c4a984..bc0614c 100644 --- a/benchmarks/rotating-cylinder-OpenFOAM/Snakefile +++ b/benchmarks/rotating-cylinder-OpenFOAM/Snakefile @@ -1,17 +1,36 @@ +# Define the parameter space +# 40 is default +meshNs = [10, 20, 40] + +rule all: + input: + expand("cases/meshN_{meshN}/postprocessing/done", meshN=meshNs) + rule run_simulation_container: input: - mesh="system/blockMeshDict", - config="system/controlDict", - initial_conditions="0/", + template="system/blockMeshDict.template", scripts="Allrun" output: - directory("1000"), + directory("cases/meshN_{meshN}/1000"), + touch("cases/meshN_{meshN}/postprocessing/done") container: "docker://opencfd/openfoam-run:2412" shell: """ set -euo pipefail + + echo "Setting up simulation {wildcards.meshN}." + mkdir -p cases/meshN_{wildcards.meshN} + cp -r 0 system constant Allclean Allrun plot cases/meshN_{wildcards.meshN}/ + cd cases/meshN_{wildcards.meshN} + sed "s/{{meshN}}/{wildcards.meshN}/g" {input.template} > system/blockMeshDict + echo "Starting simulation." + chmod +x Allrun ./Allrun + ls -la + tail log.simpleFoam + + touch postprocessing/done """ diff --git a/benchmarks/rotating-cylinder-OpenFOAM/cases/.gitkeep b/benchmarks/rotating-cylinder-OpenFOAM/cases/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict b/benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict.template similarity index 97% rename from benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict rename to benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict.template index 70b8157..d6e1215 100644 --- a/benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict +++ b/benchmarks/rotating-cylinder-OpenFOAM/system/blockMeshDict.template @@ -21,8 +21,8 @@ geom r0 1; r1 2; - nr 40; - ntheta 40; + nr {meshN}; // 40; + ntheta {meshN}; // 40; g 10;