Skip to content

Commit

Permalink
minor changes (#240)
Browse files Browse the repository at this point in the history
* minor changes

* typos

* remark for tutorials

* updated readme
  • Loading branch information
ThummeTo authored Sep 4, 2024
1 parent 3d55081 commit 84ef2dc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 82 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ If you want to migrate your project from [*FMI.jl*](https://github.com/ThummeTo/

- [x] [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) and [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) were divided into [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl), [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) and [*FMIBase.jl*](https://github.com/ThummeTo/FMIBase.jl). [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl) now holds the pure standard definition (C-types and -functions), while [*FMIBase.jl*](https://github.com/ThummeTo/FMIBase.jl) holds everything that is needed on top of that in [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl) as well as in [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl).

- [ ] Updated all library examples.

- [ ] Updated all library tests for a better code coverage.

- [ ] We tried to document every function, if you find undocumented user-level functions, please open an issue or PR.
Expand Down Expand Up @@ -73,24 +75,26 @@ unloadFMU(myFMU)
```

## What is currently supported in FMI.jl?
- importing the full FMI 2.0.3 and FMI 3.0.0 command set, including optional specials like `fmi2GetState`, `fmi2SetState` and `fmi2GetDirectionalDerivatives`
- importing the full FMI 2.0.3 and FMI 3.0.0 command set, including optional specials like `fmi2GetFMUstate`, `fmi2SetFMUstate` and `fmi2GetDirectionalDerivatives`
- parameterization, simulation & plotting of CS- and ME-FMUs
- event-handling for imported discontinuous ME-FMUs

| | **FMI2.0.3** | | **FMI3.0** | | **SSP1.0** | |
|-----------------------------------|--------------|--------|------------|--------|------------|--------|
| | Import | Export | Import | Export | Import | Export |
| CS | ✔️✔️ | 🚧 | ✔️✔️ | 📅 | 📅 | 📅 |
| ME (continuous) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| ME (discontinuous) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| SE | 🚫 | 🚫 | 🚧 | 📅 | 🚫 | 🚫 |
| Explicit solvers | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| Implicit solvers (autodiff=false) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| Implicit solvers (autodiff=true) | ✔️ | ✔️✔️ | ✔️ | 📅 | 📅 | 📅 |
| get/setState | ✔️✔️ | 📅 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| getDirectionalDerivatives | ✔️✔️ | 📅 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| getAdjointDerivatives | 🚫 | 🚫 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| FMI Cross Checks | ✔️✔️ | 📅 | 📅 | 📅 | 🚫 | 🚫 |
| CS | ✔️✔️ | 🚧 | ✔️✔️ | 📅 | 📅 | 📅 |
| ME (continuous) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| ME (discontinuous) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| SE | 🚫 | 🚫 | 🚧 | 📅 | 🚫 | 🚫 |
| Explicit solvers | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| Implicit solvers (autodiff=false) | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 📅 | 📅 |
| Implicit solvers (autodiff=true) | ✔️ | ✔️✔️ | ✔️ | 📅 | 📅 | 📅 |
| get/setFMUstate | ✔️✔️ | 📅 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| getDirectionalDerivatives | ✔️✔️ | 📅 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| getAdjointDerivatives | 🚫 | 🚫 | ✔️✔️ | 📅 | 🚫 | 🚫 |
| FMI Cross Checks | ✔️✔️ | 📅 | 📅 | 📅 | 🚫 | 🚫 |
| 64-bit binaries in FMUs | ✔️✔️ | ✔️✔️ | ✔️✔️ | 📅 | 🚫 | 🚫 |
| 32-bit binaries in FMUs | ✔️ | 📅 | 📅 | 📅 | 🚫 | 🚫 |

✔️✔️ supported & CI-tested

Expand Down Expand Up @@ -130,7 +134,7 @@ Tobias Thummerer, Johannes Tintenherr, Lars Mikelsons. 2021 **Hybrid modeling of

## Notes for contributors
Contributors are welcome. Before contributing, please read, understand and follow the [Contributor's Guide on Collaborative Practices for Community Packages](https://github.com/SciML/ColPrac).
During development of new implementations or optimizations on exisitng code, one will have to make design decissions that influence the library performance and usability. The following priorization should be the basis for decision-making:
During development of new implementations or optimizations on existing code, one will have to make design decisions that influence the library performance and usability. The following prioritization should be the basis for decision-making:
- **#1 Compliance with standard:** It is the highest priority to be compliant with the FMI standard ([fmi-standard.org](https://fmi-standard.org/)). Identifiers described in the standard must be used. Topologies should follow the specification as far as the possibilities of the Julia programming language allows.
- **#2 Performance:** Because [*FMI.jl*](https://github.com/ThummeTo/FMI.jl) is a simulation tool, performance is very important. This applies to the efficient use of CPU and GPU, but also the conscientious use of RAM and disc space.
- **#3 Usability:** The library should be as usable as possible and feel "the Julia way" (e.g. by using multiple dispatch instead of the "C coding style"), as long as being fully compliant with the FMI standard.
23 changes: 13 additions & 10 deletions examples/src/inputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"# Simulate an FMU with inputs\n",
"Tutorial by 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 Expand Up @@ -115,7 +117,7 @@
"outputs": [],
"source": [
"# we use an FMU from the FMIZoo.jl\n",
"fmu = fmiLoad(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\"; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")"
"fmu = loadFMU(\"SpringPendulumExtForce1D\", \"Dymola\", \"2022x\"; type=:ME) # load FMU in ME-Mode (\"Model Exchange\")"
]
},
{
Expand All @@ -125,7 +127,7 @@
"source": [
"#### Simulate as Model-Exchange\n",
"\n",
"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."
"In the function `simulate()` 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."
]
},
{
Expand All @@ -147,12 +149,12 @@
"end \n",
"\n",
"# simulate while setting inputs\n",
"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",
"data_extForce_t = simulate(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)"
]
},
Expand All @@ -168,7 +170,8 @@
" if x != nothing # this check is important, because inputs may be needed before the system state is known\n",
" x1 = x[1] \n",
" end\n",
" u[1] =sin(t) * x1\n",
" u[1] = sin(t) * x1\n",
" nothing\n",
"end \n",
"\n",
"# simulate while setting inputs\n",
Expand Down Expand Up @@ -198,7 +201,7 @@
},
"outputs": [],
"source": [
"fmiUnload(fmu)"
"unloadFMU(fmu)"
]
}
],
Expand Down
2 changes: 2 additions & 0 deletions examples/src/manipulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"# Manipulate a function\n",
"Tutorial by Tobias Thummerer, Johannes Stoljar\n",
"\n",
"🚧 This tutorial is under revision and will be replaced by an up-to-date version soon 🚧\n",
"\n",
"## License"
]
},
Expand Down
8 changes: 4 additions & 4 deletions examples/src/parameter_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
"outputs": [],
"source": [
"# we use an FMU from the FMIZoo.jl\n",
"fmu = fmiLoad(\"SpringPendulum1D\", \"Dymola\", \"2022x\"; type=:ME)\n",
"fmiInfo(fmu)"
"fmu = loadFMU(\"SpringPendulum1D\", \"Dymola\", \"2022x\"; type=:ME)\n",
"info(fmu)"
]
},
{
Expand Down Expand Up @@ -177,10 +177,10 @@
" x0 = [s0, v0]\n",
"\n",
" # simulate with given start stae and parameters\n",
" sol = fmiSimulate(fmu, (tStart, tStop); x0=x0, parameters=paramDict, saveat=tSave)\n",
" sol = simulate(fmu, (tStart, tStop); x0=x0, parameters=paramDict, saveat=tSave)\n",
"\n",
" # get state with index 1 (the position) from the solution\n",
" s_res = fmiGetSolutionState(sol, 1; isIndex=true) \n",
" s_res = getState(sol, 1; isIndex=true) \n",
"\n",
" return s_res\n",
"end\n",
Expand Down
40 changes: 20 additions & 20 deletions src/sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ You can force a specific simulation mode by calling [`simulateCS`](@ref), [`simu
# Keyword arguments
- `recordValues::fmi2ValueReferenceFormat` = nothing: Array of variables (Strings or variableIdentifiers) to record. Results are returned as `DiffEqCallbacks.SavedValues`
- `saveat = nothing`: Time points to save (interpolated) values at (default = nothing: save at each solver timestep)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `inputValueReferences::fmi2ValueReferenceFormat = nothing`: Input variables (Strings or variableIdentifiers) to set at each simulation step
- `inputFunction = nothing`: Function to get values for the input variables at each simulation step.
- `parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing`: Dict of parameter variables (strings or variableIdentifiers) and values (Real, Integer, Boolean, String) to set parameters during initialization
- `showProgress::Bool = true`: print simulation progressmeter in REPL
- `showProgress::Bool = true`: print simulation progress meter in REPL
## Input function pattern
[`c`: current component, `u`: current state ,`t`: current time, returning array of values to be passed to `fmi2SetReal(..., inputValueReferences, inputFunction(...))` or `fmi3SetFloat64`]:
Expand Down Expand Up @@ -110,18 +110,18 @@ State- and Time-Events are handled correctly.
- `recordEventIndicators::Union{AbstractArray{<:Integer, 1}, UnitRange{<:Integer}, Nothing} = nothing`: Array or Range of event indicators to record
- `recordEigenvalues::Bool=false`: compute and record eigenvalues
- `saveat = nothing`: Time points to save (interpolated) values at (default = nothing: save at each solver timestep)
- `x0::Union{AbstractArray{<:Real}, Nothing} = nothing`: inital fmu State (default = nothing: use current or default-inital fmu state)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `x0::Union{AbstractArray{<:Real}, Nothing} = nothing`: initial fmu State (default = nothing: use current or default-initial fmu state)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `inputValueReferences::fmi2ValueReferenceFormat = nothing`: Input variables (Strings or variableIdentifiers) to set at each simulation step
- `inputFunction = nothing`: Function to get values for the input variables at each simulation step.
- `parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing`: Dict of parameter variables (strings or variableIdentifiers) and values (Real, Integer, Boolean, String) to set parameters during initialization
- `callbacksBefore = []`: callbacks to call *before* the internal callbacks for state- and time-events are called
- `callbacksAfter = []`: callbacks to call *after* the internal callbacks for state- and time-events are called
- `showProgress::Bool = true`: print simulation progressmeter in REPL
- `showProgress::Bool = true`: print simulation progress meter in REPL
- `solveKwargs...`: keyword arguments that get passed onto the solvers solve call
## Input function pattern
Expand Down Expand Up @@ -161,7 +161,7 @@ function simulateME(
solveKwargs...,
)

@assert isModelExchange(fmu) "simulateME(...): This function supports Model Excahnge FMUs only."
@assert isModelExchange(fmu) "simulateME(...): This function supports Model Exchange FMUs only."

recordValues = prepareValueReference(fmu, recordValues)
inputValueReferences = prepareValueReference(fmu, inputValueReferences)
Expand Down Expand Up @@ -309,15 +309,15 @@ State- and Time-Events are handled internally by the FMU.
- `tolerance::Union{Real, Nothing} = nothing`: The tolerance for the internal FMU solver.
- `recordValues::fmi2ValueReferenceFormat` = nothing: Array of variables (Strings or variableIdentifiers) to record. Results are returned as `DiffEqCallbacks.SavedValues`
- `saveat = nothing`: Time points to save (interpolated) values at (default = nothing: save at each solver timestep)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMU2ExecutionConfiguration`)
- `setup::Bool`: call fmi2SetupExperiment, fmi2EnterInitializationMode and fmi2ExitInitializationMode before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `reset::Bool`: call fmi2Reset before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `instantiate::Bool`: call fmi2Instantiate! before each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `freeInstance::Bool`: call fmi2FreeInstance after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `terminate::Bool`: call fmi2Terminate after each step (default = nothing: use value from `fmu`'s `FMUExecutionConfiguration`)
- `inputValueReferences::fmi2ValueReferenceFormat = nothing`: Input variables (Strings or variableIdentifiers) to set at each simulation step
- `inputFunction = nothing`: Function to get values for the input variables at each simulation step.
- `parameters::Union{Dict{<:Any, <:Any}, Nothing} = nothing`: Dict of parameter variables (strings or variableIdentifiers) and values (Real, Integer, Boolean, String) to set parameters during initialization
- `showProgress::Bool = true`: print simulation progressmeter in REPL
- `showProgress::Bool = true`: print simulation progress meter in REPL
## Input function pattern
[`c`: current component, `u`: current state ,`t`: current time, returning array of values to be passed to `fmi2SetReal(..., inputValueReferences, inputFunction(...))` or `fmi3SetFloat64`]:
Expand Down
Loading

2 comments on commit 84ef2dc

@ThummeTo
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114525

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" 84ef2dcd82181527ff8a9e90cca3046de45ecb8b
git push origin v0.14.0

Please sign in to comment.