diff --git a/.github/workflows/Example.yml b/.github/workflows/Example.yml index a2d788d9..52ecff2c 100644 --- a/.github/workflows/Example.yml +++ b/.github/workflows/Example.yml @@ -18,9 +18,9 @@ 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.8'] + julia-version: ['1.9'] julia-arch: [x64] experimental: [false] diff --git a/README.md b/README.md index 5960236a..f73130d4 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ [![Run PkgEval](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml/badge.svg)](https://github.com/ThummeTo/FMI.jl/actions/workflows/Eval.yml) [![Coverage](https://codecov.io/gh/ThummeTo/FMI.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/ThummeTo/FMI.jl) [![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) +[![FMI Downloads](https://shields.io/endpoint?url=https://pkgs.genieframework.com/api/v1/badge/FMI)](https://pkgs.genieframework.com?packages=FMI). ## How can I use FMI.jl? @@ -20,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*). @@ -35,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) diff --git a/docs/src/examples/overview.md b/docs/src/examples/overview.md index 092bfd61..e9443e33 100644 --- a/docs/src/examples/overview.md +++ b/docs/src/examples/overview.md @@ -2,7 +2,8 @@ This section discusses the included examples of the FMI.jl library. If you require further information about the function calls, see the function sections of the [library](https://thummeto.github.io/FMI.jl/dev/library/). -Examples are subdevided into *Basics*, *Advanced* and *Publication appendices* + +Examples are subdevided into *Basics*, *Advanced* and *Publication appendices*. **Basic examples:** diff --git a/examples/src/inputs.ipynb b/examples/src/inputs.ipynb index a8fc6584..5bd463aa 100644 --- a/examples/src/inputs.ipynb +++ b/examples/src/inputs.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "source": [ "# Simulate an FMU with inputs\n", - "Tutorial (WIP) by Tobias Thummerer\n", + "Tutorial by Tobias Thummerer\n", "\n", "## License" ] @@ -33,9 +33,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Code section\n", + "## Introduction to the example\n", + "This example shows how to add custom inputs to a FMU, that are used during simulation.\n", "\n", - "To run the example, the previously installed packages must be included. " + "## Other formats\n", + "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", + "\n", + "## Code section" ] }, { @@ -93,7 +97,7 @@ "source": [ "### Import FMU\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." ] }, { @@ -111,11 +115,7 @@ "outputs": [], "source": [ "# we use an FMU from the FMIZoo.jl\n", - "pathToFMU = get_model_filename(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\")\n", - "\n", - "myFMU = fmiLoad(pathToFMU; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")\n", - "\n", - "fmiInfo(myFMU)" + "fmu = fmiLoad(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\"; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")" ] }, { @@ -125,7 +125,7 @@ "source": [ "#### Simulate as Model-Exchange\n", "\n", - "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." + "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." ] }, { @@ -147,8 +147,13 @@ "end \n", "\n", "# simulate while setting inputs\n", - "data_extForce_t = fmiSimulateME(myFMU, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_t, dtmax=1e-2)\n", - "fmiPlot(data_extForce_t)" + "data_extForce_t = fmiSimulate(fmu, (tStart, tStop); # FMU, start and stop time\n", + " saveat=tSave, # timepoints for the ODE solution to be saved\n", + " inputValueReferences=[\"extForce\"], # the value references that should be set (inputs)\n", + " inputFunction=extForce_t, # the input function to be used\n", + " dtmax=1e-2, # limit max step size to capture inputs\n", + " showProgress=false) # disable progress bar\n", + "plot(data_extForce_t)" ] }, { @@ -167,8 +172,8 @@ "end \n", "\n", "# simulate while setting inputs\n", - "data_extForce_cxt = fmiSimulateME(myFMU, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_cxt, dtmax=1e-2)\n", - "fmiPlot(data_extForce_cxt)" + "data_extForce_cxt = fmiSimulate(fmu, (tStart, tStop); saveat=tSave, inputValueReferences=[\"extForce\"], inputFunction=extForce_cxt, dtmax=1e-2, showProgress=false)\n", + "plot(data_extForce_cxt)" ] }, { @@ -193,7 +198,7 @@ }, "outputs": [], "source": [ - "fmiUnload(myFMU)" + "fmiUnload(fmu)" ] } ], @@ -207,15 +212,15 @@ "notebook_metadata_filter": "-all" }, "kernelspec": { - "display_name": "Julia 1.8.5", + "display_name": "Julia 1.9.1", "language": "julia", - "name": "julia-1.8" + "name": "julia-1.9" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.8.5" + "version": "1.9.1" }, "nteract": { "version": "0.28.0" diff --git a/examples/src/manipulation.ipynb b/examples/src/manipulation.ipynb index 951b43cc..131beaa8 100644 --- a/examples/src/manipulation.ipynb +++ b/examples/src/manipulation.ipynb @@ -5,7 +5,7 @@ "metadata": {}, "source": [ "# Manipulate a function\n", - "Tutorial by Johannes Stoljar, Tobias Thummerer\n", + "Tutorial by Tobias Thummerer, Johannes Stoljar\n", "\n", "## License" ] @@ -33,33 +33,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Motivation\n", - "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", - "\n", "## Introduction to the example\n", - "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", + "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", "\n", "![svg](https://github.com/thummeto/FMI.jl/blob/main/docs/src/examples/pics/SpringFrictionPendulum1D.svg?raw=true) \n", "\n", "\n", - "## Target group\n", - "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", - "\n", - "\n", "## Other formats\n", - "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", - "\n", - "\n", - "## Getting started\n", - "\n", - "### Installation prerequisites\n", - "| | Description | Command | Alternative | \n", - "|:----|:----------------------------------|:--------------------------|:-----------------------------------------------|\n", - "| 1. | Enter Package Manager via | ] | |\n", - "| 2. | Install FMI via | add FMI | add \" https://github.com/ThummeTo/FMI.jl \" |\n", - "| 3. | Install FMIZoo via | add FMIZoo | add \" https://github.com/ThummeTo/FMIZoo.jl \" |\n", - "| 4. | Install FMICore via | add FMICore | add \" https://github.com/ThummeTo/FMICore.jl \" |\n", - "| 5. | Install Plots via | add Plots | |" + "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. " ] }, { @@ -126,7 +107,7 @@ "source": [ "### Import FMU\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." ] }, { @@ -144,11 +125,7 @@ "outputs": [], "source": [ "# we use an FMU from the FMIZoo.jl\n", - "pathToFMU = get_model_filename(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\")\n", - "\n", - "myFMU = fmiLoad(pathToFMU)\n", - "\n", - "fmiInfo(myFMU)" + "fmu = fmiLoad(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\"; type=:ME)" ] }, { @@ -173,9 +150,10 @@ }, "outputs": [], "source": [ + "# an array of value references... or just one\n", "vrs = [\"mass.s\"]\n", "\n", - "simData = fmiSimulateME(myFMU, (tStart, tStop); recordValues=vrs)" + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=vrs)" ] }, { @@ -201,7 +179,7 @@ }, "outputs": [], "source": [ - "fig = fmiPlot(simData, states=false)" + "fig = plot(simData, states=false)" ] }, { @@ -227,7 +205,7 @@ "outputs": [], "source": [ "# save, where the original `fmi2GetReal` function was stored, so we can access it in our new function\n", - "originalGetReal = myFMU.cGetReal" + "originalGetReal = fmu.cGetReal" ] }, { @@ -293,7 +271,7 @@ "outputs": [], "source": [ "# no we overwrite the original function\n", - "fmiSetFctGetReal(myFMU, myGetReal!)" + "fmiSetFctGetReal(fmu, myGetReal!)" ] }, { @@ -318,8 +296,8 @@ }, "outputs": [], "source": [ - "simData = fmiSimulateME(myFMU, (tStart, tStop); recordValues=vrs)\n", - "fmiPlot!(fig, simData; states=false, style=:dash)" + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=vrs)\n", + "plot!(fig, simData; states=false, style=:dash)" ] }, { @@ -351,7 +329,7 @@ }, "outputs": [], "source": [ - "fmiUnload(myFMU)" + "fmiUnload(fmu)" ] }, { @@ -360,7 +338,7 @@ "source": [ "### Summary\n", "\n", - "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." + "In this tutorial it is shown how an existing function of the library can be replaced by an own implementation." ] } ], @@ -374,15 +352,15 @@ "notebook_metadata_filter": "-all" }, "kernelspec": { - "display_name": "Julia 1.8.2", + "display_name": "Julia 1.9.1", "language": "julia", - "name": "julia-1.8" + "name": "julia-1.9" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.8.2" + "version": "1.9.1" }, "nteract": { "version": "0.28.0" diff --git a/examples/src/modelica_conference_2021.ipynb b/examples/src/modelica_conference_2021.ipynb index ec3347af..8b7d5f4a 100644 --- a/examples/src/modelica_conference_2021.ipynb +++ b/examples/src/modelica_conference_2021.ipynb @@ -4,8 +4,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Advanced Simulation of an FMU\n", - "Tutorial by Johannes Stoljar, Tobias Thummerer\n", + "# Example from the Modelica Conference 2021\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" ] @@ -33,33 +37,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Motivation\n", - "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", - "\n", "## 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", - "\n", - "## Target group\n", - "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", - "\n", - "\n", "## Other formats\n", - "Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/modelica_conference_2021.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/modelica_conference_2021.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/modelica_conference_2021.md) corresponding to the notebook. \n", - "\n", - "\n", - "## Getting started\n", - "\n", - "### Installation prerequisites\n", - "\n", - "| | Description | Command | Alternative | \n", - "|:----|:----------------------------------|:--------------------------|:-----------------------------------------------|\n", - "| 1. | Enter Package Manager via | ] | |\n", - "| 2. | Install FMI via | add FMI | add \" https://github.com/ThummeTo/FMI.jl \" |\n", - "| 3. | Install FMIZoo via | add FMIZoo | add \" https://github.com/ThummeTo/FMIZoo.jl \" |\n", - "| 4. | Install Plots via | add Plots | |" + "Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/modelica_conference_2021.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/modelica_conference_2021.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/modelica_conference_2021.md) corresponding to the notebook. " ] }, { @@ -125,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." ] }, { @@ -143,17 +126,16 @@ "outputs": [], "source": [ "# we use an FMU from the FMIZoo.jl\n", - "pathToFMU = get_model_filename(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\")\n", - "\n", - "myFMU = fmiLoad(pathToFMU)\n", - "fmiInfo(myFMU)" + "fmu = fmiLoad(\"SpringFrictionPendulum1D\", \"Dymola\", \"2022x\")\n", + "fmiInfo(fmu)" ] }, { "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." ] }, { @@ -170,8 +152,8 @@ }, "outputs": [], "source": [ - "simData = fmiSimulate(myFMU, (tStart, tStop); recordValues=[\"mass.s\"], saveat=tSave)\n", - "fmiPlot(simData)" + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=[\"mass.s\"], saveat=tSave)\n", + "plot(simData)" ] }, { @@ -194,14 +176,14 @@ }, "outputs": [], "source": [ - "fmiUnload(myFMU)" + "fmiUnload(fmu)" ] }, { "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." ] @@ -219,14 +201,14 @@ }, "outputs": [], "source": [ - "myFMU = 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!()`. " ] }, { @@ -242,14 +224,14 @@ }, "outputs": [], "source": [ - "instanceFMU = fmiInstantiate!(myFMU)" + "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." ] }, { @@ -265,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." ] }, { @@ -292,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)" ] }, { @@ -321,9 +310,9 @@ }, "outputs": [], "source": [ - "fmiTerminate(instanceFMU)\n", - "fmiFreeInstance!(instanceFMU)\n", - "fmiUnload(myFMU)" + "fmi2Terminate(instanceFMU)\n", + "fmi2FreeInstance!(instanceFMU)\n", + "fmi2Unload(fmu)" ] }, { @@ -332,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." ] } ], diff --git a/examples/src/multiple_instances.ipynb b/examples/src/multiple_instances.ipynb index 8675b588..1106a1a6 100644 --- a/examples/src/multiple_instances.ipynb +++ b/examples/src/multiple_instances.ipynb @@ -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" ] }, diff --git a/examples/src/multiprocessing.ipynb b/examples/src/multiprocessing.ipynb index b8d32cda..ce9df605 100644 --- a/examples/src/multiprocessing.ipynb +++ b/examples/src/multiprocessing.ipynb @@ -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" ] }, diff --git a/examples/src/multithreading.ipynb b/examples/src/multithreading.ipynb index 6398cfd7..a3968205 100644 --- a/examples/src/multithreading.ipynb +++ b/examples/src/multithreading.ipynb @@ -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" ] }, diff --git a/examples/src/parameterize.ipynb b/examples/src/parameterize.ipynb index 028061d2..627a5b68 100644 --- a/examples/src/parameterize.ipynb +++ b/examples/src/parameterize.ipynb @@ -4,8 +4,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Manually parameterize an FMU\n", - "Tutorial by Johannes Stoljar, Tobias Thummerer\n", + "# Parameterize a FMU\n", + "Tutorial by Tobias Thummerer, Johannes Stoljar\n", + "\n", + "Last update: 09.08.2023\n", + "\n", + "🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n", "\n", "## License" ] @@ -33,28 +37,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Motivation\n", - "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", - "\n", - "## Introduction to the example\n", - "This example shows how the manually parameterization of an FMU works if very specific adjustments during system initialization is needed. For this purpose, an IO-FMU model is loaded and the various commands for parameterization are shown on the basis of this model. With this example the user shall be guided how to make certain settings at an FMU. Please note, that parameterization of a simulation is possible in a much easier fashion: Using `fmiSimulate`, `fmiSimulateME` or `fmiSimulateCS` together with a parameter dictionary for the keyword `parameters`.\n", - "\n", - "## Target group\n", - "The example is primarily intended for users who work in the field of simulation exchange. The example wants to show how simple it is to use FMUs in Julia.\n", - "\n", + "## Introduction\n", + "This example shows how to parameterize a FMU. We will show to possible ways to parameterize: The default option using the parameterization feature of `fmiSimulate`, `fmiSimulateME` or `fmiSimulateCS`. Second, a custom parameterization routine for advanced users. \n", "\n", "## Other formats\n", - "Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/parameterize.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/parameterize.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/parameterize.md) corresponding to the notebook. \n", - "\n", - "\n", - "## Getting started\n", - "\n", - "### Installation prerequisites\n", - "| | Description | Command | Alternative | \n", - "|:----|:----------------------------------|:--------------------------|:-----------------------------------------------|\n", - "| 1. | Enter Package Manager via | ] | |\n", - "| 2. | Install FMI via | add FMI | add \" https://github.com/ThummeTo/FMI.jl \" |\n", - "| 3. | Install FMIZoo via | add FMIZoo | add \" https://github.com/ThummeTo/FMIZoo.jl \" |" + "Besides, this [Jupyter Notebook](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/parameterize.ipynb) there is also a [Julia file](https://github.com/thummeto/FMI.jl/blob/examples/examples/src/parameterize.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/parameterize.md) corresponding to the notebook. " ] }, { @@ -124,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2022-10-22T13:27:25.403000Z", @@ -137,16 +124,38 @@ "outputs": [], "source": [ "# we use an FMU from the FMIZoo.jl\n", + "# just replace this line with a local path if you want to use your own FMU\n", "pathToFMU = get_model_filename(\"IO\", \"Dymola\", \"2022x\")\n", "\n", - "myFMU = fmiLoad(pathToFMU)\n", - "fmiInfo(myFMU)" + "fmu = fmiLoad(pathToFMU)\n", + "fmiInfo(fmu)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Option A: Integrated parameterization feature of *FMI.jl*\n", + "If you are using the commands for simulation integrated in *FMI.jl*, the parameters and initial conditions are set at the correct locations during the initialization process of your FMU. This is the recommended way of parameterizing your model, if you don't have very uncommon requirements regarding initialization." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dict = Dict{String, Any}()\n", + "dict" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ + "### Option B: Custom parameterization routine\n", + "If you have special requirements for initialization and parameterization, you can write your very own parameterization routine.\n", + "\n", "### Instantiate and Setup FMU\n", "\n", "Next it is necessary to create an instance of the FMU. This is achieved by the command `fmiInstantiate!()`." @@ -165,7 +174,7 @@ }, "outputs": [], "source": [ - "fmiInstantiate!(myFMU; loggingOn=true)" + "fmiInstantiate!(fmu; loggingOn=true)" ] }, { @@ -188,7 +197,7 @@ }, "outputs": [], "source": [ - "fmiSetupExperiment(myFMU, tStart, tStop)" + "fmiSetupExperiment(fmu, tStart, tStop)" ] }, { @@ -237,7 +246,7 @@ }, "outputs": [], "source": [ - "fmiEnterInitializationMode(myFMU)" + "fmiEnterInitializationMode(fmu)" ] }, { @@ -260,7 +269,7 @@ }, "outputs": [], "source": [ - "fmiGet(myFMU, params)" + "fmiGet(fmu, params)" ] }, { @@ -283,7 +292,7 @@ }, "outputs": [], "source": [ - "fmiExitInitializationMode(myFMU)" + "fmiExitInitializationMode(fmu)" ] }, { @@ -361,9 +370,9 @@ }, "outputs": [], "source": [ - "fmiTerminate(myFMU)\n", - "fmiReset(myFMU)\n", - "fmiSetupExperiment(myFMU, tStart, tStop)" + "fmiTerminate(fmu)\n", + "fmiReset(fmu)\n", + "fmiSetupExperiment(fmu, tStart, tStop)" ] }, { @@ -386,7 +395,7 @@ }, "outputs": [], "source": [ - "fmiSet(myFMU, params, collect(paramsVal))" + "fmiSet(fmu, params, collect(paramsVal))" ] }, { @@ -409,9 +418,9 @@ }, "outputs": [], "source": [ - "fmiEnterInitializationMode(myFMU)\n", - "# fmiGet(myFMU, params)\n", - "fmiExitInitializationMode(myFMU)" + "fmiEnterInitializationMode(fmu)\n", + "# fmiGet(fmu, params)\n", + "fmiExitInitializationMode(fmu)" ] }, { @@ -434,7 +443,7 @@ }, "outputs": [], "source": [ - "simData = fmiSimulate(myFMU, (tStart, tStop); recordValues=params[1:3], saveat=tSave, \n", + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=params[1:3], saveat=tSave, \n", " instantiate=false, setup=false, freeInstance=false, terminate=false, reset=false)" ] }, @@ -460,9 +469,9 @@ }, "outputs": [], "source": [ - "fmiTerminate(myFMU)\n", - "fmiReset(myFMU)\n", - "fmiSetupExperiment(myFMU, tStart, tStop)" + "fmiTerminate(fmu)\n", + "fmiReset(fmu)\n", + "fmiSetupExperiment(fmu, tStart, tStop)" ] }, { @@ -508,10 +517,10 @@ }, "outputs": [], "source": [ - "fmiSetReal(myFMU, \"p_real\", rndReal)\n", - "fmiSetBoolean(myFMU, \"p_boolean\", rndBoolean)\n", - "fmiSetInteger(myFMU, \"p_integer\", rndInteger)\n", - "fmiSetString(myFMU, \"p_string\", rndString)" + "fmiSetReal(fmu, \"p_real\", rndReal)\n", + "fmiSetBoolean(fmu, \"p_boolean\", rndBoolean)\n", + "fmiSetInteger(fmu, \"p_integer\", rndInteger)\n", + "fmiSetString(fmu, \"p_string\", rndString)" ] }, { @@ -540,12 +549,12 @@ }, "outputs": [], "source": [ - "fmiEnterInitializationMode(myFMU)\n", - "# fmiGetReal(myFMU, \"u_real\")\n", - "# fmiGetBoolean(myFMU, \"u_boolean\")\n", - "# fmiGetInteger(myFMU, \"u_integer\")\n", - "# fmiGetString(myFMU, \"p_string\")\n", - "fmiExitInitializationMode(myFMU)" + "fmiEnterInitializationMode(fmu)\n", + "# fmiGetReal(fmu, \"u_real\")\n", + "# fmiGetBoolean(fmu, \"u_boolean\")\n", + "# fmiGetInteger(fmu, \"u_integer\")\n", + "# fmiGetString(fmu, \"p_string\")\n", + "fmiExitInitializationMode(fmu)" ] }, { @@ -568,7 +577,7 @@ }, "outputs": [], "source": [ - "simData = fmiSimulate(myFMU, (tStart, tStop); recordValues=params[1:3], saveat=tSave, \n", + "simData = fmiSimulate(fmu, (tStart, tStop); recordValues=params[1:3], saveat=tSave, \n", " instantiate=false, setup=false)" ] }, @@ -594,7 +603,7 @@ }, "outputs": [], "source": [ - "fmiUnload(myFMU)" + "fmiUnload(fmu)" ] }, { @@ -619,15 +628,15 @@ "notebook_metadata_filter": "-all" }, "kernelspec": { - "display_name": "Julia 1.8.2", + "display_name": "Julia 1.9.1", "language": "julia", - "name": "julia-1.8" + "name": "julia-1.9" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.8.2" + "version": "1.9.1" }, "nteract": { "version": "0.28.0" diff --git a/examples/src/simulate.ipynb b/examples/src/simulate.ipynb index d2ce3ba0..41b8a17b 100644 --- a/examples/src/simulate.ipynb +++ b/examples/src/simulate.ipynb @@ -7,6 +7,8 @@ "# Simulate an FMU in different modes\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" ] }, diff --git a/src/FMI2/sim.jl b/src/FMI2/sim.jl index 49495692..db843b72 100644 --- a/src/FMI2/sim.jl +++ b/src/FMI2/sim.jl @@ -781,6 +781,14 @@ function fmi2Simulate(c::FMU2Component, tspan::Union{Tuple{Float64, Float64}, No fmi2Simulate(c.fmu, c, tspan; kwargs...) end +# function (c::FMU2Component)(; t::Tuple{Float64, Float64}, kwargs...) +# fmi2Simulate(c, t; kwargs...) +# end + +# function (f::FMU2)(; t::Tuple{Float64, Float64}, kwargs...) +# fmi2Simulate(c.fmu, t; kwargs...) +# end + """ Starts a simulation of the FMU instance for the matching FMU type, if both types are available, CS is preferred. @@ -791,7 +799,7 @@ Keywords: - inputValues: Array of input variables (strings or variableIdentifiers) to set at every simulation step - inputFunction: Function to retrieve the values to set the inputs to - saveat: [ME only] Time points to save values at (interpolated) - - solver: [ME only] Any Julia-supported ODE-solver (default is Tsit5) + - solver: [ME only] Any Julia-supported ODE-solver (default is default from DifferentialEquations.jl) - customFx: [ME only, deprecated] Ability to give a custom state derivative function ẋ=f(x,t) Returns: