BenThelen / python-refprop

Python (3.x & 2.x) API for NIST Standard Reference Database 23 (a.k.a. Refprop) on Linux and Windows
Other
43 stars 25 forks source link

A problem with Jowr's librefprop.so #11

Closed ghost closed 9 years ago

ghost commented 9 years ago

platform:

Ubuntu server 64bit 14.04
gcc 4.8.2
gfortran 4.8.2
refprop 9.0
librefprop.so v0.2
python 2.7.6

compiled with a lot of warnings but test successfully with the pyrp.py in librefprop.so v0.2. And the librefprop.so and fluids/mixtures folder were located in /opt/refprop/ by defaut.

So I have to modify the refprop.py at line 97:

  97 _fpath = u'/opt/refprop/'

and run the test by:

python -c "import rptest;rptest.settest('refprop')"

and the output is

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "rptest.py", line 22, in settest
    _maintest(rp)
  File "rptest.py", line 32, in _maintest
    if rp.test(): #if True; rptest =>>for testing purpose
  File "refprop.py", line 921, in test
    prop = setup(u'def', u'air')
  File "refprop.py", line 1688, in setup
    return _setmix(mix, hrf, hfmix)
  File "refprop.py", line 1957, in _setmix
    _rpsetmix_(byref(_hmxnme), byref(_hfmix), byref(_hrf), byref(_nc),
NameError: global name '_rpsetmix_' is not defined

I used ipython load refprop.py and found that there is no rpsetmix in the dict of refprop. I do not know what happened. I used ipython debugger to see what was defined in the process:

ipdb> _
Display all 210 possibilities? (y or n)
_A                   _acf                 _dhdt_p              _hfld                _nc                  _seterrordebug       _tmax
_Ar                  _b                   _dip                 _hfm                 _nc_rec              _setinputerrorcheck  _tmin
_D                   _ba                  _dnadn               _hfmix               _nmxpar              _setktv_rec          _tnbpt
_D1                  _beta                _dpdD                _hjt                 _nroot               _setmix              _ts
_D2                  _betas               _dpdt                _hmix                _outputierrcheck     _setmod              _ttrp
_D3                  _bs                  _e                   _hmodij              _p                   _setmod_pre_rec      _u
_Dcrit               _c                   _eE                  _hmxnme              _p0                  _setmod_rec          _v
_Dlbub               _ca                  _er                  _hmxrul              _p1                  _setref_rec          _vE
_Dliq                _checksetupmodel     _eta                 _hn80                _p2                  _setup0              _var1
_Dmax                _cp                  _f                   _hname               _p3                  _setup_rec           _var2
_Dmin                _cpr                 _fij                 _hpth                _pbub                _setupprop           _w
_Ds                  _cs                  _fixicomp            _hr                  _pcrit               _setwarning          _wliq
_Dvap                _csat                _fldext              _hrf                 _pdew                _sigma               _wmix
_Dvdew               _cv                  _fluidextention      _htype               _pint                _spare1              _wmm
_Fpv                 _cv2p                _fpath               _icomp               _pmax                _spare2              _ws
_G                   _cvr                 _gE                  _ierr                _pr                  _spare3              _wvap
_Gr                  _d                   _gerg04              _inputerrorcheck     _preos_rec           _spare4              _x
_Rgas                _d2pdD2              _gerg04_pre_rec      _ixflag              _prop                _spht                _x0
_Setuprecord         _dDdp                _gerg04_rec          _jcomp               _ps                  _sr                  _xbub
_Z                   _dDdt                _h                   _k1                  _purefld_rec         _t                   _xdew
__IPYTHON__          _dadn                _h0                  _k2                  _q                   _t0                  _xisenk
__IPYTHON__active    _dbt                 _hE                  _k3                  _qkg                 _t1                  _xkappa
__debug__            _dct                 _hbinp               _kguess              _routine             _t2                  _xkg
__doc__              _dct2                _hcas                _kph                 _rp                  _t3                  _xkkt
__file__             _de                  _hcite               _kq                  _s                   _tbub                _xkt
__import__           _dhdD_p              _hcode               _kr                  _s0                  _tcrit               _xliq
__name__             _dhdD_t              _hcomp               _ksat                _sE                  _tcx                 _xlkg
__package__          _dhdp_D              _herr                _loadfile            _set                 _tdew                _xvap
_aE                  _dhdp_t              _hfij                _maxcomps            _setaga_rec          _test                _xvkg
_abfl2               _dhdt_D              _hfile               _name                _seterror            _thrott              _zcrit

There is a _setmix but no global rpsetmix

I am a windows user, not familiar with debugging in command line using ipdb. I think this might be helpful to find out what happened:

ipdb> w
  <ipython-input-9-c9e031ecf5c0>(1)<module>()
----> 1 import rptest;rptest.settest('refprop')

  /home/vagrant/refprop/python-refprop/python2.7/rptest.py(22)settest()
     20     if test == u'refprop':
     21         import refprop as rp
---> 22         _maintest(rp)
     23     elif test == u'multiRP':
     24         import multiRP as rp

  /home/vagrant/refprop/python-refprop/python2.7/rptest.py(32)_maintest()
     30     rp.SetErrorDebug.off() #turn on =>> for testing purpose
     31
---> 32     if rp.test(): #if True; rptest =>>for testing purpose
     33         print u'refprop installed correctely'
     34

  /home/vagrant/refprop/python-refprop/python2.7/refprop.py(921)test()
    919
    920     #test no. 1
--> 921     prop = setup(u'def', u'air')
    922     prop = wmol(prop[u'x'])
    923     testresult += u'check molar mass of air'

> /home/vagrant/refprop/python-refprop/python2.7/refprop.py(1688)setup()
   1686         for item in listhfld:
   1687             mix = unicode(item)
-> 1688         return _setmix(mix, hrf, hfmix)
   1689     else:
   1690         if u'hmxnme' in _setupprop:

  /home/vagrant/refprop/python-refprop/python2.7/refprop.py(1957)_setmix()
   1955     _hrf.value = hrf.upper().encode(u'ascii')
   1956
-> 1957     _rpsetmix_(byref(_hmxnme), byref(_hfmix), byref(_hrf), byref(_nc),
   1958                byref(_hfld), _x, byref(_ierr), byref(_herr), c_long(255),
   1959                c_long(255), c_long(3), c_long(10000), c_long(255))
AndySchroder commented 9 years ago

Hello,

You may want to test out my branch : https://github.com/AndySchroder/python-refprop

My branch and BenThelen's are diverged a bit I believe. I'm not sure how much. Everything is working for what I have been doing, so there isn't much of a need for me to see what improvements BenThelen has made.

I am using ubuntu 13.04 and 14.04.1, and I do not have any issues running the command

python -c "import rptest;rptest.settest('refprop')"

I don't think I have made any modifications to python-refprop from what is in my repository listed above.

I am using the python2x version. I have no idea if the python3x version works because I've never needed to try it.

Curious to know if my branch works for you or not.

ghost commented 9 years ago

I realized that I should run rp2so to setup the BenThelen/python-refprop module rather than compile it myself. But I get the following test error, I am not sure if this is a bug? Should I report it in a new issue?:

In [6]: rptest.settest('refprop')
---------------------------------------------------------------------------
RefpropnormalizeError                     Traceback (most recent call last)
<ipython-input-6-f1d28732ebde> in <module>()
----> 1 rptest.settest('refprop')

/home/vagrant/refprop/python-refprop/python2.7/rptest.pyc in settest(test)
     20     if test == u'refprop':
     21         import refprop as rp
---> 22         _maintest(rp)
     23     elif test == u'multiRP':
     24         import multiRP as rp

/home/vagrant/refprop/python-refprop/python2.7/rptest.pyc in _maintest(rp)
     30     rp.SetErrorDebug.off() #turn on =>> for testing purpose
     31
---> 32     if rp.test(): #if True; rptest =>>for testing purpose
     33         print u'refprop installed correctely'
     34

/home/vagrant/refprop/python-refprop/python2.7/refprop.pyc in test(criteria)
   1101     prop = flsh(u'td', 150, 200 / wmix, x)
   1102     Dliq = prop[u'Dliq']
-> 1103     wmix = wmol(prop[u'xliq'])[u'wmix']
   1104     testresult += u'check Liquid Density of Methane / Ethane / Propane / Butane'
   1105     truefalse = printresults(481.276038325628, Dliq * wmix, truefalse)

/home/vagrant/refprop/python-refprop/python2.7/refprop.pyc in wmol(x)
   4600     output (as function value):
   4601         wmix--molar mass [g/mol], a.k.a. "molecular weight'''
-> 4602     _inputerrorcheck(locals())
   4603     for each in xrange(len(x)): _x[each] = x[each]
   4604

/home/vagrant/refprop/python-refprop/python2.7/refprop.pyc in _inputerrorcheck(deflocals)
    547                 if sum(value) != 1:
    548                     raise RefpropnormalizeError(u'sum input value '
--> 549                                                  + key + u'is unequal to 1')
    550         elif key in checklist:
    551             if not type(value) == list:

RefpropnormalizeError: u'sum input value xis unequal to 1'
> /home/vagrant/refprop/python-refprop/python2.7/refprop.py(549)_inputerrorcheck()
    548                     raise RefpropnormalizeError(u'sum input value '
--> 549                                                  + key + u'is unequal to 1')
    550         elif key in checklist:

ipdb> sum(value)
0.9999999999999999
ipdb>

I am still using

Ubuntu 14.04 TLS 64bit
refprop 9.0

And during the installation of, the following warning was produced:

......
processing /usr/local/lib/refprop/mixtures/R504.MIX
processing /usr/local/lib/refprop/mixtures/R508A.MIX
processing /usr/local/lib/refprop/mixtures/R508B.MIX
processing /usr/local/lib/refprop/mixtures/R509A.MIX
processing /usr/local/lib/refprop/mixtures/R510A.MIX
--- Applying common file fix ---
Can't rename /usr/local/lib/refprop/FOR/COMMONS.f /usr/local/lib/refprop/FOR/COMMONS.include: No such file or directory
Can't rename /usr/local/lib/refprop/FOR/COMTRN.f /usr/local/lib/refprop/FOR/COMTRN.include: No such file or directory
--- Creating shared object file ---
/usr/local/lib/refprop/FOR/UTILITY.f:1213.72:

          if (ABS(iprnterr).ge.3)  pause
                                                                        1
Warning: Deleted feature: PAUSE statement at (1)
--- Installing object file ---

Note: If you want to display ported commands, type:
nm /usr/local/lib/librefprop.so
ghost commented 9 years ago

@AndySchroder Thanks a lot! I just tested your module, it works for refprop, but multiRP failed

vagrant@vagrant-ubuntu-trusty-64:~/refprop/new/python-refprop/python2x$ python -c "import rptest;rptest.settest('refprop');rptest.settest('multiRP')">a.txt
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "rptest.py", line 22, in settest
    _maintest(rp)
  File "rptest.py", line 192, in _maintest
    print rp.sate(45000, x), u'\n'
  File "multiRP.py", line 681, in sate
    return _rpfunc_handler(prop, mRP, _rpfunc)
  File "multiRP.py", line 287, in _rpfunc_handler
    return _rpfunc()
  File "multiRP.py", line 680, in _rpfunc
    return refprop.sate(e, x, kph)
  File "refprop.py", line 3550, in sate
    herr = _herr.value, defname = defname)
  File "refprop.py", line 619, in _prop
    _outputierrcheck(prop[u'ierr'], prop[u'herr'], prop[u'defname'], prop)
  File "refprop.py", line 733, in _outputierrcheck
    raise RefpropdllError(herr.decode(u'utf-8'))
refprop.RefpropdllError: u'[SATE error 162] iteration for saturation state did not converge for both roots; e = 45000. J/mol'
AndySchroder commented 9 years ago

Actually, I don't normally use multiRP, but I just ran the command you have listed above and I am getting the same error. That looks like a refprop bug/error and not a configuration error on your end. I have cases where refprop can not get a solution, but I'm not sure why the test program has a case selected that refprop doesn't work with. In cases where refprop has problems like this converging, it seems to me like it is usually sensitive to the independent variables that you choose. A workaround I usually use is to pre-populate some tables using other independent variable combinations (making the problem independent variable now a dependent variable while pre-populating) and then interpolate instead.

ghost commented 9 years ago

@AndySchroder Thanks for your reply. I just copied your version of python_refprop to my windows 8.1 and run it under ipython with python 2.7.6, run the command below and compare the output with linux version

ipython -c "import rptest;rptest.settest('refprop');rptest.settest('multiRP')">b.txt

b.txt is generated successfully. I copied b.txt to linux

dos2unix b.txt
diff a.txt b.txt > c.txt
vim -O a.txt b.txt

Use those command to find differences

:diffthis
Ctrl+w l
:diffthis

a lot of differences!!!

I think maybe there are some compiler differences between Intel's Compiler and GCC.

AndySchroder commented 9 years ago

Hello,

I'm not exactly sure why, but the e-mail I received includes your differences, but then the text above on this web page seems to be slightly different and not include the DIFF. Did you edit it? Anyway, I have no idea what the "preos" means. Maybe there is a compiler difference, I'm not sure.

Honestly, I don't know much about how the python refprop works, nor refprop in general. It seemed like luck that I got this working for what I needed. Although the efforts of BenThelen and others who have gotten this together and working for linux have been spectacular, I'm honestly considering changing over to "cool prop" (http://coolprop.sourceforge.net/). Have you looked into it? When I originally got started with everything, cool prop lacked a few features that I needed that refprop had. Refprop is still "working" for me, so I haven't had the push to switch, but I'm preparing for it. Coolprop is free, open source, and has a very active developement team. They seem focused on making these kinds of interfaces standard and integrated into their tool, for many programing languages. With refprop, the people at NIST charge for it, they are working on an archaeic fortran codebase, and they have no concern to make these kinds of useful interfaces available on a variety of platforms and languages. It's up to great memebers of the volunteer community like BenThelen to make it happen, but here is a limit to what they can do efficiently since everyone is at the mercy of NIST. Because refprop is not free, there is a limit to how many people can even test out interfaces like this one and help to make it better.

Coolprop does actually also have an optional interface to use and compile refprop from within it. I haven't personally tried it, but I imagine it works because they have a lot of benchmark comparisons with it. They also use the refprop interface in coolprop to do some things (like mixtures) that cool prop does not yet support (last time I checked, but they could have made all the same functionality work by now). I'm curious to hear your experience with cool prop and if it is any better than refprop. I've briefly tried it, but have not done any in depth analysis or performance or accuracy benchmarks.

ghost commented 9 years ago

@AndySchroder ,thanks a lot

I am just familiar with refprop rather than coolprop, I'll look into coolprop in the future. I do not use it to do cycle analysis, I am studying hydrocarbon fuel's thermodynamic behavior in supercritical conditions. There is few data in this field. I thought refprop is made by NIST and maybe it is better. Though the programming is so bad in its source code. I used NIST 4, the supertrapp, a legacy code. The programming style is the same as refprop. And the cross-programming is more difficult.

p.s. I just found out the best way to do DIFF is vim -d a.txt b.txt diff

AndySchroder commented 9 years ago

No problem. Sorry I couldn't have been more help, but my above comment pretty much explains my perspective.

Also, I think the title of this original issue may be a complete mistake? I don't think BenThelen's work has anything to do with jowr's work, does it?

I am curious what you are doing with supercritical fuel studies, if you are interested in sharing. If so, but you don't want to continue discussion about your work on this website, you can contact me directly using my contact infromation that can be found at: http://andyschroder.com/contact/ .

AndySchroder commented 9 years ago

Also, I'm not sure if this issue should be closed or not. You may want to get BenThelen's oppinion, but I'm guessing it is dependent upon fixing the REFPROP source code, which is not really included in this project.

ghost commented 9 years ago

@AndySchroder Yes, I think you are right, the title is a complete mistake. And it should be closed. This issue is caused by my misunderstanding of the readme of python_refprop module. I thought I need to compile librefprop.so myself. So I used Jowr's work, but I used BenThelen's test. And it failed.

When I looked into the rp2so file, I found that it is used to compile librefprop.so. I do not need to use Jowr's work anymore...

Then the problem became a version issue. I should use ver 0.2 with refprop 9.0. But I got a RefpropnormalizeError. This problem may be caused by machine error or compiler incompatibility.

Then I used your version of python_refprop. It works fine with refprop 9.0, but multiRP went wrong in linux.

I think this issue should be closed.