diff --git a/quickstart/README.md b/quickstart/README.md index cd6927202..fd9220e23 100644 --- a/quickstart/README.md +++ b/quickstart/README.md @@ -115,6 +115,12 @@ You can also run OpenFOAM in parallel: `./run.sh -parallel`. In serial, the simulation should take less than a minute to compute (simulated time: 2.5s). +{% note %} +While we recommend starting with the latest OpenFOAM version from openfoam.com, +this case can alternatively be executed with foam-extend. +For that, replace `run-openfoam.sh` with `run-foam-extend.sh` in the `run.sh` script. +{% endnote %} + ## Visualizing the results You can visualize the simulation results of the `Fluid` participant using ParaView and loading the (empty) file `fluid-openfoam/fluid-openfoam.foam`. The rigid body does not generate any readable output files, but the OpenFOAM data should be enough for now: click "play" in ParaView, the flap should already be moving! 🎉 diff --git a/quickstart/fluid-openfoam/0/U b/quickstart/fluid-openfoam/0/U index ebf7eb904..7d1ead131 100644 --- a/quickstart/fluid-openfoam/0/U +++ b/quickstart/fluid-openfoam/0/U @@ -22,11 +22,14 @@ boundaryField top { type noSlip; + value uniform (0 0 0); + // Note: Values in noSlip are only needed for foam-extend } bottom { type noSlip; + value uniform (0 0 0); } inlet diff --git a/quickstart/fluid-openfoam/constant/dynamicMeshDict b/quickstart/fluid-openfoam/constant/dynamicMeshDict index ec8a77f10..eb04dd676 100644 --- a/quickstart/fluid-openfoam/constant/dynamicMeshDict +++ b/quickstart/fluid-openfoam/constant/dynamicMeshDict @@ -14,6 +14,8 @@ motionSolverLibs ("libfvMotionSolvers.so"); solver displacementLaplacian; // OpenFOAM9 or newer: rename "solver" to "motionSolver" +diffusivity uniform; // Only relevant to foam-extend + displacementLaplacianCoeffs { diffusivity quadratic inverseDistance (flap); } diff --git a/quickstart/fluid-openfoam/system/controlDict b/quickstart/fluid-openfoam/system/controlDict index a527b5781..0237a4453 100644 --- a/quickstart/fluid-openfoam/system/controlDict +++ b/quickstart/fluid-openfoam/system/controlDict @@ -3,13 +3,17 @@ FoamFile version 2.0; format ascii; class dictionary; + location "system"; object controlDict; } +// Note: This file is prepared to run with the latest supported version of OpenFOAM.com. +// The tutorials/tools/run-foam-extend.sh script can modify this and other files to run with foam-extend. +// The format of the file (e.g., linked libraries in one line each) is at parts important to the script. + application pimpleFoam; // latest OpenFOAM // application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older - startFrom startTime; startTime 0; @@ -36,7 +40,10 @@ timeFormat general; timePrecision 8; -libs ("libpreciceAdapterFunctionObject.so"); +libs +( + "libpreciceAdapterFunctionObject.so" +); functions { forces @@ -47,6 +54,13 @@ functions rho rhoInf; log true; rhoInf 10; + // The following entries are only relevant to foam-extend + functionObjectLibs ( "libforces.so" ); + outputControl timeStep; + outputInterval 1; + pName p; + UName U; + rhoName rhoInf; CofR (0 0 0); } diff --git a/quickstart/fluid-openfoam/system/fvSchemes b/quickstart/fluid-openfoam/system/fvSchemes index 2035cd05c..02b56e6fc 100644 --- a/quickstart/fluid-openfoam/system/fvSchemes +++ b/quickstart/fluid-openfoam/system/fvSchemes @@ -21,6 +21,7 @@ divSchemes { default none; div(phi,U) Gauss linearUpwind grad(U); + div((nuEff*dev(T(grad(U))))) Gauss linear; // Only relevant to foam-extend div((nuEff*dev2(T(grad(U))))) Gauss linear; } diff --git a/quickstart/fluid-openfoam/system/fvSolution b/quickstart/fluid-openfoam/system/fvSolution index 813288c04..9db2e2313 100644 --- a/quickstart/fluid-openfoam/system/fvSolution +++ b/quickstart/fluid-openfoam/system/fvSolution @@ -14,6 +14,10 @@ solvers tolerance 1e-6; relTol 1e-4; smoother DICGaussSeidel; + // The following entries are only relevant to foam-extend + agglomerator faceAreaPair; + nCellsInCoarsestLevel 10; + mergeLevels 1; } pFinal @@ -78,3 +82,17 @@ potentialFlow { nNonOrthogonalCorrectors 1; } + +// The relaxationFactors and fieldBounds are only relevant to foam-extend +relaxationFactors +{ + U 0.7; + UFinal 1; +} + +fieldBounds +{ + p -1e5 1e5; + U 100; +} + diff --git a/quickstart/fluid-openfoam/system/preciceDict b/quickstart/fluid-openfoam/system/preciceDict index c67f623a0..69e4bfdcc 100644 --- a/quickstart/fluid-openfoam/system/preciceDict +++ b/quickstart/fluid-openfoam/system/preciceDict @@ -36,4 +36,5 @@ interfaces FSI { rho rho [1 -3 0 0 0 0 0] 1000; + nu nu [0 2 -1 0 0 0 0] 0.001; // Only relevant to foam-extend } diff --git a/tools/run-foam-extend.sh b/tools/run-foam-extend.sh new file mode 100755 index 000000000..9e0aa0e95 --- /dev/null +++ b/tools/run-foam-extend.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +set -e # Not setting -u as it gets triggered by the OpenFOAM RunFunctions + +# Prepare an (intentionally empty) .foam file for the ParaView OpenFOAM reader +CASENAME="$(pwd | xargs basename)" +touch "$CASENAME.foam" + +# Keep a backup of the files to modify +echo "backing up the original files (copies: 0/U.orig, system/controlDict.orig, constant/dynamicMeshDict.orig)" +cp 0/U 0/U.orig +cp system/controlDict system/controlDict.orig +cp constant/dynamicMeshDict constant/dynamicMeshDict.orig + +# Modify code for foam-extend +echo "modifying everything now" +sed -i "s/noSlip;/noSlipWall;/g" 0/U +sed -i "s,application pimpleFoam;,//application pimpleFoam;,g" system/controlDict +sed -i "s,// application pimpleDyMFoam;,application pimpleDyMFoam;,g" system/controlDict +sed -i '41i\ \ \ \ "liblduSolvers.so"' system/controlDict +sed -i '41i\ \ \ \ "libforces.so"' system/controlDict +sed -i "s,writeCompression off,writeCompression uncompressed,g" system/controlDict + +sed -i "s/libfvMotionSolvers\./libfvMotionSolver\./g" constant/dynamicMeshDict + +# OpenFOAM run functions: getApplication, getNumberOfProcessors +# shellcheck disable=SC1090 # This is an OpenFOAM file which we don't need to check +. "${WM_PROJECT_DIR}/bin/tools/RunFunctions" +solver=$(getApplication | cut -f 1 -d " " | sed '\~//~d') +if [ "${1:-}" = "-parallel" ]; then + procs=$(getNumberOfProcessors) + decomposePar -force + mpirun -np "${procs}" "${solver}" -parallel + reconstructPar +else + ${solver} +fi + +# Reverse code for OpenFOAM +#rm -rf constant/polyMesh +#sed -i "s/noSlipWall;/noSlip;/g" 0/U +#sed -i "s,application pimpleDyMFoam;,// application pimpleDyMFoam;,g" system/controlDict +#sed -i "s,//application pimpleFoam;,application pimpleFoam;,g" system/controlDict +#sed -i '/ "liblduSolvers.so"/d' system/controlDict +#sed -i '/ "libforces.so/d' system/controlDict +#sed -i "s,writeCompression uncompressed,writeCompression off,g" system/controlDict +# +#sed -i "s/libfvMotionSolver\./libfvMotionSolvers\./g" constant/dynamicMeshDict