-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Events for @mtkmodel components #2421
Comments
Hey, me again. I implemented the feature by changing I tested the implementation with the following code and it worked: @variables t
D = Differential(t)
@mtkmodel M begin
@parameters begin
b[1:2]
end
@variables begin
f(t)
x(t)
end
@equations begin
b[1] * f ~ D(f)
b[2] * x ~ D(x)
end
@continuous_events begin
[x ~ 0.9] => [b[2] ~ 5]
[t ~ 0.5] => [x ~ 1]
[t ~ 0.75] => [x ~ 1, f ~ f + 1]
end
@discrete_events begin
(t == 0.8) => [b[2] ~ 2]
(t == 0.5) => [f ~ f + 1]
end
end
@mtkmodel N begin
@components begin
m = M(; b=[0, 1])
end
@parameters begin
ω
end
@variables begin
y(t)
v(t)
end
@equations begin
v ~ D(y)
ω*y ~ -D(v)
end
@continuous_events begin
[t ~ 1.5] => [y ~ 5]
end
end
@mtkbuild model = N(; ω=10)
u0 = [model.y => 1.0, model.v => 0, model.m.f => 1.0, model.m.x => 10]
prob = ODEProblem(model, u0, (0, 2.0))
sol = solve(prob, FBDF(), tstops=[0.5, 0.8])
p = plot(sol)
display(p) However, I needed to add some if statements to create specific ODESystem Expressions for different cases where events are defined or not. (see line 99...) |
accidently closed the issue, oops |
Okay, I think I found the best way to avoid the if statements. See the solution here: |
Hi, would the event support for @mtkmodel also include the generalized affect functions like in https://docs.sciml.ai/ModelingToolkit/stable/basics/Events/#func_affects ? Does #2427 respect this? Thanks for any comments. |
Hey,
Yes, generalized affect functions are supported too. |
In component based modeling your components might need to do event handeling. These events should be declarable within the component for easy modeling. As far as I can understand the code, there is no nice way to do this at the moment. Therefore I think additional syntax like the following would be nice:
I think this would be the easiest way to do it. Maybe a more Modelica like syntax including the events into the equation block would be possible but I think this is not necessary.
The text was updated successfully, but these errors were encountered: