You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug 🐞
It seems to be not possible to correctly re-calculate observed variables after a simulation with discrete_events. In my MRE, I do get all zeros for the flow, while it should be switching between roughly 1 and 0.
Expected behavior
I would expect to be able to calculated the correct tranjectories for the observables.
Minimal Reproducible Example 👇
My MRE is a simple tank model with a binary valve at the outlet. As you can see in the code, I use @discrete_events to switch the valve. If you plot the trajectories for the volume V and the valve state S you get the correct plots. But if you plot the volume flow Vdot you get all zeros.
using ModelingToolkit
using ModelingToolkit: D_nounits as D, t_nounits as t
using DifferentialEquations
using Plots
@mtkmodel TankWithValve begin@parametersbegin
k_V::Float64=10.0, [description ="Valve coefficient in L/min/bar"]
S(t)::Bool=false, [description ="Valve state"]
end@variablesbeginV(t)::Float64, [description ="Volume in L", guess =0.0]
Vdot(t)::Float64, [description ="Volume flow rate in L/min", guess =0.0, connect = Flow]
p_bottom(t)::Float64, [description ="Set pressure in bar", guess =1.01325]
p_outlet(t)::Float64, [description ="Set pressure in bar", guess =1.01325]
end@equationsbeginD(V) ~-Vdot/60.0# Umrechnung: 1 min/60 s
Vdot ~ S*k_V*(p_bottom - p_outlet)
p_bottom ~1.01325+9.81*1000.0*V/100000.0
p_outlet ~1.01325end@discrete_eventsbegin
[30] => [S ~true]
[60] => [S ~false]
[90] => [S ~true]
[120] => [S ~false]
endend@mtkbuild sys =TankWithValve(V =2.0)
observed(sys)
prob =ODEProblem(sys, [], (0.0, 120.0))
sol =solve(prob)
plot(sol; idxs = [sys.V,sys.S,sys.Vdot])
Environment (please complete the following information):
Ok, I talked to @AayushSabharwal who explained to me that PR #3106 in fact will not fix this bug (or rather missing feature). PR #3106 is taylored arround discrete variables in the sense of clocked variables according to FMI (red), discrete variables according to FMI (green) are not meant to be supported by this PR. But in fact this is what would actually be needed to resolve this issue.
Describe the bug 🐞
It seems to be not possible to correctly re-calculate observed variables after a simulation with discrete_events. In my MRE, I do get all zeros for the flow, while it should be switching between roughly 1 and 0.
Expected behavior
I would expect to be able to calculated the correct tranjectories for the observables.
Minimal Reproducible Example 👇
My MRE is a simple tank model with a binary valve at the outlet. As you can see in the code, I use @discrete_events to switch the valve. If you plot the trajectories for the volume V and the valve state S you get the correct plots. But if you plot the volume flow Vdot you get all zeros.
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: