-
-
Notifications
You must be signed in to change notification settings - Fork 129
Water Hammer Tutorial #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
franiqui
wants to merge
35
commits into
precice:develop
Choose a base branch
from
franiqui:WaterHammerTutorial
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2486383
Water Hammer Tutorial
franiqui 23f2f8d
Changed files
franiqui 47e2198
Update thermodynamicProperties
franiqui ee3036d
Update fvSchemes
franiqui b602a51
Update fvSolution
franiqui a722414
Update probes
franiqui 8348272
Update thermodynamicProperties
franiqui 3a49db6
Update fvSchemes
franiqui 02bc955
Update fvSolution
franiqui e59daa4
Update probes
franiqui caba83e
Update probesDict
franiqui 647cc1b
Update thermodynamicProperties
franiqui 359966d
Update fvSchemes
franiqui a9ebbdf
Update fvSolution
franiqui 516a4ba
Update probes
franiqui ec8a328
Update probesDict
franiqui f9b3a5d
Update thermodynamicProperties
franiqui d8e9408
Update fvSchemes
franiqui 8d7204e
Update fvSolution
franiqui 2618cbe
Update probes
franiqui 65fb3d3
Update probesDict
franiqui eba2d5e
Update and rename README.md to README.txt
franiqui 43e14b7
Remove obsolete plot files
franiqui e79dafa
Update precice-config.xml for 3D–3D case
franiqui e01128c
Refactor/update
franiqui 877d12e
Restore water-hammer files from before e01128cd8
franiqui bdd79ea
Deleted ENTIRE Water Hammer case
franiqui e02da82
STARTED AGAIN TUTORIAL
franiqui 2f31599
Changed participant name Fluid1DLeft
franiqui 88cc0c6
Changed ymin and ymax of 3D cases
franiqui 18c0427
Water Hammer Tutorial - New structure with only 1D-3D coupling
franiqui 1d5c577
Updated structure on the Water Hammer tutorial
franiqui 4bd38d1
Updated clean.sh and run.sh to work in the current tutorial structure
franiqui d671761
Suggested changes
franiqui 2d679a9
Suggested Changes and Updated solver-fluid1d/ directory
franiqui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| --- | ||
| title: Partitioned Water Hammer | ||
| keywords: OpenFOAM, Nutils, preCICE, geometric-multiscale, fluid, transient | ||
| summary: The Partitioned Water Hammer tutorial simulates unsteady pressure wave propagation in pipe systems using different 1D and 3D configurations coupled via preCICE. | ||
| --- | ||
|
|
||
| ## Setup | ||
|
|
||
| We solve a **partitioned water hammer problem** using a 1D–3D coupling approach. | ||
| In this tutorial, the computational domain is split into two coupled regions: a 1D pipe section and a 3D pipe section. | ||
| The coupling is performed using **preCICE**. | ||
|
|
||
| The case setup is inspired by [1]. | ||
| This tutorial extends the study conducted in [2], which implemented the water hammer benchmark using a 1D–3D coupling with preCICE. | ||
| In that study, the cross-section of the pipe was square. In this tutorial, this has been changed to a circular cross-section. | ||
| In the following, \( \text{1D} \) denotes the reduced-order domain (e.g., a Nutils solver) and \( \text{3D} \) denotes the full 3D CFD domain (e.g., OpenFOAM). | ||
|
|
||
| The problem consists of a straight pipe of length | ||
|
|
||
| $$ | ||
| L = 1000~\text{m} | ||
| $$ | ||
|
|
||
| and diameter | ||
|
|
||
| $$ | ||
| D = 2~\text{m}. | ||
| $$ | ||
|
|
||
| We partition the domain at | ||
|
|
||
| $$ | ||
| y_c = 500~\text{m}, | ||
| $$ | ||
|
|
||
| where the coupling interface is located. | ||
| The **1D domain** solves the unsteady compressible flow equations using Nutils, while the **3D domain** is solved using OpenFOAM. | ||
| Both solvers are coupled via preCICE by exchanging the **pressure** and **axial velocity** at the interface. | ||
|
|
||
| Two coupling directions are possible: | ||
|
|
||
| - **1D → 3D**: The 1D solver provides the interface pressure to the 3D solver, which responds with velocity. | ||
| - **3D → 1D**: The 3D solver provides the pressure, and the 1D solver returns the velocity. | ||
|
|
||
| The initial inlet pressure is set to | ||
|
|
||
| $$ | ||
| p_\text{in} = 98100~\text{Pa}. | ||
| $$ | ||
|
|
||
| The opening valve at the outlet is modeled through a prescribed outlet velocity, which increases linearly from | ||
|
|
||
| $$ | ||
| 0~\text{m/s} \quad \text{to} \quad 1~\text{m/s} | ||
| $$ | ||
|
|
||
| over the first | ||
|
|
||
| $$ | ||
| t = 5~\text{s} | ||
| $$ | ||
|
|
||
| and remains constant afterwards. | ||
| This sudden valve opening generates pressure disturbances that propagate through the pipe, resulting in the characteristic **pressure wave oscillations** known as the *water hammer* phenomenon. | ||
|
|
||
| --- | ||
|
|
||
| ## Configuration | ||
|
|
||
| preCICE configuration for the 1D–3D simulation (image generated using the [precice-config-visualizer](https://precice.org/tooling-config-visualization.html)): | ||
|
|
||
|  | ||
|
|
||
| preCICE configuration for the 3D–1D simulation: | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Available solvers | ||
|
|
||
| - OpenFOAM (sonicLiquidFoam). A compressible OpenFOAM solver. For more information, have a look at the [OpenFOAM adapter documentation](https://precice.org/adapter-openfoam-overview.html). | ||
| - Nutils. A Python-based finite element framework. For more information, see the [Nutils adapter documentation](https://precice.org/adapter-nutils.html). | ||
|
|
||
| --- | ||
|
|
||
| ## Running the Simulation | ||
|
|
||
| First, select which coupling you want to run. This sets the correct `precice-config.xml` symlink. | ||
|
|
||
| ```bash | ||
| # Choose one (1D → 3D or 3D → 1D) | ||
| ./setcase.sh 1d3d | ||
| # or | ||
| ./setcase.sh 3d1d | ||
| ``` | ||
|
|
||
| Open **two terminals** and start the corresponding participants for your chosen setup. | ||
|
|
||
| ### Example A — 1D → 3D coupling | ||
|
|
||
| Terminal 1: | ||
|
|
||
| ```bash | ||
| cd fluid1d-left | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| Terminal 2: | ||
|
|
||
| ```bash | ||
| cd fluid3d-right | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ### Example B — 3D → 1D coupling | ||
|
|
||
| Terminal 1: | ||
|
|
||
| ```bash | ||
| cd fluid3d-left | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| Terminal 2: | ||
|
|
||
| ```bash | ||
| cd fluid1d-right | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| > Tip: If you switch coupling direction later, rerun `./setcase.sh` with the other option before launching the participants. | ||
|
|
||
| --- | ||
|
|
||
| ## Visualization | ||
|
|
||
| The output of the coupled simulation is written into the folders `fluid1d-left`, `fluid1d-right`, `fluid3d-left`, and `fluid3d-right`, depending on which coupling direction (`1d3d` or `3d1d`) you selected. | ||
|
|
||
| ### 3D domain (OpenFOAM) | ||
|
|
||
| For the 3D participant, all simulation results are stored in the time directories inside the respective case folder (e.g., `fluid3d-right/`). | ||
| You can visualize the flow field and pressure distribution using **ParaView** by opening the case file: | ||
|
|
||
| ```bash | ||
| paraview fluid3d-right/fluid3d-right.foam | ||
| ``` | ||
|
|
||
| or, for the left domain if applicable: | ||
|
|
||
| ```bash | ||
| paraview fluid3d-left/fluid3d-left.foam | ||
| ``` | ||
|
|
||
| Typical fields to inspect include: | ||
|
|
||
| - `p` – pressure (to observe the pressure wave propagation) | ||
| - `U` – velocity (to visualize the flow development near the coupling interface) | ||
|
|
||
| In ParaView, you can also create line plots along the pipe centerline or use temporal filters to observe wave propagation over time. | ||
|
|
||
| We also record pressure and velocity at fixed points each time step using the OpenFOAM `probes` function object. | ||
|
|
||
| **Probe setup (excerpt):** | ||
|
|
||
| ```c | ||
| #includeEtc "caseDicts/postProcessing/probes/probes.cfg" | ||
|
|
||
| fields (p U); | ||
| probeLocations | ||
| ( | ||
| (0 999 0) | ||
| (0 500 0) | ||
| ); | ||
| // For the left 3D domain use instead: | ||
| // probeLocations ((0 0 0) (0 500 0)); | ||
| ``` | ||
|
|
||
| **Output location:** | ||
|
|
||
| - `fluid3d-right/postProcessing/probes/0/p` | ||
| - `fluid3d-right/postProcessing/probes/0/U` | ||
|
|
||
| Each file contains a header (commented with `#`) and time-series columns for each probe. | ||
|
|
||
| --- | ||
|
|
||
| ### 1D domain (Nutils) | ||
|
|
||
| The 1D participant writes results to a file named `watchpoint.txt`, containing the temporal evolution of key quantities at selected spatial locations. | ||
|
|
||
| The structure of each line in the file is: | ||
|
|
||
| ```text | ||
| time; p_in; u_in; p_out; u_out; p_mid; u_mid | ||
| ``` | ||
|
|
||
| where: | ||
|
|
||
| - `p_in`, `u_in` → pressure and velocity at the inlet of the 1D domain | ||
| - `p_out`, `u_out` → pressure and velocity at the outlet of the 1D domain | ||
| - `p_mid`, `u_mid` → pressure and velocity at the midpoint of the 1D domain | ||
|
|
||
| --- | ||
|
|
||
| ### Example visualization | ||
|
|
||
|  | ||
|
|
||
| Pressure evolution at the outlet of the 3D domain during the 1D–3D water hammer simulation. | ||
|
|
||
| --- | ||
|
|
||
| ## References | ||
|
|
||
| [1] C. Wang, H. Nilsson, J. Yang, *et al.* | ||
| **1D–3D coupling for hydraulic system transient simulations.** | ||
| *Computer Physics Communications*, 210:1–9, 2017. | ||
| [https://doi.org/10.1016/j.cpc.2016.09.007](https://doi.org/10.1016/j.cpc.2016.09.007) | ||
|
|
||
| [2] G. Chourdakis, B. Uekermann, G. van Zwieten, and H. van Brummelen. | ||
| **Coupling OpenFOAM to different solvers, physics, models, and dimensions using preCICE.** | ||
| [https://mediatum.ub.tum.de/doc/1515271/1515271.pdf](https://mediatum.ub.tum.de/doc/1515271/1515271.pdf) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| rm -f ./results/Fluid1D_* | ||
| clean_precice_logs . | ||
| clean_case_logs . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| setuptools # required by nutils | ||
| nutils==9 | ||
| numpy >1, <2 | ||
| pyprecice~=3.0 | ||
| matplotlib | ||
| treelog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| set -e -u | ||
|
|
||
| . ../../tools/log.sh | ||
| exec > >(tee --append "$LOGFILE") 2>&1 | ||
|
|
||
| python3 -m venv .venv | ||
| . .venv/bin/activate | ||
| pip install -r requirements.txt && pip freeze > pip-installed-packages.log | ||
|
|
||
| NUTILS_RICHOUTPUT=no python3 ../solver-fluid1d/Fluid1D.py side=Left | ||
|
|
||
| close_log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| rm -f ./results/Fluid1D_* | ||
| clean_precice_logs . | ||
| clean_case_logs . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| setuptools # required by nutils | ||
| nutils==9 | ||
| numpy >1, <2 | ||
| pyprecice~=3.0 | ||
| matplotlib | ||
| treelog |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| set -e -u | ||
|
|
||
| . ../../tools/log.sh | ||
| exec > >(tee --append "$LOGFILE") 2>&1 | ||
|
|
||
| python3 -m venv .venv | ||
| . .venv/bin/activate | ||
| pip install -r requirements.txt && pip freeze > pip-installed-packages.log | ||
|
|
||
| NUTILS_RICHOUTPUT=no python3 ../solver-fluid1d/Fluid1D.py side=Right | ||
|
|
||
| close_log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class volVectorField; | ||
| location "0"; | ||
| object U; | ||
| } | ||
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
|
||
| dimensions [0 1 -1 0 0 0 0]; | ||
|
|
||
| internalField uniform (0 0 0); | ||
|
|
||
| boundaryField | ||
| { | ||
| inlet | ||
| { | ||
| type zeroGradient; | ||
| } | ||
| outlet | ||
| { | ||
| // outOfBounds clamp; | ||
| // Time-varying outlet velocity | ||
| type fixedValue; | ||
| value uniform (0 0 0); | ||
| } | ||
| fixedWalls | ||
| { | ||
| type fixedValue; // no-slip walls | ||
| value uniform (0 0 0); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // ************************************************************************* // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class volScalarField; | ||
| object p; | ||
| } | ||
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
|
||
| dimensions [1 -1 -2 0 0 0 0]; | ||
|
|
||
| internalField uniform 98100; | ||
|
|
||
| boundaryField | ||
| { | ||
| inlet | ||
| { | ||
| type fixedValue; | ||
| value uniform 98100; | ||
| } | ||
|
|
||
| outlet | ||
| { | ||
| type zeroGradient; | ||
| } | ||
|
|
||
|
|
||
| fixedWalls | ||
| { | ||
| type zeroGradient; // no normal pressure gradient at walls | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // ************************************************************************* // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| clean_openfoam . |
18 changes: 18 additions & 0 deletions
18
water-hammer/fluid3d-left/constant/thermodynamicProperties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FoamFile | ||
| { | ||
| version 2.0; | ||
| format ascii; | ||
| class dictionary; | ||
| location "constant"; | ||
| object thermodynamicProperties; | ||
| } | ||
| // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
|
||
| rho0 rho0 [1 -3 0 0 0 0 0] 1000; | ||
|
|
||
| p0 p0 [1 -1 -2 0 0 0 0] 101325; | ||
|
|
||
| psi psi [0 -2 2 0 0 0 0] 1e-6; | ||
|
|
||
|
|
||
| // ************************************************************************* // |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default symlink is to
3d1d, but that scenario only comes next. Let's change that to1d3d.