Correction d'une faute d'orthographe
[memoirecycle.git] / refprop.py
blob6af32fba0ea4a370e76ad2863f0283a9b186b6d9
1 ## REFPROP8 library
2 ## Bruce Wernick
3 ## info@coolit.co.za
4 ## Last updated: 6 August 2010
5 ## Updated to be used with linux : 6 August 2011
7 #-------------------------------------------------------------------------------
8 # temperature K
9 # pressure, fugacity kPa
10 # density mol/L
11 # composition mole fraction
12 # quality mole basis
13 # enthalpy, internal energy J/mol
14 # Gibbs, Helmholtz free energy J/mol
15 # entropy, heat capacity J/(mol-K)
16 # speed of sound m/s
17 # Joule-Thompson coefficient K/kPa
18 # d(p)/d(rho) kPa-L/mol
19 # d2(p)/d(rho)2 kPa-(L/mol)2
20 # viscosity uPa-s
21 # thermal conductivity W/(m-K)
22 # dipole moment debye
23 # surface tension N/m
24 #-------------------------------------------------------------------------------
26 from ctypes import *
27 import os
30 ###################### OS ADD ###############################
31 dirname = 'REFPROP/'
33 class RPWrapper:
34 def __init__(self, rp):
35 self.rp=rp
36 def __getattr__(self,n):
37 return self.rp.__getattr__(n.lower()+"_")
40 if os.name == "posix":
41 rp=RPWrapper(cdll.LoadLibrary(dirname+"fortran/librefprop.so.1.0.1"))
42 elif os.name == "nt":
43 rp=windll.LoadLibrary(dirname+"refprop.dll")
44 else:
45 print "sorry your operating system is not convenient with this version of UCycLe using REFPROP"
47 ####################### END OS ADD ############################
49 k0=273.15
50 MaxComps=20
51 fpath= dirname
52 fldpath=fpath+'fluids/'
53 mixpath=fpath+'mixtures/'
54 hfld=create_string_buffer('', 10000)
55 hfm=create_string_buffer(fpath+'fluids/hmx.bnc', 255)
56 hrf=create_string_buffer('DEF', 3)
57 hfile=create_string_buffer('', 10000)
58 htype=create_string_buffer('NBS', 3)
59 hmix=create_string_buffer('NBS', 3)
60 hcomp=create_string_buffer('NBS', 3)
61 ierr=c_long(0)
62 herr=create_string_buffer('', 255)
63 hname=create_string_buffer('', 12)
64 hn80=create_string_buffer('', 80)
65 hcas=create_string_buffer('', 12)
66 nc=c_long(1)
67 wm=c_double()
68 x=(c_double*MaxComps)(1)
69 xl=(c_double*MaxComps)()
70 xv=(c_double*MaxComps)()
71 xlkg=(c_double*MaxComps)()
72 xvkg=(c_double*MaxComps)()
74 #####################################################
75 # -- INITIALIZATION SUBROUTINES --
76 #####################################################
77 def SETPATH(value = dirname):
78 '''set path to refprop root containing fluids and mixtures'''
79 global fpath, fldpath, mixpath
80 fpath=value
81 fldpath= fpath +'fluids/'
82 mixpath= fpath +'mixtures/'
84 def SETUP(FluidName='R22.FLD', FluidRef='DEF'):
85 '''define models and initialize arrays'''
86 global ierr,herr
87 global nc,hfld,hfm,hrf,wm
88 nc.value=1
89 hfld.value=fldpath+FluidName
90 hrf.value=FluidRef
91 rp.SETUPdll(byref(nc),byref(hfld),byref(hfm),byref(hrf),byref(ierr),byref(herr),c_long(10000),c_long(255),c_long(3),c_long(255))
92 if ierr.value==0:
93 ixflag=c_long(1)
94 h0,s0,t0,p0=c_double(0),c_double(0),c_double(0),c_double(0)
95 rp.SETREFdll(byref(hrf),byref(ixflag),x,byref(h0),byref(s0),byref(t0),byref(p0),byref(ierr),byref(herr),c_long(3),c_long(255))
96 if ierr.value==0:
97 rp.WMOLdll(x,byref(wm))
98 return
100 def SETMIX(FluidName='R404A.MIX', FluidRef='DEF'):
101 '''open a mixture file and read constituents and mole fractions'''
102 global ierr,herr
103 global x,nc,hfld,hfm,hrf,hfile
104 hfld.value=mixpath+FluidName
105 hrf.value=FluidRef
106 rp.SETMIXdll(byref(hfld),byref(hfm),byref(hrf),byref(nc),byref(hfile),x,byref(ierr),byref(herr),c_long(255),c_long(255),c_long(3),c_long(10000),c_long(255))
107 if ierr.value==0:
108 ixflag=c_long(0)
109 h0,s0,t0,p0=c_double(0),c_double(0),c_double(0),c_double(0)
110 rp.SETREFdll(byref(hrf),byref(ixflag),x,byref(h0),byref(s0),byref(t0),byref(p0),byref(ierr),byref(herr),c_long(3),c_long(255))
111 if ierr.value==0:
112 rp.WMOLdll(x,byref(wm))
113 return
115 def SETREF(FluidRef='DEF', ixflag=1, h0=0, s0=0, t0=0, p0=0):
116 '''set reference state enthalpy and entropy'''
117 global ierr,herr
118 global hrf
119 hrf.value=FluidRef
120 ixflag=c_long(ixflag)
121 h0,s0,t0,p0=c_double(h0),c_double(s0),c_double(t0),c_double(p0)
122 rp.SETREFdll(byref(hrf),byref(ixflag),x,byref(h0),byref(s0),byref(t0),byref(p0),byref(ierr),byref(herr),c_long(3),c_long(255))
123 return
125 def SETMOD(ncomps=1, EqnModel='NBS', MixModel='NBS', CompModel='NBS'):
126 '''set model(s) other than the NIST-recommended (NBS) ones'''
127 global ierr,herr
128 global nc,htype,hmix,hcomp
129 nc.value=ncomps
130 htype.value=EqnModel
131 hmix.value=MixModel
132 hcomp.value=CompModel
133 rp.SETMODdll(byref(nc),byref(htype),byref(hmix),byref(hcomp),byref(ierr),byref(herr),c_long(3),c_long(3),c_long(3),c_long(255))
134 return
136 def PUREFLD(icomp=0):
137 '''Change the standard mixture setup so that the properties of one fluid can
138 be calculated as if SETUP had been called for a pure fluid'''
139 icomp=c_long(icomp)
140 rp.PUREFLDdll(byref(icomp))
141 return
143 def CRITP():
144 '''critical parameters'''
145 global ierr,herr
146 tcrit=c_double()
147 pcrit=c_double()
148 Dcrit=c_double()
149 rp.CRITPdll(x,byref(tcrit),byref(pcrit),byref(Dcrit),byref(ierr),byref(herr),c_long(255))
150 return tcrit.value,pcrit.value,Dcrit.value
152 def THERM(t,D):
153 '''thermal quantities as a function of temperature and density'''
154 t=c_double(t)
155 D=c_double(D)
156 p=c_double()
157 e,h,s=c_double(),c_double(),c_double()
158 cv,cp=c_double(),c_double()
159 w=c_double()
160 hjt=c_double()
161 rp.THERMdll(byref(t),byref(D),x,byref(p),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(hjt))
162 return p.value,e.value,h.value,s.value,cv.value,cp.value,w.value,hjt.value
164 def THERM0(t,D):
165 '''ideal gas thermal quantities as a function of temperature and density'''
166 t=c_double(t)
167 D=c_double(D)
168 p=c_double()
169 e,h,s=c_double(),c_double(),c_double()
170 cv,cp=c_double(),c_double()
171 w=c_double()
172 a,g=c_double(),c_double()
173 rp.THERM0dll(byref(t),byref(D),x,byref(p),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(a),byref(g))
174 return p.value,e.value,h.value,s.value,cv.value,cp.value,w.value,a.value,g.value
176 def THERM2(t,D):
177 '''thermal quantities as a function of temperature and density'''
178 t=c_double(t)
179 D=c_double(D)
180 p=c_double()
181 e,h,s=c_double(),c_double(),c_double()
182 cv,cp=c_double(),c_double()
183 w,Z,hjt=c_double(),c_double(),c_double()
184 A,G=c_double(),c_double()
185 spare1,spare2=c_double(),c_double()
186 spare3,spare4=c_double(),c_double()
187 rp.THERM2dll(byref(t),byref(D),x,byref(p),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(Z),byref(hjt),byref(A),byref(G),byref(xkappa),byref(beta),byref(dPdD),byref(d2PdD2),byref(dPdT),byref(dDdT),byref(dDdP),byref(spare1),byref(spare2),byref(spare3),byref(spare4))
188 return t.value,D.value,p.value,e.value,h.value,s.value,cv.value,cp.value,w.value,Z.value,hjt.value,A.value,G.value,xkappa.value,beta.value,dPdD.value,d2PdD2.value,dPdT.value,dDdT.value,dDdP.value
190 def THERM3(t,D):
191 '''miscellaneous thermodynamic properties'''
192 t=c_double(t)
193 D=c_double(D)
194 xkappa=c_double()
195 beta=c_double()
196 xisenk=c_double()
197 xkt=c_double()
198 betas=c_double()
199 bs=c_double()
200 xkkt=c_double()
201 thrott=c_double()
202 pint=c_double()
203 spht=c_double()
204 rp.THERM3dll(byref(t),byref(D),x,byref(xkappa),byref(beta),byref(xisenk),byref(xkt),byref(betas),byref(bs),byref(xkkt),byref(thrott),byref(pint),byref(spht))
205 return xkappa,beta,xisenk,xkt,betas,bs,xkkt,thrott,pint,spht
207 def ENTRO(t,D):
208 '''entropy as a function of temperature and density'''
209 t=c_double(t)
210 D=c_double(D)
211 s=c_double()
212 rp.ENTROdll(byref(t),byref(D),x,byref(s))
213 return s.value
215 def ENTHAL(t,D):
216 '''enthalpy as a function of temperature and density'''
217 t=c_double(t)
218 D=c_double(D)
219 h=c_double()
220 rp.ENTHALdll(byref(t),byref(D),x,byref(h))
221 return h.value
223 def CVCP(t,D):
224 '''isochoric (constant volume) and isobaric (constant pressure) heat
225 capacity as functions of temperature and density'''
226 t=c_double(t)
227 D=c_double(D)
228 cv,cp=c_double(),c_double()
229 rp.CVCPdll(byref(t),byref(D),x,byref(cv),byref(cp))
230 return cv.value,cp.value
232 def CVCPK(icomp,t,D):
233 '''isochoric (constant volume) and isobaric (constant pressure) heat
234 capacity as functions of temperature and density for a given component'''
235 icomp=c_long(icomp)
236 t=c_double(t)
237 D=c_double(D)
238 cv,cp=c_double(),c_double()
239 rp.CVCPKdll(byref(icomp),byref(t),byref(D),byref(cv),byref(cp))
240 return cv.value,cp.value
242 def GIBBS(t,D):
243 '''residual Helmholtz and Gibbs free energy as a function of
244 temperature and density'''
245 t=c_double(t)
246 D=c_double(D)
247 Ar,Gr=c_double(),c_double()
248 rp.GIBBSdll(byref(t),byref(D),x,byref(Ar),byref(Gr))
249 return Ar.value,Gr.value
251 def AG(t,D):
252 '''Helmholtz and Gibbs energies as a function of temperature and density'''
253 t=c_double(t)
254 D=c_double(D)
255 a,g=c_double(),c_double()
256 rp.AGdll(byref(t),byref(D),x,byref(a),byref(g))
257 return a.value,g.value
259 def PRESS(t,D):
260 '''pressure as a function of temperature and density'''
261 t=c_double(t)
262 D=c_double(D)
263 p=c_double()
264 rp.PRESSdll(byref(t),byref(D),x,byref(p))
265 return p.value
267 def DPDD(t,D):
268 '''partial derivative of pressure w.r.t. density at constant temperature as a
269 function of temperature and density'''
270 t=c_double(t)
271 D=c_double(D)
272 dpdD=c_double()
273 rp.DPDDdll(byref(t),byref(D),x,byref(dpdD))
274 return dpdD.value
276 def DPDDK(icomp,t,D):
277 '''partial derivative of pressure w.r.t. density at constant temperature as a
278 function of temperature and density for a specified component'''
279 icomp=c_long(icomp)
280 t=c_double(t)
281 D=c_double(D)
282 dpdD=c_double()
283 rp.DPDDKdll(byref(icomp),byref(t),byref(D),byref(dpdD))
284 return dpdD.value
286 def DPDD2(t,D):
287 '''second partial derivative of pressure w.r.t. density at const temperature
288 as a function of temperature and density'''
289 t=c_double(t)
290 D=c_double(D)
291 d2PdD2=c_double()
292 rp.DPDD2dll(byref(t),byref(D),x,byref(d2PdD2))
293 return d2PdD2.value
295 def DPDT(t,D):
296 '''partial derivative of pressure w.r.t. temperature at constant density as a
297 function of temperature and density'''
298 t=c_double(t)
299 D=c_double(D)
300 dpt=c_double()
301 rp.DPDTdll(byref(t),byref(D),x,byref(dpt))
302 return dpt.value
304 def DPDTK(icomp,t,D):
305 '''partial derivative of pressure w.r.t. temperature at constant density as a
306 function of temperature and density for a specified component'''
307 icomp=c_long(icomp)
308 t=c_double(t)
309 D=c_double(D)
310 dpt=c_double()
311 rp.DPDTKdll(byref(icomp),byref(t),byref(D),byref(dpt))
312 return dpt.value
314 def DDDP(t,D):
315 '''partial derivative of density w.r.t. pressure at constant temperature as a
316 function of temperature and density'''
317 t=c_double(t)
318 D=c_double(D)
319 dDdp=c_double()
320 rp.DDDPdll(byref(t),byref(D),x,byref(dDdp))
321 return dDdp.value
323 def DDDT(t,D):
324 '''partial derivative of density w.r.t. temperature at constant pressure as a
325 function of temperature and density'''
326 t=c_double(t)
327 D=c_double(D)
328 dDdt=c_double()
329 rp.DDDTdll(byref(t),byref(D),x,byref(dDdt))
330 return dDdt.value
332 def DHD1(t,D):
333 '''partial derivatives of enthalpy w.r.t. t, p, or D at constant t, p, or D as
334 a function of temperature and density'''
335 t=c_double(t)
336 D=c_double(D)
337 dhdt_d=c_double()
338 dhdt_p=c_double()
339 dhdd_t=c_double()
340 dhdd_p=c_double()
341 dhdp_t=c_double()
342 dhdp_d=c_double()
343 rp.DHD1dll(byref(t),byref(D),x,byref(dhdt_d),byref(dhdt_p),byref(dhdd_t),byref(dhdd_p),byref(dhdp_t),byref(dhdp_d))
344 return dhdt_d.value,dhdt_p.value,dhdd_t.value,dhdd_p.value,dhdp_t.value,dhdp_d.value
346 def FGCTY(t,D):
347 '''fugacity for each of the nc components of a mixture by numerical
348 differentiation (using central differences) of the dimensionless residual
349 Helmholtz energy'''
350 t=c_double(t)
351 D=c_double(D)
352 f=(c_double*MaxComps)()
353 rp.FGCTYdll(byref(t),byref(D),x,f)
354 return f
356 def VIRB(t):
357 '''second virial coefficient as a function of temperature'''
358 t=c_double(t)
359 b=c_double()
360 rp.VIRBdll(byref(t),x,byref(b))
361 return b.value
363 def DBDT(t):
364 '''2nd derivative of B (B is the second virial coefficient) with respect to T
365 as a function of temperature'''
366 t=c_double(t)
367 b=c_double()
368 rp.DBDTdll(byref(t),x,byref(b))
369 return b.value
371 def VIRC(t):
372 '''third virial coefficient as a function of temperature'''
373 t=c_double(t)
374 c=c_double()
375 rp.VIRCdll(byref(t),x,byref(c))
376 return c.value
378 ######################## SAT
379 def SATT(t,kph=2):
380 '''iterate for saturated liquid and vapor states given temperature
381 kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint'''
382 global ierr,herr
383 global xl,xv
384 t=c_double(t)
385 kph=c_long(kph)
386 p=c_double()
387 Dl,Dv=c_double(),c_double()
388 rp.SATTdll(byref(t),x,byref(kph),byref(p),byref(Dl),byref(Dv),xl,xv,byref(ierr),byref(herr),c_long(255))
389 return p.value,Dl.value,Dv.value
391 def SATP(p,kph=2):
392 '''saturation temperature from pressure
393 kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint'''
394 global ierr,herr
395 global xl,xv
396 p=c_double(p)
397 kph=c_long(kph)
398 t=c_double()
399 Dl,Dv=c_double(),c_double()
400 rp.SATPdll(byref(p),x,byref(kph),byref(t),byref(Dl),byref(Dv),xl,xv,byref(ierr),byref(herr),c_long(255))
401 return t.value,Dl.value,Dv.value
403 def SATD(D,kph=1):
404 '''iterate for temperature and pressure given a density along the saturation boundary.
405 kph--flag specifying desired root for multi-valued inputs
406 (has meaning only for water at temperatures close to its triple point)
407 -1=middle root (between 0 and 4C), 1=return highest temperature root (above 4C), 3=lowest temperature root (along freezing line)'''
408 global ierr,herr
409 global xl,xv
410 D=c_double(D)
411 kph=c_long(kph)
412 kr=c_long()
413 p=c_double()
414 Dl,Dv=c_double(),c_double()
415 rp.SATDdll(byref(D),x,byref(kph),byref(kr),byref(t),byref(p),byref(Dl),byref(Dv),xl,xv,byref(ierr),byref(herr),c_long(255))
416 return kr.value,t.value,Dl.value,Dv.value
418 def SATH(h,kph=2):
419 '''iterate for temperature, pressure, and density given enthalpy along the saturation boundary
420 kph--flag specifying desired root
421 0 = all roots along the liquid-vapor line
422 1 = only liquid VLE root
423 2 = only vapor VLE roots
424 3 = liquid SLE root (melting line)
425 4 = vapor SVE root (sublimation line)'''
426 global ierr,herr
427 h=c_double(h)
428 kph=c_long(kph)
429 nroot=c_long()
430 k1,t1,p1,d1=c_double(),c_double(),c_double(),c_double()
431 k2,t2,p2,d2=c_double(),c_double(),c_double(),c_double()
432 rp.SATHdll(byref(h),x,byref(kph),byref(nroot),byref(k1),byref(t1),byref(p1),byref(d1),byref(k2),byref(t2),byref(p2),byref(d2),byref(ierr),byref(herr),c_long(255))
433 return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value
435 def SATE(e,kph=2):
436 '''iterate for temperature, pressure, and density given energy along the saturation boundary
437 kph--flag specifying desired root
438 0 = all roots along the liquid-vapor line
439 1 = only liquid VLE root
440 2 = only vapor VLE roots
441 3 = liquid SLE root (melting line)
442 4 = vapor SVE root (sublimation line)'''
443 global ierr,herr
444 e=c_double(e)
445 kph=c_long(kph)
446 nroot=c_long()
447 k1,t1,p1,d1=c_double(),c_double(),c_double(),c_double()
448 k2,t2,p2,d2=c_double(),c_double(),c_double(),c_double()
449 rp.SATEdll(byref(e),x,byref(kph),byref(nroot),byref(k1),byref(t1),byref(p1),byref(d1),byref(k2),byref(t2),byref(p2),byref(d2),byref(ierr),byref(herr),c_long(255))
450 return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value
452 def SATS(s,kph=2):
453 '''iterate for temperature, pressure, and density given an entropy along the saturation boundary
454 kph--flag specifying desired root
455 0 = all roots along the liquid-vapor line
456 1 = only liquid VLE root
457 2 = only vapor VLE roots
458 3 = liquid SLE root (melting line)
459 4 = vapor SVE root (sublimation line)
460 return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value,k3.value,t3.value,p3.value,d3.value'''
461 global ierr,herr
462 s=c_double(s)
463 kph=c_long(kph)
464 nroot=c_long()
465 k1,t1,p1,d1=c_double(),c_double(),c_double(),c_double()
466 k2,t2,p2,d2=c_double(),c_double(),c_double(),c_double()
467 k3,t3,p3,d3=c_double(),c_double(),c_double(),c_double()
468 rp.SATSdll(byref(s),x,byref(kph),byref(nroot),byref(k1),byref(t1),byref(p1),byref(d1),byref(k2),byref(t2),byref(p2),byref(d2),byref(k3),byref(t3),byref(p3),byref(d3),byref(ierr),byref(herr),c_long(255))
469 return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value,k3.value,t3.value,p3.value,d3.value
471 ######################## END SAT
473 def CSATK(icomp,t,kph=2):
474 '''heat capacity along the saturation line as a function of temperature for a given component
475 kph--flag specifying desired root
476 0 = all roots along the liquid-vapor line
477 1 = only liquid VLE root
478 2 = only vapor VLE roots
479 3 = liquid SLE root (melting line)
480 4 = vapor SVE root (sublimation line)'''
481 global ierr,herr
482 icomp=c_long(icomp)
483 t=c_double(t)
484 kph=c_long(kph)
485 p=c_double()
486 D=c_double()
487 csat=c_double()
488 rp.CSATKdll(byref(icomp),byref(t),byref(kph),byref(p),byref(D),byref(csat),byref(ierr),byref(herr),c_long(255))
489 return p.value,D.value,csat.value
491 def DPTSATK(icomp,t,kph=2):
492 '''heat capacity and dP/dT along the saturation line as a function of temperature for a given component
493 kph--flag specifying desired root
494 0 = all roots along the liquid-vapor line
495 1 = only liquid VLE root
496 2 = only vapor VLE roots
497 3 = liquid SLE root (melting line)
498 4 = vapor SVE root (sublimation line)'''
499 global ierr,herr
500 icomp=c_long(icomp)
501 t=c_double(t)
502 kph=c_long(kph)
503 p=c_double()
504 D=c_double()
505 csat=c_double()
506 dpt=c_double()
507 rp.DPTSATKdll(byref(icomp),byref(t),byref(kph),byref(p),byref(D),byref(csat),byref(dpt),byref(ierr),byref(herr),c_long(255))
508 return p.value,D.value,csat.value,dpt.value
510 def CV2PK(icomp,t,D):
511 '''isochoric heat capacity in the two phase (liquid+vapor) region'''
512 global ierr,herr
513 icomp=c_long(icomp)
514 t=c_double(t)
515 D=c_double(D)
516 cv2p,csat=c_double(),c_double()
517 rp.CV2PKdll(byref(icomp),byref(t),byref(D),byref(cv2p),byref(csat),byref(ierr),byref(herr),c_long(255))
518 return cv2p.value,csat.value
520 def TPRHO(t,p,kph=2,kguess=0,D=0):
521 '''iterate for density as a function of temperature, pressure, and composition for a specified phase
522 kph--phase flag: 1=liquid 2=vapor
523 NB: 0 = stable phase--NOT ALLOWED (use TPFLSH) (unless an initial guess is supplied for D)
524 -1 = force the search in the liquid phase
525 -2 = force the search in the vapor phase
526 kguess--input flag:
527 1 = first guess for D provided
528 0 = no first guess provided
529 D--first guess for molar density [mol/L], only if kguess=1'''
530 global ierr,herr
531 t=c_double(t)
532 p=c_double(p)
533 kph=c_long(kph)
534 kguess=c_long(kguess)
535 D=c_double(D)
536 rp.TPRHOdll(byref(t),byref(p),x,byref(kph),byref(kguess),byref(D),byref(ierr),byref(herr),c_long(255))
537 return D.value
539 #####################################################
540 # -- GENERAL FLASH SUBROUTINES --
541 #####################################################
543 def TPFLSH(t,p):
544 '''flash calculation given temperature and pressure'''
545 global ierr,herr
546 global xl,xv
547 t=c_double(t)
548 p=c_double(p)
549 D,Dl,Dv=c_double(),c_double(),c_double()
550 q,e,h,s=c_double(),c_double(),c_double(),c_double()
551 cv,cp=c_double(),c_double()
552 w=c_double()
553 rp.TPFLSHdll(byref(t),byref(p),x,byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
554 return D.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
556 def TDFLSH(t,D):
557 '''flash calculation given temperature and density'''
558 global ierr,herr
559 global xl,xv
560 t=c_double(t)
561 D=c_double(D)
562 p=c_double()
563 Dl,Dv=c_double(),c_double()
564 q,e,h,s=c_double(),c_double(),c_double(),c_double()
565 cv,cp=c_double(),c_double()
566 w=c_double()
567 rp.TDFLSHdll(byref(t),byref(D),x,byref(p),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
568 return p.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
570 def PDFLSH(p,D):
571 '''flash calculation given pressure and density'''
572 global ierr,herr
573 global xl,xv
574 p=c_double(p)
575 D=c_double(D)
576 t=c_double()
577 Dl,Dv=c_double(),c_double()
578 q,e,h,s=c_double(),c_double(),c_double(),c_double()
579 cv,cp=c_double(),c_double()
580 w=c_double()
581 rp.PDFLSHdll(byref(p),byref(D),x,byref(t),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
582 return t.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
584 def PHFLSH(p,h):
585 '''flash calculation given pressure and enthalpy'''
586 global ierr,herr
587 global xl,xv
588 p=c_double(p)
589 h=c_double(h)
590 t=c_double()
591 D,Dl,Dv=c_double(),c_double(),c_double()
592 q,e,s=c_double(),c_double(),c_double()
593 cv,cp=c_double(),c_double()
594 w=c_double()
595 rp.PHFLSHdll(byref(p),byref(h),x,byref(t),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
596 return t.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
598 def PSFLSH(p,s):
599 '''flash calculation given pressure and entropy'''
600 global ierr,herr
601 p=c_double(p)
602 s=c_double(s)
603 t=c_double()
604 D,Dl,Dv=c_double(),c_double(),c_double()
605 q,e,h=c_double(),c_double(),c_double()
606 cv,cp=c_double(),c_double()
607 w=c_double()
608 rp.PSFLSHdll(byref(p),byref(s),x,byref(t),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
609 return t.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
611 def PEFLSH(p,e):
612 '''flash calculation given pressure and energy'''
613 global ierr,herr
614 p=c_double(p)
615 e=c_double(e)
616 t=c_double()
617 D,Dl,Dv=c_double(),c_double(),c_double()
618 q,s,h=c_double(),c_double(),c_double()
619 cv,cp=c_double(),c_double()
620 w=c_double()
621 rp.PEFLSHdll(byref(p),byref(e),x,byref(t),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
622 return t.value,D.value,Dl.value,Dv.value,q.value,h.value,s.value,cv.value,cp.value,w.value
624 def THFLSH(t,h,kr=1):
625 '''flash calculation given temperature and enthalpy'''
626 global ierr,herr
627 kr=c_long(kr)
628 t=c_double(t)
629 h=c_double(h)
630 p=c_double()
631 D,Dl,Dv=c_double(),c_double(),c_double()
632 q,e,s=c_double(),c_double(),c_double()
633 cv,cp=c_double(),c_double()
634 w=c_double()
635 rp.THFLSHdll(byref(t),byref(h),x,byref(kr),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
636 return p.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
638 def TSFLSH(t,s,kr=1):
639 '''flash calculation given temperature and entropy
640 kr--phase flag:
641 1=liquid,
642 2=vapor in equilibrium with liq,
643 3=liquid in equilibrium with solid,
644 4=vapor in equilibrium with solid'''
645 global ierr,herr
646 global xl,xv
647 t=c_double(t)
648 s=c_double(s)
649 kr=c_long(kr)
650 p=c_double()
651 D,Dl,Dv=c_double(),c_double(),c_double()
652 q,e,h=c_double(),c_double(),c_double()
653 cv,cp=c_double(),c_double()
654 w=c_double()
655 rp.TSFLSHdll(byref(t),byref(s),x,byref(kr),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
656 return p.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
658 def TEFLSH(t,e,kr=1):
659 '''flash calculation given temperature and energy'''
660 global ierr,herr
661 t=c_double(t)
662 e=c_double(e)
663 kr=c_long(kr)
664 p=c_double()
665 D,Dl,Dv=c_double(),c_double(),c_double()
666 q,h,s=c_double(),c_double(),c_double()
667 cv,cp=c_double(),c_double()
668 w = c_double()
669 rp.TEFLSHdll(byref(t),byref(e),x,byref(kr),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
670 return kr.value,p.value,D.value,Dl.value,Dv.value,q.value,h.value,s.value,cv.value,cp.value,w.value
672 def DHFLSH(D,h):
673 '''flash calculation given density and enthalpy'''
674 global ierr,herr
675 D=c_double(D)
676 h=c_double(h)
677 t,p=c_double(),c_double()
678 Dl,Dv=c_double(),c_double()
679 q,e,s=c_double(),c_double(),c_double()
680 cv,cp=c_double(),c_double()
681 w=c_double()
682 rp.DHFLSHdll(byref(D),byref(h),x,byref(t),byref(p),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
683 return t.value,p.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
685 def DSFLSH(D,s):
686 '''flash calculation given density and entropy'''
687 global ierr,herr
688 D=c_double(D)
689 s=c_double(s)
690 t,p=c_double(),c_double()
691 Dl,Dv=c_double(),c_double()
692 q,e,h=c_double(),c_double(),c_double()
693 cv,cp=c_double(),c_double()
694 w=c_double()
695 rp.DSFLSHdll(byref(D),byref(s),x,byref(t),byref(p),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(h),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
696 return t.value,p.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
698 def DEFLSH(D,e):
699 '''flash calculation given density and energy'''
700 global ierr,herr
701 D=c_double(D)
702 e=c_double(e)
703 t,p=c_double(),c_double()
704 Dl,Dv=c_double(),c_double()
705 q,h,s=c_double(),c_double(),c_double()
706 cv,cp=c_double(),c_double()
707 w=c_double()
708 rp.DEFLSHdll(byref(D),byref(e),x,byref(t),byref(p),byref(Dl),byref(Dv),xl,xv,byref(q),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
709 return t.value,p.value,Dl.value,Dv.value,q.value,h.value,s.value,cv.value,cp.value,w.value
711 def HSFLSH(h,s):
712 '''flash calculation given enthalpy and entropy'''
713 global ierr,herr
714 h=c_double(h)
715 s=c_double(s)
716 t,p=c_double(),c_double()
717 D,Dl,Dv=c_double(),c_double(),c_double()
718 q,e=c_double(),c_double()
719 cv,cp=c_double(),c_double()
720 w=c_double()
721 rp.HSFLSHdll(byref(h),byref(s),x,byref(t),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(e),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
722 return t.value,p.value,D.value,Dl.value,Dv.value,q.value,e.value,cv.value,cp.value,w.value
724 def ESFLSH(e,s):
725 '''flash calculation given energy and entropy'''
726 global ierr,herr
727 e=c_double(e)
728 s=c_double(s)
729 t,p=c_double(),c_double()
730 D,Dl,Dv=c_double(),c_double(),c_double()
731 q,h=c_double(),c_double()
732 cv,cp=c_double(),c_double()
733 w=c_double()
734 rp.ESFLSHdll(byref(e),byref(s),x,byref(t),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(q),byref(h),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
735 return t.value,p.value,D.value,Dl.value,Dv.value,q.value,h.value,cv.value,cp.value,w.value
737 def TQFLSH(t,q):
738 '''flash calculation given temperature and quality'''
739 global ierr,herr,xl,xv
740 t=c_double(t)
741 q=c_double(q)
742 kq=c_long()
743 p=c_double()
744 D,Dl,Dv=c_double(),c_double(),c_double()
745 e,h,s=c_double(),c_double(),c_double()
746 cv,cp=c_double(),c_double()
747 w=c_double()
748 rp.TQFLSHdll(byref(t),byref(q),x,byref(kq),byref(p),byref(D),byref(Dl),byref(Dv),xl,xv,byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
749 return kq.value,p.value,D.value,Dl.value,Dv.value,e.value,h.value,s.value,cv.value,cp.value,w.value
750 #Correction Gauth : xh en xv a 748 + ajout du xv dans les parametres globals carle 10 eme parametre est composition of vapor phase
752 def PQFLSH(p,q,kq):
753 '''flash calculation given pressure and quality'''
754 global ierr,herr
755 p=c_double(p)
756 q=c_double(q)
757 kq=c_long(kq)
758 t=c_double()
759 D,Dl,Dv=c_double(),c_double(),c_double()
760 e,h,s=c_double(),c_double(),c_double()
761 cv,cp=c_double(),c_double()
762 w=c_double()
763 rp.PQFLSHdll(byref(p),byref(q),x,byref(kq),byref(t),byref(D),byref(Dl),byref(Dv),xl,xv,byref(e),byref(h),byref(s),byref(cv),byref(cp),byref(w),byref(ierr),byref(herr),c_long(255))
764 return kq.value,t.value,D.value,Dl.value,Dv.value,e.value,h.value,s.value,cv.value,cp.value,w.value
767 #### END FLASH > MANON
770 def CCRIT(t,p,v):
771 '''critical flow factor, C*, for nozzle flow of a gas'''
772 global ierr,herr
773 t=c_double(t)
774 p=c_double(p)
775 v=c_double(v)
776 cs,ts,Ds,ps,ws=c_double(),c_double(),c_double(),c_double(),c_double()
777 rp.CCRITdll(byref(t),byref(p),byref(v),x,byref(cs),byref(ts),byref(Ds),byref(ps),byref(ws),byref(ierr),byref(herr),c_long(255))
778 return cs.value,ts.value,Ds.value,ps.value,ws.value
780 def FPV(t,D,p):
781 '''supercompressibility factor, Fpv'''
782 t=c_double(t)
783 D=c_double(D)
784 p=c_double(p)
785 f=c_double()
786 rp.FPVdll(byref(t),byref(D),byref(p),x,byref(f))
787 return f.value
789 def CP0(t):
790 '''mixture Cp0 calculated by appropriate core CP0xxx routine(s)'''
791 t=c_double(t)
792 cp=c_double()
793 rp.CP0dll(byref(t),x,byref(cp))
794 return cp.value
796 def TRNPRP(t,D):
797 '''transport properties of thermal conductivity and
798 viscosity as functions of temperature and density
799 eta--viscosity (uPa.s)
800 tcx--thermal conductivity (W/m.K)'''
801 global ierr,herr
802 t=c_double(t)
803 D=c_double(D)
804 eta,tcx=c_double(),c_double()
805 rp.TRNPRPdll(byref(t),byref(D),x,byref(eta),byref(tcx),byref(ierr),byref(herr),c_long(255))
806 return eta.value,tcx.value
808 def INFO(icomp=1):
809 'provides fluid constants for specified component'
810 icomp=c_long(icomp)
811 wmm=c_double()
812 ttrp,tnbpt,tc=c_double(),c_double(),c_double()
813 pc=c_double()
814 Dc=c_double()
815 Zc,acf,dip=c_double(),c_double(),c_double()
816 Rgas=c_double()
817 rp.INFOdll(byref(icomp),byref(wmm),byref(ttrp),byref(tnbpt),byref(tc),byref(pc),byref(Dc),byref(Zc),byref(acf),byref(dip),byref(Rgas))
818 return wmm.value,ttrp.value,tnbpt.value,tc.value,pc.value,Dc.value,Zc.value,acf.value,dip.value,Rgas.value
820 def GETHEADER(fluid):
821 '''read and interpret text at head of FLD file'''
822 def gets():
823 s=f.readline()
824 if '!' in s:
825 lhs,rhs=s.split('!')
826 lhs=lhs.strip()
827 rhs=rhs.strip()
828 else:
829 lhs=s.strip()
830 rhs=''
831 return lhs,rhs
832 H={}
833 #f=open(fldpath+fluid+'.fld', 'r') # changed for UCyCle
834 f = open(fldpath+fluid, 'r')
835 H['shortname'],rhs=gets()
836 H['casnum'],rhs=gets()
837 H['fullname'],rhs=gets()
838 H['chemform'],rhs=gets()
839 H['synonym'],rhs=gets() # R-Number
840 H['mw'],rhs=gets()
841 H['ttp'],rhs=gets()
842 H['tnbp'],rhs=gets()
843 H['tc'],rhs=gets()
844 H['pc'],rhs=gets()
845 H['dc'],rhs=gets()
846 H['accen'],rhs=gets()
847 H['dip'],rhs=gets()
848 lhs,rhs=gets()
849 H['ref']=lhs
850 if lhs[0:2].lower()=='ot':
851 H['ref']='OTH' ## not sure why some fluids have OT0
852 lhs,rhs=gets()
853 a=lhs.split()
854 H['tphs']=a[0]+','+a[1]+','+a[2]+','+a[3]
855 H['ver'],rhs=gets()
856 lhs,rhs=gets()
857 if rhs[0:2].lower()=='un':
858 H['unnum']=lhs
859 lhs,rhs=gets()
860 else:
861 H['unnum']=''
862 H['family']=lhs
863 H['comps']=1
864 f.close()
865 return H
867 def GETMIXHEADER(mix):
868 H={}
869 f=open(mixpath+mix, 'r')
870 s=f.readline().strip()
871 H['shortname']=s
872 H['casnum']=''
873 H['fullname']=s
874 H['synonym']=s
875 H['ref']=''
876 H['family']=''
877 s=f.readline()
878 a=s.split()
879 H['mw']=a[0]
880 H['tc']=a[1]
881 H['pc']=a[2]
882 H['dc']=a[3]
883 nc=int(f.readline().strip())
884 H['comps']=nc
885 # read component names
886 chemform=[]
887 for i in range(nc):
888 lhs,rhs=f.readline().strip().split('.')
889 chemform.append(lhs)
890 H['chemform']=chemform
891 # read proportions
892 for i in range(nc):
893 s=f.readline().strip()
894 f.close()
895 return H
897 def NAME(icomp):
898 global hname, hn80, hcas
899 icomp=c_long(icomp)
900 rp.NAMEdll(byref(icomp),byref(hname),byref(hn80),byref(hcas),c_long(12),c_long(80),c_long(12))
901 lhs,rhs=hn80.value.split('!')
902 lhs=lhs.strip()
903 return hname.value.strip(),lhs,hcas.value.strip()
905 def XMASS(xmol):
906 rp.XMASSdll(xmol,xkg,byref(wmix))
907 return wmix.value
909 def XMOLE(xkg):
910 rp.XMOLEdll(xkg,xmol,byref(wmix))
911 return wmix.value
913 def LIMITX(htyp='EOS',t=0,D=0,p=0):
914 global ierr,herr
915 htyp=create_string_buffer(htyp, 3)
916 t=c_double(t)
917 D=c_double(D)
918 p=c_double(p)
919 tmin,tmax,Dmax,pmax=c_double(),c_double(),c_double(),c_double()
920 rp.LIMITXdll(byref(htyp),byref(t),byref(D),byref(p),x,byref(tmin),byref(tmax),byref(Dmax),byref(pmax),byref(ierr),byref(herr),c_long(3),c_long(255))
921 return tmin.value,tmax.value,Dmax.value,pmax.value
923 def LIMITK(htyp='EOS',icomp=1,t=0,D=0,p=0):
924 global ierr,herr
925 htyp=create_string_buffer(htyp, 3)
926 icomp=c_long(icomp)
927 t=c_double(t)
928 D=c_double(D)
929 p=c_double(p)
930 tmin,tmax,Dmax,pmax=c_double(),c_double(),c_double(),c_double()
931 rp.LIMITKdll(byref(htyp),byref(icomp),byref(t),byref(D),byref(p),byref(tmin),byref(tmax),byref(Dmax),byref(pmax),byref(ierr),byref(herr),c_long(3),c_long(255))
932 return tmin.value,tmax.value,Dmax.value,pmax.value
934 def LIMITS(htyp='EOS'):
935 'limits of Model'
936 htyp=create_string_buffer(htyp, 3)
937 tmin, tmax, Dmax, pmax=c_double(),c_double(),c_double(),c_double()
938 rp.LIMITSdll(byref(htyp),x,byref(tmin),byref(tmax),byref(Dmax),byref(pmax),c_long(3))
939 return tmin.value,tmax.value,Dmax.value,pmax.value
941 def QMASS(qmol):
942 global ierr,herr
943 global xlkg,xvkg
944 qmol=c_double(qmol)
945 qkg=c_double()
946 wl,wv=c_double(),c_double()
947 rp.QMASSdll(byref(qmol),xl,xv,byref(qkg),xlkg,xvkg,byref(wl),byref(wv),byref(ierr),byref(herr),c_long(255))
948 return qkg.value,wl.value,wv.value
950 def QMOLE(qkg):
951 global ierr,herr
952 global xlkg,xvkg
953 qkg=c_double(qkg)
954 qmol=c_double()
955 wl,wv=c_double(),c_double()
956 rp.QMOLEdll(byref(qkg),xlkg,xvkg,byref(qmol),xl,xv,byref(wl),byref(wv),byref(ierr),byref(herr),c_long(255))
957 return qmol.value,wl.value,wv.value
959 def WMOL():
960 'molecular weight of mixture'
961 global wm
962 rp.WMOLdll(x,byref(wm))
963 return
965 def DIELEC(t,D):
966 '''dielectric constant as a function of temperature, density'''
967 t=c_double(t)
968 D=c_double(D)
969 rp.DIELECdll(byref(t),byref(D),x,byref(de))
970 return de.value
972 def SURFT(t,D):
973 '''surface tension'''
974 global ierr,herr
975 t=c_double(t)
976 D=c_double(D)
977 sigma=c_double()
978 rp.SURFTdll(byref(t),byref(D),x,byref(sigma),byref(ierr),byref(herr),c_long(255))
979 return sigma.value
981 def SURTEN(t):
982 '''surface tension'''
983 global ierr,herr
984 t=c_double(t)
985 sigma=c_double()
986 Dl,Dv=c_double(),c_double()
987 rp.SURTENdll(byref(t),byref(Dl),byref(Dv),xl,xv,byref(sigma),byref(ierr),byref(herr),c_long(255))
988 return sigma.value
990 #####################################################
991 # single phase flash routines
992 #####################################################
994 def PDFL1(p,D):
995 '''from pressure and density'''
996 global ierr,herr
997 p=c_double(p)
998 D=c_double(D)
999 t=c_double()
1000 rp.PDFL1dll(byref(p),byref(D),x,byref(t),byref(ierr),byref(herr),c_long(255))
1001 return t.value
1003 def PHFL1(p,h,kph=2):
1004 '''from pressure and enthalpy'''
1005 global ierr,herr
1006 p=c_double(p)
1007 h=c_double(h)
1008 kph=c_long(kph)
1009 t,D=c_double(),c_double()
1010 rp.PHFL1dll(byref(p),byref(h),x,byref(kph),byref(t),byref(D),byref(ierr),byref(herr),c_long(255))
1011 return t.value,D.value
1013 def PSFL1(p,s,kph=2):
1014 '''from pressure and entropy'''
1015 global ierr,herr
1016 p=c_double(p)
1017 s=c_double(s)
1018 kph=c_long(kph)
1019 t,D=c_double(),c_double()
1020 rp.PSFL1dll(byref(p),byref(s),x,byref(kph),byref(t),byref(D),byref(ierr),byref(herr),c_long(255))
1021 return t.value,D.value
1023 def SETKTV(icomp,jcomp):
1024 '''set mixture model and/or parameters'''
1025 global ierr,herr
1026 global hmodij, hfmix
1027 icomp=c_long(icomp)
1028 jcomp=c_long(jcomp)
1029 fij=c_double()
1030 rp.SETKTVdll(byref(icomp),byref(jcomp),byref(hmodij),byref(fij),byref(hfmix),byref(ierr),byref(herr),c_long(3),c_long(255),c_long(255))
1031 return fij.value
1033 def GETKTV(icomp,jcomp):
1034 '''retrieve mixture model and parameter info for a specified binary'''
1035 global hmodij,hfmix,hfij2,hbinp,hmxrul
1036 icomp=c_long(icomp)
1037 jcomp=c_long(jcomp)
1038 fij=c_double()
1039 rp.GETKTVdll(byref(icomp),byref(jcomp),byref(hmodij),byref(fij),byref(hfmix),byref(hfij2),byref(hbinp),byref(hmxrul),c_long(3),c_long(255),c_long(48),c_long(255),c_long(255))
1040 return fij.value
1042 def GETFIJ(hmodij):
1043 '''retrieve parameter info for a specified mixing rule'''
1044 global hmxrul
1045 fij,hfij2=c_double(),c_double()
1046 rp.GETFIJdll(byref(hmodij),byref(fij),byref(hfij2),byref(hmxrul),c_long(255))
1047 return fij.value,hfij2.value
1049 def MELTT(t):
1050 '''melting line pressure as a function of temperature'''
1051 global ierr,herr
1052 t=c_double(t)
1053 p=c_double()
1054 rp.MELTTdll(byref(t),x,byref(p),byref(ierr),byref(herr),c_long(255))
1055 return p.value
1057 def MLTH2O(t):
1058 '''melting pressure of water'''
1059 t=c_double(t)
1060 p1,p2=c_double(),c_double()
1061 rp.MLTH2Odll(byref(t),byref(p1),byref(p2))
1062 return p1.value,p2.value
1064 def MELTP(p):
1065 '''melting line temperature as a function of pressure'''
1066 global ierr,herr
1067 p=c_double(p)
1068 t=c_double()
1069 rp.MELTPdll(byref(p),x,byref(t),byref(ierr),byref(herr),c_long(255))
1070 return t.value
1072 def SUBLT(t):
1073 '''sublimation line pressure as a function of temperature'''
1074 global ierr,herr
1075 t=c_double(t)
1076 p=c_double()
1077 rp.SUBLTdll(byref(t),x,byref(p),byref(ierr),byref(herr),c_long(255))
1078 return p.value
1080 def SUBLP(p):
1081 '''sublimation line temperature as a function of pressure'''
1082 global ierr,herr
1083 p=c_double(p)
1084 t=c_double()
1085 rp.SUBLPdll(byref(p),x,byref(t),byref(ierr),byref(herr),c_long(255))
1086 return t.value
1088 #####################################################
1089 ## REFPROP FOR UCycLe TEST
1090 #####################################################
1091 def function(fun,In1,In2, fluid):
1092 fun = fun.lower()
1093 SETUP(fluid+'.FLD')
1095 #***************************************************************************
1096 #1.1 Molar mass
1097 #***************************************************************************
1098 if fun =='wm':
1099 return wm.value
1101 #***************************************************************************
1102 #1.2 Temperature
1103 #***************************************************************************
1104 if fun == 'tsat_p':
1105 #SATP(p,kph=2):
1106 #saturation temperature from pressure
1107 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1108 # return t.value,Dl.value,Dv.value
1109 satp = SATP(In1)
1110 return satp[0]
1112 elif fun == 'tsat_s':
1113 #SATS(s,kph=2):
1114 #iterate for temperature, pressure, and density given an entropy along the saturation boundary
1115 #kph--flag specifying desired root
1116 # 0 = all roots along the liquid-vapor line
1117 # 1 = only liquid VLE root
1118 # 2 = only vapor VLE roots
1119 # 3 = liquid SLE root (melting line)
1120 # 4 = vapor SVE root (sublimation line)
1121 # return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value,k3.value,t3.value,p3.value,d3.value
1122 sats = SATS(In1, kph = 0)
1123 return sats[2]
1125 elif fun == 't_ph':
1126 #PHFLSH(p,h):
1127 #flash calculation given pressure and enthalpy
1128 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
1129 ph = PHFLSH(In1, In2)
1130 return ph[0]
1132 elif fun == 't_ps':
1133 #PSFLSH(p,s):
1134 #flash calculation given pressure and entropy
1135 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
1136 ps = PSFLSH(In1, In2)
1137 return ps[0]
1139 elif fun == 't_hs':
1140 #HSFLSH(h,s):
1141 #flash calculation given enthalpy and entropy
1142 # return t.value,p.value,D.value,Dl.value,Dv.value,q.value,e.value,cv.value,cp.value,w.value
1143 hs = HSFLSH(In1, In2)
1144 return hs[0]
1146 #***************************************************************************
1147 #1.3 Pressure (p)
1148 #***************************************************************************
1149 elif fun == 'psat_t':
1150 #SATT(t,kph=2):
1151 #iterate for saturated liquid and vapor states given temperature
1152 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1153 # return p.value,Dl.value,Dv.value
1154 satt = SATT(In1)
1155 return satt[0]
1157 elif fun == 'psat_s':
1158 #SATS(s,kph=2):
1159 #iterate for temperature, pressure, and density given an entropy along the saturation boundary
1160 #kph--flag specifying desired root
1161 # 0 = all roots along the liquid-vapor line
1162 # 1 = only liquid VLE root
1163 # 2 = only vapor VLE roots
1164 # 3 = liquid SLE root (melting line)
1165 # 4 = vapor SVE root (sublimation line)
1166 # return nroot.value,k1.value,t1.value,p1.value,d1.value,k2.value,t2.value,p2.value,d2.value,k3.value,t3.value,p3.value,d3.value
1167 sats = SATS(In1, kph = 0) #Correction Gauth : kph = 0 , sinon il donne pas toutes les valeurs
1168 return sats[3]
1170 elif fun == 'p_hs':
1171 #HSFLSH(h,s):
1172 #flash calculation given enthalpy and entropy
1173 # return t.value,p.value,D.value,Dl.value,Dv.value,q.value,e.value,cv.value,cp.value,w.value
1174 hs = HSFLSH(In1, In2)
1175 return hs[1]
1177 elif fun == 'p_hrho':
1178 #DHFLSH(D,h):
1179 #flash calculation given density and enthalpy
1180 # return t.value,p.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
1181 dh = DHFLSH(In2, In1)
1182 return dh[1]
1185 #***************************************************************************
1186 #1.4 Enthalpy (h)
1187 #***************************************************************************
1189 elif fun == 'hv_p':
1190 pq = PQFLSH(In1,1)
1191 return sq[6]
1193 elif fun == 'hl_p':
1194 pq = PQFLSH(In1,0)
1195 return sq[6]
1197 elif fun == 'hv_t':
1198 tq = TQFLSH(In1,1)
1199 return tq[6]
1201 elif fun == 'hl_t':
1202 tq = TQFLSH(In1,0)
1203 return tq[6]
1205 elif fun == 'h_pt':
1206 #TPFLSH(t,p):
1207 #flash calculation given temperature and pressure
1208 #return D.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1209 tp = TPFLSH(In2, In1)
1210 return tp[5]
1212 elif fun == 'h_ps':
1213 #PSFLSH(p,s):
1214 #flash calculation given pressure and entropy
1215 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
1216 ps = PSFLSH(In1, In2)
1217 return ps[6]
1219 elif fun == 'h_px':
1220 #PQFLSH(p,q,kq):
1221 #flash calculation given pressure and quality
1222 # return kq.value,t.value,D.value,Dl.value,Dv.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1223 pq = PQFLSH(In1, In2,2) #Changement Gauth : rajout du 2pour avoir la quality sur base massique
1224 return pq[6]
1226 elif fun == 'h_prho':
1227 #PDFLSH(p,D):
1228 #flash calculation given pressure and density
1229 # return t.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1230 pd = PDFLSH(In1, In2)
1231 return pd[5]
1233 elif fun == 'h_tx':
1234 #TQFLSH(t,q):
1235 #flash calculation given temperature and quality
1236 # return kq.value,p.value,D.value,Dl.value,Dv.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1237 tq = TQFLSH(In1, In2)
1238 return tq[6]
1240 #***************************************************************************
1241 #1.5 Specific volume (v)
1242 #***************************************************************************
1244 #Convertion from D to specific volume
1245 #D = mole/litre
1246 #wm = kg/mole
1247 #1m3 = 1000 litres
1249 #D = mole/litre *1000/1000 = 1000*mole/m3
1250 #D*wm = kg/mole * 1000*mole/m3 = 1000*kg/m3
1252 #1/(wm*D) = m3/(1000*kg)
1253 elif fun == 'vv_p':
1254 #SATP(p,kph=2):
1255 #saturation temperature from pressure
1256 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1257 # return t.value,Dl.value,Dv.value
1258 satp = SATP(In1,kph=2)
1259 return 1/(satp[2]*wm.value)
1261 elif fun == 'vl_p':
1262 #SATP(p,kph=2):
1263 #saturation temperature from pressure
1264 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1265 # return t.value,Dl.value,Dv.value
1266 satp = SATP(In1,kph=1)
1267 return 1/(satp[1]*wm.value)
1269 elif fun == 'vv_T':
1270 #SATT(t,kph=2):
1271 #iterate for saturated liquid and vapor states given temperature
1272 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1273 # return p.value,Dl.value,Dv.value
1274 satt = SATT(In1,kph=2)
1275 return 1/(satt[2]*wm.value)
1277 elif fun == 'vl_T':
1278 #SATT(t,kph=2):
1279 #iterate for saturated liquid and vapor states given temperature
1280 #kph--phase flag: 1=bubblepoint, 2=dewpoint, 3=freezingpoint, 4=sublimationpoint
1281 # return p.value,Dl.value,Dv.value
1282 satt = SATT(In1,kph=1)
1283 return 1/(satt[1]*wm.value)
1285 elif fun == 'v_pt':
1286 #TPFLSH(t,p):
1287 #flash calculation given temperature and pressure
1288 #return D.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1289 tp = TPFLSH(In2,In1)
1290 return 1/(tp[0]*wm.value)
1292 elif fun == 'v_ph':
1293 #PHFLSH(p,h):
1294 #flash calculation given pressure and enthalpy
1295 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
1296 ph = PHFLSH(In1, In2)
1297 return 1/(ph[1]*wm.value)
1299 elif fun == 'v_ps':
1300 #PSFLSH(p,s):
1301 #flash calculation given pressure and entropy
1302 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
1303 ps = PSFLSH(In1, In2)
1304 return 1/(ps[1]*wm.value)
1306 #***************************************************************************
1307 #1.7 Specific entropy (s)
1308 #***************************************************************************
1310 elif fun == 'sv_p':
1311 pq = PQFLSH(In1,1)
1312 return pq[7]
1314 elif fun == 'sl_p':
1315 pq = PQFLSH(In1,0)
1316 return pq[7]
1318 elif fun == 'sv_t':
1319 tq = TQFLSH(In1,1)
1320 return tq[7]
1322 elif fun == 'sl_t':
1323 tq = TQFLSH(In1,0)
1324 return tq[7]
1326 elif fun == 's_pt':
1327 #TPFLSH(t,p):
1328 #flash calculation given temperature and pressure
1329 #return D.value,Dl.value,Dv.value,q.value,e.value,h.value,s.value,cv.value,cp.value,w.value
1330 tp = TPFLSH(In2, In1)
1331 return tp[6]
1333 elif fun == 's_ph':
1334 #PHFLSH(p,h):
1335 #flash calculation given pressure and enthalpy
1336 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
1337 ph = PHFLSH(In1, In2)
1338 return ph[6]
1342 #***************************************************************************
1343 #*1.17 Vapour fraction
1344 #***************************************************************************
1346 elif fun == 'x_ph':
1347 #PHFLSH(p,h):
1348 #flash calculation given pressure and enthalpy
1349 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,s.value,cv.value,cp.value,w.value
1350 ph = PHFLSH(In1, In2)
1351 return ph[4]
1353 elif fun == 'x_ps':
1354 #PSFLSH(p,s):
1355 #flash calculation given pressure and entropy
1356 # return t.value,D.value,Dl.value,Dv.value,q.value,e.value,h.value,cv.value,cp.value,w.value
1357 ps = PSFLSH(In1, In2)
1358 return ps[4]
1360 ############################ END REFPROP FOR UCycLe TEST #########################'''
1364 #####################################################
1365 ## test routines
1366 #####################################################
1368 if __name__ == '__main__':
1370 # setup for single fluid
1371 A = 'WATER.FLD'
1372 SETUP(A)
1373 #print A
1375 H = GETHEADER(A)
1376 print H
1378 wm = wm.value
1379 pp = 10*100
1381 # setup for mixture
1382 # SETMIX('R407C.MIX')
1384 # H = GETMIXHEADER('R407C.MIX')
1385 # print H
1387 print 'wm=%0.3f g/mol'%(wm) # la masse
1388 tf,dl,dv=SATP(0,3) # get freezing point
1389 tc,pc,Dc=CRITP() # get critical point
1390 print 'tc=%0.2f C pc=%0.0fkPa Dc=%0.1fkg/m3'%(tc-k0,pc,Dc*wm)
1392 tl=0.0+k0
1393 p,dl,dv=SATT(tl,1)
1394 hl=ENTHAL(tl,dl)
1395 sl=ENTRO(tl,dl)
1396 #print 'tl=%0.2f C Dl=%0.1fkg/m3 hl=%0.2fkJ/kg sl=%0.3fkJ/kg-K'%(tl-k0,dl*wm.value,hl/wm.value,sl/wm.value)
1398 p=1100.0
1399 tv,dl,dv=SATP(p,2)
1400 hv=ENTHAL(tv,dv)
1401 tl,dl,dv=SATP(p,1)
1402 hl=ENTHAL(tl,dl)
1403 #print 'tl=%0.2f C tv=%0.2f C Dl=%0.1fkg/m3 hl=%0.2fkJ/kg hv=%0.2fkJ/kg'%(tl-k0,tv-k0,dl*wm.value,hl/wm.value,hv/wm.value)