-
Notifications
You must be signed in to change notification settings - Fork 168
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
Initial values for polyphase inductor currents etc. #4457
Comments
@AHaumer, @christiankral what do you think? |
Lets investigate the polyphase inductor, the capacitor can be treated analogous. extends Modelica.Electrical.Polyphase.Basic.Inductor(i(start=zeros(m))); initial equation //i[m] = zeros(m); i[1:m-1]=zeros(m-1); end Inductor;` |
What I propose is to give users the possibility to set initial currents, possibly using a way such as the obtainable flexibility is lower than having individual Electrical.Analog inductors.
So, in a three-phase system the user will be allowed to set a vector of 3 or two currents. In the first case it is expected that current can flow through neutral (i.e. we have a 3-phase, 4-wire system), and therefore for t=0 the three currents are independent states. In the second case, the code should automatically set the third current to the opposite of the sum of the two set currents. Obviously the user can mistakenly fix m currents for a m-wire m-phase system (e.g. 3 currents for a three-wire three-phase system), resulting in an overdimensioned initial system of equations. This is what already occurs if the user implements the same three-phase system with Analog.Basic components. To summarise. The GUI would propt the user for a vector of intial currents and a unique flag for these values being fixed=true or not. |
In MSL we try to keep the models as general as possible without restricting the freedom of usage.
In the first case (m wires, no neutral) I wouldn't initialize one (may be the last) current to -sum(all other initial currents), this easily leads to numerical problems. We have to leave this up to the tool. Specifying an array of initial currents i0[m-1] or i0[m] looks clumsy compared to the initialization menu presented automatically due to the alias variable. We should also take care of the following facts:
I'm not sure whether we don't forget a special case which is not covered by the solution. |
I understand this. Two notes:
So, any "restriction" in Polyphase is not restriction in general since we have individual components from Analog.Basic. Whenever Polyphase usage tends to become tricky, there is for the user this fallback option. In reality, in the first version of my message I intended to propose a solution that allowed users to choose the wires to which to set initial values (the remaining to be computed by the tool). It was easy-peasy also from the GUI point of view. This solution involved the user to input two arrays, one with the currents, the other with the indexes. the array would have m or m-1 elements: the tool will act correspondingly. My position is that there must be a balance between generality and ease of use. That's why I finally resorted to propose that the balance current be always the m-th. But I'm not against the other way that I myself initially conceived. |
As a general comment, I think that for consistency reasons, the Polyphase components should be usable as much as possible in the same way as the the regular, single-phase components, that have been around for 20+ years without anybody complaining. If I double-click on an instance of Modelica.Electrical.Analog.Basic.Inductor with any Modelica tool, I get a parameter dialog with one field for the If I double-click on an instance of Modelica.Electrical.Polyphase.Basic.Inductor myInductor1(inductor(i(each start = 1, each fixed = true)));
Modelica.Electrical.Polyphase.Basic.Inductor myInductor2(inductor(i(start = {1, 2, 3}, fixed = {true, true, false})); This goes against the principle of encapsulation, I think one should be able to use the polyphase inductor without the need to understand how it is implemented. In any case, writing that code is tricky and unnecessarily unconfortable for beginners, that would just like to use the GUI without delving into the intricacies of Modelica syntax and lots of silly parentheses 😃. So, I'd say that we need to provide some infrastructure that allows to set the start and fixed attribute of none, m-1, or m currents easily in the parameter input window of the polyphase inductor. Advanced users could also write initial equations (in that case the fixed attribute should be set to false) but we shouldn't force beginners to do that, if they simply want to set some initial value. Again, writing syntactically correct Modelica code in such cases involving arrays is not entirely trivial. If we agree on this requirement, I see two ways of implementing it. 1. Using the GUI to set fixed/start attributesThis is the way that requires minimal intervention on the MSL source code. Inside Modelica.Units.SI.Current i[m](start = fill(0, m), fixed = fill({false, m}) = inductor.i; The GUI will see this variable with start and fixed modifiers and automatically generate the fields in the parameter input window to change them, as it already happens with the single-phase inductor. This is maximally flexible, as the user can provide any combination of start values and decide which phases should be fixed and which should not. Last, but not least, if the default values are kept, then the behaviour is the same that we have now, so it would be backwards compatible. If this feature is used, 2. Definining parameters to set fixed/start attributesAlternatively, we could define parameters in Modelica.Units.SI.Current i_start[m] = fill(0, m) annotation(group = "Initialization");
Boolean i_fixed = fill(false, m) annotation(group = "Initialization");
...
Modelica.Electrical.Analog.Basic.Inductor inductor[m](start = i_start, fixed = i_fixed, L = L);
... In principle we should make the modifiers on the inductor array final, but this would break backwards compatibility if someone actually set the initial values by appling modifers to them, so I'd leave the as non-final. DecisionI am personally in favour of the first solution, because it needs less code and is more consistent with the single-phase components. But I'd like to hear your opinion. |
@casella you're right, we should go for your proposal 1. @christiankral what do you think? |
Yes, I agree to apply proposal 1. @AHaumer Please prepare a PR. |
I'll try. @ceraolo keep in mind: |
Nice try ;-) but:
|
Even another try with parameters for initialization:
|
@AHaumer we shouldn't design the MSL based on the currently implemented GUIs, but rather the other way round: GUIs should properly support user-friendly editing of the MSL Modelica code. Bear in mind that this is for MSL 4.2.0, so there will be time to implement that feature. |
@AHaumer I downloaded your first PolyPhaseInductor test package, but it doesn't seem to me to be fully implementing my proposal 1. I see the following code: model Inductor "Ideal linear electrical inductors"
extends Modelica.Electrical.Polyphase.Interfaces.TwoPlug(i(start=zeros(m)));
... but it should be model Inductor "Ideal linear electrical inductors"
extends Modelica.Electrical.Polyphase.Interfaces.TwoPlug(i(start=zeros(m), fixed = fill(false, m)));
... right? |
An alternative would be: (but hopefully with a better name). That should show up as a start-value. Or:
|
@casella your proposal won't make a difference since fixed=false is the default. |
It would. What OMEdit does is to automatically generate a GUI item to change start and fixed attributes if an explicit modifier exists, unless of course it is final. So the presence of an explicit modifier is taken as a hint that the user may want to change it also via the GUI. I understand Dymola does the same, not sure about other tools. The Note that a start attribute modifier can be introduced upon inheritance, e.g.
while an annotation cannot, which would force us to define a new variable i2 and then add final i = i2, as suggested above by @HansOlsson. No big deal, except that one may wonder why the current that I need to fix is called i2, perhaps it is the square of the current? I find it a bit confusing. My point is: the start attribute heuristic has been in place for inductors since the dark ages. Why not just using the same pattern for polyphase component? That would be the most straighforward solution to me. It just requires to add modifiers to the extends clause: model Inductor "Ideal linear electrical inductors"
extends Modelica.Electrical.Polyphase.Interfaces.TwoPlug(i(start=zeros(m), fixed = fill(false, m)));
... That is from a library point of view. Regarding tool support, I would say that tools should support both this construct and the showStartAttribute annotation also for arrays. Do we agree on that? We could also decide to deprecate that practice and mandate the use of the showStartAttribute. To me, that won't be a particuarly good idea, because it would make a lot of existing library unusable (start attribute dialogs disappear), unless you add those attributes. It's ok to deprecate despicable practices, but this one doesn't seem despicable to me. To me, not bothering people with unnecessary non-backwards compatible changes of the language is a golden rule. |
@casella i2 is just a not very descriptive name for the alias current, in my example i named it iL. I have no objections against both solutions, either the annotation nor the pressure that all tools have to implement the behavior to present an initialization menu for an array variable if a vector of start values is provided, The only impediment is the fact that all tools have to avoid presenting "fixed" as a checkbox, otherwise you can't provide fixed=true for m-1 currents and fixed=false for the last one which is necessary in the case of start connection with star-point not connected i.e. sum of all m currents = 0. |
Sure. What I mean is, I wont' implement a convoluted solution using separate boolean parameter arrays such as as There is time until the release of 4.2.0 for tool vendors to adapt to this. @HansOlsson, @adea31, @eshmoylova, @maltelenz, @gkurzbach do you agree? |
Yes. The model should be clear and the tools should adapt to that. Whether Dymola will do it for 4.2.0 release I cannot state at this time. |
Yes @maltelenz you are right we tend to implement this version. |
Thanks @AHaumer for the summary. It seems you have buy-in from Dymola (@HansOlsson), OM (@casella) and System Modeler (me, and also already reasonably working, even if not perfect) for the tools to adapt to such a change in the library. |
This is my preference, as we avoid to add an additional redundant variable, which is not needed from a modeling point of view. The tools shall be able to handle such a case. |
We decided to give it a try: see #4488 for PolyPhase Capacitor and Inductor, tested in an example. |
#4488 is merged, but let's keep this discussion open since the initialization shall get implemented in other models in the same style: |
Good modelica models have initial values defined, otherwise the results can be depending on the used tool and the assumptions it makes on those inital values.
When creating electric circuits, the most common state variables whose initial values are to be set are capacitor voltages and inductor currents. Modelica.Electrical.Analog.Basic capacitors allow setting initial voltages, and inductors intial currents.
Unfortunately the same does not occur with Modelica.Electrical.Polyphase capacitors and inductors.
Maybe one can set initial values for a polyphase inductor through modifiers, but this, if possible, is tricky. Personally, I could not find a way, at least in a three-wire circuit for which only two of the three currents must be set.
It seems to me that polyphase inductors and capacitors, and the other polyphase components having state variables, should have a way to set initial values from their masks, similar to their single phase counterparts.
The text was updated successfully, but these errors were encountered: