-
Notifications
You must be signed in to change notification settings - Fork 41
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
Should periodic clock and event clock get same result? #3557
Comments
In System Modeler, the clock of |
As I understand, there is no reason why The two concepts (discrete and clocked variables) are completely different and there is no guarantee that they are synchronous with each other just because you are using the same numerical value for the sample operator and for the Clock operator. In fact, clocked variables were created exactly to avoid this kind of ambiguity, i.e., to avoid that synchroncity depends on numerical time values and dubious magic involving small epsilons, rather giving a formal definition of syncronous partitions, which are guaranteed to change at the same time in a consistent way. That's why If you really worry about syncronicity, you should avoid using discrete variables and only use clocked variables instead. BTW, OpenModelica's output should be improved here, as the clocked variables are only defined at the clock instants, contrary to discrete variables that are also defined outside their switching time points, see OpenModelica/OpenModelica#12770, but that's another story. It is also true that this model may work in some other tools than OpenModelica, which employ better magic to handle events, or maybe are just luckier in this specific case. My point is, if you only use clocked variables you have formal guarantees of syncronicity. That's much better than relying on magic. |
Well, even if they are ultimately given by the same clock there's a small difference. Note that for That doesn't happen for I can see the reason for Dymola (which generates the same result as OpenModelica; except that we only plot the signals when they tick) and also that it was implemented more than a decade ago. It might be something we could include in the specification.
Agreed. |
Can you please elaborate on that? I remember I had this discussion on some ticket (not sure if it was a Modelica or an OpenModelica ticket) and the conclusion was that clocked partions generated by the same literal Clock expression should be merged together. Am I mistaken here? |
Yes.
Having the code generation merge partitions would be possible, but doesn't impact the semantics and thus doesn't matter from the language perspective. |
I apologize, I'm not sure what I had in mind when I wrote the the second part of my comment, starting from "That's why Of course @HansOlsson are we on the same page if we state that given the current language specification, there is no reason for |
What I referred to about equal clocks being merged is demonstrated by the following MWE: model SameClock1
Real x1 = sin(time);
Real y1;
Real y2;
equation
when Clock(0.1) then
y1 = sample(x1);
end when;
when Clock(0.1) then
y2 = sample(x1);
end when;
end SameClock1; The clocked variables
the equations determining model SameClock2
Real x1 = sin(time);
Real y1;
Real y2;
Real y3;
equation
when Clock(0.1) then
y1 = sample(x1);
end when;
when Clock(0.1) then
y2 = sample(x1);
end when;
y3 = y1 - y2;
end SameClock2; is not legal, because @HansOlsson is that correct? |
Yes, Francesco, that is consistent with my interpretation. |
BTW: The reason for the difference in Dymola (and assumedly something similar in OpenModelica) is that Event clocks don't use the event directly, but sort of use pre(event) (assumedly to avoid systems of equations in some cases). To me it would make sense to update the specification to either:
|
Could you provide an example where such equation systems are avoided, so that I can compare with our handling? |
Poll for change: Henrik (1 or 3), Elena(abstain), Markus(abstain), Gerd(abstain), Dag(2 or 3). |
When simulated in OpenModelica 1.21.0, we see the following result:
y2
andy3
give different result. This behavior is incomprehensible to the users.The text was updated successfully, but these errors were encountered: