Repository navigation
Fix unit inconsistencies caused by 'pi' carrying a unit - #4817
henrikt-ma wants to merge 2 commits into
Conversation
|
Just some preliminary comments. We need to first ensures that CI/CD handling can handle the syntax. |
| startTime=startTime) annotation (Placement(transformation(extent={{-160, | ||
| -30},{-140,-10}}))); | ||
| Modelica.Blocks.Sources.Sine sine(amplitude=200, f=50/pi) | ||
| Modelica.Blocks.Sources.Sine sine(amplitude=200, f=50'Hz'/pi) |
There was a problem hiding this comment.
We should be careful with Hertz (just a note on this, but all need to be checked).
Despite being defined as 1/s it shouldn't be used for everything with unit 1/s according to BIPM, but only periodic signals that are something/s.
In this case it seems like a complete mess and 50/pi might be intended to be 100'rad/s'/(2*pi).
There was a problem hiding this comment.
The unit of f is "Hz", so having "Hz" in its modification seems correct to me.
| Modelica.Blocks.Sources.Constant const2(k=1'F'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{70,70},{50,90}}))); | ||
| Modelica.Blocks.Sources.Constant const3(k=1'H'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{100,50},{80,70}}))); |
There was a problem hiding this comment.
I believe this needs to be considered more, the 100*pi is 50'Hz'2pi, where 50 Hertz is the normal frequency in Europe.
There was a problem hiding this comment.
This is where the constants are used:
connect(const2.y, variableCapacitor.C) annotation (Line(points={{49,80},{40,80},{40,42}}, color={0,0,127}));
connect(const3.y, variableInductor.L) annotation (Line(points={{79,60},{70,60},{70,42}}, color={0,0,127}));
Here, variableCapacitor.C has unit "F", and variableInductor.L has unit "H".
That's as far as the units go. Regarding how to express the value, would you prefer this?
| Modelica.Blocks.Sources.Constant const2(k=1'F'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{70,70},{50,90}}))); | |
| Modelica.Blocks.Sources.Constant const3(k=1'H'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{100,50},{80,70}}))); | |
| Modelica.Blocks.Sources.Constant const2(k=0.02'F'/(2*Modelica.Constants.pi)) annotation (Placement(transformation(extent={{70,70},{50,90}}))); | |
| Modelica.Blocks.Sources.Constant const3(k=0.02'H'/(2*Modelica.Constants.pi)) annotation (Placement(transformation(extent={{100,50},{80,70}}))); |
There was a problem hiding this comment.
That is one possibility, the other would be something like:
| Modelica.Blocks.Sources.Constant const2(k=1'F'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{70,70},{50,90}}))); | |
| Modelica.Blocks.Sources.Constant const3(k=1'H'/100/Modelica.Constants.pi) annotation (Placement(transformation(extent={{100,50},{80,70}}))); | |
| Modelica.Blocks.Sources.Constant const2(k=1'S'/(2*Modelica.Constants.pi*50'Hz')) annotation (Placement(transformation(extent={{70,70},{50,90}}))); | |
| Modelica.Blocks.Sources.Constant const3(k=1'Ohm'/(2*Modelica.Constants.pi*50'Hz')) annotation (Placement(transformation(extent={{100,50},{80,70}}))); |
I could see some explanation along those lines based on resonance circuits etc, but I don't have the domain knowledge to judge whether people normally write (and/or understand) formulas like that or not.
There was a problem hiding this comment.
So the suggestion is simply to introduce new parameters instead of the unitful literals? If this is what everyone wants, I'll do it that way. @AHaumer ?
There was a problem hiding this comment.
To be clear it is new parameters revealing the logic of the model, as indicated in that comment.
There was a problem hiding this comment.
I think the suggestion in "that comment" is missing some use of final. @AHaumer would you agree with this?
parameter SI.Frequency fNom=50;
parameter SI.Admittance Y=1;
final parameter SI.Capacitance C=Y/(2*pi*fNom);
parameter SI.Reactance X=1;
final parameter SI.Inductance L=X/(2*pi*fNom);
Modelica.Blocks.Sources.Constant const2(final k=C);
Modelica.Blocks.Sources.Constant const3(final k=L);
Or should some of {fNom, Y, X} also be final?
(ParallelResonance and SeriesResonance would make similar use of final, I suppose.)
| rotation=270, | ||
| origin={-10,70}))); | ||
| Basic.Inductor inductor1(i(fixed=true), L=0.1/(2*pi)) annotation (Placement( | ||
| Basic.Inductor inductor1(i(fixed=true), L=0.1'H'/(2*pi)) annotation (Placement( |
There was a problem hiding this comment.
Those changes disclose another dilemma that moparser fron deprecated repository https://github.com/modelica-tools/ModelicaSyntaxChecker is still used here while no adequate replacement is in sight or in-place. Therefore we need to address this CI issue beforehand -> #4821.
There was a problem hiding this comment.
See #4774 (comment) for a better alternative for this model
| input SI.Area A_cross(min=Modelica.Constants.eps) = PI*0.1^2/4 | ||
| input SI.Area A_cross(min=Modelica.Constants.eps) = PI*(0.1'm')^2/4 | ||
| "Cross sectional area" annotation (Dialog(group="Geometry")); | ||
| input SI.Length perimeter(min=Modelica.Constants.eps) = PI*0.1 | ||
| input SI.Length perimeter(min=Modelica.Constants.eps) = PI*0.1'm' |
There was a problem hiding this comment.
This also indicates that the classes aren't well-designed.
Both the cross area and perimeter have defaults based on the diameter being 0.1'm', but instead of having one default depending on the other input (or on a common diameter input), the default diameter is duplicated in this function and related ones (it can only be a default as the goal is to support non-circular cross-sections). That makes it more error-prone.
It would be possible to introduce a backwards compatible change for that by having a new trailing diameter-input that only impacts the defaults. The down-side is that existing calls wouldn't modify the default-diameter and that value would be a bit confusing.
Alternatively, it would also be possible to have the default for the cross-section depend on the perimeter (A_cross=perimeter^2/(4*PI) without that down-side. Technically it would be non-backwards compatible, but any impacted model would be problematic.
(Note that it uses the general term "perimeter", not "circumference".)
The default areas and perimeters of the Fluid.Dissipation records, and of the inputs of dp_twoPhaseMomentum_DP, are computed from a diameter written as a plain number, such as pi*0.1^2/4 for an area and pi*0.1 for a perimeter. Since pi carries a unit, these defaults had the unit of pi instead of m2 and m. The diameters are now given as unitful literals, as already done for the same defaults in ModelicaTest.Fluid.Dissipation. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
3adcd2d to
41ddd37
Compare
|
Sorry, no I won't accept what is discussed here (and in other PRs touching that topic). |
This PR fixes unit inconsistencies which are caused by
Modelica.Constants.picarrying a unit. That is, the presence of a unit onpimakes an entire expression such as0.1/(2*pi)have unit, but not the consistent unit for the component it modifies.I am personally convinced that
pishould not have a unit at all (the topic of #4774), which would make this entire PR unnecessary, but fortunately the changes introduced in this PR are not relying onpihaving a unit.