-
Notifications
You must be signed in to change notification settings - Fork 12
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
Inconsistency with converting units #259
Comments
Thanks for reporting! I will take a better look, but some of this issues may actually come from Unitful. julia> a*b
500000.0 Pa MPa This is worrying... |
I can add another example, maybe this helps to understand whats going on using GeoParams
E = 500kJ/mol
V = 15cm^3/mol
P = 2000MPa
R = 8.314J/mol/K
T = 800K
julia> (E + P*V)/(R*T)
79.68486889583835 kg m^2.0 J^-1.0 s^-2.0 <-- this should all cancel
julia> exp((E + P*V)/(R*T))
4.0429544897502273e34 <-- exponential seems to force the resolution of the units |
Commenting on that, as I remember having the same problem some years ago. It is an issue coming from Unitful, which doesn't convert automatically when the units are different, when things can cancel. The reasonning behind that behaviour, is that for some units, you don't want the units to cancel out by default. For instance, if you have somehow a unit of kg / Pa, it is often useful to keep like that, than to have m s^2 output.
whereas
because the same units are used. Now, the problem is that there is no default parameter you could modify to change that behaviour (see for instance PainterQubits/Unitful.jl#373). So the common practice to work around that is to use So, in your case:
The drawback of that, it that it converts to the units preferred, which is by default SI. So your Pa will be converted to kg/m/s^-2 even if you want it to keep showing up as Pa. The reason why |
@Iddingsite that is some useful insight. This is why I posted the example with the exponential. To see if we find something that forces simplification of units. |
Yes, your guess is correct concerning the
|
I am not sure if this is a concern of GeoParams or Unitful, but I think that this behavior is a bit silly:
Same thing happens if
b
is inJ/m^3
which is equivalent toPa
The text was updated successfully, but these errors were encountered: