usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
190 stars 127 forks source link

Example case for multicomponent (liquid and vapor) 2 fluids mixture for REFPROP 10 #39

Closed aqeelahmed168 closed 6 years ago

aqeelahmed168 commented 6 years ago

Hi,

I am trying to study a mixture of Dodecane and Nitrogen. From the graphical user interface I am able to extract the saturation states as a fucntion of mole fraction and pressure. Please see attached files. I would like to use Python to get the same data. nDodecaneNitrogenPx.pdf nDodecaneNitrogen0.5_0.5.pdf

I started with the example of a mixture setup as psuedo-pure fluid. My inputs are T and P so this works well for single phase. However, I am looking for mixture where "Dodecane" could exist as vapor or liquid, while Nitrogen is always vapor for my conditions. Could you please produce an example case for such a system.

import ctREFPROP.ctREFPROP as ct
import os
import numpy as np
import matplotlib.pyplot as plt

os.environ['RPPREFIX'] = r'C:\Program Files (x86)\REFPROP'
root = os.environ['RPPREFIX']
print("RP installation dir: ", root)
r = ct.REFPROPFunctionLibrary(os.path.join(root, 'REFPRP64.dll'))
r.SETPATHdll(root)
print("RP version: ", r.RPVersion())

z = [0.5, 0.5]
T = 344.4 # K

P = 30e6 # Pa
kph = 2 # phase flag: 1 for liquid, 2 for vapor

# r.SETMODdll(2,'EOS','HMX','FEQ')

print('Using DODECANE.FLD|NITROGEN.FLD mixture')
print(r.SETUPdll(2, 'DODECANE.FLD|NITROGEN.FLD', 'HMX.BNC', 'DEF'))
rho_mol_L = (r.TPRHOdll(T, P/1e3, z, kph, kguess = 0, D = -1)).D
print('TP rho call : ', r.TPRHOdll(T, P/1e3, z, kph, kguess = 0, D = -1))
print('Build the spline : ', r.SATSPLNdll(z))
WM = r.WMOLdll(z)
print("Molar Mass [g/mol]: ", WM)
print("Molar Density [mol/L]: ", rho_mol_L)
print("Density [kg/m^3]: ", rho_mol_L*WM)
print('Critical Conditions : ', r.CRITPdll(z))
print('Saturation Conditions at T =',  T,  'K :' , r.SATTdll(T, z, kph))
print('Saturation Conditions at P =',  P/1e6,  'MPa :' , r.SATPdll(P/1e3, z, kph))

T_list = np.linspace(303,503,11)
print("Size of T", len(T_list))
rho_list = np.zeros_like(T_list)

for i in range(0,len(T_list)):
    rho_list[i] = (r.TPRHOdll(T_list[i], P/1e3, z, kph, kguess = 0, D = -1)).D
    rho_list[i] *= WM

print("rho_list",rho_list)
plt.plot(T_list,rho_list)
plt.show()

There is an example for two-phase system in REFPROP.xls file provided in the installation directory. How can I use a call in excel via Python, meaning what is the corresponding call in Python. Forexample, in excel for two phase system the call for mixture density at bubble point is REPFROP('D', 'mixture', 'Pliq', 'SI', 0.1325) what is the equivalent call in Python.

Lastly, is there any way to obtain the critical locus for the mixture as a function of pressure and mol fraction of each fluid, as reported in this paper [1] Figure 4.

[1] García-Córdova et al. Vapor-liquid equilibrium data for the nitrogen + dodecane system at temperatures from (344 to 593) K and at pressures up to 60 MPa

ianhbell commented 6 years ago
  1. To get the saturated liquid density for an equimolar mixture I would recommend that you do:
    units = RP.GETENUMdll("DEFAULT").iEnum
    RP.REFPROPdll("Dodecane * nitrogen","PQ","D",units,0,0,101.325,0,[0.5,0.5])
  2. To get the critical locus, you should consider doing something like:
    for z0 in np.linspace(0,1):
    RP.REFPROPdll("Dodecane * nitrogen","","PC;TC;DC;",units,0,1,101.325,0,[z0,1-z0])

    The 1 turns on the saturation splines

Does that answer your questions?

aqeelahmed168 commented 6 years ago

Thanks for the response.

I will explain here again. I have given pressure P, temperature T, and mole fraction of Dodecane x. In a mixture of Dodecane and Nitrogen, I would like to predict the density of final mixture, where I also want to compute the state of final mixture either it is liquid or vapor or two-phase. Also if it is two phase, how much vapor of Dodecane is present in the whole mixture and how much is the Dodecane liquid.

From you previous reply:

  1. Regarding first input
units = r.GETENUMdll("DEFAULT").iEnum # this does not work
units = r.GETENUMdll(0,"DEFAULT").iEnum # this works
  1. The critical locus works. However, if I decrease the interval of mole fraction increment, it gives strange results.
z0 = np.linspace(0,1,100) # 100 points works, 500 points fails
t = np.zeros((len(z0),3))

