CoolProp icon indicating copy to clipboard operation
CoolProp copied to clipboard

Unexpected exception when calling viscosity via PropsSI for mixture

Open andr1976 opened this issue 4 years ago • 8 comments

Description

ValueError: PropsSI failed ungracefully :: inputs were:"V","P",2.0000000000000000e+07,"T",2.5000000000000000e+02,"HEOS::CO2[0.01]&N2[0.1]&Methane[0.796]&Ethane[0.057]&Propane[0.02]&n-Butane[0.005]&IsoButane[0.005]&n-Pentane[0.002]&Isopentane[0.002]&n-Hexane[0.001]&n-Heptane[0.001]&n-Octane[0.001]"; please file a ticket at https://github.com/CoolProp/CoolProp/issues

[Description of the issue]

Steps to Reproduce

from CoolProp.CoolProp import PropsSI

T = 250
P = 200e5
fluid_str = 'HEOS::CO2[0.01]&N2[0.1]&Methane[0.796]&Ethane[0.057]&Propane[0.02]&n-Butane[0.005]&IsoButane[0.005]&n-Pentane[0.002]&Isopentane[0.002]&n-Hexane[0.001]&n-Heptane[0.001]&n-Octane[0.001]'

D = PropsSI("V","P",P,"T",T,fluid_str)

Trying with

>>> D = PropsSI("V","P|gas",P,"T",T,fluid_str)

Traceback (most recent call last):
  File "c:\Users\ANRA\Downloads\methane-ethane.py", line 21, in <module>
    D = PropsSI("V","P|gas",P,"T",T,fluid_str)
  File "CoolProp\CoolProp.pyx", line 377, in CoolProp.CoolProp.PropsSI
  File "CoolProp\CoolProp.pyx", line 457, in CoolProp.CoolProp.PropsSI
  File "CoolProp\CoolProp.pyx", line 344, in CoolProp.CoolProp.__Props_err2
ValueError: solver_rho_Tp was unable to find a solution for T=       250, p=     2e+07, with guess value    13694.6 with error: The molar density of -9660.938367 mol/m3 
is below the minimum of 0.000000 mol/m3 : PropsSI("V","P|gas",20000000,"T",250,"HEOS::CO2[0.01]&N2[0.1]&Methane[0.796]&Ethane[0.057]&Propane[0.02]&n-Butane[0.005]&IsoButane[0.005]&n-Pentane[0.002]&Isopentane[0.002]&n-Hexane[0.001]&n-Heptane[0.001]&n-Octane[0.001]") 

Expected behavior: [What you expect to happen] A value for viscosity

Actual behavior: [What actually happens] Exception

Versions

CoolProp Version: 6.4.1 Operating System and Version: [OS you are running CoolProp on] Win 10 x64 Access Method: [How you are accessing CoolProp (i.e. Python, other wrapper, direct C++ calls, etc.)] Python 3.8

andr1976 avatar Jan 22 '22 15:01 andr1976

What about density as an output? Does that work? That is the first step in such a calculation.

ibell avatar Jan 23 '22 22:01 ibell

Density is fine 283.086 kg/m3

D = PropsSI("D","P",P,"T",T,fluid_str)

When calling via the low-level interface i get nan for viscosity

import CoolProp.CoolProp as CP
from CoolProp.CoolProp import PropsSI
import numpy as np

HEOS = CP.AbstractState('HEOS','CO2&N2&Methane&Ethane&Propane&n-Butane&IsoButane&n-Pentane&Isopentane&n-Hexane&n-Heptane&n-Octane')
x = np.asarray([0.01, 0.1,0.796,0.057,0.02,0.005,0.005,0.002,0.002,0.001,0.001,0.001])
x = x/x.sum()
T = 250.0
P = 200.0e5

HEOS.set_mole_fractions(x)
HEOS.update(CP.PT_INPUTS,  P, T)
print(HEOS.viscosity())

viscosity is nan

andr1976 avatar Jan 23 '22 22:01 andr1976

First off, the way that mixture viscosity is handled in CoolProp is not very good. But that is not related to this error. I have no idea why it occurs, a bit of debugging in C++ is probably required.

ibell avatar Jan 24 '22 04:01 ibell

Hi, is there any update on this issue? I get the same error as this using a similar gas mix. The error seems to occur when the viscosity is greater than 2e-5 Pa.s. For all p,T combinations that give viscosity below this, it works fine. @ibell

sci-sjj avatar Mar 18 '24 02:03 sci-sjj

I don't know. As I said above, you should not use the mixture viscosity methods in CoolProp. They are essentially just placeholders.

ibell avatar Mar 19 '24 01:03 ibell

HI @ibell OK thank you - can you elaborate on why these are not suitable? How about using the mixture viscosity models with REFPROP through CoolProp?

sci-sjj avatar Mar 19 '24 02:03 sci-sjj

I am tempted to just purchase REFPROP and call this through CoolProp; this is a reasonable approach for mixture viscosities @ibell ?

sci-sjj avatar Mar 20 '24 03:03 sci-sjj

Yes REFPROP is your best bet here

ibell avatar Mar 21 '24 23:03 ibell