jjgomera / iapws Goto Github PK
View Code? Open in Web Editor NEWpython libray for IAPWS standard calculation of water and steam properties
License: GNU General Public License v3.0
python libray for IAPWS standard calculation of water and steam properties
License: GNU General Public License v3.0
Hello,
Thanks for this great repo allowing us to make use of the IAPWS standards. I was playing around with the ammonia.NH3 class and noticed some very unusual behaviour:
import iapws
iapws.ammonia.NH3(T=110+273.15,P=0.621325).rho #383 K and 6.2 bar (clearly gas phase)
/Users/yvc/anaconda3/lib/python3.7/site-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
Out[14]: 366.92738568157847
However when passing the correct density for that P and T, 3.4 kg/m3, the module is instantly returning the correct P without any issue:
iapws.ammonia.NH3(T=110+273.15,rho=3.4).P
Out[15]: 0.6199719347952626 #Pretty much 6.2 bar
It seems the MEoS is not able to converge to the right density but is having no problem working backwards to the pressure. Passing an initial rho0 did nothing:
iapws.ammonia.NH3(T=110+273.15,P=0.62, rho0=3.4).rho
/Users/yvc/anaconda3/lib/python3.7/site-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last five Jacobian evaluations.
warnings.warn(msg, RuntimeWarning)
Out[16]: 367.0501795698331
Trying this with the thermo package:
from thermo import Chemical
Chemical('Ammonia',T=110+273.15,P=620000).rho #Thermo uses Pascal
Out[17]: 3.400078841476925
I noticed that in the ammonia.py file, the critical pressure is defined in kPa and not MPa so I was wondering whether that might be one of the issues but could it be something with the root finder too?
OS version: macOS Catalina version 10.15.4
Python version: 3.7.6
Conda version: 4.8.3
IAPWS version: 1.4
Hi!
First of all, I would like to thank you very much for your awesome effort of maintaining this repository. Secondly, I think there is some problem with specific heat at constant pressure value for heavy water. I was checking it against the steam table by Hill (http://www.iaea.org/inis/collection/NCLCollectionStore/_Public/14/730/14730979.pdf?r=1) and its values are good upto 6 MPa but after that at 8 MPa pressure and 290 Celsius, it gives a value of 2.784817 although the value quoted in document is 5.218.
Thanks once again and looking forward to your feedback.
This is probably just a documentation problem combined with my lack of knowledge about IAPWS, but I can't find anything in the documentation to explain why this:
iapws.IAPWS95(T=298.15, P=1.0).Hvap
returns None.
In fact the documentation implies that if IAPWS95 is initialized with two parameters (e.g. T & P) then Hvap will be defined. The property calculable is set to True.
Line 875 of iapws95.py sets HVap to None unless 0<x<1, but setting x to any practically any value in that range just results in tracebacks. For example:
$ python3 -c "import iapws; print(iapws.IAPWS95(T=274.15, P=1, x=0.5))"
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 167, in init
self.call(**kwargs)
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 186, in call
self.calculo()
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 843, in calculo
self.fill(self.Liquid, liquido)
UnboundLocalError: local variable 'liquido' referenced before assignment
$ python3 -c "import iapws; print(iapws.IAPWS95(T=274.15, P=1, x=1))"
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 167, in init
self.call(**kwargs)
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 186, in call
self.calculo()
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 840, in calculo
self.fill(self.Gas, propiedades)
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 897, in fill
fase.rho = estado["rho"]
TypeError: 'NoneType' object is not subscriptable
Neither of these results seem to intended.
I have a AttributeError in wet region of HS diagram.
import iapws
s = iapws.IAPWS97(P=0.1, h=2600.)
s.nu
AttributeError: 'IAPWS97' object has no attribute 'nu'
Why IAPWS97 does not calculate nu value?
116 P = [P0]*N
117 P_last = [0]*N
118 Tf = [T0]*N
119 x_last = 0
120 h = prop(P=P0/(10**6),T=T0).h*1000
121
122 for n in range(N-1):
123 while(P[n] - P_last[n] > tol):
124 P_last[n] = P[n]
125 if (Tf[n] <= prop(P=P[n]/(10**6),x=0).T):
126 x = 0
127 else:
128 x = Quality(h,P[n]/(10**6))
129 P[n+1] = Pressure(P[n]/(10**6),x,x_last,Tf[n])
130 h = enthalpy(n+1)
131 Tf[n+1] = prop(P=P[n+1]/(10**6),h=h).T
132 x_last = x
Earlier in the Code I have:
from iapws import IAPWS97 as prop
Hi, I'm trying to use IAPWS97 package, but it keeps giving me this attribute error function. Another person had a similar issue but the poblem here isn't being in the mixed region. When I used iapws on its own outside my code, it works fine in any region. But in my code (This is only a small portion) I get this attribute error with any property. Sorry about the formatting. I've never used Github before.
Hi Juan José,
I think there is a problem in the computation of gamma in your IAPWS97 library. I notice a factor 1000 between your IAPWS97 and IAPWS95 gamma values.
fase.gamma = -self.v/self.P/1000*self.derivative("P", "v", "s", fase)
should be :
fase.gamma = -self.v/self.P*self.derivative("P", "v", "s", fase)
You can also compute gamma as well if you do not want to use derivatives:
fase.gamma = 1.e-6*self.w**2/self.P/self.v
(if P is in MPa)
I use this last expression in my C code and the results are close to RefProp and IAPWS95 results.
Regards.
The iapws package including the ability to 'self' generate a pdf table would be of benefit for anyone investigating results produced by packages that use it. (Perhaps it would just generate tex to avoid a dependency on pdflatex or similar tool). I think it would be of benefit to add a module to the package that walks ranges to build out the tables. This was done in a wrapper for freesteam called pywatprop which has not been sustained; but, the code is at ... https://github.com/tntmatthews/pywatprop/blob/master/pywatprop/steamtab.py.
which produces
https://github.com/tntmatthews/pywatprop/blob/master/pywatprop/steamtab.pdf
Has anything like this been done? I am thinking about forking and adding ... Good Idea/Bad Idea?
Hi,
For some input values, there may be multiple solutions in the whole IAPWS 97 data. For instance,
steam=IAPWS97(T=300, h=120)
the steam may be wet steam or unsanturated water.
The program will feed no warning when I set this status, and it seems to feed me AttributeError no matter any attribute I want to get.
Is there any possible way that I can get every solution of the steam at these input values? Or what should I do to limit the solution at a certain phase?
Thanks.
If I try to install iapws with the command
pip install iapws
using Python 3.4 on Windows:
>python -V
Python 3.4.3
I get the following error message:
Collecting iapws
Using cached iapws-1.1.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "C:\Users\xxx\AppData\Local\Temp\pip-build-0m244txa\iapws\setup.py", line 7, in <module>
long_description = file.read()
File "C:\opt\Python34\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 4975: character maps to <undefined>
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\xxx\AppData\Local\Temp\pip-build-0m244txa\iapws
It seems HumidAir return grossly wrong calculations at temperatures under around 295K, 1atm.
Please try:
import iapws.humidAir as ha
a = ha.HumidAir(T=295, P=0.101325, W=0.00858)
print(a.RH)
It should return around 50%, or 0.5, but prints -0.9678.
It seems calculations at higher temperatures are right:
a = ha.HumidAir(T=323, P=0.101325, W=0.0388)
print(a.RH)
shows 0.5009.
Hi, maybe you should write json with double quotes, not with single quotes.
like this:
{"name":1}
Now like this:
{'name':1}
For IAPWS97, using the Table 3 from Supp-PHS12-2014.pdf the first entry returns an "Incoming out of bound" error.
import iapws
prop = iapws.IAPWS97(h=0.001, s=0)
Traceback (most recent call last):
File "", line 1, in
File "c:\Python27\lib\site-packages\iapws\iapws97.py", line 2756, in init
self.call(**kwargs)
File "c:\Python27\lib\site-packages\iapws\iapws97.py", line 2763, in call
self.calculo()
File "c:\Python27\lib\site-packages\iapws\iapws97.py", line 2940, in calculo
raise NotImplementedError("Incoming out of bound")
NotImplementedError: Incoming out of bound
When debugging, it appears to be getting the correct pressure value but gets kicked out at line 2552 of iapws97.py, "if T-0.0218 >= 273.15 and Pt <= P <= 100:", where T-0.0218 is a value less than 273.15. Is it possible that the -0.0218 should be +0.0218? T + 0.0218 would be above 273.15.
The other entries in Table 3 return close to the correct values:
prop = iapws.IAPWS97(h=90, s=0)
prop.P
91.930758227675483
prop = iapws.IAPWS97(h=1500, s=3.4)
prop.P
58.677689985997915
Thanks for your great work on the IAPWS for python.
I think that the FIXME in the H2ONH3() _prop() _phir() routine is related to using mass density where molar density should be used. The original source uses mole fraction and mole density. The critical densities of water and ammonia need to be converted molar densities and then used to calculate rhoc12 and rhon.
There also seems to be a couple of sign errors (+/-) in the drhonx formula
The pressures still don't match exactly. I haven't completely checked this either though.
# Density reducing value, Eq 5
b = 0.8978069
# molar densities
rhoc1m=IAPWS95.rhoc/(IAPWS95.M/1000)
rhoc2m=NH3.rhoc/(NH3.M/1000)
# Mixture molar mass
M=(1-x)IAPWS95.M + xNH3.M
# Molar mixture critical density and mass critical density
rhoc12m = 1/(1.2395117/2*(1/rhoc1m+1/rhoc2m))
rhoc12 = rhoc12mM/1000
# Molar rhon, and mass rhon
rhonm = 1/((1-x)2/rhoc1m + x2/rhoc2m +
2x*(1-xb)/(rhoc12m))
rhon = rhonmM/1000
# I think these are the correct signs?
drhonx = -(M/1000)(2bxb/rhoc12m + 2*(1-xb)/rhoc12m -2x/rhoc2m + 2(1-x)/rhoc1m)/(2x(1-xb)/rhoc12m + x**2/rhoc2m + (1-x)**2/rhoc1m)**2
sat_pressue = IAPWS97(h=4197.3, s=7.82)
p = sat_pressue.P
print(p)
I want calculate the P use h、s , but when h is invariable, s in range(7.82,7.88),will appear math domain error.
G:\python>cd g:\python && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && python c:\Users\Administrator.vscode\extensions\ms-python.python-2018.5.0\pythonFiles\PythonTools\visualstudio_py_launcher.py g:\python 61692 34806ad9-833a-4524-8cd6-18ca4aa74f14 RedirectOutput,RedirectOutput g:\python\cal.py "
Traceback (most recent call last):
File "g:\python\cal.py", line 44, in
sat_pressue = IAPWS97(h=4197.3, s=7.82)
File "D:\python\lib\site-packages\iapws\iapws97.py", line 4306, in init
self.call(**kwargs)
File "D:\python\lib\site-packages\iapws\iapws97.py", line 4313, in call
self.calculo()
File "D:\python\lib\site-packages\iapws\iapws97.py", line 4518, in calculo
T, P = fsolve(funcion, [1400, 1])
File "D:\python\lib\site-packages\scipy\optimize\minpack.py", line 146, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "D:\python\lib\site-packages\scipy\optimize\minpack.py", line 224, in _root_hybr
ml, mu, epsfcn, factor, diag)
File "D:\python\lib\site-packages\iapws\iapws97.py", line 4516, in funcion
return (_Region5(par[0], par[1])["h"]-h,
File "D:\python\lib\site-packages\iapws\iapws97.py", line 3717, in _Region5
go, gop, gopp, got, gott, gopt = Region5_cp0(Tr, Pr)
File "D:\python\lib\site-packages\iapws\iapws97.py", line 3781, in Region5_cp0
go = log(Pr)
ValueError: math domain error
Hello,
When using IAPWS97 I am having a problem with Px initialization. It seems that if x==1 or x==0 returns properties for x==0 only if P>16.529 MPa. Example:
>>> from iapws import IAPWS97
>>> satL=IAPWS97(P=17.0,x=0)
>>> satL.h
1690.0370435729556
>>> satV=IAPWS97(P=17.0,x=1)
>>> satV.h
1690.0370435729556
The results should not be identical. I expected satV.h to be about 2547.
I am using python 3.4.2 and iapws 1.1.1. I originally got iapws from pip. I saw there was a change made to the Px routine with a commit about a week ago. I tried implementing this but I don't think it fixes my problem.
Let me know if you need anything else.
Thanks
I found a performance bottleneck in the IAPWS97 module.
Here my analysis (in Jupyter notebook):
For whole function on my machine it take (tested in Region 2):
%timeit iapws97.IAPWS97(P=3., s=6.5)
100 loops, best of 3: 9.36 ms per loop
import iapws97
from scipy.optimize import newton
P, s = 3., 6.5
# initial value of Temperature
To = iapws97._Backward2a_T_Ps(P, s)
funcion = lambda T: iapws97._Region2(T, P)["s"]-s
# fsolve
a = %timeit -o -q iapws97.fsolve(funcion, To)[0]
val = iapws97.fsolve(funcion, To)[0]
print("{:10s} {:.4f} {}".format('fsolve', a.best, val))
# newton
a = %timeit -o -q newton(funcion, To)
val = newton(funcion, To)
print("{:10s} {:.4f} {}".format('newton', a.best, val))
fsolve 0.0080 564.036985544
newton 0.0005 564.036985544
The bottleneck is in 'fsolve' method which performs 85% of time for whole function. If we change 'fsolve' method to 'newton' we get significant speed improvement.
%timeit iapws97.IAPWS97(P=3., s=6.5)
1000 loops, best of 3: 1.36 ms per loop
The newton method is much simpler than fsolve but for given tasks it enough.
It would be useful to add a few things to the documentations:
Units of the inputs (pressure, temperature, ...)
Examples for known entropy (P,S),(T,S)
EDIT
I found this link that explains how to use your library very well. You might want to add it to the read me section:
http://kitchingroup.cheme.cmu.edu/blog/2013/02/28/Meet-the-steam-tables/
Hi,
the issue is in line 2237 fase.alfav=estado["alfav"]
using iapws-1.0.3-py3.3.egg
btw: when you import "import iapws" in python3.x you get an error, the last line is not python3 compatible. print mix -> print (mix)
Hello,
I just installed iapws (WinPython, Win 7 64 bit, Python 3.4) and wanted to run the examples from the intro page.
The one for IAPWS97 runs fine:
from iapws import IAPWS97
sat_steam=IAPWS97(P=1,x=1) #saturated steam with known P
sat_liquid=IAPWS97(T=370, x=0) #saturated liquid with known T
steam=IAPWS97(P=2.5, T=500) #steam with known P and T
print(sat_steam.h, sat_liquid.h, steam.h) #calculated enthalpies
But the second one for IAPWS95
from iapws import IAPWS95
sat_steam=IAPWS95(P=1,x=1) #saturated steam with known P
sat_liquid=IAPWS95(T=370, x=0) #saturated liquid with known T
steam=IAPWS95(P=2.5, T=500) #steam with known P and T
print(sat_steam.h, sat_liquid.h, steam.h) #calculated enthalpies
throws an error
TypeError: fsolve: there is a mismatch between the input and output shape of the 'func' argument 'f'.Shape should be (2,) but it is (2, 1).
while calling fsolve
elif self._mode == "Px":
# Iterate over saturation routine to get T
def funcion(T):
rhol, rhov, Ps = self._saturation(T)
return Ps/1000-P
To = _TSat_P(P)
T = fsolve(funcion, To)[0]
I was trying to add iapws to another project when I noticed that IAPWS95 takes significantly longer to initialize than IAPWS97. I had hope to use -95 because it can calculate the density of water below zero degrees C, whereas 97 cannot.
In [5]: from iapws import IAPWS95
In [6]: %timeit h2o=IAPWS95(P=0.1,T=298)
10 loops, best of 3: 40.5 ms per loop
In [7]: from iapws import IAPWS97
In [8]: %timeit h2o=IAPWS97(P=0.1,T=298)
1000 loops, best of 3: 226 µs per loop
I understand there are probably underlying differences in the algorithms, but can this huge performance difference be improved?
What is happening and wrong here?
from iapws import IAPWS97
px = IAPWS97(h=3199,s=6.66)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-2-0b60695a8b57> in <module>()
----> 1 px = IAPWS97(h=3199,s=6.66)
c:\anaconda3\lib\site-packages\iapws-1.1.1-py3.5.egg\iapws\iapws97.py in __init__(self, **kwargs)
2690 def __init__(self, **kwargs):
2691 self.kwargs = IAPWS97.kwargs.copy()
-> 2692 self.__call__(**kwargs)
2693
2694 def __call__(self, **kwargs):
c:\anaconda3\lib\site-packages\iapws-1.1.1-py3.5.egg\iapws\iapws97.py in __call__(self, **kwargs)
2697 if self.calculable:
2698 self.status = 1
-> 2699 self.calculo()
2700 self.msg = "Solved"
2701
c:\anaconda3\lib\site-packages\iapws-1.1.1-py3.5.egg\iapws\iapws97.py in calculo(self)
2843 _Region2(par[0], par[1])["s"]-s)
2844 T, P = fsolve(funcion, [To, Po])
-> 2845 propiedades = _Region2(T[0], P[0])
2846 elif region == 3:
2847 P = _Backward3_P_hs(h, s)
IndexError: invalid index to scalar variable.
Now, when I use - Zittau´s Fluid Property Calculator
Pressure p(h,s)
Specific enthalpy h=3199 kJ/Kg
Specific entropy s=6.66 kJ/(Kg K)
Result:
Pressure p=4.90455 MPa
Hi, maybe you should write json with double quotes, not with single quotes.
like this:
{"name":1}
Now like this:
{'name':1}
There is still a bug in region 3 in the two-phases area (Px and Tx), at least for the specific volume (was trying to plot a P-v diagram for students).
You search rho from P,T without considering the value of x ! (iapws97.py, around line 2877, version 1.2.2)
but rho(x=0) is not equal to rho(x=1) !!
I think you need to search rho on both sides of P(T) and : rho = x_rho1+(1.-x)_rho2
Anyway thanks for your work.
setup.py can failed by import __version__
File "<string>", line 1, in <module>
File "...\iapws\setup.py", line 3, in <module>
from iapws import __version__
File "iapws\__init__.py", line 5, in <module>
from ._iapws import (_Ice, _Sublimation_Pressure, _Melting_Pressure, # noqa
File "iapws\_iapws.py", line 35, in <module>
from scipy.optimize import minimize
ImportError: No module named scipy.optimize
Hi!
When following your instructions regarding the usage and trying to import the "package" via
"from iapws import IAPWS97"
I get the error message
"ImportError: cannot import name IAPWS97".
However, importing via
"from iapws.iapws import IAPWS97"
works.
Cheers and thanks again for your work!
Hi, jjgomera,
It seams there is a mistake in the computation of the isentropic compressibility ks in IAPWS08 module (file iapws08.py) if we refer to the document "IAPWS R13-08" (http://www.iapws.org/relguide/seawater.pdf, bottom of page 7):
self.ks = (prop["gtp"]**2-prop["gt"]*prop["gpp"])/prop["gp"] / \ ...
should be:
self.ks = (prop["gtp"]**2-prop["gtt"]*prop["gpp"])/prop["gp"] / \ ...
What is your opinion ?
Thank you very much for your great and usefull work !
Regards.
Hello, I've stumbled unpon an issue with the h-s plane:
Pt=611.657 is in Pa on line 1881
It breaks the Pt<=P<=100 test on line 1816 where P is in MPa
Pt in MPa seems to fix it
But there is a typo To=_Backward3_T_ph(P, h) on line 2061
Changing it to To=_Backward3_T_Ph(P, h) makes the calculation to run fine.
Thank you for this useful piece of code.
I'm not able to install iapws with python 3. I'm running 3.4.2 specifically. Here is the debug printout when I try to use pip.
~/Downloads $ pip install iapws
Downloading/unpacking iapws
Downloading iapws-1.1.tar.gz (85kB): 85kB downloaded
Running setup.py (path:/tmp/pip_build_smed/iapws/setup.py) egg_info for package iapws
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_smed/iapws/setup.py", line 3, in <module>
from iapws import __version__
File "/tmp/pip_build_smed/iapws/iapws/__init__.py", line 8, in <module>
from iapws97 import IAPWS97
ImportError: No module named 'iapws97'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_smed/iapws/setup.py", line 3, in <module>
from iapws import __version__
File "/tmp/pip_build_smed/iapws/iapws/__init__.py", line 8, in <module>
from iapws97 import IAPWS97
ImportError: No module named 'iapws97'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_smed/iapws
Storing debug log for failure in /home/smed/.pip/pip.log
If I understand correctly, IAPWS95 is the more exact routine, while IAPWS97 is the faster routine. However, in some respects, they give very different results, e.g.:
print((iapws.IAPWS95(T=300,x=0).s0, (iapws.IAPWS95(T=370,x=0).s0)))
print((iapws.IAPWS97(T=300,x=0).s0, (iapws.IAPWS97(T=370,x=0).s0)))
returns:
(3.6428700449292255, 3.9563090741522546)
(8.521813980885716, 7.418560249940249)
Not only are the absolute values different, but they have opposite sensitivies to T.
Hye.
I encountered strange behavior (once again, remember #32 ) although I did new installation back then and it solved my problem. This time I am having problem with properties that the boiling is taking place way past the saturation temperature for example saturation temperature at 10 MPa is close to 583K but even if i use hw = D2O(P=10, T=593.15) i still get hw.phase = 'Liquid'. The same thing happens at other pressure values too.
Am i making some mistake (again)?
I cannot calculate property for specific temperature
from iapws import IAPWS97
IAPWS97(T=623.15, x=0).t
`---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
in ()
----> 1 IAPWS97(T=623.15, x=0).t
/usr/local/lib/python2.7/dist-packages/iapws/iapws97.pyc in init(self, **kwargs)
2690 def init(self, **kwargs):
2691 self.kwargs = IAPWS97.kwargs.copy()
-> 2692 self.call(**kwargs)
2693
2694 def call(self, **kwargs):
/usr/local/lib/python2.7/dist-packages/iapws/iapws97.pyc in call(self, **kwargs)
2697 if self.calculable:
2698 self.status = 1
-> 2699 self.calculo()
2700 self.msg = "Solved"
2701
/usr/local/lib/python2.7/dist-packages/iapws/iapws97.pyc in calculo(self)
2891 propiedades = _Region4(P, x)
2892 elif P > Ps_623 and x in (0, 1):
-> 2893 rho = 1./_Backward3_v_PT(P, T)
2894 propiedades = _Region3(rho, T)
2895 elif Tt <= T <= Tc and x == 0:
/usr/local/lib/python2.7/dist-packages/iapws/iapws97.pyc in _Backward3_v_PT(P, T)
1637 region = "t"
1638
-> 1639 return _Backward3x_v_PT(T, P, region)
1640
1641
UnboundLocalError: local variable 'region' referenced before assignment`
When using iapws.humidAir it returns incorrect values for RH which where used to initialise the state in the first place, check code below.
Here the relative humidity is used to calculate the molar fraction for the initialisation of hum_air_state.
However hum_air_state.RH does not return the proper phi.
import iapws
T_degC = 14
T_K = T_degC + 273.15
p_mbar = 1000# 013.25
p_bar = p_mbar * 1e-3
p_Pa = p_mbar * 1e+2
p_MPa = p_Pa * 1e-6
phi_p = 60
phi_r = phi_p * 1e-2
p_sat_w = iapws.iapws97._PSat_T(T_K) #Temperature, [K]; Returns:Pressure, [MPa]
p_w = phi_r * p_sat_w
xa = (p_MPa - p_w)/p_MPa
hum_air_state = iapws.humidAir.HumidAir(T=T_K, P=p_MPa, xa=xa)
print(phi_r) #OUT 0.6
print(hum_air_state.RH) #16.210589116125586
from iapws.iapws97 import IAPWS97
f_px =IAPWS97(P=0.00353658941,x=0.20)
f_hs = IAPWS97(h=f_px.h, s=f_px.s)
print(f_hs.P)
_Bound_hs(h, s) Returns region = None
raise
NotImplementedError("Incoming out of bound")
Since the IAPWS-documents define that the entropy and energy at the tripple point (t=273.160 K , p= 611.657) are by definition zero, is there a way to fix that also in your implementation?
When I run the following small script
from iapws import IAPWS95
from iapws import _Ice
p0 = 101325. # Pa
t0 = 1. # can not pass zero K
pt = 611.657 # Pa
tt = 273.160 # K
ice_1h_ref1 = _Ice(P=p0*1E-6, T=t0)
ice_1h_ref2 = _Ice(P=pt*1E-6, T=tt)
liq_ref2 = IAPWS95(P=pt*1E-6, T=tt)
print('s',ice_1h_ref1['s'],ice_1h_ref2['s'],liq_ref2.s)
print('u',ice_1h_ref1['u'],ice_1h_ref2['u'],liq_ref2.u)
print('g',ice_1h_ref1['g'],ice_1h_ref2['g'],liq_ref2.g)
I get as a result
s -3.3273345133447987 -1.2206943393968697 9.155491719295108
u -632.1287397782819 -333.444921196524 2374.9196737638176
g -628.6928965324292 0.0006117841346053865 0.0010709336770560185
Thanks
Dear Juan,
Surface tension sigma property in IAPWS97 does not work.
Objet has no attribute in IAPWS97
I installed IAPWS with pip, in Linux redhat
Congratulattions for your work,
Kind regards,
Eugenio.
The entropy calculation at certain values, around P=.7 bar and T=312 K, goes haywire.
The code producing this is as follows:
import matplotlib.pyplot as plt import numpy as np from iapws import IAPWS97 P = .7 # bar T_arr = np.linspace(300, 320) # kelvin plt.plot(T_arr, [IAPWS97(P=P4, T=T).s for T in T_arr])
Hello,
I am using your tool for calculating thermal power plants. As I need to access derivatives of the properties, I am using the IAPWS95 formulation. Trying to calculate the enthalpy at the high pressure side of a pump with the entropy of the lower pressure side (isentropic pump) using the following code
print(IAPWS95(s=IAPWS95(P=0.1,h=85).s,P=50).h)
I found the following error:
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:802: RuntimeWarning: invalid value encountered in double_scalars
fir += n*delta**d*tau**t
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:803: RuntimeWarning: invalid value encountered in double_scalars
fird += n*d*delta**(d-1)*tau**t
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:804: RuntimeWarning: invalid value encountered in double_scalars
firdd += n*d*(d-1)*delta**(d-2)*tau**t
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:805: RuntimeWarning: invalid value encountered in double_scalars
firt += n*t*delta**d*tau**(t-1)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:806: RuntimeWarning: invalid value encountered in double_scalars
firtt += n*t*(t-1)*delta**d*tau**(t-2)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:807: RuntimeWarning: invalid value encountered in double_scalars
firdt += n*t*d*delta**(d-1)*tau**(t-1)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:808: RuntimeWarning: invalid value encountered in double_scalars
firdtt += n*t*d*(t-1)*delta**(d-1)*tau**(t-2)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:809: RuntimeWarning: invalid value encountered in double_scalars
B += n*d*delta_0**(d-1)*tau**t
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:810: RuntimeWarning: invalid value encountered in double_scalars
C += n*d*(d-1)*delta_0**(d-2)*tau**t
/home/francesco/.local/lib/python3.5/site-packages/scipy/optimize/minpack.py:224: ComplexWarning: Casting complex values to real discards the imaginary part
ml, mu, epsfcn, factor, diag)
/home/francesco/.local/lib/python3.5/site-packages/scipy/optimize/minpack.py:161: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:1000: RuntimeWarning: invalid value encountered in double_scalars
Tita = Tita**(1./3)
/home/francesco/.local/lib/python3.5/site-packages/iapws/iapws95.py:1016: RuntimeWarning: invalid value encountered in double_scalars
Tita = Tita**(1./3)
The result is then h=2914 kJ/kg which is obviously wrong. However,
print(IAPWS97(s=IAPWS97(P=0.1,h=85).s,P=50).h)
works perfectly fine.
I am working on Ubuntu 16.04, iapws version: 1.1.3, python 3.5.
Can you help me with this issue? Thank you very much and have a nice day!
Francesco
function _Region1(T, P) and _Region2(T, P) have the same Var, why we need run iapws97._Bound_TP first?
https://images2018.cnblogs.com/blog/1285395/201804/1285395-20180404221857518-2043536130.png
In the steam-water property curve, one T and one P to one point.
Hi. I wonder if is it possible for this project to be distributed under the MIT license instead of GPL. We would like very much to use it in our project, however the GPL license is a blocker.
I hope that this could be possible. Best regards.
The surface tension, sigma, does not appear to be working. I receive the same attribute error in both Python 2.7.9 and 3.4.3.
from iapws import IAPWS97
sat_liquid=IAPWS97(T=370, x=0) #saturated liquid with known T
print(sat_liquid.h) #calculated enthalpies
print(sat_liquid.sigma) #calculated surface tension
405.81466030352686
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-4e60866677df> in <module>()
2 sat_liquid=IAPWS97(T=370, x=0) #saturated liquid with known T
3 print(sat_liquid.h) #calculated enthalpies
----> 4 print(sat_liquid.sigma)
AttributeError: 'IAPWS97' object has no attribute 'sigma'
After updating from 1.4.1 to 1.5.2, pyInstaller
cannot find the VERSION
file when using the iapws
package as part of the bundle:
Traceback (most recent call last):
File "ydb\ydb_server.py", line 30, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "ydb\__init__.py", line 7, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "ydb\iapws_ydb.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "iapws\__init__.py", line 15, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\dist_test_3\\ydb_server\\iapws\\VERSION'
I don't know how other packages do not cause this trouble with their datafiles, otherwise I could suggest a solution directly.
I was a bit in a hurry .. will investigate more on my side:
The Prandtl number calculation is off by a factor of 1000.
On line 2268 the Prandtl number is calculated as:
fase.Prandt=fase.mu*fase.cp/fase.k
cp has units kJ/kgK but in the above equation it is expected to have J/kgK. The above equation is missing a factor 1000.
>>> from iapws import IAPWS97
>>> steam=IAPWS97(P=50, T=400)
>>> print(steam.region)
1
3 is right
Hi!
When following your instruction how to install via pip I get an error message telling me that README.rst is missing. When directly downloading the package from pip the README.rst is indeed missing after unpacking. I wouldn't know this on my own but a friend who is much more literate when it comes to python told me that the problem is somewhere in your setup.py.
Cloning it from the github page however works fine.
Thanks for your work!
Thanks for your implementation! It has been a help for me to do some calculations.
But while using the scientific formulation IAPWS-95 to plot 3D a PvT diagram, I became sceptical about the output data:
IAPWS95(T=250+273.15, v=10).P
Out[6]: 2.2080623654368261
IAPWS95(T=250+273.15, v=5).P
Out[7]: 1.156479877280217
IAPWS95(T=250+273.15, v=1).P
Out[8]: 0.2394463065087358
IAPWS95(T=250+273.15, v=0.1).P
Out[9]: 0.024124428435807685
Shouldn't the pressure increase with a decreasing specific volume like in every T,s-diagram?
Cheers
Cord
Hello again. Hopefully these reports are helpful and not just annoying. As I mentioned previously, I'm trying to use IAPWS because I'm not terribly knowledgeable about the subject matter. I suspect that these results are also unintended:
$ python3 -c "import iapws; print(iapws.IAPWS95(T=647.0959, x=0.5).Hvap)"
-4.444518708623946e-08
$ python3 -c "import iapws; print(iapws.IAPWS95(T=647.0958, x=0.5).Hvap)"
/home/cory/.local/lib/python3.6/site-packages/scipy/optimize/minpack.py:163: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
1.0171681899464602
$ python3 -c "import iapws; print(iapws.IAPWS95(T=647.097, x=0.5).Hvap)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 396, in __init__
self.__call__(**kwargs)
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 420, in __call__
raise(err)
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 415, in __call__
self.calculo()
File "/usr/lib/python3/dist-packages/iapws/iapws95.py", line 1358, in calculo
raise NotImplementedError("Incoming out of bound")
NotImplementedError: Incoming out of bound
$ python3 -c "import iapws; print(iapws.IAPWS95(T=647.096, x=0.5).Hvap)"
/usr/lib/python3/dist-packages/iapws/iapws95.py:172: RuntimeWarning: divide by zero encountered in double_scalars
DeltaBd = b*Delta**(b-1)*Deltad
/usr/lib/python3/dist-packages/iapws/iapws95.py:172: RuntimeWarning: invalid value encountered in double_scalars
DeltaBd = b*Delta**(b-1)*Deltad
/home/cory/.local/lib/python3.6/site-packages/scipy/optimize/minpack.py:163: RuntimeWarning: The iteration is not making good progress, as measured by the
improvement from the last ten iterations.
warnings.warn(msg, RuntimeWarning)
/usr/lib/python3/dist-packages/iapws/iapws95.py:1867: RuntimeWarning: divide by zero encountered in double_scalars
DeltaBd = b*Delta**(b-1)*Deltad
/usr/lib/python3/dist-packages/iapws/iapws95.py:1867: RuntimeWarning: invalid value encountered in double_scalars
...
The lower bound for validity was zero Celsius, which makes sense, but apparently there's an upper limit as well (100C?, Hvap <0?), but it's not properly enforced.
Since the value of x doesn't change the Hvap result at all, why does the system require that parameter to be passed, instead of just populating Hvap from T when given T & P?
Is there a reason why returning None is superior to returning the value that's evaluated at the minimum or maximum? I ask because in some contexts it's easier for the function to return the same data type. Say for example a graph from 0K to 500K... If you explicitly want to signal that value was outside the validity range by returning None, I understand that as well.
我得到一个错误:
>>> r4 = IAPWS97(P=0.101325,T=300)
>>> r4._PSat_T(500)
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'IAPWS97' object has no attribute '_PSat_T'
Hi there,
I installed the package under Python 2.7 with no problems at all using
pip install iapws
However, when trying to do the same under Python 3.3.4, I get an ImportError
:
Downloading/unpacking iapws
Running setup.py (path:c:\users\poverl~1\appdata\local\temp\pip_build_pOverlor
d\iapws\setup.py) egg_info for package iapws
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\poverl~1\appdata\local\temp\pip_build_pOverlord\iapws\setup
.py", line 3, in <module>
from iapws import __version__
File ".\iapws\__init__.py", line 8, in <module>
from iapws97 import IAPWS97
ImportError: No module named 'iapws97'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "c:\users\poverl~1\appdata\local\temp\pip_build_pOverlord\iapws\setup.py"
, line 3, in <module>
from iapws import __version__
File ".\iapws\__init__.py", line 8, in <module>
from iapws97 import IAPWS97
ImportError: No module named 'iapws97'
Is there any solution or alternative approach to installing the package? I get also an ImportError
when downloading the package and executing setup.py install
.
Hi all,
while comparing ammonia densities against other property modules I noticed some abnormality around Tc= 405.4K with huge changes in density.
`from iapws import ammonia as iapws
NH3_1 = iapws.NH3(T=273.15+115,P=0.1)
NH3_1.calculo()
print(f"Density at 110°C, 1 bar: {NH3_1.rho} [kg/m³]")
print(f"x = {NH3_1.x}")
#print(f"h = {NH3_1.x} kJ/kg")
NH3_2 = iapws.NH3(T=273.15+130,P=0.1)
NH3_2.calculo()
print(f"Density at 130°C, 1 bar: {NH3_2.rho} [kg/m³]")
print(f"x = {NH3_2.x}")
#print(f"h = {NH3_2.x} kJ/kg")
NH3_3 = iapws.NH3(T=273.15+140,P=0.1)
NH3_3.calculo()
print(f"Density at 140°C, 1 bar: {NH3_3.rho} [kg/m³]")
print(f"x = {NH3_3.x}")`
Best regards,
Florian
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.