CoolProp / CoolProp

Thermophysical properties for the masses
http://coolprop.org/
MIT License
782 stars 307 forks source link

Error at pmax for methane #1657

Closed ghost closed 6 years ago

ghost commented 6 years ago

I am getting the following error (also reported in #107 ) at the dew point calculation [=HEOS.update(CP.PT_INPUTS, P, T)] while computing chemical potential of methane. The P, T values for which it's failing are the maximum allowed pressure for methane (=1000 MPa) and 318 K. This 1000 MPa pressure value is estimated using P_max string input in PropsSI at the same temperature. I am using the maximum allowed pressure to find the maximum allowable density of methane, which I assume will be for the maximum allowed pressure for methane (@ 1000 MPa). If I change the gas to 'CO2' and keep the other values to be same then I don't get this error.

ValueError: Inputs in Brent [4787.840987,34206.787162] do not bracket the root. Function values are [-0.988841,-0.126030]

I am not sure what I am doing wrong, but the only place I can think where I might be going wrong is the way I am estimating the maximum fluid density. I am trying to replicate the maximum fluid density from a refprop command where it is computed as refprop.limitx(x, htype='EOS', t=T, D=0, p=0)['Dmax']. I didn't find an analogous command in CoolProp to estimate the maximum fluid density, so I am using the following commands to find maximum fluid density:

#------ maximum pressure allowed for CH4
p_max = CP.CoolProp.PropsSI('P_max', 'CH4')

#------ calculate maximum density
d = CP.CoolProp.PropsSI('Dmolar', 'T', 318, 'P', p_max, 'CH4')

Basically, to calculate the chemical potential I then convert the density to pressure, which in the case of maximum density turns out to be 1000 MPa that throws an error in dew point calculation as described above.

I would appreciate your help in figuring out if I am doing something wrong.

ibell commented 6 years ago

That's not a dew point calculation that you are doing - it is a homogenous phase flash calculation with T,P as inputs. Can you please provide a complete, runnable example demonstrating the problem? Also show the error you get.

What REFPROP does to calculate the density limit for a mixture is actually just a weighted average of the values for the pure fluids, which is usually (approximately) the saturated liquid density at the triple-point. You could do the same in CoolProp!

You don't need to do the flash from TP to T,D in order to calculate the chemical potential (which is equal to the molar Gibbs energy). You could in principle do something like

d = CP.CoolProp.PropsSI('Gmolar', 'T', 318, 'P', p_max, 'CH4')

On Thu, Mar 1, 2018 at 12:35 PM, L4student notifications@github.com wrote:

I am getting the error following error (also reported in #107 https://github.com/CoolProp/CoolProp/issues/107 ) at the dew point calculation [=HEOS.update(CP.PT_INPUTS, P, T)] while computing chemical potential of methane. The P, T values for which it's failing are the maximum allowed pressure for methane (=1000 MPa) and 318 K. This 1000 MPa pressure value is estimated using P_max string input in PropsSI at the same temperature. I am using the maximum allowed pressure to find the maximum allowable density of methane, which I assume will be for the maximum allowed pressure for methane (@ 1000 MPa). If I change the gas to 'CO2' and keep the other values to be same then I don't get this error.

ValueError: Inputs in Brent [4787.840987,34206.787162] do not bracket the root. Function values are [-0.988841,-0.126030]

I am not sure what I am doing wrong, but the only place I can think where I might be going wrong is the way I am estimating the maximum fluid density. I am trying to replicate the maximum fluid density from a refprop command where it is computed as refprop.limitx(x, htype='EOS', t=T, D=0, p=0)['Dmax']. I didn't find an analogous command in CoolProp to estimate the maximum fluid density, so I am using the following commands to find maximum fluid density:

------ maximum pressure allowed for CH4

p_max = CP.CoolProp.PropsSI('P_max', 'CH4')

------ calculate maximum density

d = CP.CoolProp.PropsSI('Dmolar', 'T', 318, 'P', p_max, 'CH4')

Basically, to calculate the chemical potential I then convert the density to pressure, which in the case of maximum density turns out to be 1000 MPa that throws an error in dew point calculation as described above.

I would appreciate your help in figuring out if I am doing something wrong.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CoolProp/CoolProp/issues/1657, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxha-rZt22IZclGvCCqDnd7_ESjNbEuks5taE2IgaJpZM4SY3uJ .

ghost commented 6 years ago

Dear Ian @ibell Please find the runnable example demonstrating the problem as shown below:

import CoolProp as CP

#------ maximum pressure allowed for CH4
p_max = CP.CoolProp.PropsSI('P_max', 'CH4')

#------ calculate maximum density
d = CP.CoolProp.PropsSI('Dmolar', 'T', 318, 'P', p_max, 'CH4')

#------ set a mixture of methane and CO2
HEOS = CP.AbstractState("HEOS", "CH4&CO2")

#------ set mole fractions of the mixture
HEOS.set_mole_fractions([1, 0])

#------ convert density to pressure
P = CP.CoolProp.PropsSI('P', 'Dmolar', d, 'T', 318, 'CH4')

#------ do homogenous phase flash calculation
HEOS.update(CP.PT_INPUTS, P, 318)

#------ retrieve chemical potential of i-th component of mixture
mu_CH4 =  HEOS.chemical_potential(0)

I get the following error on running the above code:

  File "<ipython-input-20-ad3008b98862>", line 19, in <module>
    HEOS.update(CP.PT_INPUTS, P, 318)

  File "CoolProp\AbstractState.pyx", line 90, in CoolProp.CoolProp.AbstractState.update (CoolProp\CoolProp.cpp:17921)

  File "CoolProp\AbstractState.pyx", line 92, in CoolProp.CoolProp.AbstractState.update (CoolProp\CoolProp.cpp:17813)

ValueError: Inputs in Brent [4787.840987,34206.787162] do not bracket the root.  Function values are [-0.988852,-0.126425]

It throws this error in both Windows and Linux OS, although I don't think that's an issue.

ibell commented 6 years ago

What exactly are you trying to do? From your code there are parts that are for a mixture, and parts that are for the pure fluid. Flash calculations for mixtures in CoolProp are not totally reliable. Someone else, not me, needs to update the mixture calculations.

You should know that CoolProp does not currently support mixtures with mole fractions of zero, though this is not well-documented.

On Thu, Mar 1, 2018 at 8:17 PM, L4student notifications@github.com wrote:

Dear Ian @ibell https://github.com/ibell Please find the runnable example demonstrating the problem as shown below:

import CoolProp as CP

------ maximum pressure allowed for CH4

p_max = CP.CoolProp.PropsSI('P_max', 'CH4')

------ calculate maximum density

d = CP.CoolProp.PropsSI('Dmolar', 'T', 318, 'P', p_max, 'CH4')

------ set a mixture of methane and CO2

HEOS = CP.AbstractState("HEOS", "CH4&CO2")

------ set mole fractions of the mixture

HEOS.set_mole_fractions([1, 0])

------ convert density to pressure

P = CP.CoolProp.PropsSI('P', 'Dmolar', d, 'T', 318, 'CH4')

------ do homogenous phase flash calculation

HEOS.update(CP.PT_INPUTS, P, 318)

------ retrieve chemical potential of i-th component of mixture

mu_CO2 = HEOS.chemical_potential(0)

I get the following error on running the above code:

File "", line 19, in HEOS.update(CP.PT_INPUTS, P, 318)

File "CoolProp\AbstractState.pyx", line 90, in CoolProp.CoolProp.AbstractState.update (CoolProp\CoolProp.cpp:17921)

File "CoolProp\AbstractState.pyx", line 92, in CoolProp.CoolProp.AbstractState.update (CoolProp\CoolProp.cpp:17813)

ValueError: Inputs in Brent [4787.840987,34206.787162] do not bracket the root. Function values are [-0.988852,-0.126425]

It throws this error in both Windows and Linux OS, although I don't think that's an issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CoolProp/CoolProp/issues/1657#issuecomment-369807794, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxha90NBE1PLp7V9WTL2j3zjrFGbnBlks5taLmzgaJpZM4SY3uJ .

ghost commented 6 years ago

How can I calculate for a single/pure component? I tried it be keeping just 'CH4', but the place where I get an error (=kernel died) is HEOS.chemical_potential(0). I had mentioned this in another issue, but you didn't suggest what the problem is. I think you suggested that it may work after you did some changes to the code, so should I update the CoolProp again using pip? I didn't compile it from source using git.

ghost commented 6 years ago

@ibell : I tried updating coolprop using pip, but it says it's up-to-date. I tried calculating chemical potential for a pure component, but it still gives me the Kernel died, restarting error as discussed in #1653 .

ghost commented 6 years ago

Dear @ianhbell : Your suggestion to compute chemical potential using d = CP.CoolProp.PropsSI('Gmolar', 'T', 318, 'P', P, 'CH4') works even at p_max. So, I am using this as an alternative and have overcome the above error with this command. Thanks for the help.