CoolProp: CoolProp can't load REFPROP v10 mixtures on Debian 9
Description
Corresponding REFPROP-cmake repo issue thread
I am installing REFPROP v10 and Python CoolProp v6.3.0 inside a docker container. To build REFPROP, I’m using Ian Bell’s cmake repo. The build executes successfully and I am able to use REFPROP through CoolProp in Python, but only for pure fluids. I am able to use mixtures if I run commands from the /opt/refprop
folder where I have copied the REFPROP files, but nowhere else. Setting the ALTERNATIVE_REFPROP_PATH
using CP.set_config_string(CP.ALTERNATIVE_REFPROP_LIBRARY_PATH, '/opt/refprop/')
does not solve my issue.
Contents of my local Dockerfile:
FROM python:3.7 as build
# Install dependencies needed to build C extensions
RUN apt-get -y -m update && \
apt-get install -y cmake g++ gfortran python-pip python3-dev
RUN pip install numpy six
WORKDIR /usr/local/refprop
# Copy in the refprop repo for building
COPY . .
# Make the default refprop location
RUN mkdir /opt/refprop
# Set path
ENV LD_LIBRARY_PATH="/opt/refprop:/usr/local/lib:$LD_LIBRARY_PATH"
ENV PATH="/opt/refprop:$PATH"
ENV RPPREFIX="/opt/refprop:/usr/local/lib:$RPPREFIX"
WORKDIR /usr/local/refprop/build
RUN cmake .. -DREFPROP_FORTRAN_PATH=/usr/local/refprop/files/fortran -DCMAKE_BUILD_TYPE=Release && \
cmake --build .
# copy files to the default refprop locations
COPY files/fluids /opt/refprop/fluids/
COPY files/mixtures /opt/refprop/mixtures/
RUN cp -r /usr/local/refprop/build/librefprop.so /opt/refprop/librefprop.so
RUN cp -r /usr/local/refprop/build/librefprop.so /usr/local/lib/librefprop.so
WORKDIR /usr/local/refprop/
# Used for testing, doesn't hurt anything except image size
RUN pip install coolprop
Steps to Reproduce
- Recursively clone the NIST REFPROP cmake repo: https://github.com/usnistgov/REFPROP-cmake
- Copy above Dockerfile to repo root
- Make a
files
folder in repo root - Copy
FORTRAN
,MIXTURES
,FLUIDS
REFPROP folders intofiles/
as lowercase directories (FORTRAN
-->fortran
) - run
docker build -t refprop .
from the repo root - Once build is completed, run
docker run -it refprop bash
to shell into the docker container - From /usr/local/refprop, open python
root@b050b185315f:/usr/local/refprop£ python
Python 3.7.2 (default, Dec 29 2018, 07:16:08)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import CoolProp.CoolProp as CP
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::R407A.MIX")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "CoolProp/CoolProp.pyx", line 347, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 427, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 314, in CoolProp.CoolProp.__Props_err2
ValueError: Initialize failed for backend: "REFPROP", fluid: "R407A.MIX" fractions "[ 1.0000000000 ]"; error: Unable to load mixture: R407A.MIX : PropsSI("H","P",100000,"T",300,"REFPROP::R407A.MIX")
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::water")
112653.67968889134
>>> CP.set_config_string(CP.ALTERNATIVE_REFPROP_LIBRARY_PATH, '/opt/refprop/')
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::R407A.MIX")
Good news: It is possible to use REFPROP on your system! However, the library
could not be loaded. Please make sure that REFPROP is available on your system.
Neither found in current location nor found in system PATH.
If you already obtained a copy of REFPROP from http://www.nist.gov/srd/,
add location of REFPROP to the PATH environment variable or your library path.
In case you do not use Windows, have a look at https://github.com/jowr/librefprop.so
to find instructions on how to compile your own version of the REFPROP library.
ALTERNATIVE_REFPROP_PATH:
ERROR: Could not load REFPROP (/opt/refprop/) due to: /opt/refprop/: cannot read file data: Is a directory. Make sure the library is in your system search path. In case you run 64bit Windows and you have a REFPROP license, try installing the 64bit DLL from NIST.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "CoolProp/CoolProp.pyx", line 347, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 427, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 314, in CoolProp.CoolProp.__Props_err2
ValueError: Initialize failed for backend: "REFPROP", fluid: "R407A.MIX" fractions "[ 1.0000000000 ]"; error: You cannot use the REFPROPMixtureBackend. : PropsSI("H","P",100000,"T",300,"REFPROP::R407A.MIX")
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::water")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "CoolProp/CoolProp.pyx", line 347, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 427, in CoolProp.CoolProp.PropsSI
File "CoolProp/CoolProp.pyx", line 314, in CoolProp.CoolProp.__Props_err2
ValueError: Initialize failed for backend: "REFPROP", fluid: "water" fractions "[ 1.0000000000 ]"; error: You cannot use the REFPROPMixtureBackend. : PropsSI("H","P",100000,"T",300,"REFPROP::water")
- Run Python from the refprop folder:
cd /opt/refprop && python
to see CoolProp work inside the REFPROP folder for both fluids and mixtures.
root@b050b185315f:/usr/local/refprop£ cd /opt/refprop/ && python
Python 3.7.2 (default, Dec 29 2018, 07:16:08)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import CoolProp.CoolProp as CP
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::water")
112653.67968889134
>>> CP.PropsSI("H", "P", 1e5, "T", 300, "REFPROP::R407A.MIX")
428158.16100957023
Expected behavior:
CoolProp should have access to both pure and mixture REFPROP backends, not just pure fluids.
Actual behavior:
CoolProp only has access to mixture REFPROP backends when commands are run from the /opt/refprop
folder where the mixtures
REFPROP folder is.
Versions
CoolProp Version: Python v6.3.0 Operating System and Version: Debian GNU/Linux 9 (stretch) (docker container: https://github.com/docker-library/python/blob/34c9df35e9a69e9f0edde88e861b543edb8bc07a/3.7/stretch/Dockerfile) Access Method: Python3.7
Additional Information
If possible, please post examples and/or screenshots of the issue.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 18 (13 by maintainers)
A warning… you are now entering the danger zone. On most platforms, the same library can only be loaded once into a process, and calls to this library all call the same chunk of memory, the source of some very surprising behaviors. While your solution should work, a better solution is to wait for REFPROP to fix this bug. In the meantime, your solution should work. I don’t remember why we went away in CoolProp from also calling SETPATHdll when a different path was specified, but I think it was to work around a different path-related bug.
No - when you specify “R410A”, that is an alias to “R410A.PPF”, not “R410A.MIX”; note the values that are returned in my code above. In my opinion, this is a bug in REFPROP, but this is for historical reasons, and unlikely to change. In either case, if ‘REFPROP’ is specified as backend, it still uses REFPROP to do the calculations.
It’s a REFPROP bug. REFPROP does not load the fluid files correctly when an absolute path to the mixture file is provided. In this case, you’ll need to specify the mole fractions directly, that should still “work”, but that’s not a nice workaround.