Skip to content

Commit b119683

Browse files
authored
Update master (v202104.1.1)
2 parents 15e5240 + c97f3d3 commit b119683

File tree

11 files changed

+60
-75
lines changed

11 files changed

+60
-75
lines changed

elastic-tube-1d/README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ The following parameters have been chosen:
2525
- Fluid density: $$ \rho = 1 $$
2626
- Young modulus: E = 10000
2727

28+
Additionally the solvers use the parameters `N = 100` (number of cells), `tau = 0.01` (dimensionless timestep size), `kappa = 100` (dimensionless structural stiffness) by default. These values can be modified directly in each solver.
29+
2830
## Available solvers
2931

3032
Both fluid and solid participant are supported in:
@@ -70,8 +72,6 @@ cd solid-cpp
7072
./run.sh
7173
```
7274

73-
The solvers use the parameters `N = 100`, `tau = 0.01`, `kappa = 100` by default and can be modified in the solver.
74-
7575
### Python
7676

7777
Open two separate terminals and start each participant by calling the respective run script. Only serial run is possible:
@@ -88,25 +88,21 @@ cd solid-python
8888
./run.sh
8989
```
9090

91-
Parameters such as `N` can be modified directly at the `FluidSolver.py` and at the `SolidSolver.py`. The parameters must be consistent between the different solvers and participants.
92-
93-
**Optional:** Visualization and video output of the fluid participant can be triggered via the options `--enable-plot` and `--write-video` of `FluidSolver.py`. To generate .vtk files during execution, you need to add the flag `--write-vtk`.
94-
95-
![Elastic tube animation](images/tutorials-elastic-tube-1d-animation.gif)
91+
**Optional:** A run-time plot visualization can be trigged by passing `--enable-plot` in `run.sh` of `FluidSolver.py`. Additionally a video of the run-time plot visualization can be generated by additionally passing `--write-video`
9692

9793
{% include warning.html content= "The C++ and Python solvers lead to different results. Please consider the Python results as the correct ones and refer to this [open issue](https://github.com/precice/tutorials/issues/195) for more insight. Contributions are particularly welcome here." %}
9894

9995
## Post-processing
10096

97+
![Elastic tube animation](images/tutorials-elastic-tube-1d-animation.gif)
98+
10199
The results from each simulation are stored in each `fluid-<participant>/output/` folder. You can visualize these VTK files using the provided `plot-diameter.sh` script
102100

103101
```bash
104102
./plot-diameter.sh
105103
```
106104

107-
which will try to visualize the results from both fluid cases, if available.
108-
109-
This script calls the more flexible `plot-vtk.py` Python script, which you can use as
105+
which will try to visualize the results from both fluid cases, if available. This script calls the more flexible `plot-vtk.py` Python script, which you can use as
110106

