Skip to content

Commit

Permalink
Fix inconsistencies in structure of some tutorials (#490)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerasimos Chourdakis <chourdak@in.tum.de>
  • Loading branch information
uekerman and MakisH authored Mar 22, 2024
1 parent 2ae74fe commit b395993
Show file tree
Hide file tree
Showing 49 changed files with 73 additions and 11 deletions.
14 changes: 7 additions & 7 deletions oscillator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ Note that this case applies a Schwarz-type coupling method and not (like most ot
There are two different implementations:

- *Python*: A solver using the preCICE [Python bindings](https://www.precice.org/installation-bindings-python.html). This solver also depends on the Python libraries `numpy`, which you can get from your system package manager or with `pip3 install --user <package>`. Using the option `-ts` allows you to pick the time stepping scheme being used. Available choices are Newmark beta, generalized alpha, explicit Runge Kutta 4, and implicit RadauIIA. The solver uses subcycling: Each participant performs 4 time steps in each time window. The data of these 4 substeps is then used by preCICE to create a third order B-spline interpolation (`waveform-degree="3"` in `precice-config.xml`).
- *FMI*: A solver using the [preCICE-FMI runner](https://github.com/precice/fmi-runner) (requires at least v0.2). The Runner executes the FMU model `Oscillator.fmu` for computation. The provided run script (see below) builds this model if not already there. If you want to change the model parameters or the initial conditions of the simulation, have a look inside the setting files for [MassLeft](https://github.com/precice/tutorials/tree/master/oscillator/fmi/MassLeft) and [MassRight](https://github.com/precice/tutorials/tree/master/oscillator/fmi/MassRight). For more information, please refer to [2].
- *FMI*: A solver using the [preCICE-FMI runner](https://github.com/precice/fmi-runner) (requires at least v0.2). The Runner executes the FMU model `Oscillator.fmu` for computation. The provided run scripts (see below) build this model if not already there. For more information, please refer to [2].

## Running the simulation

Open two separate terminals and start both participants. For example, you can run a simulation where the left participant is computed in Python and the right participant is computed with FMI with these commands:

```bash
cd python
./run.sh -l
cd mass-left-python
./run.sh
```

and

```bash
cd fmi
./run.sh -r
cd mass-right-fmi
./run.sh
```

Of course, you can also use the same solver for both sides.

## Post-processing

Each simulation run creates two files containing position and velocity of the two masses over time. These files are called `trajectory-Mass-Left.csv` and `trajectory-Mass-Right.csv`. You can use the script `plot-trajectory.py` for post-processing. Type `python3 plot-trajectory --help` to see available options. You can, for example, plot the trajectory of the Python solver by running
Each simulation run creates two files containing position and velocity of the two masses over time. These files are called `trajectory-Mass-Left.csv` and `trajectory-Mass-Right.csv`. You can use the script `plot-trajectory.py` for post-processing. Type `python3 plot-trajectory --help` to see available options. You can, for example, plot the trajectory of the left mass of the Python solver by running

```bash
python3 plot-trajectory.py python/output/trajectory-Mass-Left.csv TRAJECTORY
python3 plot-trajectory.py mass-left-python/output/trajectory-Mass-Left.csv TRAJECTORY
```

The solvers allow you to study the effect of different time stepping schemes on energy conservation. Newmark beta conserves energy:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"mass.a": -197.392088022
},
"simulation_params": {
"fmu_file_name": "./Oscillator.fmu",
"fmu_file_name": "../solver-fmi/Oscillator.fmu",
"output_file_name": "./output/trajectory-Mass-Left.csv",
"output": ["mass.u", "mass.v"],
"fmu_read_data_names": ["force_in"],
Expand Down
18 changes: 18 additions & 0 deletions oscillator/mass-left-fmi/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e -u


if [ ! -f ../solver-fmi/Oscillator.fmu ]; then
cd ../solver-fmi/fmu
rm -rf build
mkdir build
cd build
# Both FMI_VERSION=3 and FMI_VERSION=2 are supported
cmake -DFMI_TYPE=CS -DFMI_VERSION=3 ..
make
cp ./Oscillator.fmu ../..
cd ../../../mass-left-fmi
fi

fmiprecice fmi-settings.json precice-settings.json
python3 ../solver-fmi/calculate-error.py ../mass-left-fmi/fmi-settings.json ../mass-left-fmi/precice-settings.json ../mass-right-fmi/fmi-settings.json ../mass-right-fmi/precice-settings.json Mass-Left
File renamed without changes.
4 changes: 4 additions & 0 deletions oscillator/mass-left-python/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e -u

python3 ../solver-python/oscillator.py Mass-Left
8 changes: 8 additions & 0 deletions oscillator/mass-right-fmi/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e -u

. ../../tools/cleaning-tools.sh

rm -rfv ./output/

clean_precice_logs .
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"mass.a": 157.913670417
},
"simulation_params": {
"fmu_file_name": "./Oscillator.fmu",
"fmu_file_name": "../solver-fmi/Oscillator.fmu",
"output_file_name": "./output/trajectory-Mass-Right.csv",
"output": ["mass.u", "mass.v"],
"fmu_read_data_names": ["force_in"],
Expand Down
18 changes: 18 additions & 0 deletions oscillator/mass-right-fmi/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
set -e -u


if [ ! -f ../solver-fmi/Oscillator.fmu ]; then
cd ../solver-fmi/fmu
rm -rf build
mkdir build
cd build
# Both FMI_VERSION=3 and FMI_VERSION=2 are supported
cmake -DFMI_TYPE=CS -DFMI_VERSION=3 ..
make
cp ./Oscillator.fmu ../..
cd ../../../mass-right-fmi
fi

fmiprecice fmi-settings.json precice-settings.json
python3 ../solver-fmi/calculate-error.py ../mass-left-fmi/fmi-settings.json ../mass-left-fmi/precice-settings.json ../mass-right-fmi/fmi-settings.json ../mass-right-fmi/precice-settings.json Mass-Right
8 changes: 8 additions & 0 deletions oscillator/mass-right-python/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e -u

. ../../tools/cleaning-tools.sh

rm -rfv ./output/

clean_precice_logs .
4 changes: 4 additions & 0 deletions oscillator/mass-right-python/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e -u

python3 ../solver-python/oscillator.py Mass-Right
6 changes: 4 additions & 2 deletions oscillator/plot-trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class PlotType(Enum):
args = parser.parse_args()

filename = args.csvFile
split_filename = filename.split('/')
solver = split_filename[0]
split_foldername = filename.split('/')
casename = split_foldername[0]
split_casename = casename.split('-')
solver = split_casename[-1]

if solver == 'python':
df = pd.read_csv(filename, delimiter=';')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit b395993

Please sign in to comment.