diff --git a/perpendicular-flap-stress/README.md b/perpendicular-flap-stress/README.md new file mode 100644 index 000000000..52b0b57f1 --- /dev/null +++ b/perpendicular-flap-stress/README.md @@ -0,0 +1,60 @@ +--- +title: Perpendicular flap with stresses +keywords: G+Smo, fluid-structure interaction, FSI, OpenFOAM +summary: This tutorial is a modified version of the “perpendicular flap” tutorial using stresses instead of forces. + +--- + +{% note %} +Get the [case files of this tutorial](https://github.com/precice/tutorials/tree/master/perpendicular-flap-stresses). Read how in the [tutorials introduction](https://precice.org/tutorials.html). +{% endnote %} + +## Setup + +The scenario is exactly the same as the one described in the [perpendicular flap tutorial](https://precice.org/tutorials-perpendicular-flap.html). The only difference is that we use stresses instead of forces as data sent from the fluid to the solid participant. This requires changing the mapping constraint from conservative (forces) to consistent (stresses). To avoid a "write-consistent" combination, which [cannot be used in parallel](ttps://precice.org/configuration-mapping.html#restrictions-for-parallel-participants), we exchange both meshes. + +## Configuration + +preCICE configuration (image generated using the [precice-config-visualizer](https://precice.org/tooling-config-visualization.html)): + +![preCICE configuration visualization](images/tutorials-perpendicular-flap-stress-precice-config.png) + +## Available solvers + +Fluid participant: + +* OpenFOAM (pimpleFoam). In case you are using a very old OpenFOAM version, you will need to adjust the solver to `pimpleDyMFoam` in the `Fluid/system/controlDict` file. For more information, have a look at the [OpenFOAM adapter documentation](https://precice.org/adapter-openfoam-overview.html). + +Solid participant: + +* G+Smo (perpendicular-flap-vertex-gismo). This solver includes both linear and nonlinear versions of the Newmark time integrator for time-dependent structural problems. The linear version iterates using a constant stiffness matrix. The nonlinear version iterates using an updated Jacobian matrix to account for material or geometric nonlinearity. By default, the solver runs in linear mode. To switch to nonlinear mode, add `--nonlinear` as option in `run.sh`. For more information, have a look at the [G+Smo adapter documentation](https://precice.org/adapter-gismo-overview.html). + +## Running the simulation + +Open two separate terminals and start the desired fluid and solid participants by calling the respective run scripts `run.sh` located in the participants' directories. For example: + +```bash +cd fluid-openfoam +./run.sh +``` + +and + +```bash +cd solid-gismo +./run.sh +``` + +## Post-processing + +On the OpenFOAM side, you can open the `.foam` file with ParaView, or create VTK files with `foamToVTK`. + +On the G+Smo side, you can open the `.pvd` file located in the `solid-gismo/output` folder using ParaView. If you prefer not to plot the simulation, simply edit the `run.sh` script and remove the `--plot` option. + +As we defined a watchpoint on the 'Solid' participant at the flap tip (see `precice-config.xml`), we can plot it with gnuplot using the script `plot-displacement.sh.` You need to specify the directory of the selected solid participant as a command line argument, so that the script can pick-up the desired watchpoint file, e.g. `plot-displacement.sh solid-gismo`. The resulting graph shows the x displacement of the flap tip. You can modify the script to plot the force instead. + +![Flap watchpoint](images/tutorials-perpendicular-flap-stress-displacement-watchpoint.png) + +{% disclaimer %} +This offering is not approved or endorsed by OpenCFD Limited, producer and distributor of the OpenFOAM software via www.openfoam.com, and owner of the OPENFOAM® and OpenCFD® trade marks. +{% enddisclaimer %} diff --git a/perpendicular-flap-stress/clean-tutorial.sh b/perpendicular-flap-stress/clean-tutorial.sh new file mode 100755 index 000000000..5c4aa46e9 --- /dev/null +++ b/perpendicular-flap-stress/clean-tutorial.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +set -e -u + +# shellcheck disable=SC1091 +. ../tools/cleaning-tools.sh + +clean_tutorial . +clean_precice_logs . +rm -fv ./*.log +rm -fv ./*.vtu diff --git a/perpendicular-flap-stress/fluid-openfoam/0/U b/perpendicular-flap-stress/fluid-openfoam/0/U new file mode 100644 index 000000000..5ad191331 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/0/U @@ -0,0 +1,41 @@ +FoamFile +{ + version 2.0; + format ascii; + class volVectorField; + object U; +} + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (10 0 0); + +boundaryField +{ + inlet + { + type fixedValue; + value $internalField; + } + outlet + { + type zeroGradient; + } + flap + { + type movingWallVelocity; + value uniform (0 0 0); + } + upperWall + { + type noSlip; + } + lowerWall + { + type noSlip; + } + frontAndBack + { + type empty; + } +} diff --git a/perpendicular-flap-stress/fluid-openfoam/0/p b/perpendicular-flap-stress/fluid-openfoam/0/p new file mode 100644 index 000000000..9ab45570b --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/0/p @@ -0,0 +1,45 @@ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + object p; +} + +dimensions [0 2 -2 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + inlet + { + type zeroGradient; + } + + outlet + { + type fixedValue; + value uniform 0; + } + + flap + { + type zeroGradient; + } + + upperWall + { + type zeroGradient; + } + + lowerWall + { + type zeroGradient; + } + + frontAndBack + { + type empty; + } +} diff --git a/perpendicular-flap-stress/fluid-openfoam/0/phi b/perpendicular-flap-stress/fluid-openfoam/0/phi new file mode 100644 index 000000000..9221e0315 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/0/phi @@ -0,0 +1,44 @@ +FoamFile +{ + version 2.0; + format ascii; + class surfaceScalarField; + object phi; +} + +dimensions [0 3 -1 0 0 0 0]; + +internalField uniform 0; +boundaryField +{ + inlet + { + type calculated; + value $internalField; + } + outlet + { + type calculated; + value $internalField; + } + flap + { + type calculated; + value uniform 0; + } + upperWall + { + type calculated; + value uniform 0; + } + lowerWall + { + type calculated; + value uniform 0; + } + frontAndBack + { + type empty; + value nonuniform 0; + } +} diff --git a/perpendicular-flap-stress/fluid-openfoam/0/pointDisplacement b/perpendicular-flap-stress/fluid-openfoam/0/pointDisplacement new file mode 100644 index 000000000..4ac8684e8 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/0/pointDisplacement @@ -0,0 +1,47 @@ +FoamFile +{ + version 2.0; + format ascii; + class pointVectorField; + object pointDisplacement; +} + +dimensions [0 1 0 0 0 0 0]; + +internalField uniform (0 0 0); + +boundaryField +{ + inlet + { + type fixedValue; + value uniform (0 0 0); + } + + outlet + { + type fixedValue; + value uniform (0 0 0); + } + + flap + { + type fixedValue; + value $internalField; + } + + upperWall + { + type slip; + } + + lowerWall + { + type slip; + } + + frontAndBack + { + type empty; + } +} diff --git a/perpendicular-flap-stress/fluid-openfoam/clean.sh b/perpendicular-flap-stress/fluid-openfoam/clean.sh new file mode 100755 index 000000000..b64fc5101 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/clean.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -e -u + +. ../../tools/cleaning-tools.sh + +clean_openfoam . diff --git a/perpendicular-flap-stress/fluid-openfoam/constant/dynamicMeshDict b/perpendicular-flap-stress/fluid-openfoam/constant/dynamicMeshDict new file mode 100644 index 000000000..2a3c1a2ae --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/constant/dynamicMeshDict @@ -0,0 +1,18 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object dynamicMeshDict; +} + +dynamicFvMesh dynamicMotionSolverFvMesh; + +motionSolverLibs ("libfvMotionSolvers.so"); + +solver displacementLaplacian; +// OpenFOAM9 or newer: rename "solver" to "motionSolver" + +displacementLaplacianCoeffs { + diffusivity quadratic inverseDistance (flap); +} diff --git a/perpendicular-flap-stress/fluid-openfoam/constant/transportProperties b/perpendicular-flap-stress/fluid-openfoam/constant/transportProperties new file mode 100644 index 000000000..5383adaad --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/constant/transportProperties @@ -0,0 +1,11 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} + +transportModel Newtonian; + +nu nu [ 0 2 -1 0 0 0 0 ] 1; diff --git a/perpendicular-flap-stress/fluid-openfoam/constant/turbulenceProperties b/perpendicular-flap-stress/fluid-openfoam/constant/turbulenceProperties new file mode 100644 index 000000000..592f6d52d --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/constant/turbulenceProperties @@ -0,0 +1,9 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object turbulenceProperties; +} + +simulationType laminar; diff --git a/perpendicular-flap-stress/fluid-openfoam/run.sh b/perpendicular-flap-stress/fluid-openfoam/run.sh new file mode 100755 index 000000000..8f55fbfa5 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/run.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -e -u + +. ../../tools/log.sh +exec > >(tee --append "$LOGFILE") 2>&1 + +blockMesh + +../../tools/run-openfoam.sh "$@" +. ../../tools/openfoam-remove-empty-dirs.sh && openfoam_remove_empty_dirs + +close_log diff --git a/perpendicular-flap-stress/fluid-openfoam/system/blockMeshDict b/perpendicular-flap-stress/fluid-openfoam/system/blockMeshDict new file mode 100644 index 000000000..875f42294 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/blockMeshDict @@ -0,0 +1,145 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} + +x0 -3.; +x1 -0.05; +x2 0.05; +x3 3.; + +y0 0.; +y1 1.; +y2 4.; + +z0 0; +z1 1; + +vertices +( + ($x0 $y0 $z0 ) // 0 + ($x1 $y0 $z0 ) // 1 + ($x2 $y0 $z0 ) // 2 + ($x3 $y0 $z0 ) // 3 + ($x0 $y1 $z0 ) // 4 + ($x1 $y1 $z0 ) // 5 + ($x2 $y1 $z0 ) // 6 + ($x3 $y1 $z0 ) // 7 + ($x0 $y2 $z0 ) // 8 + ($x1 $y2 $z0 ) // 9 + ($x2 $y2 $z0 ) // 10 + ($x3 $y2 $z0 ) // 11 + + ($x0 $y0 $z1 ) // 12 + ($x1 $y0 $z1 ) // 13 + ($x2 $y0 $z1 ) // 14 + ($x3 $y0 $z1 ) // 15 + ($x0 $y1 $z1 ) // 16 + ($x1 $y1 $z1 ) // 17 + ($x2 $y1 $z1 ) // 18 + ($x3 $y1 $z1 ) // 19 + ($x0 $y2 $z1 ) // 20 + ($x1 $y2 $z1 ) // 21 + ($x2 $y2 $z1 ) // 22 + ($x3 $y2 $z1 ) // 23 +); + +// Grading +h1 30; +h2 3; +v1 15; +v2 30; + +blocks +( + hex ( 0 1 5 4 12 13 17 16 ) + ($h1 $v1 1 ) + simpleGrading (0.5 1 1) + + hex ( 2 3 7 6 14 15 19 18 ) + ($h1 $v1 1) + simpleGrading (2 1 1) + + hex ( 4 5 9 8 16 17 21 20 ) + ($h1 $v2 1) + simpleGrading (0.5 2 1) + + hex ( 5 6 10 9 17 18 22 21 ) + ($h2 $v2 1) + simpleGrading (1 2 1) + + hex ( 6 7 11 10 18 19 23 22 ) + ($h1 $v2 1 ) + simpleGrading (2 2 1) +); + +boundary +( + inlet + { + type patch; + faces + ( + ( 0 4 16 12 ) + ( 4 8 20 16 ) + ); + } + outlet + { + type patch; + faces + ( + ( 3 7 19 15 ) + ( 7 11 23 19 ) + ); + } + flap + { + type wall; + faces + ( + ( 1 5 17 13 ) + ( 5 6 18 17 ) + ( 6 2 14 18 ) + ); + } + upperWall + { + type wall; + faces + ( + ( 8 9 21 20 ) + ( 9 10 22 21 ) + ( 10 11 23 22 ) + ); + } + lowerWall + { + type wall; + faces + ( + ( 0 1 13 12 ) + ( 2 3 15 14 ) + ); + } + frontAndBack + { + type empty; + faces + ( + ( 0 1 5 4 ) + ( 2 3 7 6 ) + ( 4 5 9 8 ) + ( 5 6 10 9 ) + ( 6 7 11 10 ) + ( 12 13 17 16 ) + ( 14 15 19 18 ) + ( 16 17 21 20 ) + ( 17 18 22 21 ) + ( 18 19 23 22 ) + ); + } +); diff --git a/perpendicular-flap-stress/fluid-openfoam/system/controlDict b/perpendicular-flap-stress/fluid-openfoam/system/controlDict new file mode 100644 index 000000000..9d35646a2 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/controlDict @@ -0,0 +1,45 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object controlDict; +} + +application pimpleFoam; // latest OpenFOAM +// application pimpleDyMFoam; // OpenFOAM v1712, OpenFOAM 5.x, or older + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 5; + +deltaT 0.01; + +writeControl adjustableRunTime; + +writeInterval 0.1; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression off; + +timeFormat general; + +timePrecision 6; + +functions +{ + preCICE_Adapter + { + type preciceAdapterFunctionObject; + libs ("libpreciceAdapterFunctionObject.so"); + } +} diff --git a/perpendicular-flap-stress/fluid-openfoam/system/decomposeParDict b/perpendicular-flap-stress/fluid-openfoam/system/decomposeParDict new file mode 100644 index 000000000..31d721d1d --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/decomposeParDict @@ -0,0 +1,17 @@ +FoamFile { + version 2.0; + class dictionary; + object decomposeParDict; + format ascii; +} + +numberOfSubdomains 4; + +method simple; + +simpleCoeffs +{ + n (2 2 1); + delta 0.001; +} + diff --git a/perpendicular-flap-stress/fluid-openfoam/system/fvSchemes b/perpendicular-flap-stress/fluid-openfoam/system/fvSchemes new file mode 100644 index 000000000..80c096192 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/fvSchemes @@ -0,0 +1,39 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + div(phi,U) bounded Gauss upwind; + div((nuEff*dev2(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} diff --git a/perpendicular-flap-stress/fluid-openfoam/system/fvSolution b/perpendicular-flap-stress/fluid-openfoam/system/fvSolution new file mode 100644 index 000000000..064d7f372 --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/fvSolution @@ -0,0 +1,75 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} + +solvers +{ + + p + { + + solver PCG; + preconditioner DIC; + tolerance 1e-8; + relTol 1.0e-3; + } + + pFinal + { + $p; + relTol 0; + } + + pcorr + { + $p; + } + + pcorrFinal + { + $pcorr; + relTol 0; + } + + Phi + { + $p; + } + + "(U|cellDisplacement)" + { + solver smoothSolver; + smoother symGaussSeidel; + tolerance 1e-6; + relTol 1e-4; + minIter 2; + } + + "(U|cellDisplacement)Final" + { + $U; + relTol 0; + } +} + +PIMPLE +{ + nCorrectors 4; + nNonOrthogonalCorrectors 1; + // tolerance 1.0e-14; + // relTol 5e-3; + consistent true; + correctPhi true; + momentumPredictor true; + nOuterCorrectors 1; +} + + +potentialFlow +{ + nNonOrthogonalCorrectors 10; +} diff --git a/perpendicular-flap-stress/fluid-openfoam/system/preciceDict b/perpendicular-flap-stress/fluid-openfoam/system/preciceDict new file mode 100644 index 000000000..22c8858ef --- /dev/null +++ b/perpendicular-flap-stress/fluid-openfoam/system/preciceDict @@ -0,0 +1,38 @@ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object preciceDict; +} + +preciceConfig "../precice-config.xml"; + +participant Fluid; + +modules (FSI); + +interfaces +{ + Interface1 + { + mesh Fluid-Mesh; + patches (flap); + locations faceCenters; + + readData + ( + Displacement + ); + + writeData + ( + Stress + ); + }; +}; + +FSI +{ + rho rho [1 -3 0 0 0 0 0] 1; +} diff --git a/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-displacement-watchpoint.png b/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-displacement-watchpoint.png new file mode 100644 index 000000000..963944fe5 Binary files /dev/null and b/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-displacement-watchpoint.png differ diff --git a/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-precice-config.png b/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-precice-config.png new file mode 100644 index 000000000..e3d750eca Binary files /dev/null and b/perpendicular-flap-stress/images/tutorials-perpendicular-flap-stress-precice-config.png differ diff --git a/perpendicular-flap-stress/plot-displacement.sh b/perpendicular-flap-stress/plot-displacement.sh new file mode 100755 index 000000000..367351abc --- /dev/null +++ b/perpendicular-flap-stress/plot-displacement.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh + +if [ "${1:-}" = "" ]; then + echo "No target directory specified. Please specify the directory of the solid participant containing the watchpoint, e.g. ./plot-displacement.sh solid-gismo." + exit 1 +fi + +FILE="$1/precice-Solid-watchpoint-Flap-Tip.log" + +if [ ! -f "$FILE" ]; then + echo "Unable to locate the watchpoint file (precice-Solid-watchpoint-Flap-Tip.log) in the specified solid directory '${1}'. Make sure the specified directory matches the solid participant you used for the calculations." + exit 1 +fi + +gnuplot -p << EOF + set grid + set title 'x-displacement of the flap tip' + set xlabel 'time [s]' + set ylabel 'x-displacement [m]' + plot "$1/precice-Solid-watchpoint-Flap-Tip.log" using 1:4 with lines title "$1" +EOF diff --git a/perpendicular-flap-stress/precice-config.xml b/perpendicular-flap-stress/precice-config.xml new file mode 100644 index 000000000..1ea013d05 --- /dev/null +++ b/perpendicular-flap-stress/precice-config.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/perpendicular-flap-stress/solid-gismo/clean.sh b/perpendicular-flap-stress/solid-gismo/clean.sh new file mode 100755 index 000000000..5249e1586 --- /dev/null +++ b/perpendicular-flap-stress/solid-gismo/clean.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env sh +set -e -u + +. ../../tools/cleaning-tools.sh + +clean_gismo . diff --git a/perpendicular-flap-stress/solid-gismo/run.sh b/perpendicular-flap-stress/solid-gismo/run.sh new file mode 100755 index 000000000..624de5f23 --- /dev/null +++ b/perpendicular-flap-stress/solid-gismo/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e -u + +. ../../tools/log.sh +exec > >(tee --append "$LOGFILE") 2>&1 + +perpendicular-flap-vertex-gismo -c ../precice-config.xml --plot -r 2 + +close_log diff --git a/tools/cleaning-tools.sh b/tools/cleaning-tools.sh index 90dd7fbb4..0f810ca6f 100755 --- a/tools/cleaning-tools.sh +++ b/tools/cleaning-tools.sh @@ -189,10 +189,27 @@ clean_fmi() { clean_matlab(){ ( - set -e -u - cd "$1" - echo "- Cleaning up MATLAB case in $(pwd)" - clean_precice_logs . - clean_case_logs . + set -e -u + cd "$1" + echo "- Cleaning up MATLAB case in $(pwd)" + clean_precice_logs . + clean_case_logs . ) } +clean_gismo(){ + ( + set -e -u + cd "$1" + echo "- Cleaning up G+Smo case in $(pwd)" + for ext in pvd vts vtp log txt; do + for file in **/*."$ext"; do + # Check if the file exists + [ -f "$file" ] && rm -f "$file" + done + done + rm -fv pointData.csv + rm -rfv ./output/ + clean_precice_logs . + clean_case_logs . + ) +}