Skip to content

Commit f93ebd4

Browse files
Examples update 1.9 (#190)
* ci: use latest julia 1.9 (#189) * started updating examples * marked outdated tutorials, will be updated soon --------- Co-authored-by: Sathvik Bhagavan <35105271+sathvikbhagavan@users.noreply.github.com>
1 parent 8e25b07 commit f93ebd4

12 files changed

+172
-173
lines changed

.github/workflows/Example.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [windows-latest, ubuntu-latest]
21+
os: [windows-latest] # ubuntu-latest
2222
file-name: [manipulation, modelica_conference_2021, multiple_instances, multiprocessing, multithreading, parameterize, simulate, parameter_optimization]
23-
julia-version: ['1.8']
23+
julia-version: ['1.9']
2424
julia-arch: [x64]
2525
experimental: [false]
2626

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
[![Run PkgEval](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml)
1414
[![Coverage](https://codecov.io/gh/ThummeTo/FMI.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ThummeTo/FMI.jl)
1515
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
16+
[![FMI Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/FMI)](https://pkgs.genieframework.com?packages=FMI).
1617

1718

1819
## How can I use FMI.jl?
1920
1\. Open a Julia-REPL, switch to package mode using `]`, activate your preferred environment.
2021

2122
2\. Install [*FMI.jl*](https://github.com/ThummeTo/FMI.jl):
2223
```julia-repl
23-
(@v1.X) pkg> add FMI
24+
(@v1) pkg> add FMI
2425
```
2526

2627
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):
2728
```julia-repl
28-
(@v1.X) pkg> test FMI
29+
(@v1) pkg> test FMI
2930
```
3031

3132
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*).
@@ -35,13 +36,13 @@
3536
using FMI, Plots
3637

3738
# load and instantiate a FMU
38-
myFMU = fmiLoad(pathToFMU)
39+
fmu = fmiLoad(pathToFMU)
3940

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

4344
# plot it!
44-
fmiPlot(simData)
45+
plot(simData)
4546

4647
# free memory
4748
fmiUnload(myFMU)

docs/src/examples/overview.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
This section discusses the included examples of the FMI.jl library.
44
If you require further information about the function calls, see the function sections of the [library](https://thummeto.github.io/FMI.jl/dev/library/).
5-
Examples are subdevided into *Basics*, *Advanced* and *Publication appendices*
5+
6+
Examples are subdevided into *Basics*, *Advanced* and *Publication appendices*.
67

78

89
**Basic examples:**

examples/src/inputs.ipynb

+23-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"source": [
88
"# Simulate an FMU with inputs\n",
9-
"Tutorial (WIP) by Tobias Thummerer\n",
9+
"Tutorial by Tobias Thummerer\n",
1010
"\n",
1111
"## License"
1212
]
@@ -33,9 +33,13 @@
3333
"cell_type": "markdown",
3434
"metadata": {},
3535
"source": [
36-
"## Code section\n",
36+
"## Introduction to the example\n",
37+
"This example shows how to add custom inputs to a FMU, that are used during simulation.\n",
3738
"\n",
38-
"To run the example, the previously installed packages must be included. "
39+
"## Other formats\n",
40+
"Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/inputs.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/inputs.jl) with the same name, which contains only the code cells and for the documentation there is a [Markdown file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/inputs.md) corresponding to the notebook. \n",
41+
"\n",
42+
"## Code section"
3943
]
4044
},
4145
{
@@ -93,7 +97,7 @@
9397
"source": [
9498
"### Import FMU\n",
9599
"\n",
96-
"In the next lines of code the FMU model from *FMIZoo.jl* is loaded and the information about the FMU is shown."
100+
"Next, the FMU model from *FMIZoo.jl* is loaded."
97101
]
98102
},
99103
{
@@ -111,11 +115,7 @@
111115
"outputs": [],
112116
"source": [
113117
"# we use an FMU from the FMIZoo.jl\n",
114-
"pathToFMU = get_model_filename(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\")\n",
115-
"\n",
116-
"myFMU = fmiLoad(pathToFMU; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")\n",
117-
"\n",
118-
"fmiInfo(myFMU)"
118+
"fmu = fmiLoad(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\"; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")"
119119
]
120120
},
121121
{
@@ -125,7 +125,7 @@
125125
"source": [
126126
"#### Simulate as Model-Exchange\n",
127127
"\n",
128-
"In the function `fmiSimulateME()` the FMU is simulated in model-exchange mode (ME) with an adaptive step size but with fixed save points `tSave`. In addition, the start and end time are specified. Note, that the dynamics of the input variables are not considered by the steps ize control of the solver, so it is highly recommended to limit the solver step size with the keyword argument `dtmax` if the input is more dynamic than the system."
128+
"In the function `fmiSimulate()` the FMU is simulated with an adaptive step size but with fixed save points `tSave`. In addition, the start and end time are specified. Note, that the dynamics of the input variables are not considered by the steps ize control of the solver, so it is highly recommended to limit the solver step size with the keyword argument `dtmax` if the input is more dynamic than the system."
129129
]
130130
},
131131
{
@@ -147,8 +147,13 @@
147147
"end \n",
148148
"\n",
149149
"# simulate while setting inputs\n",
150-
"data_extForce_t = fmiSimulateME(myFMU, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_t, dtmax=1e-2)\n",
151-
"fmiPlot(data_extForce_t)"
150+
"data_extForce_t = fmiSimulate(fmu, (tStart, tStop); # FMU, start and stop time\n",
151+
" saveat=tSave, # timepoints for the ODE solution to be saved\n",
152+
" inputValueReferences=[\"extForce\"], # the value references that should be set (inputs)\n",
153+
" inputFunction=extForce_t, # the input function to be used\n",
154+
" dtmax=1e-2, # limit max step size to capture inputs\n",
155+
" showProgress=false) # disable progress bar\n",
156+
"plot(data_extForce_t)"
152157
]
153158
},
154159
{
@@ -167,8 +172,8 @@
167172
"end \n",
168173
"\n",
169174
"# simulate while setting inputs\n",
170-
"data_extForce_cxt = fmiSimulateME(myFMU, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_cxt, dtmax=1e-2)\n",
171-
"fmiPlot(data_extForce_cxt)"
175+
"data_extForce_cxt = fmiSimulate(fmu, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_cxt, dtmax=1e-2, showProgress=false)\n",
176+
"plot(data_extForce_cxt)"
172177
]
173178
},
174179
{
@@ -193,7 +198,7 @@
193198
},
194199
"outputs": [],
195200
"source": [
196-
"fmiUnload(myFMU)"
201+
"fmiUnload(fmu)"
197202
]
198203
}
199204
],
@@ -207,15 +212,15 @@
207212
"notebook_metadata_filter": "-all"
208213
},
209214
"kernelspec": {
210-
"display_name": "Julia 1.8.5",
215+
"display_name": "Julia 1.9.1",
211216
"language": "julia",
212-
"name": "julia-1.8"
217+
"name": "julia-1.9"
213218
},
214219
"language_info": {
215220
"file_extension": ".jl",
216221
"mimetype": "application/julia",
217222
"name": "julia",
218-
"version": "1.8.5"
223+
"version": "1.9.1"
219224
},
220225
"nteract": {
221226
"version": "0.28.0"

examples/src/manipulation.ipynb

+17-39
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"metadata": {},
66
"source": [
77
"# Manipulate a function\n",
8-
"Tutorial by Johannes Stoljar, Tobias Thummerer\n",
8+
"Tutorial by Tobias Thummerer, Johannes Stoljar\n",
99
"\n",
1010
"## License"
1111
]
@@ -33,33 +33,14 @@
3333
"cell_type": "markdown",
3434
"metadata": {},
3535
"source": [
36-
"## Motivation\n",
37-
"This Julia Package *FMI.jl* is motivated by the use of simulation models in Julia. Here the FMI specification is implemented. FMI (*Functional Mock-up Interface*) is a free standard ([fmi-standard.org](http://fmi-standard.org/)) that defines a container and an interface to exchange dynamic models using a combination of XML files, binaries and C code zipped into a single file. The user can thus use simulation models in the form of an FMU (*Functional Mock-up Units*). Besides loading the FMU, the user can also set values for parameters and states and simulate the FMU both as co-simulation and model exchange simulation.\n",
38-
"\n",
3936
"## Introduction to the example\n",
40-
"This example shows how to overwrite a library function with an own function. For this the FMU model is simulated first without changes. Then the function `fmi2GetReal()` is overwritten and simulated again. Both simulations are displayed in a graph to show the change caused by overwriting the function. The model used is a one-dimensional spring pendulum with friction. The object-orientated structure of the *SpringFrictionPendulum1D* can be seen in the following graphic.\n",
37+
"This example shows how to overwrite a FMI function with a custom C-function. For this the FMU model is simulated first without changes. Then the function `fmi2GetReal()` is overwritten and simulated again. Both simulations are displayed in a graph to show the change caused by overwriting the function. The model used is a one-dimensional spring pendulum with friction. The object-orientated structure of the *SpringFrictionPendulum1D* can be seen in the following graphic.\n",
4138
"\n",
4239
"![svg](https://github.com/thummeto/FMI.jl/blob/main/docs/src/examples/pics/SpringFrictionPendulum1D.svg?raw=true) \n",
4340
"\n",
4441
"\n",
45-
"## Target group\n",
46-
"The example is primarily intended for users who work in the field of simulations. The example wants to show how simple it is to use FMUs in Julia.\n",
47-
"\n",
48-
"\n",
4942
"## Other formats\n",
50-
"Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.jl) with the same name, which contains only the code cells and for the documentation there is a [Markdown file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.md) corresponding to the notebook. \n",
51-
"\n",
52-
"\n",
53-
"## Getting started\n",
54-
"\n",
55-
"### Installation prerequisites\n",
56-
"| | Description | Command | Alternative | \n",
57-
"|:----|:----------------------------------|:--------------------------|:-----------------------------------------------|\n",
58-
"| 1. | Enter Package Manager via | ] | |\n",
59-
"| 2. | Install FMI via | add FMI | add \" https://github.com/ThummeTo/FMI.jl \" |\n",
60-
"| 3. | Install FMIZoo via | add FMIZoo | add \" https://github.com/ThummeTo/FMIZoo.jl \" |\n",
61-
"| 4. | Install FMICore via | add FMICore | add \" https://github.com/ThummeTo/FMICore.jl \" |\n",
62-
"| 5. | Install Plots via | add Plots | |"
43+
"Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.jl) with the same name, which contains only the code cells and for the documentation there is a [Markdown file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/manipulation.md) corresponding to the notebook. "
6344
]
6445
},
6546
{
@@ -126,7 +107,7 @@
126107
"source": [
127108
"### Import FMU\n",
128109
"\n",
129-
"In the next lines of code the FMU model from *FMIZoo.jl* is loaded and the information about the FMU is shown."
110+
"Next, the FMU model from *FMIZoo.jl* is loaded."
130111
]
131112
},
132113
{
@@ -144,11 +125,7 @@
144125
"outputs": [],
145126
"source": [
146127
"# we use an FMU from the FMIZoo.jl\n",
147-
"pathToFMU = get_model_filename(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\")\n",
148-
"\n",
149-
"myFMU = fmiLoad(pathToFMU)\n",
150-
"\n",
151-
"fmiInfo(myFMU)"
128+
"fmu = fmiLoad(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\"; type=:ME)"
152129
]
153130
},
154131
{
@@ -173,9 +150,10 @@
173150
},
174151
"outputs": [],
175152
"source": [
153+
"# an array of value references... or just one\n",
176154
"vrs = [\"mass.s\"]\n",
177155
"\n",
178-
"simData = fmiSimulateME(myFMU, (tStart, tStop); recordValues=vrs)"
156+
"simData = fmiSimulate(fmu, (tStart, tStop); recordValues=vrs)"
179157
]
180158
},
181159
{
@@ -201,7 +179,7 @@
201179
},
202180
"outputs": [],
203181
"source": [
204-
"fig = fmiPlot(simData, states=false)"
182+
"fig = plot(simData, states=false)"
205183
]
206184
},
207185
{
@@ -227,7 +205,7 @@
227205
"outputs": [],
228206
"source": [
229207
"# save, where the original `fmi2GetReal` function was stored, so we can access it in our new function\n",
230-
"originalGetReal = myFMU.cGetReal"
208+
"originalGetReal = fmu.cGetReal"
231209
]
232210
},
233211
{
@@ -293,7 +271,7 @@
293271
"outputs": [],
294272
"source": [
295273
"# no we overwrite the original function\n",
296-
"fmiSetFctGetReal(myFMU, myGetReal!)"
274+
"fmiSetFctGetReal(fmu, myGetReal!)"
297275
]
298276
},
299277
{
@@ -318,8 +296,8 @@
318296
},
319297
"outputs": [],
320298
"source": [
321-
"simData = fmiSimulateME(myFMU, (tStart, tStop); recordValues=vrs)\n",
322-
"fmiPlot!(fig, simData; states=false, style=:dash)"
299+
"simData = fmiSimulate(fmu, (tStart, tStop); recordValues=vrs)\n",
300+
"plot!(fig, simData; states=false, style=:dash)"
323301
]
324302
},
325303
{
@@ -351,7 +329,7 @@
351329
},
352330
"outputs": [],
353331
"source": [
354-
"fmiUnload(myFMU)"
332+
"fmiUnload(fmu)"
355333
]
356334
},
357335
{
@@ -360,7 +338,7 @@
360338
"source": [
361339
"### Summary\n",
362340
"\n",
363-
"In this tutorial it is shown how an existing function of the library can be replaced by an own implementation. Through this possibility, there are almost no limits for the user, whereby the user can customize the function to his liking."
341+
"In this tutorial it is shown how an existing function of the library can be replaced by an own implementation."
364342
]
365343
}
366344
],
@@ -374,15 +352,15 @@
374352
"notebook_metadata_filter": "-all"
375353
},
376354
"kernelspec": {
377-
"display_name": "Julia 1.8.2",
355+
"display_name": "Julia 1.9.1",
378356
"language": "julia",
379-
"name": "julia-1.8"
357+
"name": "julia-1.9"
380358
},
381359
"language_info": {
382360
"file_extension": ".jl",
383361
"mimetype": "application/julia",
384362
"name": "julia",
385-
"version": "1.8.2"
363+
"version": "1.9.1"
386364
},
387365
"nteract": {
388366
"version": "0.28.0"

0 commit comments

Comments
 (0)