-
Notifications
You must be signed in to change notification settings - Fork 167
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
Added more options for homotopy-based initialization of limiters #2561
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.
Fine for me, looks good.
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.
Modelica/Blocks/Nonlinear.mo
Outdated
<li><code>noHomotopy</code>: the actual expression with limits is used</li> | ||
<li><code>linear</code>: a linear behaviour y = u is assumed (default option)</li> | ||
<li><code>uMax</code>: it is assumed that the output is stuck at the upper limit u = uMax</li> | ||
<li><code>uMin</code>: it is assumed that the output is stuck at the lower limit u = uMax</li> |
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.
Should read u = uMin.
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.
Of course, that was a stupid copy&paste mistake
Modelica/Blocks/Types.mo
Outdated
linear "Simplified model: y = u", | ||
fixed "Simplified model: y = ySimplified") | ||
"Enumeration defining use of homotopy in variable limiter components" annotation (Evaluate=true); | ||
|
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.
Should these enumeration alternatives start with a capital letter?
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.
Sure, will do
Rescheduling milestone since MSL v3.2.3 is feature-complete, i.e., no more enhancements are allowed. Furthermore, test models for the other homotopy options are required. |
@beutlich I pushed in the fixes you requested. Regarding your comment concerning #2017, I'm not sure I get your point. Please note this PR is not adding homotopy to the component, it is just fixing the way homotopy was already introduced in MSL 3.2.2, which actually broke some models in a way that was not possible to fix (so it was not really backwards compatible with MSL 3.2.1). With these changes, it is possible to get models that ran in MSL 3.2.1 to run again by just changing one parameter. For the above-mentioned reasons, I do not consider this PR an enhancement, but rather a bug fix. We had models that ran in MSL 3.2.1 (and used homotopy for other components) and stopped running in MSL 3.2.2 because the new implementation in there using homotopy cannot have limits enforced, so it breaks stuff downstream the limiter. Unfortunately these models are confidential, so I cannot share them. I can open a specific ticket about that, though I thought the explanation of this PR was enough motivation. Maybe that was not clear enough, my fault. So, I hope you can reconsider your decision to reschedule the milestone. Regarding tests with the homotopy feature, I can provide them by next week. |
@casella Thanks for exaplanation that this PR rather is considered to be a bug-fix. In that case it is valid to be included in the MSL v3.2.3. Please provide a test model (for ModelicaTest.Blocks). I still believe, we also should add the homotopy choices to the limiter in Modelica.Electrical.Analog.Ideal.IdealizedOpAmpLimted. What do you think? |
|
@beutlich, regarding IdealizedOpAmpLimited and IdealOpAmpLimited, These models not only include a saturation on the output voltage, but they also change the relationship between the input voltages according to that. Basically, if the output voltage is not saturated, then the two input voltage are bound to be equal, otherwise they are not. As you can see, this involves an auxiliary variable s. The logic is a bit the same as the one of the ideal diode. I'm not sure how this model could be improved by using homotopy, because I'm not an expert of electrical models (my degree in electronic engineering is now almost 25 years old...). Anyway, it's way beyond the scope of this PR, which is only meant to provide Limiter blocks that can be used with homotopy. |
@beutlich, regarding LimPID, I guess propagating homotopyType is a good idea. I'lll do that and build a couple of test cases then I'll get back to you |
In fact, LimPID is still using the obsolete limitsAtIniti parameter, which is propagated to the limiter but actually not used sinces 3.2.2. I'll move that to a Dummy tab as for Limiter and put homotopyType instead |
I agree wirh Francesco, Ideal(ized)OpAmpLimited need some more investigation. |
Regarding the LimPID (which is a commonly used block) I apperciate Franseco's idea propagating homotopyType. |
Updated implementation of LimPID and added relevant test cases to ModelicaTest in 153352f. |
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.
Nice and useful improvement.
I do not quite understand why there are two enumeration types InitPIDHomotopy and LimiterHomotopy with the same semantics of the alternatives. I'd simply reuse LimiterHomotopy in LimPID and generalize the alternative names and descriptions, say NoHomotopy, Linear, UpperLimit, LowerLimit. |
@beutlich I just could not find general enough names for the enumeration, but I guess your idea is good. I'll take care of that later today. |
@beutlich do we need another review? I lost track after so many changes |
Yes by either @AHaumer or @MartinOtter |
@HansOlsson 9d7df7b and 68f1beb should fix the Modelica.Electrical.Analog.Examples.OpAmps.Multivibrator issue of #2270 (comment) while still generating events for Modelica.Electrical.Analog.Examples.OpAmps.SignalGenerator (see #2017). Can you please cross-check and give your review. |
@HansOlsson Can you please check if this fixes all examples in Modelica.Electrical.Analog.Examples.OpAmps? |
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.
All of the MSL-models using the model now works (also with homotopy).
However, to make it more backwards compatible I would prefer that strict was as default true - corresponding to the previous version.
You mean the IdealizedOpAmpLimted.strict? |
Yes; having it as default true would mean that we as default had the same semantics as in 3.2.2. |
And touch each of the examples to have strict modified to false, at least if we want to see events (as in Modelica.Electrical.Analog.Examples.OpAmps.SignalGenerator)? |
I would skip that for the examples in MSL - since I the events are not needed. |
According to #2017, Modelica.Electrical.Analog.Examples.OpAmps.SignalGenerator should generate events, right? Thus strict=false. |
According to that issue, yes, but based on the problem we had with examples in MSL I thought that backwards compatibility was more important, so to get #2017 to run you set strict=false. |
* Restore MSL 3.2.2 behaviour, i.e., without events * Force events for SignalGenerator example model
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.
Looks good.
With MSL 3.2.2, the behaviour of limiters in the Modelica.Blocks library was slightly changed, so that if homotopy-based initialization was used, a linear behaviour y = u was always assumed.
Although this obviously makes the simplified model more linear, and thus potentially easier to solve, it can be problematic if the model receiving the output of the limiter breaks for values outside the limiting range and one still wants to use homotopy.
Also, in some cases it is known a priori that in the initial conditions the output of the limiter is stuck at the upper or lower limit. In this case, it is much better to use y = uMin or y = uMax as output in the simplified model.
This pull requests solves all these issues by allowing to choose among several options that span all these cases, using an enumeration parameter in the Advanced tab.
The change is 100% backwards compatible, as the behaviour with the default values of the newly added parameters is exactly the same as with MSL 3.2.2
close #2270