Skip to content

Commit

Permalink
v0.11.2 (#163)
Browse files Browse the repository at this point in the history
* fixed testa

* added test for execution config, fixed bug with freeInstance

* compatibility to new FMI3 topology
  • Loading branch information
ThummeTo authored Dec 21, 2022
1 parent 8493882 commit 9055475
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMI"
uuid = "14a09403-18e3-468f-ad8a-74f8dda2d9ac"
authors = ["TT <[email protected]>", "LM <[email protected]>", "JK <[email protected]>"]
version = "0.11.1"
version = "0.11.2"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -20,7 +20,7 @@ ChainRulesCore = "1.15.0"
DiffEqCallbacks = "2.24.0"
DifferentialEquations = "7.5.0"
FMIExport = "0.1.0"
FMIImport = "0.13.0"
FMIImport = "0.14.0"
ForwardDiff = "0.10.0"
ProgressMeter = "1.7.0"
Requires = "1.3.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To keep dependencies nice and clean, the original package [*FMI.jl*](https://git
- ...

## What Platforms are supported?
[*FMI.jl*](https://github.com/ThummeTo/FMI.jl) is tested (and testing) under Julia Versions *1.6 LTS* (64-bit) and *latest* (64-bit) on Windows *latest* (64-bit) and Ubuntu *latest* (64-bit). Mac and Julia (32-bit) should work, but untested.
[*FMI.jl*](https://github.com/ThummeTo/FMI.jl) is tested (and testing) under Julia Versions *1.6 LTS* (64-bit) and *latest* (64-bit) on Windows *latest* (64-bit) and Ubuntu *latest* (64-bit). Mac and Julia (32-bit) should work, but untested. For the best performance, we recommend using Julia >= 1.7.

## How to cite?
Tobias Thummerer, Lars Mikelsons and Josef Kircher. 2021. **NeuralFMU: towards structural integration of FMUs into neural networks.** Martin Sjölund, Lena Buffoni, Adrian Pop and Lennart Ochel (Ed.). Proceedings of 14th Modelica Conference 2021, Linköping, Sweden, September 20-24, 2021. Linköping University Electronic Press, Linköping (Linköping Electronic Conference Proceedings ; 181), 297-306. [DOI: 10.3384/ecp21181297](https://doi.org/10.3384/ecp21181297)
Expand Down
23 changes: 22 additions & 1 deletion docs/src/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

This list some common - often numerical - errors, that can be fixed by better understanding the ODE-Problem inside your FMU.



## Solving non-linear system
### Description
Error message or warning, that solving of a non-linear system failed, close to the simulation start time.
Expand All @@ -14,4 +16,23 @@ Error message or warning, that solving of a non-linear system failed, close to t
This could be, because the first step of the integration is accepted by the solver's error estimation, but shouldn't. This is usually, if the first step is picked to large by the solver's start step size heuristics.

### Fix
- Try a small start value for the integration with keyword `dt`.
- Try a small start value for the integration with keyword `dt`.



## Access denied
### Description
Error message, that the binary for callback functions can't be accessed/opened.

### Example
```
ERROR:
could not load library "...\src\FMI2\callbackFunctions\binaries\win64\callbackFunctions.dll"
Access denied
```

### Reason
This is because your OS doesn't allow to interact with the binaries shipped with *FMI.jl*.

### Fix
This can easily be solved by fixing the binary's permission options or is automatically fixed if Julia runs with admin privileges.
4 changes: 2 additions & 2 deletions src/FMI2/sim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function fmi2SimulateME(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tsp
ProgressMeter.finish!(progressMeter)
end

finishSolveFMU(fmu, c, terminate, freeInstance)
finishSolveFMU(fmu, c, freeInstance, terminate)

return fmusol
end
Expand Down Expand Up @@ -587,7 +587,7 @@ function fmi2SimulateCS(fmu::FMU2, c::Union{FMU2Component, Nothing}=nothing, tsp
fmusol.success = true
end

finishSolveFMU(fmu, c, terminate, freeInstance)
finishSolveFMU(fmu, c, freeInstance, terminate)

return fmusol
end
Expand Down
72 changes: 72 additions & 0 deletions test/FMI2/exec_config.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Copyright (c) 2021 Tobias Thummerer, Lars Mikelsons, Josef Kircher
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

using FMI.FMIImport

t_start = 0.0
t_stop = 1.0

myFMU = fmiLoad("SpringPendulum1D", ENV["EXPORTINGTOOL"], ENV["EXPORTINGVERSION"])

comp = fmiInstantiate!(myFMU; loggingOn=false, type=fmi2TypeCoSimulation)
@test comp != 0
# choose FMU or FMUComponent
fmuStruct = nothing
envFMUSTRUCT = ENV["FMUSTRUCT"]
if envFMUSTRUCT == "FMU"
fmuStruct = myFMU
elseif envFMUSTRUCT == "FMUCOMPONENT"
fmuStruct = comp
end
@assert fmuStruct !== nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

for execConf in (FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGURATION_RESET, FMU2_EXECUTION_CONFIGURATION_NO_RESET) # ToDo: Add `FMU2_EXECUTION_CONFIGURATION_NOTHING`
for mode in (:CS, :ME)
global fmuStruct
@info "\t$(mode) | $(execConf)"

myFMU.executionConfig = execConf

# sim test
numInst = length(myFMU.components)

if mode == :CS
fmiSimulateCS(fmuStruct, (t_start, t_stop))
elseif mode == :ME
fmiSimulateME(fmuStruct, (t_start, t_stop))
else
@assert false "Unknown mode `$(mode)`."
end

if execConf.instantiate
numInst += 1
end
if execConf.freeInstance
numInst -= 1
end

@test length(myFMU.components) == numInst

# prepare next run start
if envFMUSTRUCT == "FMU"
if !execConf.freeInstance
fmi2FreeInstance!(myFMU)
end
fmi2Instantiate!(myFMU; type=(mode==:CS ? fmi2TypeModelExchange : fmi2TypeCoSimulation))

elseif envFMUSTRUCT == "FMUCOMPONENT"
if !execConf.freeInstance
fmi2FreeInstance!(fmuStruct)
end
fmuStruct = fmi2Instantiate!(myFMU; type=(mode==:CS ? fmi2TypeModelExchange : fmi2TypeCoSimulation))

end

# prepare next run end

end
end

fmiUnload(myFMU)
22 changes: 14 additions & 8 deletions test/FMI2/sim_ME.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,22 @@ elseif envFMUSTRUCT == "FMUCOMPONENT"
end
@assert fmuStruct != nothing "Unknown fmuStruct, environment variable `FMUSTRUCT` = `$envFMUSTRUCT`"

solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver_ad, dtmin=dtmin, dtmax=dtmax_inputs) # dtmax to force resolution
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0
# there are issues with AD in Julia < 1.7.0
# ToDo: Fix Linux FMU
if VERSION >= v"1.7.0" && !Sys.islinux()
solution = fmiSimulateME(fmuStruct, (t_start, t_stop); abstol=abstol, solver=solver_ad, dtmin=dtmin, dtmax=dtmax_inputs) # dtmax to force resolution

@test solution.states.t[1] == t_start
@test solution.states.t[end] == t_stop
@test length(solution.states.u) > 0
@test length(solution.states.t) > 0

@test solution.states.t[1] == t_start
@test solution.states.t[end] == t_stop

# reference values (no force) from Simulation in Dymola2020x (Dassl)
@test solution.states.u[1] == [0.5, 0.0]
@test sum(abs.(solution.states.u[end] - [0.509219, 0.314074])) < 0.01
end

# reference values (no force) from Simulation in Dymola2020x (Dassl)
@test solution.states.u[1] == [0.5, 0.0]
@test sum(abs.(solution.states.u[end] - [0.509219, 0.314074])) < 0.01
fmiUnload(myFMU)

# case 3c: ME-FMU without events, but with input signal (implicit solver: Rosenbrock23, no autodiff)
Expand Down
10 changes: 8 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ using FMIZoo
using Test
import Random

import FMI.FMIImport.FMICore: fmi2StatusOK
import FMI.FMIImport.FMICore: fmi2StatusOK, fmi2ComponentStateTerminated, fmi2ComponentStateInstantiated
import FMI.FMIImport.FMICore: FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGURATION_NO_RESET, FMU2_EXECUTION_CONFIGURATION_RESET, FMU2_EXECUTION_CONFIGURATION_NOTHING

exportingToolsWindows = [("Dymola", "2022x")]
exportingToolsLinux = [("Dymola", "2022x")]
fmuStructs = ["FMU", "FMUCOMPONENT"]

# enable assertions for warnings/errors for all default execution configurations
for exec in [FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGURATION_NO_RESET, FMU2_EXECUTION_CONFIGURATION_RESET]
for exec in [FMU2_EXECUTION_CONFIGURATION_NO_FREEING, FMU2_EXECUTION_CONFIGURATION_NO_RESET, FMU2_EXECUTION_CONFIGURATION_RESET, FMU2_EXECUTION_CONFIGURATION_NOTHING]
exec.assertOnError = true
exec.assertOnWarning = true
end
Expand All @@ -35,6 +36,11 @@ function runtests(exportingTool)
include("FMI2/getter_setter.jl")
end

@info "Execution Configurations (exec_config.jl)"
@testset "Execution Configurations" begin
include("FMI2/exec_config.jl")
end

@info "State Manipulation (state.jl)"
@testset "State Manipulation" begin
include("FMI2/state.jl")
Expand Down

2 comments on commit 9055475

@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/74452

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.11.2 -m "<description of version>" 9055475a13e49c9f93b6fa88d5bef2bb51e2cc00
git push origin v0.11.2

Please sign in to comment.