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
correct usage of units in MSL? #1134
Comments
Comment by ahaumer on 28 May 2013 12:29 UTC |
Comment by majetta on 29 May 2013 08:06 UTC
were temp has the unit K and cbe, in_p.m_transitTimeHighCurrentDensity have the unit current. Hence the right site of this assignment has unit 1. Since this unit 1 results from the calculation cbe/(cbe+in_p.m_transitTimeHighCurrentDensity), I see no other possibility as to define cbe and in_p.m_transitTimeHighCurrentDensity as Real. Does anyone has an opinion on that? |
Comment by sjoelund.se on 29 May 2013 10:17 UTC
At least the following OpenModelica tests fail from yesterday's MSL changes:
|
Comment by fcasella on 29 May 2013 11:01 UTC
I had a look at the code of bjtNoBypassCode where this assignment is, it looks like a one-to-one translation of FORTRAN code, where typically unit checking is not a concern and all variables are just double precision floats. In the field of fluid systems you often see FORTRAN code like this:
explanation: first convert a pressure from bar to Pascal, do the math in SI units, then convert back to bar because the interface is in bar. Obviously it doesn't make sense at all to apply dimensional analysis to this kind of procedural code. Regarding the code you specifically mention, I see the following lines in the function's body:
this only makes sense if On the other hand My conclusion would be that if we include in the MSL some functions which are taken from trusted 3rd party FORTRAN codes (such as SPICE), we should probably forget about unit checking entirely inside algorithms, and only make sure we define proper units at the function interface (and that the code is correctly translated from FORTRAN to Modelica). Unless we want to find bugs in the SPICE code, but I guess this is out of the scope of MSL development |
Comment by sjoelund.se on 29 May 2013 11:09 UTC
So just use |
Comment by hansolsson on 29 May 2013 11:26 UTC
Well, if cbe and n_p.m_transitTimeHighCurrentDensity both have unit="A"and temp has unit="1" it is also unit-consistent, and to me it looks better to keep that. If temp is intended to be a temperature the solution would be:
Yes, as any other cast there is a risk that it was added without understanding the issue, and obviously this only works if temp has the same unit the entire algorithm (which means that we otherwise need to split it into different variables - the Fortran code should have used equivalence statements!) Thus the question is if temp should have unit="1" or temp has unit="K", but argtf is the temporary that changes units, e.g. on the line:
|
Comment by fcasella on 29 May 2013 11:39 UTC My two cents. |
Comment by majetta on 29 May 2013 11:48 UTC |
Comment by otter on 29 May 2013 13:33 UTC
Fixed in a8b0e5f (sorry). |
Comment by dietmarw on 29 May 2013 16:03 UTC tounit1 I would suggest to change the name to |
Comment by otter on 29 May 2013 20:28 UTC
All function names under Modelica.SIunits.Conversion (about 30) use the naming convention to_XXX or from_XXX. It looks odd, if one of the function names looks differently. |
Comment by majetta on 30 May 2013 05:36 UTC |
Comment by otter on 21 Jun 2014 17:54 UTC |
Comment by beutlich on 16 Mar 2015 09:54 UTC |
Comment by beutlich on 22 Jul 2015 22:25 UTC |
Modified by dietmarw on 23 Jul 2015 06:34 UTC |
Reported by dzimmer on 27 May 2013 15:18 UTC
The correct usage of units within the MSL shall be checked. Many tools (as Dymola for instance) apply only very relaxed checks for units because otherwise (according to their reports) too many examples in the MSL would break.
Especially, one issue is annoying: Reals of units 1 are treated the same way as Reals with an undefined unit. Hence you can write stuff like this:
without getting a warning in some tools. We suggest that the MSL is corrected that Reals of unit 1 have to comply with unit checks whereas Reals with undefined unit do not have to comply with unit checks. So the following code shall not generate a warning:
This is currently (rightfully) the case in most unit checkers.
We know it is difficult to comply to unit checks since they are not standardized (it is not part of the specification) but when tool developers complain that they cannot improve their checks because otherwise they break standard library code the dog really starts to eat its own tail.
This topic probably requires discussion between the library group and the design group and vendors. Maybe this issue also has been addressed for the new MSL version but we are not aware of it.
Migrated-From: https://trac.modelica.org/Modelica/ticket/1134
The text was updated successfully, but these errors were encountered: