-
-
Notifications
You must be signed in to change notification settings - Fork 44
Electrical switch added #387
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This component is placed in ideal_components.jl
, but it's not an ideal switch? The docstring does not really indicate how the switch works, it appears to transition from conducting to not conducting exponentially rather that instantaneously like one would expect from a simple switch model?
Yes, I should explain better in the docstring how it works. Should this rather be modeled as a continuous event? I wanted to avoid using events, but this might not be scalable (using delays). |
I believe the modelica ideal switch model uses an event It could make sense to include both an ideal and a filtered switch, but exactly how the filter works would be important, the default time constant of 1e-3 is an eternity for many analog electronics applications. It's likely also the case that the logic that provides the boolean input will introduce the event anyways, even with the filter you'd have a discontinuity in the first derivative, and many solvers would thus be unhappy without an event. |
Thanks @baggepinnen I would need to better understand events in MTK. Good point - the step function in this case creates an event (as far as I understand). |
MTK has the ability to automatically create the required events for functions that are known to be discontinuous. It's implemented, but not yet documented, you can see how it is invoked here structural_simplify(sys, additional_passes = [IfLifting]) In any case, I don't think you have to worry about creating the event in the switch component, the input is already assumed to be boolean, so it's the responsibility of the one creating the boolean in the first place to generate the event. |
This is very cool. I will look into this. So in theory, @continuous_events is no longer required then? I agree the switch itself is not 'eventful', but I want to make sure that the test works with no delay/filtering, with the step (in my test case) being eventful, and it all being handled. |
Unfortunately, it seems IfLifting does not work for DAE's yet (An RC circuit is a DAE) - point 3 is therefore a short-term 'hack'. Any further feedback would be much appreciated. |
I'm confused by two things here, (1) it is tested with DAEs? and (2) the RC circuit is an ODE? |
I am not sure what the root cause is. Maybe I am doing something wrong. Let me copy the code I attempted and the outputs. The only difference with the test in the PR is that step(smooth=false) to create an event.
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
┌ Warning: At t=9.999999999999996, dt was forced below floating point epsilon 1.7763568394002505e-15, and step error estimate = 709.7217741210751. Aborting. There is either an error in your model specification or the true solution is unstable (or the true solution can not be represented in the precision of Float64).
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
{ |
The tests didn't start when I pushed an update? The test passed on my machine, but not on here, so I was trying to figure out why. |
@baggepinnen @ChrisRackauckas I believe this PR is ready for review:
|
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context