111107
```bash
112108
python3 plot-vtk.py <quantity> <case>/output/<prefix>

elastic-tube-1d/fluid-cpp/src/FluidSolver.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ int main(int argc, char **argv)
7272

7373
interface.setMeshVertices(meshID, chunkLength, grid.data(), vertexIDs.data());
7474

75-
std::cout << "Initialize preCICE..." << std::endl;
76-
interface.initialize();
77-
7875
double t = 0.0;
79-
double dt = 0.01;
76+
std::cout << "Initialize preCICE..." << std::endl;
77+
double dt = interface.initialize();
8078

8179
if (interface.isActionRequired(actionWriteInitialData())) {
8280
interface.writeBlockScalarData(pressureID, chunkLength, vertexIDs.data(), pressure.data());
@@ -102,7 +100,6 @@ int main(int argc, char **argv)
102100
if (interface.isActionRequired(actionWriteIterationCheckpoint())) {
103101
interface.markActionFulfilled(actionWriteIterationCheckpoint());
104102
}
105-
106103

107104
if (interface.isReadDataAvailable()) {
108105
interface.readBlockScalarData(crossSectionLengthID, chunkLength, vertexIDs.data(), crossSectionLength.data());

elastic-tube-1d/fluid-python/FluidSolver.py

+32-43
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,40 @@
66
from thetaScheme import perform_partitioned_implicit_trapezoidal_rule_step, perform_partitioned_implicit_euler_step
77
import numpy as np
88
import tubePlotting
9-
109
import matplotlib.pyplot as plt
1110
import matplotlib.animation as manimation
12-
1311
from output import writeOutputToVTK
14-
1512
import precice
16-
from precice import *
13+
from precice import action_write_initial_data, action_write_iteration_checkpoint, \
14+
action_read_iteration_checkpoint
15+
16+
# physical properties of the tube
17+
r0 = 1 / np.sqrt(np.pi) # radius of the tube
18+
a0 = r0**2 * np.pi # cross sectional area
19+
u0 = 10 # mean velocity
20+
ampl = 3 # amplitude of varying velocity
21+
frequency = 10 # frequency of variation
22+
t_shift = 0 # temporal shift of variation
23+
p0 = 0 # pressure at outlet
24+
kappa = 100
25+
26+
L = 10 # length of tube/simulation domain
27+
N = 100
28+
dx = L / kappa
29+
# helper function to create constant cross section
30+
31+
32+
def velocity_in(t): return u0 + ampl * np.sin(frequency *
33+
(t + t_shift) * np.pi) # inflow velocity
34+
35+
36+
def crossSection0(N):
37+
return a0 * np.ones(N + 1)
38+
1739

1840
parser = argparse.ArgumentParser()
1941
parser.add_argument("configurationFileName", help="Name of the xml precice configuration file.",
2042
nargs='?', type=str, default="../precice-config.xml")
21-
parser.add_argument(
22-
"--write-vtk", help="Save vtk files of each timestep in the 'VTK' folder.", action='store_true')
2343
parser.add_argument(
2444
"--enable-plot", help="Show a continuously updated plot of the tube while simulating.", action='store_true')
2545
parser.add_argument("--write-video", help="Save a video of the simulation as 'writer_test.mp4'. \
@@ -33,7 +53,6 @@
3353
print("Try '$ python FluidSolver.py precice-config.xml'")
3454
quit()
3555

36-
output_mode = config.OutputModes.VTK if args.write_vtk else config.OutputModes.OFF
3756
plotting_mode = config.PlottingModes.VIDEO if args.enable_plot else config.PlottingModes.OFF
3857
if args.write_video and not args.enable_plot:
3958
print("")
@@ -42,41 +61,14 @@
4261
quit()
4362
writeVideoToFile = True if args.write_video else False
4463

45-
print("Starting Fluid Solver...")
46-
47-
configFileName = args.configurationFileName
48-
49-
# physical properties of the tube
50-
r0 = 1 / np.sqrt(np.pi) # radius of the tube
51-
a0 = r0**2 * np.pi # cross sectional area
52-
u0 = 10 # mean velocity
53-
ampl = 3 # amplitude of varying velocity
54-
frequency = 10 # frequency of variation
55-
t_shift = 0 # temporal shift of variation
56-
p0 = 0 # pressure at outlet
57-
kappa = 100
58-
59-
60-
def velocity_in(t): return u0 + ampl * np.sin(frequency *
61-
(t + t_shift) * np.pi) # inflow velocity
62-
63-
64-
L = 10 # length of tube/simulation domain
65-
N = 100
66-
dx = L / kappa
67-
# helper function to create constant cross section
68-
69-
70-
def crossSection0(N):
71-
return a0 * np.ones(N + 1)
64+
print("Plotting Mode: {}".format(plotting_mode))
7265

66+
print("Starting Fluid Solver...")
7367

7468
print("N: " + str(N))
7569

76-
solverName = "Fluid"
77-
7870
print("Configure preCICE...")
79-
interface = precice.Interface(solverName, configFileName, 0, 1)
71+
interface = precice.Interface("Fluid", args.configurationFileName, 0, 1)
8072
print("preCICE configured...")
8173

8274
dimensions = interface.get_dimensions()
@@ -88,7 +80,6 @@ def crossSection0(N):
8880
crossSectionLength = a0 * np.ones(N + 1)
8981
crossSectionLength_old = a0 * np.ones(N + 1)
9082

91-
9283
if plotting_mode == config.PlottingModes.VIDEO:
9384
fig, ax = plt.subplots(1)
9485
if writeVideoToFile:
@@ -110,11 +101,10 @@ def crossSection0(N):
110101
vertexIDs = interface.set_mesh_vertices(meshID, grid)
111102

112103
t = 0
113-
precice_dt = 0.01
114104

115105
print("Fluid: init precice...")
116106
# preCICE defines timestep size of solver via precice-config.xml
117-
interface.initialize()
107+
precice_dt = interface.initialize()
118108

119109
if interface.is_action_required(action_write_initial_data()):
120110
interface.write_block_scalar_data(pressureID, vertexIDs, pressure)
@@ -161,9 +151,8 @@ def crossSection0(N):
161151
velocity_old = np.copy(velocity)
162152
pressure_old = np.copy(pressure)
163153
crossSectionLength_old = np.copy(crossSectionLength)
164-
if output_mode is config.OutputModes.VTK:
165-
writeOutputToVTK(time_it, "out_fluid_", dx, datanames=["velocity", "pressure", "diameter"], data=[
166-
velocity_old, pressure_old, crossSectionLength_old])
154+
writeOutputToVTK(time_it, "out_fluid_", dx, datanames=["velocity", "pressure", "diameter"], data=[
155+
velocity_old, pressure_old, crossSectionLength_old])
167156
time_it += 1
168157

169158
print("Exiting FluidSolver")

elastic-tube-1d/fluid-python/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
set -e -u
33

4-
python3 ./FluidSolver.py ../precice-config.xml --write-vtk
4+
python3 ./FluidSolver.py ../precice-config.xml

elastic-tube-1d/plot-diameter.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/bin/sh
22
set -e -u
33

4+
# File check solution from: https://stackoverflow.com/questions/91368/checking-from-shell-script-if-a-directory-contains-files
5+
46
# Plot diameter from fluid-cpp
5-
if [ -d "./fluid-cpp/output/" ]; then
7+
if [ -n "$(ls -A ./fluid-cpp/output/*.vtk 2>/dev/null)" ]; then
68
python3 plot-vtk.py diameter fluid-cpp/output/out_fluid_ &
79
else
810
echo "No results to plot from fluid-cpp."
911
fi
1012

1113
# Plot diameter from fluid-python
12-
if [ -d "./fluid-python/output/" ]; then
14+
if [ -n "$(ls -A ./fluid-python/output/*.vtk 2>/dev/null)" ]; then
1315
python3 plot-vtk.py diameter fluid-python/output/out_fluid_ &
1416
else
1517
echo "No results to plot from fluid-python."

elastic-tube-1d/solid-cpp/src/SolidSolver.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ int main(int argc, char **argv)
4545

4646
std::vector<int> vertexIDs(chunkLength);
4747
interface.setMeshVertices(meshID, chunkLength, grid.data(), vertexIDs.data());
48-
std::cout << "Initialize preCICE..." << std::endl;
49-
interface.initialize();
5048

5149
double t = 0;
52-
double dt = 0.01;
50+
std::cout << "Initialize preCICE..." << std::endl;
51+
double dt = interface.initialize();
5352

5453
if (interface.isActionRequired(actionWriteInitialData())) {
5554
interface.writeBlockScalarData(crossSectionLengthID, chunkLength, vertexIDs.data(), crossSectionLength.data());

elastic-tube-1d/solid-python/SolidSolver.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import argparse
66
import numpy as np
77
import precice
8-
from precice import *
8+
from precice import action_write_initial_data, action_read_iteration_checkpoint, \
9+
action_write_iteration_checkpoint
910

1011

1112
r0 = 1 / np.sqrt(np.pi) # radius of the tube
@@ -21,8 +22,6 @@
2122
def crossSection0(N):
2223
return a0 * np.ones(N + 1)
2324

24-
###############
25-
2625

2726
print("Starting Solid Solver...")
2827

@@ -38,14 +37,10 @@ def crossSection0(N):
3837
print("Try '$ python SolidSolver.py precice-config.xml'")
3938
quit()
4039

41-
configFileName = args.configurationFileName
42-
4340
print("N: " + str(N))
4441

45-
solverName = "Solid"
46-
4742
print("Configure preCICE...")
48-
interface = precice.Interface(solverName, configFileName, 0, 1)
43+
interface = precice.Interface("Solid", args.configurationFileName, 0, 1)
4944
print("preCICE configured...")
5045

5146
dimensions = interface.get_dimensions()

multiple-perpendicular-flaps/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,7 @@ After the simulation has finished, you can visualize your results using e.g. Par
111111

112112
## References
113113

114-
[1] H. Bungartz, F. Linder, M. Mehl, B. Uekerman. A plug-and-play coupling approach for parallel multi-field simulations. 2014.
114+
<!-- markdownlint-configure-file {"MD034": false } -->
115+
[1] H. Bungartz, F. Linder, M. Mehl, B. Uekermann. A plug-and-play coupling approach for parallel multi-field simulations. _Comput Mech_ **55**, 1119-1129 (2015). https://doi.org/10.1007/s00466-014-1113-2
116+
117+
{% include disclaimer.html content="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." %}

perpendicular-flap/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ Reasons for the differences:
7171

7272
* The CalculiX adapter only supports linear finite elements (deal.II uses 4th order, FEniCS 2nd order).
7373
* SU2 models a compressible fluid, OpenFOAM and Nutils an incompressible one.
74+
75+
{% include disclaimer.html content="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." %}

quickstart/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ You may be curious what displacements OpenFOAM received from the rigid body solv
110110

111111
![result](images/quickstart-result.png)
112112

113+
{% include disclaimer.html content="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." %}
114+
113115
## What's next?
114116

115117
To become a preCICE pro:

tools/openfoam-remove-empty-dirs.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ openfoam_remove_empty_dirs() {
66
echo "Looking for any time directories without results (e.g. stray functionObjectProperties files, see openfoam-adapter issue #26 on GitHub)..."
77

88
for f in [0-9]* [0-9]*.[0-9]*; do
9-
if ! [ -f "${f}/U" ] && ! [ -f "${f}/T" ]; then
9+
if ! [ -f "${f}/U" ] && ! [ -f "${f}/T" ] && ! [ -f "${f}/U.gz" ] && ! [ -f "${f}/T.gz" ]; then
1010
rm -rfv "${f}"
1111
fi
1212
done
1313
if [ -d processor0 ]; then
1414
for d in processor*; do
1515
cd "${d}"
1616
for f in [0-9]* [0-9]*.[0-9]*; do
17-
if ! [ -f "${f}"/U ] && ! [ -f "${f}"/T ]; then
17+
if ! [ -f "${f}/U" ] && ! [ -f "${f}/T" ] && ! [ -f "${f}/U.gz" ] && ! [ -f "${f}/T.gz" ]; then
1818
rm -rfv "${f}"
1919
fi
2020
done

0 commit comments

Comments
 (0)