-
Notifications
You must be signed in to change notification settings - Fork 27
Description
When simulating a Cosimuation-FMU with Inputs in FMI.jl, the algorithm tries to read values (via fmi2GetReal...) immediately after inputs have been set. This is wrong. The specification explicitly states that:
There is the additional restriction in “slaveInitialized” state that it is not allowed to call fmi2GetXXX
functions after fmi2SetXXX functions without an fmi2DoStep call in between. [The reason is to avoid
different interpretations of the caching, since contrary to FMI for Model Exchange, fmi2DoStep will
perform the actual calculation instead of fmi2GetXXX, and therefore, dummy algebraic loops at
communication points cannot be handeled by an appropriate sequence of fmi2GetXXX and fmi2SetXXX
calls as for ModelExchange.
FMI Spec. 2.0.5., page 109.
MWE (with one of the SX-FMUs in the respective FMIZoo-Branch)
using FMI
using FMIZoo
ENV["JULIA_DEBUG"]=FMICore
fmustruct=loadFMU("SpringPendulumExtForce1DCS", "SimulationX","4.6.2", 2.0)
t_start = 0.0
t_stop = 8.0
extForce_ct! = function (c::Union{FMUInstance,Nothing}, t::Real, u::AbstractArray{<:Real})
u[1] = 0.42*cos(t)
end
inpfct! = extForce_ct!
solution = simulateCS(
fmustruct,
(t_start, t_stop);
dt = 1e-2,
recordValues = ["mass.s", "mass.v"],
inputValueReferences = ["extForce"],
inputFunction = inpfct!,
)
<- observe that the simulation leaves the initialization (i.e. slaveInitialized-State should be given), and then runs into an error because of the wrong calling sequence.
┌ Debug: fmi2Instantiate(instanceName: Ptr{UInt8} @0x000002135ff69668, fmuType: 1, fmuGUID: Ptr{UInt8} @0x00000213601d2938, fmuResourceLocation: Ptr{UInt8} @0x00000213040bfec8, functions: Ptr{fmi2CallbackFunctions} @0x000002135fc38fd0, visible: 0, loggingOn: 0) → Ptr{Nothing} @0x00000213a588b950
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:43
┌ Debug: fmi2SetupExperiment(c: Ptr{Nothing} @0x00000213a588b950, toleranceDefined: 1, tolerance: 1.0e-5, startTime: 0.0, stopTimeDefined: 1, stopTime: 8.0) → 0
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:141
┌ Debug: fmi2EnterInitializationMode(c: Ptr{Nothing} @0x00000213a588b950) → 0
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:153
┌ Debug: fmi2SetReal(c: Ptr{Nothing} @0x00000213a588b950, vr: UInt32[0x20000000], nvr: 1, value: [0.42])
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:241
┌ Debug: fmi2ExitInitializationMode(c: Ptr{Nothing} @0x00000213a588b950) → 0
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:165
┌ Debug: fmi2SetReal(c: Ptr{Nothing} @0x00000213a588b950, vr: UInt32[0x20000000], nvr: 1, value: [0.42])
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:241
┌ Debug: fmi2GetReal(c: Ptr{Nothing} @0x00000213a588b950, vr: UInt32[0x40000008, 0x4000000d], nvr: 2, value: [0.5, 0.0]) → 0
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:215
┌ Debug: fmi2DoStep(c: Ptr{Nothing} @0x00000213a588b950, currentCommunicationPoint: 0.0, communicationStepSize: 0.01, noSetFMUStatePriorToCurrentPoint: 1) → 0
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:651
┌ Debug: fmi2SetReal(c: Ptr{Nothing} @0x00000213a588b950, vr: UInt32[0x20000000], nvr: 1, value: [0.4199790001749994])
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:241
[Error][logStatusError][SpringPendulumExtForce1DCS]: Error in fmi2GetReal(): Wrong calling sequence. Inputs have been changed and fmi2DoStep was not called before getting outputs.
┌ Debug: fmi2GetReal(c: Ptr{Nothing} @0x00000213a588b950, vr: UInt32[0x40000008, 0x4000000d], nvr: 2, value: [0.5, 0.0]) → 3
└ @ FMICore C:\Users\juligund\.julia\packages\FMICore\JuzJq\src\FMI2\cfunc.jl:215
ERROR: AssertionError: Assert on `fmi2StatusError`. See stack for errors.