Skip to content

Commit

Permalink
Merge branch 'main' into doc14main
Browse files Browse the repository at this point in the history
  • Loading branch information
ThummeTo committed Sep 4, 2024
2 parents 7208265 + 84ef2dc commit 6da2e76
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 75 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.
15 changes: 9 additions & 6 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 @@ -148,11 +150,11 @@
"\n",
"# simulate while setting inputs\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",
" 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
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
2 changes: 1 addition & 1 deletion examples/src/parameter_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
" 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 = fmi2GetSolutionState(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

0 comments on commit 6da2e76

Please sign in to comment.