-
Notifications
You must be signed in to change notification settings - Fork 40
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
Clocked algorithm variables: Unspecified behavior in case of missing equations #3107
Comments
I think so, good point.
I think this was probably an oversight. Clocked variable semantics is based on synchronous system theory, which is based on equations, algorithms were probably not considered back then, when Modelica 3.3 was written. Maybe @HildingElmqvist, @MartinOtter and @HansOlsson who worked on the original proposal and its implementation can comment on that. Clocked variables can describe the behaviour of digital controllers where algorithms are run at each clock tick, so algorithms in clocked models are probably useful. For sure a lot more useful than algorithms for continuous variables, which I find pretty confusing. If algorithms involving continuous variables are allowed, it would be odd not to do so for algorithms including clocked variables. In this case the obvious semantics is that any clocked variable |
You are right, this should be clarified in the spec, something like:
|
Dear all, thank you very much for your quick response. And we will be glad if this is added to the upcoming version of the specification. We are as well convinced, that the previous value will be the best choice for this purpose:
Let us also hint to the circumstance, that several Modelica tools behave unconsistently in this situation. (Some using the start value, others using previous value.)
We agree on this. Clocked systems are quite a useful way for modelling discrete controls. |
That's too bad, but consistent with the current status of unspecified behaviour 😄 @HansOlsson I guess this could be processed by the MAP-LANG group without too much effort. |
This is a bit more complicated. If the model is just a normal clocked model I agree that However, if the model was continuous and is then clocked discretized (see #3091 for a discussion of having better names for that) it becomes less clear. Since the goal is that clocked discretization should be possible for every continuous model (and obviously give a result close to the original), it seems that we should preserve that semantics and in those cases initialize to the start-value. However, I am not sure if there's a simple definition of those cases (as we also want to clock discretization of discrete parts of that model). Related to that the clarification in #3090 requires some minor changes in model3. It is also unclear how much this will matter in practice for a continuous variable.
|
I agree. I remain with my personal conviction that algorithms in continuous time models are fishy, and that algorithms in continuous time models that do not initialize all their variables explicitly are even more fishy. You can imagin what I think of the case where the latter ones are turned into clocked models, maybe using an implicit integration algorithm that required iterations. My head spins... 😄 Maybe would could at least bar this specific case. Honestly, I can't think of any sensible application of it.
And therein lies the rub.
With my proposal, one would be forced to write
which IMHO is way clearer and less ambiguous than relying on a start value, which is declared elsewhere. |
Note that I explicitly did set the start-value of |
That's precisely what I mean, this formulation is fishy 😄 |
It's a bit like writing a = ++b + (c = d / b) – 1; in C. For sure it is legal C code, but why would one want to write something that is deliberately obscure? |
Code golf |
Such C-code would likely be the result of using macros - especially if the code pre-dates proper inline functions; I've seen similar one. Not very relevant for Modelica. |
Yeah, what I mean is that the initialization with the start attribute is a bit tricky and not very easily readable. |
For algorithm sections the Modelica Specification requires in general all variables, which are assigned somewhere in the algorithm section, to be initialized always when the algorithm is called (Modelica specification 3.5, Section 11.1.2). Concretely:
However variables of clocked variability are not listed here.
Note, that clocked variability is different to discrete variability: Modelica specification 3.5, Section 16.8.1:
Natural suggestions for initialization would be the previous value or the start value.
Our Questions:
For the follwing three examples, the behavior of signal ‘internal’ seems not to be specified:
Model1: Missing equations for ‘internal’ after first tick.
or
Model2: Missing equation for ‘internal’ at first tick.
Model3: Missing equations for ‘internal’ at first tick and after time 0.5
The text was updated successfully, but these errors were encountered: