usnistgov / REFPROP-wrappers

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

Calculating Vapor Liquid Equilibrium (VLE) of binary mixtures in REFPROP 10 in python #552

Closed Darz2 closed 1 year ago

Darz2 commented 1 year ago

Hi, I am using the REFRPROP 10 via python to calculate the phase diagram of the binary mixture, I was able to create the TP diagram using the code shown below:

1) This is how I loaded my REFPROP

      import os
      from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary
      os.environ['RPPREFIX'] = r'C:/Program Files (x86)/REFPROP_10'
      RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
      RP.SETPATHdll(os.environ['RPPREFIX'])
      MOLAR_BASE_SI = RP.GETENUMdll(0, "MOLAR BASE SI").iEnum
      RP.RPVersion()
      '10.0'

2) Following that I used GERG 2008 model

      RP.GERG08dll(1,1)
      GERG08dlloutput(ierr=0, herr='')

3) I used the SATSPLNdll routine to calculate the phase diagram (TP) for a binary mixture

   # 1st mixture
   RP.SETFLUIDSdll('CO2 * N2')
   RP.SATSPLNdll([0.95,0.05])
   nc = 2 # two component
   rhomolarmin = RP.SPLNVALdll(nc+1, -1, 0).f
   rhomolarmax = RP.SPLNVALdll(nc+1, -2, 0).f

   Nnodes = RP.REFPROPdll("","SPLINENODES","",0,0,0,0,0,[0.95,0.05]).iUCode
   iT = nc+1
   iP = nc+2
   iD = nc+3
   iH = nc+4
   iS = nc+5

   data1 = []
   for rho in np.geomspace(rhomolarmin, rhomolarmax, 1000000):
     T,p,rho_eq,h,s = [RP.SPLNVALdll(k, 0, rho).f for k in [iT, iP, iD, iH, iS]]
     data1.append(dict(rho_vap=rho_eq, T=T-273, p=p/100))

Likewise I did the same for other mixture and finally plotted them image

Now, my question is how do I plot the pressure composition (p-x) diagram for the mixture, like the plot I get in the REFPROP GUI . Is there any specific routine to calculate the pressure and composition of the mixtures ?

ianhbell commented 1 year ago

Well, p-x coordinates are only available for binary mixtures. You have a couple of options for p-x. One is just do a whole lot of bubble-point and dew point calculations and hope that the calculations all converge. The calculations are not reliable near critical points for instance.

Alternatively, you can use the isochoric tracing technique with this library in Python: https://github.com/usnistgov/isochoric .

Or you can convert all the fluid files to teqp format and use the nicer interface of teqp: https://teqp.readthedocs.io/en/latest/algorithms/VLE.html#Tracing-(isobars-and-isotherms)

It all comes down to how much work you want to do. And what more you need to do with the results.

Darz2 commented 1 year ago

Many Thanks!