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
Changed default of PadeDelay to robust implementation (balance = true) #3459
base: master
Are you sure you want to change the base?
Conversation
Added missing initial equations to case balance = false Updated test cases, also ensuring that the initial problem is fully specified
This looks like a reasonable change indeed, but did you actually forget to change the default value of Changing default values requires conversion rules and test model(s), whhich are missing. Since we won't touch upcoming MSL 4.0.0 to introduce any new conversion rules, we need to postpone this PR until MSL 4.0.0 is released and branched to maint/4.0.x. |
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.
see my above comment
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 pull request is a good idea, but please improve:
- balance=true is not set as default (should be changed).
- I would keep the balance=false exactly as it is (so no change of initial conditions), in order that exisiting models are not influenced by this change. With a conversion script it should be (somehow) defined that models without balance definition, use balance=false (= the current definition)
Sorry about that, I don't know why this happened. Just added a new commit to the PR.
@MartinOtter, I'm not sure I get your point here. I see the lack of initial equations as a bug, because it forces to rely on the tools' automatic addition of initial equations, which is dangerous and may lead to wrong results. I don't think users ever added those extra initial equations themselves manually when using balance = false, they were just relying on the tool to add them automatically. Adding them explicitly should just reduce the chance of getting wrong initial conditions. Furthermore, we agreed long time ago that all examples in MSL and ModelicaTest have fully specified initial conditions. If I remove those initial equations, should I add extra initial equations to the two ModelicaTest test models? That looks a bit ugly to me. |
I read the specification of convertModifiers carefully, but I really have a hard time figuring out exactly how to do that. See the discussion in #2518. |
Here you go:
|
The problem is that users might have added enough initial conditions in their models and with |
Should I then add the extra initial equations manually to the ModelicaTest? |
@beutlich, are we sure? The specification says
In this case Do I miss something? Also (minor comment), why are we using an array of strings with one element as the first argument and not just the string, as in
|
@casella I don't understand your second question as you are just restating the exact same conversion rule. Did you mean that you wonder why the syntax is not: - convertModifiers("Modelica.Blocks.Nonlinear.PadeDelay", fill("",0), {"balance=false"})
+ convertModifiers("Modelica.Blocks.Nonlinear.PadeDelay", "", {"balance=false"}) then I agree but maybe @HansOlsson can explain why it needs to be an empty array. |
Well, if viewed as a function it is a function with a String-array as argument (in order to be able to support multiple old modifiers), and thus the current variant is straightforward. Considered variants:
|
An alternative would be to make the initial equations conditional on a new flag. That way users don't have to manually add the initial equations, but it doesn't break models that have added initial equations. (I would in general say that it should be possible to disable initial equations.) I haven't investigated this to see what the defaults for this flag should be (ideally they should be compatible with existing models - but if they differ depending on balance, and the default for balance is changed then it becomes a bit complicated). |
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.
Conversion script still is missing.
Sure. That will take some time. After the coronavirus hit I no longer had time to deal with that. Will take care in September, when we'll implement them in OMC. |
A few days ago @GiovanniMangola brought my attention on the
Modelica.Blocks.Nonlinear.PadeDelay
model.If
balance = true
, the model works just fine: the implementation is numerically sound, and so it is the initialization, which is full steady-state and corresponds exactly to what would happen if you had a pure delay model, which is by definition initialized in steady-state, see the Specification.However, for reasons of backwards compatibility with MSL 3.2.1, the default is still balanced = false, which provides a numerically ill-conditiond textbook implementation, and furthermore has only one initial equation instead of N, leading to a model with missing initial equations, which is in general not a good idea.
In the case of our application, the block (with the default choice) was put inside a big plant model, which failed miserably to initialize because some other (unfortunately unwanted and wrong) initial equations were picked instead by Dymola, because of the incompletely specified initial problem stemming from the lack of initial equations in the block. I think this a very dangerous behaviour that should be avoided. What initial equations are needed is very clear for this model, there is really no point at leaving them out for reasons of backwards compatibility.
I think the transition to MSL 4.0.0 is a good opportunity to get a better behaviour, even though it is slightly non-backwards compatible. This means:
I guess this may be listed in the release notes.
I also updated the two tests in ModelicaTest accordingly. Both compare the output and performance of the block with the old one from MSL 3.2.1, which is copied inside the test cases. I slightly changed that copy to always have full initial equations. We agreed long time ago that all the examples in MSL and ModelicaTest should have fully specified initial conditions to avoid ambiguities in the selection of initial equations with different tools, so this change is necessary to fulfill that requirement.