Skip to content

Commit

Permalink
marked outdated tutorials, will be updated soon
Browse files Browse the repository at this point in the history
  • Loading branch information
ThummeTo committed Aug 9, 2023
1 parent e841cd7 commit 39c4ac2
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
os: [windows-latest] # ubuntu-latest
file-name: [manipulation, modelica_conference_2021, multiple_instances, multiprocessing, multithreading, parameterize, simulate, parameter_optimization]
julia-version: ['1.9']
julia-arch: [x64]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

2\. Install [*FMI.jl*](https://github.com/ThummeTo/FMI.jl):
```julia-repl
(@v1.X) pkg> add FMI
(@v1) pkg> add FMI
```

3\. If you want to check that everything works correctly, you can run the tests bundled with [*FMI.jl*](https://github.com/ThummeTo/FMI.jl):
```julia-repl
(@v1.X) pkg> test FMI
(@v1) pkg> test FMI
```

4\. Have a look inside the [examples folder](https://github.com/ThummeTo/FMI.jl/tree/examples/examples) in the examples branch or the [examples section](https://thummeto.github.io/FMI.jl/dev/examples/overview/) of the documentation. All examples are available as Julia-Script (*.jl*), Jupyter-Notebook (*.ipynb*) and Markdown (*.md*).
Expand All @@ -36,13 +36,13 @@
using FMI, Plots

# load and instantiate a FMU
myFMU = fmiLoad(pathToFMU)
fmu = fmiLoad(pathToFMU)

# simulate from t=0.0s until t=10.0s and record the FMU variable named "mass.s"
simData = fmiSimulate(myFMU, (0.0, 10.0); recordValues=["mass.s"])
simData = fmiSimulate(fmu, (0.0, 10.0); recordValues=["mass.s"])

# plot it!
fmiPlot(simData)
plot(simData)

# free memory
fmiUnload(myFMU)
Expand Down
57 changes: 32 additions & 25 deletions examples/src/modelica_conference_2021.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"metadata": {},
"source": [
"# Example from the Modelica Conference 2021\n",
"Tutorial by Johannes Stoljar, Tobias Thummerer\n",
"Tutorial by Tobias Thummerer, Johannes Stoljar\n",
"\n",
"This example was updated over time to keep track with developments and changes in *FMI.jl*.\n",
"\n",
"🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n",
"\n",
"## License"
]
},
Expand Down Expand Up @@ -36,7 +38,7 @@
"metadata": {},
"source": [
"## Introduction to the example\n",
"In this example we would like to show that besides the simple simulation of an FMU there is also a more advanced version of the simulation. The advantage of the more advanced variant is that there are more possibilities to intervene in the simulation to make changes. After the FMU has been simulated, the simulation results are displayed in a graph. The used model is a one-dimensional spring pendulum with friction. The object-orientated structure of the *SpringFrictionPendulum1D* can be seen in the following graphic.\n",
"FMUs can be simulated in multiple ways using *FMI.jl*. You can use a very simple interface, that offers possibilities that satisfy almost any user requirement. However, if you need to build a custom simulation loop for your use case using the core FMI functions, we show that too.\n",
"\n",
"![svg](https://github.com/thummeto/FMI.jl/blob/main/docs/src/examples/pics/SpringFrictionPendulum1D.svg?raw=true) \n",
"\n",
Expand Down Expand Up @@ -107,8 +109,7 @@
"metadata": {},
"source": [
"### Simple FMU Simulation\n",
"\n",
"In the next lines of code the FMU model from *FMIZoo.jl* is loaded and the information about the FMU is shown."
"Next, the FMU model from *FMIZoo.jl* is loaded and the information about the FMU is shown."
]
},
{
Expand All @@ -125,8 +126,6 @@
"outputs": [],
"source": [
"# we use an FMU from the FMIZoo.jl\n",
"pathToFMU = get_model_filename()\n",
"\n",
"fmu = fmiLoad(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\")\n",
"fmiInfo(fmu)"
]
Expand All @@ -135,7 +134,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next commands the FMU is simulated, for which the start and end time and recorded variables are declared. Afterwards the simulation result is shown in a graph. In the plot for the FMU, it can be seen that the oscillation keeps decreasing due to the effect of friction. If one simulates long enough, the oscillation comes to a standstill after a certain time."
"### Easy Simulation\n",
"In the next commands the FMU is simulated, for which the start and end time and recorded variables are declared. Afterwards the simulation result is plotted. In the plot for the FMU, it can be seen that the oscillation keeps decreasing due to the effect of friction. If one simulates long enough, the oscillation comes to a standstill after a certain time."
]
},
{
Expand All @@ -153,7 +153,7 @@
"outputs": [],
"source": [
"simData = fmiSimulate(fmu, (tStart, tStop); recordValues=[\"mass.s\"], saveat=tSave)\n",
"fmiPlot(simData)"
"plot(simData)"
]
},
{
Expand Down Expand Up @@ -183,7 +183,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Advanced FMU Simulation\n",
"### Custom Simulation\n",
"\n",
"In the following type of simulation a more advanced variant is presented, which allows intervening more in the simulation process. Analogous to the simple variant, an FMU model must be loaded."
]
Expand All @@ -201,14 +201,14 @@
},
"outputs": [],
"source": [
"fmu = fmiLoad(pathToFMU);"
"fmu = fmiLoad(pathToFMU)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, it is necessary to create an instance of the FMU, this is achieved by the command `fmiInstantiate!()`. "
"Next, it is necessary to create an instance of the FMU, this is achieved by the command `fmi2Instantiate!()`. "
]
},
{
Expand All @@ -224,14 +224,14 @@
},
"outputs": [],
"source": [
"instanceFMU = fmiInstantiate!(fmu)"
"instanceFMU = fmi2Instantiate!(fmu)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the following code block, start and end time for the simulation is set by the `fmiSetupExperiment()` command. Next, the FMU is initialized by the calls of `fmiEnterInitializationMode()` and `fmiExitInitializationMode()`. It would also be possible to set initial states for the FMU before these two commands. "
"In the following code block, start and end time for the simulation is set by the `fmi2SetupExperiment()` command. Next, the FMU is initialized by the calls of `fmi2EnterInitializationMode()` and `fmi2ExitInitializationMode()`. It would also be possible to set initial states, parameters or inputs at this place in code."
]
},
{
Expand All @@ -247,18 +247,18 @@
},
"outputs": [],
"source": [
"fmiSetupExperiment(instanceFMU, tStart, tStop)\n",
"fmi2SetupExperiment(instanceFMU, tStart, tStop)\n",
"# set initial model states\n",
"fmiEnterInitializationMode(instanceFMU)\n",
"fmi2EnterInitializationMode(instanceFMU)\n",
"# get initial model states\n",
"fmiExitInitializationMode(instanceFMU)"
"fmi2ExitInitializationMode(instanceFMU)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The actual simulation loop is shown in the following block. Here a simulation step `fmiDoStep()` with the fixed step size `tStep` is executed. As indicated in the code by the comments, the input values and output values of the FMU could be changed in the simulation loop as desired, whereby the higher possibility of adjustments arises."
"The actual simulation loop is shown in the following block. Here a simulation step `fmi2DoStep()` with the fixed step size `tStep` is executed. As indicated in the code by the comments, the input values and output values of the FMU could be changed in the simulation loop as desired, whereby the higher possibility of adjustments arises."
]
},
{
Expand All @@ -274,13 +274,20 @@
},
"outputs": [],
"source": [
"values = []\n",
"\n",
"for t in tSave\n",
" # set model inputs \n",
" # set model inputs if any\n",
" # ...\n",
" fmiDoStep(instanceFMU, tStep)\n",
"\n",
" fmi2DoStep(instanceFMU, tStep)\n",
" \n",
" # get model outputs\n",
" # ...\n",
"end"
" value = fmi2GetReal(instanceFMU, \"mass.s\")\n",
" push!(values, value)\n",
"end\n",
"\n",
"plot(tSave, values)"
]
},
{
Expand All @@ -303,9 +310,9 @@
},
"outputs": [],
"source": [
"fmiTerminate(instanceFMU)\n",
"fmiFreeInstance!(instanceFMU)\n",
"fmiUnload(fmu)"
"fmi2Terminate(instanceFMU)\n",
"fmi2FreeInstance!(instanceFMU)\n",
"fmi2Unload(fmu)"
]
},
{
Expand All @@ -314,7 +321,7 @@
"source": [
"### Summary\n",
"\n",
"The tutorial has shown that besides the usual simple variant of simulating an FMU, there is another way to make more adjustments."
"The tutorial has shown how to use the default simulation command and how to deploy a custom simulation loop."
]
}
],
Expand Down
2 changes: 2 additions & 0 deletions examples/src/multiple_instances.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"# Multiple Instances of an FMU\n",
"Tutorial by Johannes Stoljar, Tobias Thummerer\n",
"\n",
"🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n",
"\n",
"## License"
]
},
Expand Down
2 changes: 2 additions & 0 deletions examples/src/multiprocessing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"# Multiprocessing\n",
"Tutorial by Jonas Wilfert, Tobias Thummerer\n",
"\n",
"🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n",
"\n",
"## License"
]
},
Expand Down
2 changes: 2 additions & 0 deletions examples/src/multithreading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"# Multithreading\n",
"Tutorial by Jonas Wilfert, Tobias Thummerer\n",
"\n",
"🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n",
"\n",
"## License"
]
},
Expand Down
Loading

0 comments on commit 39c4ac2

Please sign in to comment.