CP.PropsSI('d(P)/d(Dmass)|T','T',T,'Dmass',Dmass_vector,fluid)
383 virtual void calc_build_spinodal(){ throw NotImplementedError("calc_build_spinodal is not implemented for this backend"); };384 virtual SpinodalData calc_get_spinodal_data(){ throw NotImplementedError("calc_get_spinodal_data is not implemented for this backend"); };
finding the first inflection from each side of the saturation curve.
finding the first read zero crossing from each side of the saturation curve.
from CoolProp import CoolProp as CP
from matplotlib import pyplot as plt
import numpy as np
# Phase envelope
HEOS = CP.AbstractState('HelmholtzEOSMixtureBackend','R134a')
HEOS.build_phase_envelope('dummy')
p_e = HEOS.get_phase_envelope_data()
plt.plot(p_e.T,np.divide(p_e.p,1e6))
plt.xlabel('$T$ (K)')
plt.ylabel('$P$ (MPa)')
# Spinodal
HEOS.build_spinodal()
from CoolProp import CoolProp as CP
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
fluidA = 'n-Decane'
fluidB = 'n-Dodecane'
# Pure fluid A phase envelope
HEOS = CP.AbstractState('HEOS','{}'.format(fluidA))
HEOS.build_phase_envelope('dummy')
binodal = HEOS.get_phase_envelope_data()
molar_mass = HEOS.molar_mass()
ax.plot(np.multiply(binodal.rhomolar_liq,molar_mass),np.zeros(len(binodal.T)),binodal.T,'k')
# Mixtures
HEOS = CP.AbstractState('HelmholtzEOSMixtureBackend','{}&{}'.format(fluidA,fluidB))
tol = 1e-3
fluidB_mole_fractions = np.linspace(tol,1-tol,25)
# Mixture phase envelope and spinodal
for i in range(0,len(fluidB_mole_fractions)):
fluidB_mole_fraction = fluidB_mole_fractions[i]
fluidA_mole_fraction = 1-fluidB_mole_fraction
HEOS.set_mole_fractions([fluidA_mole_fraction,fluidB_mole_fraction])
molar_mass = HEOS.molar_mass()
HEOS.build_phase_envelope('dummy')
binodal = HEOS.get_phase_envelope_data()
ax.plot(np.multiply(binodal.rhomolar_liq,molar_mass),fluidB_mole_fraction*np.ones(len(binodal.T)),binodal.T,'k',label='Binodal')
ax.plot(np.multiply(binodal.rhomolar_vap,molar_mass),fluidB_mole_fraction*np.ones(len(binodal.T)),binodal.T,'k')
HEOS.build_spinodal()
spinodal = HEOS.get_spinodal_data()
ax.plot(np.multiply(spinodal.delta,HEOS.rhomolar_reducing())*molar_mass,fluidB_mole_fraction*np.ones(len(spinodal.tau)),np.multiply(np.power(spinodal.tau,-1),HEOS.T_reducing()),'k--',label='Spinodal')
Axes3D.set_xlabel(ax,xlabel='Density (kg/m$^3$)')
Axes3D.set_ylabel(ax,ylabel='{} mole fraction'.format(fluidB))
Axes3D.set_zlabel(ax,zlabel='$T$ (K)')
handles,labels = ax.get_legend_handles_labels()
ax.legend(handles[0:2],labels[0:2])
--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
Visit this group at https://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.
https://doi.org/10.1134/S0036024406040030--
You received this message because you are subscribed to a topic in the Google Groups "coolprop-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/coolprop-users/prZVxyKzH0o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.
Dear all, thanks a lot for Coolprop, it is an amazing tool!.
I am trying to calculate the Spinodal line for low pressures < 100 kg/m3 in the vapor region for a methane carbon dioxide mixture, nevertheless I can´t use the command HEOS.build_spinodal() because it can't get the data for low pressures. Attached you will find the curves of the Spinodal data obtained using the code of Nick Mason-Smith (Thanks for the code), as you can see in the plot, it is not possible to obtain a low pressure Spinodal curve.
I have tried to do something with python and the scipy.optimize module to find the place where the partial derivative of the pressure and volume becomes zero, I have obtained some results but I am not sure if the data obtained corresponds to the vapor Spinodal curve, because I don´t know if there are several roots in the region above the binodal curve. Attached will find a plot with the Binodal and Spinodal data (spinodal_binodal.png), obtained with this code, for a mixture of 50% Methane, 50% carbon dioxide.
import CoolProp as cp
import scipy.optimize as optimize
import numpy as np
import math
import matplotlib.pyplot as plt
Tmin =200 #Minimum temperature [K]
x0 = 0.5 #Carbon dioxide molar fraction
F= 'Methane&CarbonDioxide' #Fluid String
F2='HEOS::Methane['+str(1-x0)+']&CarbonDioxide['+str(x0)+']' #Fluid String High Level Interface
"Binodal Line construction using CoolProp"
HEOS = cp.AbstractState('HelmholtzEOSMixtureBackend',F)
HEOS.set_mole_fractions([1-x0,x0])
molar_mass = HEOS.molar_mass()
HEOS.build_phase_envelope('dummy')
binodal = HEOS.get_phase_envelope_data()
Tmax=math.floor(max(binodal.T)) # Max temp
n= Tmax-Tmin #Number of data
P = np.zeros((n,1))
psat = np.zeros((n,1))
rho = np.zeros((n,1))
T=np.zeros((n,1))
for dt in range(0,n):
try:
psat[dt,0]=cp.CoolProp.PropsSI('P','T',Tmin+dt,'Q',1,F2)*0.6
T[dt,0]=Tmin+dt
def spinodal(R):
P[dt,0]=R
HEOS=cp.AbstractState("HEOS", F)
HEOS.set_mole_fractions([1-x0,x0])
HEOS.update(cp.PT_INPUTS,P[dt,0],T[dt,0])
rho[dt,0]=HEOS.rhomass()
return (HEOS.first_partial_deriv(cp.iP, cp.iDmass, cp.iT)/rho[dt,0]**2)
P[dt,0]=(optimize.fsolve(spinodal,psat[dt,0],xtol=1e-04,maxfev=1000))
except ValueError as VE:
print(VE)
My questions are:
I am doing something wrong with CoolProp? I should obtain the Spinodal curve for low pressures with the HEOS.build_spinodal() command?
The roots that I find with fsolve, corresponds to the Spinodal curve?
Thanks a lot for your help!!
Kind regards from Brazil.
Julián.
--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.
Thanks a lot Ian! I will start to work with it.
Have a good day!