| title | Oscillator |
|---|---|
| permalink | tutorials-oscillator.html |
| keywords | Python, ODE, FMI |
| summary | We solve an oscillator with two masses in a partitioned fashion. Each mass is solved by an independent ODE. |
{% 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 %}
This tutorial solves a simple mass-spring oscillator with two masses and three springs. The system is cut at the middle spring and solved in a partitioned fashion:
Note that this case applies a Schwarz-type coupling method and not (like most other tutorials in this repository) a Dirichlet-Neumann coupling. This results in a symmetric setup of the solvers. We will refer to the solver computing the trajectory of Mass-Left and to the solver computing the trajectory of Mass-Right. For more information, please refer to [1].
preCICE configuration (image generated using the precice-config-visualizer):
There are two different implementations:
- Python: A solver using the preCICE Python bindings. The run script installs the dependencies automatically via pip in a virtual environment. Using the option
-tsallows 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"inprecice-config.xml). - FMI: A solver using the preCICE-FMI runner (requires at least v0.2). The Runner executes the FMU model
Oscillator.fmufor computation. The provided run scripts (see below) build this model if not already there. For more information, please refer to [2].
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:
cd mass-left-python
./run.shand
cd mass-right-fmi
./run.shOf course, you can also use the same solver for both sides.
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
python3 plot-trajectory.py mass-left-python/output/trajectory-Mass-Left.csv TRAJECTORYThe solvers allow you to study the effect of different time stepping schemes on energy conservation. Newmark beta conserves energy:
Generalized alpha does not conserve energy:
For details, refer to [1].
[1] V. Schüller, B. Rodenberg, B. Uekermann and H. Bungartz, A Simple Test Case for Convergence Order in Time and Energy Conservation of Black-Box Coupling Schemes, in: WCCM-APCOM2022. URL
[2] L. Willeke, D. Schneider and B. Uekermann, A preCICE-FMI Runner to Couple FMUs to PDE-Based Simulations, Proceedings 15th Intern. Modelica Conference, 2023. DOI