for i in range(0,len(z0)):
    RP_Prop = r.REFPROPdll("Dodecane * nitrogen","","PC;TC;DC;",units,0,1,101.325,0,[z0[i],1-z0[i]])
    t[i,:] = RP_Prop.Output[0:3]

# print(t)

plt.plot(z0,t[:,0])
plt.figure()
plt.plot(z0,t[:,1])
plt.figure()
plt.plot(t[:,1],t[:,0], "+-")
ianhbell commented 6 years ago
  1. Yes, that was a typo on my side.

  2. This mixture is not Type I, I believe. That is why you do not have a continuous critical line between pure fluid endpoints. See for instance my paper in FPE: https://www.sciencedirect.com/science/article/pii/S0378381216305349 . In the future, please copy-paste the entire script, rather than just a snippet. Otherwise, you have done a good job of specifying your question.

  3. With regards to your question, here it is:

import ctREFPROP.ctREFPROP as ct
import os

os.environ['RPPREFIX'] = r'D:\REFPROP'
root = os.environ['RPPREFIX']
r = ct.REFPROPFunctionLibrary(os.path.join(root, 'REFPRP64.dll'))
r.SETPATHdll(root)

units = r.GETENUMdll(0,'DEFAULT').iEnum
o = r.REFPROPdll("Dodecane * nitrogen","TP","D;Qmole",units,0,0,300,101.325,[0.4, 0.6])
print(o)

with

 Output=[0.06732759598608312, 0.5997394529521832, ....

The density is 0.067327 mol/L and the vapor quality (on a molar basis) is 0.6(ish). Therefore, two-phase.

aqeelahmed168 commented 6 years ago

Thanks for the support.

  1. Yes, the mixture is of Type-III. I have compared the results obtained with REFPROP and the experimental data. Even the points predicted by REFPROF does not conform to the experimental data. Is this the limitation of REFPROP that it cannot predict such behaviour?

I have uploaded the experimental data. criticalLocusDodecanN2_Exp.txt

import ctREFPROP.ctREFPROP as ct
import os
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

os.environ['RPPREFIX'] = r'C:\Program Files (x86)\REFPROP'
root = os.environ['RPPREFIX']
print("RP installation dir: ", root)
r = ct.REFPROPFunctionLibrary(os.path.join(root, 'REFPRP64.dll'))
r.SETPATHdll(root)
print("RP version: ", r.RPVersion())

units = r.GETENUMdll(0,"DEFAULT").iEnum

def getCriticalStates(noOfPoints):
    z0 = np.linspace(0,1,noOfPoints)
    t = np.zeros((len(z0),3))
    for i in range(0,len(z0)):
        RP_Prop = r.REFPROPdll("Dodecane * nitrogen","","PC;TC;DC;",units,0,1,101.325,0,[z0[i],1-z0[i]])
        t[i,:] = RP_Prop.Output[0:3]
    return z0, t

z0, t = getCriticalStates(190)

print("Experimental data from [García-Córdova et al., 2011]")
data = pd.read_csv('criticalLocusDodecanN2_Exp.txt', delimiter='\t', skiprows=0, usecols=(0,1,2))
data.columns = ["Critical Temperature [K]", "Critical Pressure [MPa]", "Mole Fraction N2 [-]"]
print(data)

plt.figure()
plt.plot(t[:,1],t[:,0]*1e3/1e6, "+-", label="REFPROP")
plt.plot(data.iloc[:,0].values, data.iloc[:,1].values, "or", label="Exp")
plt.legend()
plt.xlim(100,700)
plt.xlabel("Temperature [K]")
plt.ylabel("Pressure [MPa]")
plt.legend()
plt.savefig("CriticalLocus_N2Dodecane.png")
plt.show()
ianhbell commented 6 years ago

Can you please insert the figure?

aqeelahmed168 commented 6 years ago

criticallocus_n2dodecane

ianhbell commented 6 years ago

Nice figure! Yes, our interaction parameters for this mixture clearly miss the critical locus. This is a sad reality for many mixtures in REFPROP. If you wanted to help fit a new departure function that did this better, we could help you do that. Asymmetric mixtures like these are tricky to get right.

aqeelahmed168 commented 6 years ago

Thanks. I am quite new to this mixture thermodynamics. If you can suggest some literature I can work on that. Just for reference in this paper [2] Fig 6, PR-EOS combined with mixing rules, does seem to predict the critical locus, still not perfectly.

[2] Daniel T. Banuti et al. Phase separation analysis in supercritical injection using large-eddy simulation and vapor-liquid equilibrium

ianhbell commented 6 years ago

In short, mixtures are complicated, and critical loci, even more so :) So do not feel overwhelmed and take things slowly. PR does in general a pretty ok job with some mixtures like this (see, again, my paper in FPE).

aqeelahmed168 commented 6 years ago

Thanks for the tip. Have a good day.

ianhbell commented 6 years ago

If I have (sort of) answered your question, can you please close this issue?