diff --git a/Project.toml b/Project.toml index 334e2454..258c6827 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "FMI" uuid = "14a09403-18e3-468f-ad8a-74f8dda2d9ac" authors = ["TT ", "LM ", "JK "] -version = "0.11.1" +version = "0.11.2" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" @@ -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" diff --git a/README.md b/README.md index 39f77a1f..3c41332d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/src/faq.md b/docs/src/faq.md index f663b6eb..e4579c6a 100644 --- a/docs/src/faq.md +++ b/docs/src/faq.md @@ -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. @@ -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`. \ No newline at end of file +- 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. \ No newline at end of file diff --git a/src/FMI2/sim.jl b/src/FMI2/sim.jl index 239e0415..f7251364 100644 --- a/src/FMI2/sim.jl +++ b/src/FMI2/sim.jl @@ -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 @@ -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 diff --git a/test/FMI2/exec_config.jl b/test/FMI2/exec_config.jl new file mode 100644 index 00000000..b90bf7ec --- /dev/null +++ b/test/FMI2/exec_config.jl @@ -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) \ No newline at end of file diff --git a/test/FMI2/sim_ME.jl b/test/FMI2/sim_ME.jl index 5a449a32..0938b0d6 100644 --- a/test/FMI2/sim_ME.jl +++ b/test/FMI2/sim_ME.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 12b3f36f..987cc819 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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")