|
5 | 5 | "metadata": {},
|
6 | 6 | "source": [
|
7 | 7 | "# Manipulate a function\n",
|
8 |
| - "Tutorial by Johannes Stoljar, Tobias Thummerer\n", |
| 8 | + "Tutorial by Tobias Thummerer, Johannes Stoljar\n", |
9 | 9 | "\n",
|
10 | 10 | "## License"
|
11 | 11 | ]
|
|
33 | 33 | "cell_type": "markdown",
|
34 | 34 | "metadata": {},
|
35 | 35 | "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", |
39 | 36 | "## 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", |
41 | 38 | "\n",
|
42 | 39 | " \n",
|
43 | 40 | "\n",
|
44 | 41 | "\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", |
49 | 42 | "## 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. " |
63 | 44 | ]
|
64 | 45 | },
|
65 | 46 | {
|
|
126 | 107 | "source": [
|
127 | 108 | "### Import FMU\n",
|
128 | 109 | "\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." |
130 | 111 | ]
|
131 | 112 | },
|
132 | 113 | {
|
|
144 | 125 | "outputs": [],
|
145 | 126 | "source": [
|
146 | 127 | "# 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)" |
152 | 129 | ]
|
153 | 130 | },
|
154 | 131 | {
|
|
173 | 150 | },
|
174 | 151 | "outputs": [],
|
175 | 152 | "source": [
|
| 153 | + "# an array of value references... or just one\n", |
176 | 154 | "vrs = [\"mass.s\"]\n",
|
177 | 155 | "\n",
|
178 |
| - "simData = fmiSimulateME(myFMU, (tStart, tStop); recordValues=vrs)" |
| 156 | + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=vrs)" |
179 | 157 | ]
|
180 | 158 | },
|
181 | 159 | {
|
|
201 | 179 | },
|
202 | 180 | "outputs": [],
|
203 | 181 | "source": [
|
204 |
| - "fig = fmiPlot(simData, states=false)" |
| 182 | + "fig = plot(simData, states=false)" |
205 | 183 | ]
|
206 | 184 | },
|
207 | 185 | {
|
|
227 | 205 | "outputs": [],
|
228 | 206 | "source": [
|
229 | 207 | "# 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" |
231 | 209 | ]
|
232 | 210 | },
|
233 | 211 | {
|
|
293 | 271 | "outputs": [],
|
294 | 272 | "source": [
|
295 | 273 | "# no we overwrite the original function\n",
|
296 |
| - "fmiSetFctGetReal(myFMU, myGetReal!)" |
| 274 | + "fmiSetFctGetReal(fmu, myGetReal!)" |
297 | 275 | ]
|
298 | 276 | },
|
299 | 277 | {
|
|
318 | 296 | },
|
319 | 297 | "outputs": [],
|
320 | 298 | "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)" |
323 | 301 | ]
|
324 | 302 | },
|
325 | 303 | {
|
|
351 | 329 | },
|
352 | 330 | "outputs": [],
|
353 | 331 | "source": [
|
354 |
| - "fmiUnload(myFMU)" |
| 332 | + "fmiUnload(fmu)" |
355 | 333 | ]
|
356 | 334 | },
|
357 | 335 | {
|
|
360 | 338 | "source": [
|
361 | 339 | "### Summary\n",
|
362 | 340 | "\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." |
364 | 342 | ]
|
365 | 343 | }
|
366 | 344 | ],
|
|
374 | 352 | "notebook_metadata_filter": "-all"
|
375 | 353 | },
|
376 | 354 | "kernelspec": {
|
377 |
| - "display_name": "Julia 1.8.2", |
| 355 | + "display_name": "Julia 1.9.1", |
378 | 356 | "language": "julia",
|
379 |
| - "name": "julia-1.8" |
| 357 | + "name": "julia-1.9" |
380 | 358 | },
|
381 | 359 | "language_info": {
|
382 | 360 | "file_extension": ".jl",
|
383 | 361 | "mimetype": "application/julia",
|
384 | 362 | "name": "julia",
|
385 |
| - "version": "1.8.2" |
| 363 | + "version": "1.9.1" |
386 | 364 | },
|
387 | 365 | "nteract": {
|
388 | 366 | "version": "0.28.0"
|
|
0 commit comments