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
Blocks.Math.Mean: Order of when-equations relevant => rewrite as algorithm! #963
Comments
Comment by hansolsson on 16 Jan 2013 10:34 UTC If reinit was defined as proposed in that ticket (i.e. the reinit in equations is done after evaluating the model) then both orderings will give the same result. |
Comment by naehring on 16 Jan 2013 12:16 UTC
Therefore,
is conceptually replaced by:
Note, that I've read #578 including the associated comments before writing this comment. Shifting the reinits to the end of the event step evaluation would just break the freedom of the tool to sort the equations. Up to now this freedom is guaranteed by the specification. To access the left limit of the continuous states within when-blocks one has the |
Comment by sjoelund.se on 16 Jan 2013 12:32 UTC
|
Comment by anonymous on 16 Jan 2013 12:45 UTC |
Comment by naehring on 16 Jan 2013 12:59 UTC |
Comment by hansolsson on 16 Jan 2013 13:30 UTC As for that: when-clauses are defined one-by-one so that
is according to 8.3.5.1 split into two equations, the first is conceptually:
The second is the problematic one. The definition states that we evaluate the 2nd argument to reinit - and then change the equations and resort - and it is not clear exactly how this sorting works (and having multiple sorting of all equations seems expensive at least). The first proposal in #578 was to avoid this additional sorting, but unfortunately it changed behaviour of models and was not as well-defined as intended. The reason that resorting matter is that we could have:
The resorting semantic seem to imply that we evaluate it as follows:
Note that with resorting there is not a system of equations since val_x is evaluated - and then x is made unknown. The first proposal in #578 would change this to be a system of equations. The idea with delaying the reinitialization was to still allow the equations to be sorted freely, but delay the effect of the new value until the next event iteration. The benefits are that the models behave consistently, the overhead is low, and models that are in use continue to work as before. It will require an additional event iteration for reinit, but since we want to avoid using reinit that should not be a major issue. For algorithms no sorting is done (neither now - nor in the proposal); and I now realize that this might also gives unpredictable result if any equation/algorithm depend on the reinitialized variable. As long as the use is outside of when-clauses an additional event-iteration will fix it (exactly as for other reinit). For algorithms one possibility to get predictable result would be to update the variable inside the algorithm - but delay the effect outside of the algorithm until the end of the model evaluation. |
Comment by otter on 16 Jan 2013 13:57 UTC
I am not able to completely follow. My (first) proposal in #578 is to (conceptually) rewrite the equation to:
Meaning that x is either computed in the reinit-clause, or the (known) value provided by the integrator is used. Sorting the above equation results in an algebraic loop, since y depends on x and x depends on y. Since algebraic loops are not allowed between a when-clause and a continuous-time part, the model would be rejected (the model is wrong). |
Comment by hansolsson on 16 Jan 2013 14:08 UTC
... I agree Martin for the first proposal in #578, it is just that if we follow the resorting semantics from 8.3.6 as quoted above there would not be an algebraic loop; instead the equations would be duplicated. |
Comment by otter on 17 Jan 2013 11:29 UTC Changed the equations by using pre(x). Therefore, the model is correct, independently |
Comment by anonymous on 17 Jan 2013 13:35 UTC |
Modified by otter on 17 Jan 2013 13:36 UTC |
Reported by naehring on 15 Jan 2013 12:16 UTC
If one swaps the evaluation order of the two equations
in
Blocks.Math.Mean
the result would always be y=0.But, the specification requires that the order of equations is irrelevant.
Therefore, the when-block should be located within an algorithm. An alternative would be to replace
x
bypre(x)
in the assignment toy
. I.e.:Migrated-From: https://trac.modelica.org/Modelica/ticket/963
The text was updated successfully, but these errors were encountered: