Skip to content
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

Default pressure does not obey units #29

Closed
akiss-ic opened this issue Oct 25, 2021 · 3 comments
Closed

Default pressure does not obey units #29

akiss-ic opened this issue Oct 25, 2021 · 3 comments

Comments

@akiss-ic
Copy link

akiss-ic commented Oct 25, 2021

Hi, apologies in advance if this is not the correct place to ask this or if this is a stupid user error rather than an actual bug (I am very new to PyroMat).

I have modified my config.py file to set unit_pressure = 'Pa' rather than bar and this works well with one exception. If I run the pressure method with no arguments, e.g. air.p() I get the result in bar still rather than Pascals: array([1.01325]). Running it with named arguments, however, air.p(T=300, d=1.225) returns Pascals as expected: array([105491.85213083]). This does not seem to be the case for the default enthalpy when I change the energy units from kJ to J and it reports the enthalpy in J as expected.

Am I missing something obvious?

Thanks!

@chmarti1
Copy link
Owner

chmarti1 commented Oct 26, 2021

Thanks for raising the question! You are missing something, but it is definitely not obvious. This is the second question I've gotten about the same issue in a week, which means I need to adjust the documentation to be more clear about this question.

When you call a function with no arguments, the interface falls back to the default pressure and temperature values, which are def_p and def_T in the pm.config system. Those values are always interpreted in the units currently configured, so when you change the units, you also need to change those values if you plan to rely on them.

>>> import pyromat as pm
>>> air = pm.get('ig.air')
>>> air.d()
array([1.18391419])
>>> pm.config['unit_pressure'] = 'Pa'
>>> air.d()
array([1.18391419e-05])
>>> pm.config['def_p'] = 101325.
>>> air.d()
array([1.18391419])

It is also worth noting that when you call air.p() with no arguments, you will always get the default pressure, because the property methods always assume you specified air.p(T=pm.config['def_T'], p=pm.config['def_p']) when you don't specify arguments. The p() method has an especially easy time when you pass it pressure explicitly. It is happy to simply return it verbatim.

@akiss-ic
Copy link
Author

Ah thank you very much! That makes things much clearer, and also explains why the enthalpy was in the correct (but changed) units.

I changed the config.py to be consistent with the new units and it works as expected now.

Cheers!

@chmarti1
Copy link
Owner

No problem. Thanks for raising the question. I'm sure other people will find having it on record helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants