| title | Water hammer |
|---|---|
| permalink | tutorials-water-hammer.html |
| keywords | OpenFOAM, Nutils, preCICE, geometric-multiscale, fluid, transient |
| summary | The water hammer tutorial simulates unsteady pressure wave propagation in pipe systems using different 1D and 3D configurations coupled via preCICE. |
{% note %} Get the case files of this tutorial, as continuously rendered here, or see the latest released version (if there is already one). Read how in the tutorials introduction. {% endnote %}
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.
In addition to the 1D–3D setup, this tutorial also includes configurations for 1D–1D and 3D–3D coupling.
These variants can be beneficial for validation studies, solver comparisons, or for investigating the influence of model dimensionality on transient wave propagation.
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,
The problem consists of a straight pipe of length
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
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.
preCICE configuration for the 1D–3D simulation (image generated using the precice-config-visualizer):
preCICE configuration for the 3D–1D simulation:
- OpenFOAM (sonicLiquidFoam). A compressible OpenFOAM solver. For more information, have a look at the OpenFOAM adapter documentation.
- Nutils. A Python-based finite element framework. For more information, see the Nutils adapter documentation.
First, select which coupling you want to run. This sets the correct precice-config.xml symlink (by default, set to 1d3d).
# Choose one configuration
./setcase.sh 1d3d
# or
./setcase.sh 3d1d
# or
./setcase.sh 1d1d
# or
./setcase.sh 3d3dThe additional 1D–1D and 3D–3D configurations are particularly useful for validation purposes and for comparing reduced-order and full-order modeling approaches.
Open two terminals and start the corresponding participants for your chosen setup.
Terminal 1:
cd fluid1d-left-nutils
./run.shTerminal 2:
cd fluid3d-right-openfoam
./run.shRun ./setcase.sh 3d1d and then navigate to the respective directories.
Terminal 1:
cd fluid3d-left-openfoam
./run.shTerminal 2:
cd fluid1d-right-nutils
./run.shThe output of the coupled simulation is written into the folders fluid1d-left-nutils, fluid1d-right-nutils, fluid3d-left-openfoam, and fluid3d-right-openfoam, depending on which coupling direction (1d3d or 3d1d) you selected.
For the 3D participant, all simulation results are stored in the time directories inside the respective case folder (e.g., fluid3d-right-openfoam/).
You can visualize the flow field and pressure distribution using ParaView by opening the case file:
paraview fluid3d-right-openfoam/fluid3d-right-openfoam.foamor, for the left domain if applicable:
paraview fluid3d-left-openfoam/fluid3d-left-openfoam.foamTypical 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):
#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-openfoam/postProcessing/probes/0/pfluid3d-right-openfoam/postProcessing/probes/0/U
Each file contains a header (commented with #) and time-series columns for each probe.
The 1D participant writes results to a file named probes.txt, containing the temporal evolution of key quantities at selected spatial locations.
The structure of each line in the file is:
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 domainp_out,u_out→ pressure and velocity at the outlet of the 1D domainp_mid,u_mid→ pressure and velocity at the midpoint of the 1D domain
To reproduce the outlet pressure time history shown in the figure below, a helper script is provided:
python plot-pressure.pyBy default, the script reads the probe data from the OpenFOAM case:
fluid3d-right-openfoam/postProcessing/probes/0/pand generates the outlet pressure plot.
You can also specify the case directory explicitly:
python plot-pressure.py fluid3d-right-openfoamor
python plot-pressure.py fluid1d-right-nutilsThe script automatically selects the correct input file depending on the solver:
-
OpenFOAM case (
fluid3d-right-openfoam)
Reads probe data from
postProcessing/probes/0/p -
Nutils case (
fluid1d-right-nutils)
Reads probe data from
probes.txt
The generated plot is saved to:
images/p_outlet_<case-directory>.pngPressure evolution at the outlet of the 3D domain during the 1D–3D water hammer simulation.
[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
[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


