├── LICENCE ├── README ├── python2.7 ├── multiRP.py ├── refprop.py └── rptest.py ├── python3.2 ├── multiRP.py ├── refprop.py └── rptest.py └── rp2so /LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, B.J. Thelen 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL B.J. Thelen BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This Python module (available for both python version 2.7 and 3.2) uses a 2 | compiled fortran version of the NIST Standard Reference Database 23 3 | (a.k.a. REFPROP (REFerence fluid PROPerties)), version 9.1. 4 | 5 | REFPROP source code has copyright by the United States Secretary of Commerce and 6 | its distribution is controlled by the National Institute of Standards and 7 | Technology (NIST). 8 | 9 | In order to legally obtain a copy of the REFPROP software and fortran source 10 | codes, use the following web page: http://www.nist.gov/srd/nist23.cfm. 11 | Once purchased, the software will be delivered as a windows self extracting 12 | installation file (.exe). In order to access the files required by this python module, you must install REFPROP using this self extracting installation file and install REFPROP in windows. 13 | 14 | FOR WINDOWS: 15 | Install the REFPROP software on your system. 16 | Add two environment variables called RPprefix and Path. See 17 | http://www.boulder.nist.gov/div838/theory/refprop/Frequently_asked_questions.htm 18 | at Excel Applications for more details. 19 | Install the python API to refprop in your python dist-packages 20 | 21 | FOR LINUX: 22 | Use WINE to install refprop.exe in the C:\Program Files\REFPROP\ directory or 23 | use a virtual machine with windows to install REFPROP (if WINE doesn't work for 24 | you) and then make the installed files available on a linux accessible partition. 25 | 26 | Execute the shell script, rp2so, to compile and link the refprop shared object 27 | files. In order for rp2so to run successfully, you will need to have the 28 | following installed on Linux: 29 | gfortran 30 | sed 31 | dos2unix 32 | Install the python API to refprop into your python dist-packages folder 33 | -------------------------------------------------------------------------------- /python2.7/multiRP.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | #Name: multiRP 3 | #Purpose: allowing multiple refprop calculations simultaneously with 4 | # multiple CPU support using python multiprocessing module 5 | # 6 | #Author: Thelen, B.J. 7 | # thelen_ben@yahoo.com 8 | #------------------------------------------------------------------------------- 9 | 10 | u'''Multiprocessing can be done with refprop.py module provided that the setup 11 | details of each refprop routine called simultaneously is identical. 12 | 13 | This module manage and control call of various routines of different setup 14 | details such that only routines of identical setup details are being called 15 | simultanously. The no. cores and threads of cpu matches the the maximum multiple 16 | refprop calculations to be performed simultanously. 17 | 18 | The aim of this module is to gain time of fluid cycle calculations. 19 | 20 | All the same functions as found in the refprop module are available with 21 | additional input of the setup details and porting of the multiprocessing 22 | variables 23 | 24 | Note for windows users, initialtion of multirefprop does require some time 25 | which could render the time gain. On my system the initiation difference ratio 26 | between Linux and Windows is 14.04365604 times (in favour for Linux)''' 27 | 28 | ## to be implemented 29 | ## put _fldext in parent shared lib. for general access to all children this saves time.... 30 | 31 | 32 | 33 | from __future__ import with_statement 34 | import os 35 | import sys 36 | import refprop 37 | import time 38 | import multiprocessing as mp 39 | from decimal import Decimal 40 | 41 | #input declarations 42 | RefpropError = refprop.RefpropError 43 | RefpropdllError = refprop.RefpropdllError 44 | RefpropicompError = refprop.RefpropicompError 45 | RefpropinputError = refprop.RefpropinputError 46 | RefpropnormalizeError = refprop.RefpropnormalizeError 47 | RefproproutineError = refprop.RefproproutineError 48 | RefpropWarning = refprop.RefpropWarning 49 | RefpropdllWarning = refprop.RefpropdllWarning 50 | 51 | #Classes 52 | class _MultiRefProp(mp.Process): 53 | u'''initiate multiprocessing for refprop, 54 | 55 | this function needs to be called prior to usage of multiRP and under 56 | "if __name__ == '__main__':" enable to function properly''' 57 | def __init__(self): 58 | self.process = mp.Process 59 | self.mgr = mp.Manager() 60 | self.sem = mp.Semaphore(mp.cpu_count()) 61 | self.result = self.mgr.dict() #result dict 62 | self.ppipe, self.cpipe = mp.Pipe() #parent pipe, #child pipe 63 | 64 | class MultiRPError(RefpropError): 65 | u'General error for multiRP' 66 | pass 67 | 68 | class SetupError(MultiRPError): 69 | u'Raise input error when Setups are blocked' 70 | def __init__(self, value): 71 | self.value = value 72 | def __str__(self): 73 | return repr(self.value) 74 | 75 | class MultiRPInputError(MultiRPError): 76 | u'Raise input error when Setups are blocked' 77 | def __init__(self, value): 78 | self.value = value 79 | def __str__(self): 80 | return repr(self.value) 81 | 82 | class MultiRPChildError(MultiRPError): 83 | u'Raise input error when Setups are blocked' 84 | def __init__(self, value): 85 | self.value = value 86 | def __str__(self): 87 | return repr(self.value) 88 | 89 | 90 | #Classes from refprop.py 91 | class FluidModel(refprop.FluidModel): 92 | u'''return array of fluid model''' 93 | pass 94 | 95 | class SetWarning(): 96 | u'Return RefpropdllWarning status (on / off)' 97 | def __repr__(self): 98 | return unicode(refprop.SetWarning()) 99 | @staticmethod 100 | def on(prop=None, mRP=None): 101 | u'Sets RefpropdllWarning on, initiate Error on Refpropdll ierr value < 0' 102 | global _inhibt_setuperror 103 | _inhibt_setuperror = True 104 | def _rpfunc(): 105 | global _inhibt_setuperror, _setupprop 106 | _inhibt_setuperror = False 107 | prop = refprop.SetWarning.on() 108 | #adjust _setupprop 109 | _setupprop = setup_details(prop) 110 | return prop 111 | return _rpfunc_handler(prop, mRP, _rpfunc) 112 | @staticmethod 113 | def off(prop=None, mRP=None): 114 | u'Sets RefpropdllWarning off, no Error raised on Refpropdll ierr value < 0' 115 | global _inhibt_setuperror 116 | _inhibt_setuperror = True 117 | def _rpfunc(): 118 | global _inhibt_setuperror, _setupprop 119 | _inhibt_setuperror = False 120 | prop = refprop.SetWarning.off() 121 | #adjust _setupprop 122 | _setupprop = setup_details(prop) 123 | return prop 124 | return _rpfunc_handler(prop, mRP, _rpfunc) 125 | 126 | class SetError(): 127 | u'Return RefpropdllError status (on / off)' 128 | def __repr__(self): 129 | return unicode(refprop.SetError()) 130 | @staticmethod 131 | def on(prop=None, mRP=None): 132 | u'Sets RefpropdllError on, initiate Error on Refpropdll ierr value != 0' 133 | global _inhibt_setuperror 134 | _inhibt_setuperror = True 135 | def _rpfunc(): 136 | global _inhibt_setuperror, _setupprop 137 | _inhibt_setuperror = False 138 | prop = refprop.SetError.on() 139 | #adjust _setupprop 140 | _setupprop = setup_details(prop) 141 | return prop 142 | return _rpfunc_handler(prop, mRP, _rpfunc) 143 | @staticmethod 144 | def off(prop=None, mRP=None): 145 | u'Sets RefpropdllError off, no Error raised on Refpropdll ierr value != 0' 146 | global _inhibt_setuperror 147 | _inhibt_setuperror = True 148 | def _rpfunc(): 149 | global _inhibt_setuperror, _setupprop 150 | _inhibt_setuperror = False 151 | prop = refprop.SetError.off() 152 | #adjust _setupprop 153 | _setupprop = setup_details(prop) 154 | return prop 155 | return _rpfunc_handler(prop, mRP, _rpfunc) 156 | 157 | class SetErrorDebug(): 158 | u'Return SetErrorDebug status (on / off)' 159 | def __repr__(self): 160 | return unicode(refprop.SetErrorDebug()) 161 | @staticmethod 162 | def on(prop=None, mRP=None): 163 | u'Sets error debug mode on, displays error message only' 164 | global _inhibt_setuperror 165 | _inhibt_setuperror = True 166 | def _rpfunc(): 167 | global _inhibt_setuperror, _setupprop 168 | _inhibt_setuperror = False 169 | prop = refprop.SetErrorDebug.on() 170 | #adjust _setupprop 171 | _setupprop = setup_details(prop) 172 | return prop 173 | return _rpfunc_handler(prop, mRP, _rpfunc) 174 | @staticmethod 175 | def off(prop=None, mRP=None): 176 | u'Sets error debug mode off, displays error message only' 177 | global _inhibt_setuperror 178 | _inhibt_setuperror = True 179 | def _rpfunc(): 180 | global _inhibt_setuperror, _setupprop 181 | _inhibt_setuperror = False 182 | prop = refprop.SetErrorDebug.off() 183 | #adjust _setupprop 184 | _setupprop = setup_details(prop) 185 | return prop 186 | return _rpfunc_handler(prop, mRP, _rpfunc) 187 | 188 | 189 | #functions 190 | def multirefprop(): 191 | u'initiate multiprocessing variables' 192 | global mRP 193 | #identify parent process (only parent can call this) 194 | if mp.current_process()._parent_pid == None: 195 | #only call if never called 196 | if not u'mRP' in globals(): 197 | _mRP = _MultiRefProp() 198 | mRP = {u'sem':_mRP.sem, 199 | u'process':_mRP.process, 200 | u'result':_mRP.result, u'ppipe':_mRP.ppipe, 201 | u'cpipe':_mRP.cpipe} 202 | else: 203 | raise MultiRPChildError( 204 | u'Only parent process can initiate mRP variables') 205 | 206 | return mRP 207 | 208 | def run_mRP(processlist): 209 | u'start, close and check child processes' 210 | #start child processes 211 | for each in processlist: 212 | each.start() 213 | #close child processes 214 | for each in processlist: 215 | each.join() 216 | #check for errors in child processes 217 | for each in processlist: 218 | if each.exitcode != 0: 219 | raise MultiRPChildError(u'child error in ' + each.name + 220 | u' exitcode = ' + unicode(each.exitcode)) 221 | 222 | 223 | def _multirefprop(_mRP): 224 | u'Set parent multiprocessing variables as globals' 225 | global sem, process, result, mRP, ppipe, cpipe 226 | sem = _mRP[u'sem'] 227 | result = _mRP[u'result'] 228 | process = _mRP[u'process'] 229 | mRP = _mRP 230 | cpipe = _mRP[u'cpipe'] 231 | ppipe = _mRP[u'ppipe'] 232 | 233 | def ppip(): 234 | u'return parent pipe' 235 | if u'mRP' in globals(): 236 | return mRP[u'pipe'] 237 | else: 238 | raise MultiRPInputError(u'parent pipe can not be return without a' + 239 | u' multirefprop() call') 240 | 241 | def _rpfunc_handler(prop, mRP, _rpfunc): 242 | global _setupprop 243 | #verify either prop has value or value has been set before' 244 | if prop == None \ 245 | and (u'_setupprop' not in dir(refprop) \ 246 | or refprop._setupprop == {}) \ 247 | and u'_inhibt_setuperror' in globals() \ 248 | and not _inhibt_setuperror: 249 | raise MultiRPInputError( 250 | u'First refprop function in child needs setup' + 251 | u' details in "prop" to be defined' + 252 | u' or parent process needs setup input first') 253 | if mRP != None: 254 | #set mRP values as globals 255 | _multirefprop(mRP) 256 | if prop != None: 257 | #store prop as global for continue function call in same child 258 | _setupprop = setup_details(prop) 259 | #identify child process 260 | if mp.current_process()._parent_pid != None: 261 | if prop == None: 262 | if u'_setupprop' not in globals() or _setupprop == None: 263 | raise MultiRPInputError( 264 | u'child process needs "prop" input for first refprop function') 265 | #function call to inherite prop values from previous call 266 | prop = _setupprop 267 | #raise error if child process is initiated without mRP settings 268 | if not u'mRP' in globals(): 269 | raise MultiRPInputError( 270 | u'child process needs "mRP" input for first refprop function') 271 | #resetup fluid 272 | refprop.resetup(prop) 273 | with sem: 274 | #run function, this is where the refprop function is called 275 | prps = _rpfunc() 276 | #return result in result.dict (for child processes only) 277 | result[process().name.rsplit(u':', 1)[0]] = prps 278 | return prps 279 | #identify parent process 280 | elif mp.current_process()._parent_pid == None: 281 | #confirm active children 282 | if len(mp.active_children()) > 1: 283 | #raise error if children are active 284 | raise MultiRPInputError( 285 | u'parent process can not proceed with ' + 286 | u'child processes being handled. Wait untill ' + 287 | u'child processes have joined. Use run_mRP ' + 288 | u'command to start and join child processes.') 289 | #resetup 290 | if prop != None: 291 | refprop.resetup(prop) 292 | #run function 293 | return _rpfunc() 294 | 295 | def _checksetupblock(name): ##################################################################perhaps this whole function can be ommitted, but carefully as settings are passed through 296 | if mp.current_process()._parent_pid != None: 297 | #raise error if child process request for setup 298 | raise SetupError(u'function "' + unicode(name) + 299 | u'" is blocked for multiRP child processes') 300 | elif len(mp.active_children()) > 1: 301 | #raise error if parent process request for setup while child process(es) 302 | #are active. 303 | raise SetupError( 304 | u'function "' + unicode(name) + 305 | u'" is blocked while multiRP child processes are active') 306 | 307 | 308 | #functions from refprop.py 309 | def setpath(path=u'c:/program files/refprop/'): 310 | u'''Set Directory to refprop root containing fluids and mixtures.''' 311 | refprop.setpath(path) 312 | 313 | def fluidlib(): 314 | u'''Displays all fluids and mixtures available on root directory.''' 315 | refprop.fluidlib() 316 | 317 | def normalize(x): 318 | u'''Normalize the sum of list x value's to 1''' 319 | return refprop.normalize(x) 320 | 321 | def resetup(prop, force=False, mRP=None): 322 | u"""Resetup models and re-initialize arrays. 323 | Initiate child process with prop and mRP transfer""" 324 | #resetup only to be run in parent process, in child process the passed prop 325 | #value will be used for resetup 326 | def _rpfunc(): 327 | return refprop.resetup(prop, force) 328 | return _rpfunc_handler(prop, mRP, _rpfunc) 329 | 330 | def setup_details(prop): 331 | u'''Returns basic setup details.''' 332 | return refprop.setup_details(prop) 333 | 334 | def getphase(prop, mRP=None): 335 | u'''Return fluid phase''' 336 | def _rpfunc(): 337 | return refprop.getphase(prop) 338 | return _rpfunc_handler(prop, mRP, _rpfunc) 339 | 340 | def setup_setting(mRP=None): 341 | u"""Returns current setup settings""" 342 | #identify parent process and confirm no active children 343 | if (mp.current_process()._parent_pid == None and 344 | len(mp.active_children()) <= 1): 345 | return refprop.setup_setting() 346 | #else multiprocessing active 347 | else: 348 | #check if mRP is included 349 | if u'mRP' not in globals(): 350 | raise MultiRPInputError( 351 | u'"mRP" input required when multiprocessing') 352 | #check if setup_prop is already populated (done through first call) 353 | if u'_setupprop' not in globals() or _setupprop == None: 354 | raise MultiRPInputError( 355 | u'child process needs "prop" input for first refprop function') 356 | #return _Setupprop (which contains setup-properties). 357 | return _setupprop 358 | 359 | def _test(): 360 | u"""execute detailed test run of multiRP""" 361 | import rptest 362 | rptest.settest(u'multiRP') 363 | 364 | def test(criteria = 0.00001): 365 | u'''verify that the user's computer is returning proper calculations''' 366 | global testresult 367 | refproptest = refprop.test(criteria) 368 | testresult = refprop.testresult 369 | return refproptest 370 | 371 | def psliq(p, s, x, prop=None, mRP=None): 372 | u"""flsh1 calculations with boundery check, raise RefpropinputError when 373 | input is outside bounderies""" 374 | def _rpfunc(): 375 | return refprop.psliq(p, s, x) 376 | return _rpfunc_handler(prop, mRP, _rpfunc) 377 | 378 | def psvap(p, s, x, prop=None, mRP=None): 379 | u"""flsh1 calculations with boundery check, raise RefpropinputError when 380 | input is outside bounderies""" 381 | def _rpfunc(): 382 | return refprop.psvap(p, s, x) 383 | return _rpfunc_handler(prop, mRP, _rpfunc) 384 | 385 | def ps2ph(p, s, x, prop=None, mRP=None): 386 | u"""flsh2 calculations with boundery check, raise RefpropinputError when 387 | input is outside bounderies""" 388 | def _rpfunc(): 389 | return refprop.ps2ph(p, s, x) 390 | return _rpfunc_handler(prop, mRP, _rpfunc) 391 | 392 | def phliq(p, h, x, prop=None, mRP=None): 393 | u"""flsh1 calculations with boundery check, raise RefpropinputError when 394 | input is outside bounderies""" 395 | def _rpfunc(): 396 | return refprop.phliq(p, h, x) 397 | return _rpfunc_handler(prop, mRP, _rpfunc) 398 | 399 | def phvap(p, h, x, prop=None, mRP=None): 400 | u"""flsh1 calculations with boundery check, raise RefpropinputError when 401 | input is outside bounderies""" 402 | def _rpfunc(): 403 | return refprop.phvap(p, h, x) 404 | return _rpfunc_handler(prop, mRP, _rpfunc) 405 | 406 | def ph2ph(p, h, x, prop=None, mRP=None): 407 | u"""flsh2 calculations with boundery check, raise RefpropinputError when 408 | input is outside bounderies""" 409 | def _rpfunc(): 410 | return refprop.ph2ph(p, h, x) 411 | return _rpfunc_handler(prop, mRP, _rpfunc) 412 | 413 | def setup(hrf, *hfld, **_3to2kwargs): 414 | if 'hfmix' in _3to2kwargs: hfmix = _3to2kwargs['hfmix']; del _3to2kwargs['hfmix'] 415 | else: hfmix = u'HMX.BNC' 416 | u'''Define models and initialize arrays.''' 417 | _checksetupblock(u'setup') 418 | return refprop.setup(hrf, *hfld, hfmix=hfmix) 419 | 420 | def setmod(htype, hmix, *hcomp): 421 | u'''Set model(s) other than the NIST-recommended ('NBS') ones.''' 422 | _checksetupblock(u'setmod') 423 | refprop.setmod(htype, hmix, *hcomp) 424 | 425 | def gerg04(ixflag=0): 426 | u'''set the pure model(s) to those used by the GERG 2004 formulation.''' 427 | _checksetupblock(u'gerg04') 428 | refprop.gerg04(ixflag) 429 | 430 | def setref(hrf=u'DEF', ixflag=1, x0=[1], h0=0, s0=0, t0=273, p0=100): 431 | u'''set reference state enthalpy and entropy''' 432 | _checksetupblock(u'setref') 433 | return refprop.setref(hrf, ixflag, x0, h0, s0, t0, p0) 434 | 435 | def critp(x, prop=None, mRP=None): 436 | u'''critical parameters as a function of composition''' 437 | def _rpfunc(): 438 | return refprop.critp(x) 439 | return _rpfunc_handler(prop, mRP, _rpfunc) 440 | 441 | def therm(t, D, x, prop=None, mRP=None): 442 | u'''Compute thermal quantities as a function of temperature, density and 443 | compositions using core functions''' 444 | def _rpfunc(): 445 | return refprop.therm(t, D, x) 446 | return _rpfunc_handler(prop, mRP, _rpfunc) 447 | 448 | def therm0(t, D, x, prop=None, mRP=None): 449 | u'''Compute ideal gas thermal quantities as a function of temperature, 450 | density and compositions using core functions.''' 451 | def _rpfunc(): 452 | return refprop.therm0(t, D, x) 453 | return _rpfunc_handler(prop, mRP, _rpfunc) 454 | 455 | def residual (t, D, x, prop=None, mRP=None): 456 | u'''compute the residual quantities as a function of temperature, density, 457 | and compositions (where the residual is the property minus the ideal gas 458 | portion)''' 459 | def _rpfunc(): 460 | return refprop.residual (t, D, x) 461 | return _rpfunc_handler(prop, mRP, _rpfunc) 462 | 463 | def therm2(t, D, x, prop=None, mRP=None): 464 | u'''Compute thermal quantities as a function of temperature, density and 465 | compositions using core functions''' 466 | def _rpfunc(): 467 | return refprop.therm2(t, D, x) 468 | return _rpfunc_handler(prop, mRP, _rpfunc) 469 | 470 | def therm3(t, D, x, prop=None, mRP=None): 471 | u'''Compute miscellaneous thermodynamic properties''' 472 | def _rpfunc(): 473 | return refprop.therm3(t, D, x) 474 | return _rpfunc_handler(prop, mRP, _rpfunc) 475 | 476 | def purefld(icomp=0): 477 | u'''Change the standard mixture setup so that the properties of one fluid 478 | can be calculated as if SETUP had been called for a pure fluid.''' 479 | _checksetupblock(u'purefld') 480 | return refprop.purefld(icomp) 481 | 482 | def name(icomp=1, prop=None, mRP=None): 483 | u'''Provides name information for specified component''' 484 | def _rpfunc(): 485 | return refprop.name(icomp) 486 | return _rpfunc_handler(prop, mRP, _rpfunc) 487 | 488 | def entro(t, D, x, prop=None, mRP=None): 489 | u'''Compute entropy as a function of temperature, density and composition 490 | using core functions''' 491 | def _rpfunc(): 492 | return refprop.entro(t, D, x) 493 | return _rpfunc_handler(prop, mRP, _rpfunc) 494 | 495 | def enthal(t, D, x, prop=None, mRP=None): 496 | u'''Compute enthalpy as a function of temperature, density, and 497 | composition using core functions''' 498 | def _rpfunc(): 499 | return refprop.enthal(t, D, x) 500 | return _rpfunc_handler(prop, mRP, _rpfunc) 501 | 502 | def cvcp(t, D, x, prop=None, mRP=None): 503 | u'''Compute isochoric (constant volume) and isobaric (constant pressure) 504 | heat capacity as functions of temperature, density, and composition 505 | using core functions''' 506 | def _rpfunc(): 507 | return refprop.cvcp(t, D, x) 508 | return _rpfunc_handler(prop, mRP, _rpfunc) 509 | 510 | def cvcpk(icomp, t, D, prop=None, mRP=None): 511 | u'''Compute isochoric (constant volume) and isobaric (constant pressure) 512 | heat capacity as functions of temperature for a given component.''' 513 | def _rpfunc(): 514 | return refprop.cvcpk(icomp, t, D) 515 | return _rpfunc_handler(prop, mRP, _rpfunc) 516 | 517 | def gibbs(t, D, x, prop=None, mRP=None): 518 | u'''Compute residual Helmholtz and Gibbs free energy as a function of 519 | temperature, density, and composition using core functions''' 520 | def _rpfunc(): 521 | return refprop.gibbs(t, D, x) 522 | return _rpfunc_handler(prop, mRP, _rpfunc) 523 | 524 | def ag(t, D, x, prop=None, mRP=None): 525 | u'''Ccompute Helmholtz and Gibbs energies as a function of temperature, 526 | density, and composition.''' 527 | def _rpfunc(): 528 | return refprop.ag(t, D, x) 529 | return _rpfunc_handler(prop, mRP, _rpfunc) 530 | 531 | def press(t, D, x, prop=None, mRP=None): 532 | u'''Compute pressure as a function of temperature, density, and 533 | composition using core functions''' 534 | def _rpfunc(): 535 | return refprop.press(t, D, x) 536 | return _rpfunc_handler(prop, mRP, _rpfunc) 537 | 538 | def dpdd(t, D, x, prop=None, mRP=None): 539 | u'''Compute partial derivative of pressure w.r.t. density at constant 540 | temperature as a function of temperature, density, and composition''' 541 | def _rpfunc(): 542 | return refprop.dpdd(t, D, x) 543 | return _rpfunc_handler(prop, mRP, _rpfunc) 544 | 545 | def dpddk(icomp, t, D, prop=None, mRP=None): 546 | u'''Compute partial derivative of pressure w.r.t. density at constant 547 | temperature as a function of temperature and density for a specified 548 | component''' 549 | def _rpfunc(): 550 | return refprop.dpddk(icomp, t, D) 551 | return _rpfunc_handler(prop, mRP, _rpfunc) 552 | 553 | def dpdd2(t, D, x, prop=None, mRP=None): 554 | u'''Compute second partial derivative of pressure w.r.t. density at 555 | const. temperature as a function of temperature, density, and 556 | composition.''' 557 | def _rpfunc(): 558 | return refprop.dpdd2(t, D, x) 559 | return _rpfunc_handler(prop, mRP, _rpfunc) 560 | 561 | def dpdt(t, D, x, prop=None, mRP=None): 562 | u'''Compute partial derivative of pressure w.r.t. temperature at constant 563 | density as a function of temperature, density, and composition.''' 564 | def _rpfunc(): 565 | return refprop.dpdt(t, D, x) 566 | return _rpfunc_handler(prop, mRP, _rpfunc) 567 | 568 | def dpdtk(icomp, t, D, prop=None, mRP=None): 569 | u'''Compute partial derivative of pressure w.r.t. temperature at constant 570 | density as a function of temperature and density for a specified 571 | component''' 572 | def _rpfunc(): 573 | return refprop.dpdtk(icomp, t, D) 574 | return _rpfunc_handler(prop, mRP, _rpfunc) 575 | 576 | def dddp(t, D, x, prop=None, mRP=None): 577 | u'''ompute partial derivative of density w.r.t. pressure at constant 578 | temperature as a function of temperature, density, and composition.''' 579 | def _rpfunc(): 580 | return refprop.dddp(t, D, x) 581 | return _rpfunc_handler(prop, mRP, _rpfunc) 582 | 583 | def dddt(t, D, x, prop=None, mRP=None): 584 | u'''Compute partial derivative of density w.r.t. temperature at constant 585 | pressure as a function of temperature, density, and composition.''' 586 | def _rpfunc(): 587 | return refprop.dddt(t, D, x) 588 | return _rpfunc_handler(prop, mRP, _rpfunc) 589 | 590 | def dhd1(t, D, x, prop=None, mRP=None): 591 | u'''Compute partial derivatives of enthalpy w.r.t. t, p, or D at constant 592 | t, p, or D as a function of temperature, density, and composition''' 593 | def _rpfunc(): 594 | return refprop.dhd1(t, D, x) 595 | return _rpfunc_handler(prop, mRP, _rpfunc) 596 | 597 | def fgcty(t, D, x, prop=None, mRP=None): 598 | u'''Compute fugacity for each of the nc components of a mixture by 599 | numerical differentiation (using central differences) of the 600 | dimensionless residual Helmholtz energy''' 601 | def _rpfunc(): 602 | return refprop.fgcty(t, D, x) 603 | return _rpfunc_handler(prop, mRP, _rpfunc) 604 | 605 | #~ def fgcty2(t, D, x, prop=None, mRP=None): 606 | #~ '''Compute fugacity for each of the nc components of a mixture by 607 | #~ analytical differentiation of the dimensionless residual Helmholtz energy.''' 608 | #~ def _rpfunc(): 609 | #~ return refprop.fgcty2(t, D, x) 610 | #~ return _rpfunc_handler(prop, mRP, _rpfunc) 611 | 612 | def dbdt(t, x, prop=None, mRP=None): 613 | u'''Compute the 2nd derivative of B (B is the second virial coefficient) 614 | with respect to T as a function of temperature and composition.''' 615 | def _rpfunc(): 616 | return refprop.dbdt(t, x) 617 | return _rpfunc_handler(prop, mRP, _rpfunc) 618 | 619 | def virb(t, x, prop=None, mRP=None): 620 | u'''Compute second virial coefficient as a function of temperature and 621 | composition.''' 622 | def _rpfunc(): 623 | return refprop.virb(t, x) 624 | return _rpfunc_handler(prop, mRP, _rpfunc) 625 | 626 | def virc(t, x, prop=None, mRP=None): 627 | u'''Compute the third virial coefficient as a function of temperature and 628 | composition.''' 629 | def _rpfunc(): 630 | return refprop.virc(t, x) 631 | return _rpfunc_handler(prop, mRP, _rpfunc) 632 | 633 | def vird(t, x, prop=None, mRP=None): 634 | u'''Compute the fourth virial coefficient as a function of temperature 635 | and composition.''' 636 | def _rpfunc(): 637 | return refprop.vird(t, x) 638 | return _rpfunc_handler(prop, mRP, _rpfunc) 639 | 640 | def virba(t, x, prop=None, mRP=None): 641 | u'''Compute second acoustic virial coefficient as a function of temperature 642 | and composition.''' 643 | def _rpfunc(): 644 | return refprop.virba(t, x) 645 | return _rpfunc_handler(prop, mRP, _rpfunc) 646 | 647 | def virca(t, x, prop=None, mRP=None): 648 | u'''Compute third acoustic virial coefficient as a function of temperature 649 | and composition.''' 650 | def _rpfunc(): 651 | return refprop.virca(t, x) 652 | return _rpfunc_handler(prop, mRP, _rpfunc) 653 | 654 | def satt(t, x, kph=2, prop=None, mRP=None): 655 | u'''Iterate for saturated liquid and vapor states given temperature and 656 | the composition of one phase''' 657 | def _rpfunc(): 658 | return refprop.satt(t, x, kph) 659 | return _rpfunc_handler(prop, mRP, _rpfunc) 660 | 661 | def satp(p, x, kph=2, prop=None, mRP=None): 662 | u'''Iterate for saturated liquid and vapor states given pressure and the 663 | composition of one phase.''' 664 | def _rpfunc(): 665 | return refprop.satp(p, x, kph) 666 | return _rpfunc_handler(prop, mRP, _rpfunc) 667 | 668 | def satd(D, x, kph=2, prop=None, mRP=None): 669 | u'''Iterate for temperature and pressure given a density along the 670 | saturation boundary and the composition.''' 671 | def _rpfunc(): 672 | return refprop.satd(D, x, kph) 673 | return _rpfunc_handler(prop, mRP, _rpfunc) 674 | 675 | def sath(h, x, kph=2, prop=None, mRP=None): 676 | u'''Iterate for temperature, pressure, and density given enthalpy along 677 | the saturation boundary and the composition.''' 678 | def _rpfunc(): 679 | return refprop.sath(h, x, kph) 680 | return _rpfunc_handler(prop, mRP, _rpfunc) 681 | 682 | def sate(e, x, kph=2, prop=None, mRP=None): 683 | u'''Iterate for temperature, pressure, and density given energy along the 684 | saturation boundary and the composition.''' 685 | def _rpfunc(): 686 | return refprop.sate(e, x, kph) 687 | return _rpfunc_handler(prop, mRP, _rpfunc) 688 | 689 | def sats(s, x, kph=2, prop=None, mRP=None): 690 | u'''Iterate for temperature, pressure, and density given entropy along 691 | the saturation boundary and the composition.''' 692 | def _rpfunc(): 693 | return refprop.sats(s, x, kph) 694 | return _rpfunc_handler(prop, mRP, _rpfunc) 695 | 696 | def csatk(icomp, t, kph=2, prop=None, mRP=None): 697 | u'''Compute the heat capacity along the saturation line as a function of 698 | temperature for a given component.''' 699 | def _rpfunc(): 700 | return refprop.csatk(icomp, t, kph) 701 | return _rpfunc_handler(prop, mRP, _rpfunc) 702 | 703 | def dptsatk(icomp, t, kph=2, prop=None, mRP=None): 704 | u'''Compute the heat capacity and dP/dT along the saturation line as a 705 | function of temperature for a given component.''' 706 | def _rpfunc(): 707 | return refprop.dptsatk(icomp, t, kph) 708 | return _rpfunc_handler(prop, mRP, _rpfunc) 709 | 710 | def cv2pk(icomp, t, D=0, prop=None, mRP=None): 711 | u'''Compute the isochoric heat capacity in the two phase (liquid+vapor) 712 | region.''' 713 | def _rpfunc(): 714 | return refprop.cv2pk(icomp, t, D) 715 | return _rpfunc_handler(prop, mRP, _rpfunc) 716 | 717 | def tprho(t, p, x, kph=2, kguess=0, D=0, prop=None, mRP=None): 718 | u'''Iterate for density as a function of temperature, pressure, and 719 | composition for a specified phase.''' 720 | def _rpfunc(): 721 | return refprop.tprho(t, p, x, kph, kguess, D) 722 | return _rpfunc_handler(prop, mRP, _rpfunc) 723 | 724 | def flsh(routine, var1, var2, x, kph=1, prop=None, mRP=None): 725 | u'''Flash calculation given two independent variables and bulk 726 | composition.''' 727 | def _rpfunc(): 728 | return refprop.flsh(routine, var1, var2, x, kph) 729 | return _rpfunc_handler(prop, mRP, _rpfunc) 730 | 731 | def flsh1(routine, var1, var2, x, kph=1, Dmin=0, Dmax=0, prop=None, mRP=None): 732 | u'''Flash calculation given two independent variables and bulk 733 | composition.''' 734 | def _rpfunc(): 735 | return refprop.flsh1(routine, var1, var2, x, kph, Dmin, Dmax) 736 | return _rpfunc_handler(prop, mRP, _rpfunc) 737 | 738 | def flsh2(routine, var1, var2, x, kq=1, ksat=0, tbub=0, tdew=0, pbub=0, pdew=0, 739 | Dlbub=0, Dvdew=0, xbub=None, xdew=None, prop=None, mRP=None): 740 | u'''Flash calculation given two independent variables and bulk composition''' 741 | def _rpfunc(): 742 | return refprop.flsh2( 743 | routine, var1, var2, x, kq, ksat, tbub, tdew, pbub, pdew, Dlbub, 744 | Dvdew, xbub, xdew) 745 | return _rpfunc_handler(prop, mRP, _rpfunc) 746 | 747 | def info(icomp=1, prop=None, mRP=None): 748 | u'''Provides fluid constants for specified component.''' 749 | def _rpfunc(): 750 | return refprop.info(icomp) 751 | return _rpfunc_handler(prop, mRP, _rpfunc) 752 | 753 | def xmass(x, prop=None, mRP=None): 754 | u'''Converts composition on a mole fraction basis to mass fraction.''' 755 | def _rpfunc(): 756 | return refprop.xmass(x) 757 | return _rpfunc_handler(prop, mRP, _rpfunc) 758 | 759 | def xmole(xkg, prop=None, mRP=None): 760 | u'''Converts composition on a mass fraction basis to mole fraction.''' 761 | def _rpfunc(): 762 | return refprop.xmole(xkg) 763 | return _rpfunc_handler(prop, mRP, _rpfunc) 764 | 765 | def limitx(x, htype=u'EOS', t=0, D=0, p=0, prop=None, mRP=None): 766 | u'''returns limits of a property model as a function of composition 767 | and/or checks input t, D, p against those limits.''' 768 | def _rpfunc(): 769 | return refprop.limitx(x, htype, t, D, p) 770 | return _rpfunc_handler(prop, mRP, _rpfunc) 771 | 772 | def limitk(htype=u'EOS', icomp=1, t=u'tnbp', D=0, p=0, prop=None, mRP=None): 773 | u'''Returns limits of a property model (read in from the .fld files) for 774 | a mixture component and/or checks input t, D, p against those limits.''' 775 | def _rpfunc(): 776 | return refprop.limitk(htype, icomp, t, D, p) 777 | return _rpfunc_handler(prop, mRP, _rpfunc) 778 | 779 | def limits(x, htype = u'EOS', prop=None, mRP=None): 780 | u'''Returns limits of a property model as a function of composition.''' 781 | def _rpfunc(): 782 | return refprop.limits(x, htype) 783 | return _rpfunc_handler(prop, mRP, _rpfunc) 784 | 785 | def qmass(q, xliq, xvap, prop=None, mRP=None): 786 | u'''converts quality and composition on a mole basis to a mass basis.''' 787 | def _rpfunc(): 788 | return refprop.qmass(q, xliq, xvap) 789 | return _rpfunc_handler(prop, mRP, _rpfunc) 790 | 791 | def qmole(qkg, xlkg, xvkg, prop=None, mRP=None): 792 | u'''Converts quality and composition on a mass basis to a molar basis.''' 793 | def _rpfunc(): 794 | return refprop.qmole(qkg, xlkg, xvkg) 795 | return _rpfunc_handler(prop, mRP, _rpfunc) 796 | 797 | def wmol(x, prop=None, mRP=None): 798 | u'''Molecular weight for a mixture of specified composition.''' 799 | def _rpfunc(): 800 | return refprop.wmol(x) 801 | return _rpfunc_handler(prop, mRP, _rpfunc) 802 | 803 | def dielec(t, D, x, prop=None, mRP=None): 804 | u'''Compute the dielectric constant as a function of temperature, 805 | density, and composition.''' 806 | def _rpfunc(): 807 | return refprop.dielec(t, D, x) 808 | return _rpfunc_handler(prop, mRP, _rpfunc) 809 | 810 | def surft(t, x, prop=None, mRP=None): 811 | u'''Compute surface tension.''' 812 | def _rpfunc(): 813 | return refprop.surft(t, x) 814 | return _rpfunc_handler(prop, mRP, _rpfunc) 815 | 816 | def surten(t, Dliq, Dvap, xliq, xvap, prop=None, mRP=None): 817 | u'''Compute surface tension.''' 818 | def _rpfunc(): 819 | return refprop.surten(t, Dliq, Dvap, xliq, xvap) 820 | return _rpfunc_handler(prop, mRP, _rpfunc) 821 | 822 | def meltt(t, x, prop=None, mRP=None): 823 | u'''Compute the melting line pressure as a function of temperature and 824 | composition.''' 825 | def _rpfunc(): 826 | return refprop.meltt(t, x) 827 | return _rpfunc_handler(prop, mRP, _rpfunc) 828 | 829 | def meltp(p, x, prop=None, mRP=None): 830 | u'''Compute the melting line temperature as a function of pressure and 831 | composition.''' 832 | def _rpfunc(): 833 | return refprop.meltp(p, x) 834 | return _rpfunc_handler(prop, mRP, _rpfunc) 835 | 836 | def sublt(t, x, prop=None, mRP=None): 837 | u'''Compute the sublimation line pressure as a function of temperature 838 | and composition.''' 839 | def _rpfunc(): 840 | return refprop.sublt(t, x) 841 | return _rpfunc_handler(prop, mRP, _rpfunc) 842 | 843 | def sublp(p, x, prop=None, mRP=None): 844 | u'''Compute the sublimation line temperature as a function of pressure 845 | and composition.''' 846 | def _rpfunc(): 847 | return refprop.sublp(p, x) 848 | return _rpfunc_handler(prop, mRP, _rpfunc) 849 | 850 | def trnprp(t, D, x, prop=None, mRP=None): 851 | u'''Compute the transport properties of thermal conductivity and 852 | viscosity as functions of temperature, density, and composition.''' 853 | def _rpfunc(): 854 | return refprop.trnprp(t, D, x) 855 | return _rpfunc_handler(prop, mRP, _rpfunc) 856 | 857 | def getktv(icomp, jcomp, prop=None, mRP=None): 858 | u'''Retrieve mixture model and parameter info for a specified binary.''' 859 | def _rpfunc(): 860 | return refprop.getktv(icomp, jcomp) 861 | return _rpfunc_handler(prop, mRP, _rpfunc) 862 | 863 | def setktv(icomp, jcomp, hmodij, fij=([0] * refprop._nmxpar), 864 | hfmix=u'hmx.bnc'): 865 | u'''Set mixture model and/or parameters.''' 866 | _checksetupblock(u'setktv') 867 | return refprop.setktv(icomp, jcomp, hmodij, fij, hfmix) 868 | 869 | def setaga(): 870 | u'''Set up working arrays for use with AGA8 equation of state.''' 871 | _checksetupblock(u'setaga') 872 | return refprop.setaga() 873 | 874 | def unsetaga(): 875 | u'''Load original values into arrays changed in the call to SETAGA.''' 876 | _checksetupblock(u'unsetaga') 877 | return refprop.unsetaga() 878 | 879 | def preos(ixflag): 880 | u'''Turn on or off the use of the PR cubic equation.''' 881 | _checksetupblock(u'preos') 882 | return refprop.preos(ixflag) 883 | 884 | def getfij(hmodij, prop=None, mRP=None): 885 | u'''Retrieve parameter info for a specified mixing rule.''' 886 | def _rpfunc(): 887 | return refprop.getfij(hmodij) 888 | return _rpfunc_handler(prop, mRP, _rpfunc) 889 | 890 | def b12(t, x, prop=None, mRP=None): 891 | u'''Compute b12 as a function of temperature and composition.''' 892 | def _rpfunc(): 893 | return refprop.b12(t, x) 894 | return _rpfunc_handler(prop, mRP, _rpfunc) 895 | 896 | def excess(t, p, x, kph=0, prop=None, mRP=None): 897 | u'''Compute excess properties as a function of temperature, pressure, and 898 | composition.''' 899 | def _rpfunc(): 900 | return refprop.excess(t, p, x, kph) 901 | return _rpfunc_handler(prop, mRP, _rpfunc) 902 | 903 | def getmod(icomp, htype, prop=None, mRP=None): 904 | u'''Retrieve citation information for the property models used''' 905 | def _rpfunc(): 906 | return refprop.getmod(icomp, htype) 907 | return _rpfunc_handler(prop, mRP, _rpfunc) 908 | 909 | def cstar(t, p, v, x, prop=None, mRP=None): 910 | u'''Calculate the critical flow factor, C*, for nozzle flow of a gas 911 | (subroutine was originally named CCRIT)''' 912 | def _rpfunc(): 913 | return refprop.cstar(t, p, v, x) 914 | return _rpfunc_handler(prop, mRP, _rpfunc) 915 | 916 | def phiderv(icomp, jcomp, t, D, x, prop=None, mRP=None): 917 | u'''Calculate various derivatives needed for VLE determination''' 918 | def _rpfunc(): 919 | return refprop.phiderv(icomp, jcomp, t, D, x) 920 | return _rpfunc_handler(prop, mRP, _rpfunc) 921 | 922 | def chempot(t, D, x, prop=None, mRP=None): 923 | u'''Compute the chemical potentials for each of the nc components of a 924 | mixture.''' 925 | def _rpfunc(): 926 | return refprop.chempot(t, D, x) 927 | return _rpfunc_handler(prop, mRP, _rpfunc) 928 | 929 | def fugcof(t, D, x, prop=None, mRP=None): 930 | u'''Compute the fugacity coefficient for each of the nc components of a 931 | mixture.''' 932 | def _rpfunc(): 933 | return refprop.fugcof(t, D, x) 934 | return _rpfunc_handler(prop, mRP, _rpfunc) 935 | 936 | def dcdt(t, x, prop=None, mRP=None): 937 | u'''Compute the 1st derivative of C (C is the third virial coefficient) with 938 | respect to T as a function of temperature and composition.''' 939 | def _rpfunc(): 940 | return refprop.dcdt(t, x) 941 | return _rpfunc_handler(prop, mRP, _rpfunc) 942 | 943 | def dcdt2(t, x, prop=None, mRP=None): 944 | u'''Compute the 2nd derivative of C (C is the third virial coefficient) with 945 | respect to T as a function of temperature and composition.''' 946 | def _rpfunc(): 947 | return refprop.dcdt2(t, x) 948 | return _rpfunc_handler(prop, mRP, _rpfunc) 949 | 950 | def fpv(t, D, p, x, prop=None, mRP=None): 951 | u'''Compute the supercompressibility factor, Fpv.''' 952 | def _rpfunc(): 953 | return refprop.fpv(t, D, p, x) 954 | return _rpfunc_handler(prop, mRP, _rpfunc) 955 | 956 | def rmix2(x, prop=None, mRP=None): 957 | u'''Return the gas "constant" as a combination of the gas constants for 958 | the pure fluids.''' 959 | def _rpfunc(): 960 | return refprop.rmix2(x) 961 | return _rpfunc_handler(prop, mRP, _rpfunc) 962 | 963 | #compilations 964 | 965 | #create function (to demonstrate pipe) 966 | def _mRPpipe(fluid, mRP): 967 | resetup(fluid, mRP=mRP) 968 | for each in xrange(100): 969 | #put value into pipe 970 | mRP[u'cpipe'].send( 971 | press(303 + each, 58, [0.4, 0.6])[u'p']) 972 | mRP[u'cpipe'].close() 973 | 974 | if __name__ == u'__main__': 975 | #add module file path to python sys path 976 | import multiRP as _filename 977 | _filename = (os.path.dirname(_filename.__file__)) 978 | sys.path.append(_filename) 979 | 980 | #test multiRP without multiprocessing 981 | import rptest 982 | rptest.settest(u'multiRP') 983 | 984 | #initiate multirefprop, this will create global 'mRP' 985 | multirefprop() 986 | 987 | #create setup details 988 | H2O = setup(u'def', u'WATER') 989 | H2O_NH3 = setup(u'def', u'AMMONIA', u'WATER') 990 | CH4 = setup(u'def', u'METHANE') 991 | CH4_C2H6 = setup(u'def', u'METHANE', u'ETHANE') 992 | 993 | #various refprop functions named 994 | peen = mRP[u'process'](target=critp, args=([1], H2O, mRP)) 995 | ptwee = mRP[u'process'](target=critp, args=([0.4, 0.6],), 996 | kwargs={u'prop':H2O_NH3, u'mRP':mRP})#alternative input 997 | pdrie = mRP[u'process'](target=critp, args=([1], CH4, mRP)) 998 | pvier = mRP[u'process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 999 | qeen = mRP[u'process'](target=critp, args=([1], H2O, mRP)) 1000 | qtwee = mRP[u'process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 1001 | qdrie = mRP[u'process'](target=critp, args=([1], CH4, mRP)) 1002 | qvier = mRP[u'process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 1003 | ween = mRP[u'process'](target=critp, args=([1], H2O, mRP)) 1004 | wtwee = mRP[u'process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 1005 | wdrie = mRP[u'process'](target=critp, args=([1], CH4, mRP)) 1006 | wvier = mRP[u'process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 1007 | reen = mRP[u'process'](target=critp, args=([1], H2O, mRP)) 1008 | rtwee = mRP[u'process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 1009 | rdrie = mRP[u'process'](target=critp, args=([1], CH4, mRP)) 1010 | rvier = mRP[u'process'](target=critp, args=([0.35, 0.65], 1011 | CH4_C2H6, mRP)) 1012 | sfun = mRP[u'process'](target=_mRPpipe, args=(H2O_NH3, mRP))#pipe 1013 | 1014 | #list refprop functions 1015 | processlist = [peen, ptwee, pdrie, pvier, qeen, qtwee, qdrie, qvier, 1016 | ween, wtwee, wdrie, wvier, reen, rtwee, rdrie, rvier, 1017 | sfun] 1018 | 1019 | #now run the functions 1020 | run_mRP(processlist) 1021 | 1022 | #print the results 1023 | for each in processlist: 1024 | if each.name in mRP[u'result']: 1025 | print mRP[u'result'][each.name] #only returns the last refprop function results unless tweaked at function call 1026 | 1027 | #loop untill pipe is empty 1028 | while mRP[u'ppipe'].poll():#parentpipe 1029 | #print value from pipe 1030 | print mRP[u'ppipe'].recv() 1031 | -------------------------------------------------------------------------------- /python2.7/rptest.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | #Name: rptest 3 | #Purpose: test module for refprop and multiRP 4 | # 5 | #Author: Thelen, B.J. 6 | # thelen_ben@yahoo.com 7 | #------------------------------------------------------------------------------- 8 | u'''Allow refprop and multiRP module functional test of all functions''' 9 | 10 | 11 | ####################################################### test if some windows functions are working now with rp9.1 12 | 13 | from decimal import Decimal 14 | import platform 15 | 16 | def settest(test): 17 | u'''set test module 18 | 'refprop' or 'multiRP' 19 | and execute test run''' 20 | if test == u'refprop': 21 | import refprop as rp 22 | _maintest(rp) 23 | elif test == u'multiRP': 24 | import multiRP as rp 25 | _maintest(rp) 26 | 27 | #main test def. for usage at refprop and multiRP 28 | def _maintest(rp): 29 | #examples and test setup 30 | rp.SetErrorDebug.off() #turn on =>> for testing purpose 31 | 32 | if rp.test(): #if True; rptest =>>for testing purpose 33 | print u'refprop installed correctely' 34 | 35 | print u'test results' 36 | print rp.testresult 37 | 38 | print u'fluidlib' 39 | rp.fluidlib() 40 | print u'\n' 41 | 42 | prop = rp.setup(u'def', u'air',) 43 | print u'setup air' 44 | print prop, u'\n' 45 | 46 | x = prop[u'x'] 47 | 48 | print u'critp(x)' 49 | print rp.critp(x), u'\n' 50 | 51 | print u'setup water ammonia' 52 | print rp.setup(u'def', u'water', u'ammonia',), u'\n' 53 | 54 | #alternative setup input 55 | rp.setup(u'def', [u'water', u'ammonia'],) 56 | 57 | x = [0.5, 0.3] 58 | prop = rp.normalize(x) 59 | x = prop[u'x'] 60 | 61 | prop = rp.critp(x) 62 | prop = rp.therm(prop[u'tcrit'], prop[u'Dcrit'], x) 63 | print u'therm' 64 | print prop, u'\n' 65 | 66 | p = prop[u'p'] 67 | 68 | print u'therm2' 69 | print rp.therm2(prop[u't'], prop[u'D'], x), u'\n' 70 | 71 | print u'therm0' 72 | print rp.therm0(prop[u't'], prop[u'D'], x), u'\n' 73 | 74 | print u'residual' 75 | print rp.residual(prop[u't'], prop[u'D'], x), u'\n' 76 | 77 | print u'entro' 78 | print rp.entro(prop[u't'], prop[u'D'], x), u'\n' 79 | 80 | print u'enthal' 81 | print rp.enthal(prop[u't'], prop[u'D'], x), u'\n' 82 | 83 | print u'ag' 84 | print rp.ag(prop[u't'], prop[u'D'], x), u'\n' 85 | 86 | print u'cvcp' 87 | print rp.cvcp(prop[u't'], prop[u'D'], x), u'\n' 88 | 89 | print u'dddp' 90 | print rp.dddp(prop[u't'], prop[u'D'], x), u'\n' 91 | 92 | print u'dddt' 93 | print rp.dddt(prop[u't'], prop[u'D'], x), u'\n' 94 | 95 | print u'dhd1' 96 | print rp.dhd1(prop[u't'], prop[u'D'], x), u'\n' 97 | 98 | print u'dpdd' 99 | print rp.dpdd(prop[u't'], prop[u'D'], x), u'\n' 100 | 101 | print u'dpdd2' 102 | print rp.dpdd2(prop[u't'], prop[u'D'], x), u'\n' 103 | 104 | print u'dpdt' 105 | print rp.dpdt(prop[u't'], prop[u'D'], x), u'\n' 106 | 107 | D = prop[u'D'] 108 | 109 | #function not supported in Windows 110 | if platform.system() == u'Linux': 111 | print u'dcdt' 112 | print rp.dcdt(prop[u't'], x), u'\n' 113 | 114 | #function not supported in Windows 115 | if platform.system() == u'Linux': 116 | print u'dcdt2' 117 | print rp.dcdt2(prop[u't'], x), u'\n' 118 | 119 | print u'fgcty' 120 | print rp.fgcty(prop[u't'], D, x), u'\n' 121 | 122 | print u'gibbs' 123 | print rp.gibbs(prop[u't'], prop[u'D'], x), u'\n' 124 | 125 | #~ print('fgcty2') 126 | #~ print(rp.fgcty2(prop['t'], prop['D'], x), '\n') 127 | 128 | prop = rp.therm3(prop[u't'], prop[u'D'], x) 129 | print u'therm3' 130 | print prop, u'\n' 131 | 132 | D = prop[u'D'] 133 | 134 | print u'virb' 135 | print rp.virb(prop[u't'], x), u'\n' 136 | 137 | print u'virc' 138 | print rp.virc(prop[u't'], x), u'\n' 139 | 140 | #function not supported in Windows 141 | if platform.system() == u'Linux': 142 | print u'vird' 143 | print rp.vird(prop[u't'], x), u'\n' 144 | 145 | print u'virba' 146 | print rp.virba(prop[u't'], x), u'\n' 147 | 148 | print u'virca' 149 | print rp.virca(prop[u't'], x), u'\n' 150 | 151 | print u'cvcpk' 152 | print rp.cvcpk(1, prop[u't'], D), u'\n' 153 | 154 | print u'dbdt' 155 | print rp.dbdt(prop[u't'], x), u'\n' 156 | 157 | print u'dpddk' 158 | print rp.dpddk(1, prop[u't'], D), u'\n' 159 | 160 | print u'dpdtk' 161 | print rp.dpdtk(2, prop[u't'], D), u'\n' 162 | 163 | D = 55 164 | t = 373 165 | 166 | prop = rp.press(t, D, x) 167 | print u'press' 168 | print prop, u'\n' 169 | 170 | p = prop[u'p'] 171 | 172 | print u'purefld(1)' 173 | prop = rp.purefld(1) 174 | print prop, u'\n' 175 | 176 | x = [1] 177 | 178 | resetup_test_prop_d = prop 179 | 180 | print u'satt' 181 | prop = rp.satt(t, x) 182 | print prop, u'\n' 183 | 184 | print u'satp' 185 | prop = rp.satp(prop[u'p'], x) 186 | print prop, u'\n' 187 | 188 | print u'satd' 189 | print rp.satd(prop[u'Dliq'], x), u'\n' 190 | 191 | print u'sath' 192 | print rp.sath(47000, x, 0), u'\n' 193 | 194 | print u'sate' 195 | print rp.sate(0.46047E-13, x), u'\n' 196 | 197 | print u'sats' 198 | print rp.sats(50, x, 0), u'\n' 199 | 200 | print u'purefld(0)' 201 | print rp.purefld(0), u'\n' 202 | 203 | x = [0.5, 0.3] 204 | x = rp.normalize(x)[u'x'] 205 | 206 | print u'csatk' 207 | print rp.csatk(1, t), u'\n' 208 | 209 | print u'dptsatk' 210 | print rp.dptsatk(1, t), u'\n' 211 | 212 | print u'cv2pk' 213 | print rp.cv2pk(2, t, D), u'\n' 214 | 215 | print u'tprho' 216 | print rp.tprho(t, p, x, 2, 1, 58), u'\n' 217 | 218 | print u'flsh, tp' 219 | prop = rp.flsh(u'tp', t, p, x) 220 | print prop, u'\n' 221 | 222 | print u'flsh, th' 223 | print rp.flsh(u'tH', 305, prop[u'h'], x, 1), u'\n' 224 | 225 | print u'flsh, tD' 226 | print rp.flsh(u'tD', t, 30, x), u'\n' 227 | 228 | print u'info()' 229 | print rp.info(), u'\n' 230 | 231 | print u'info(2)' 232 | print rp.info(2), u'\n' 233 | 234 | #unsupported in Windows 235 | if platform.system() == u'Linux': 236 | print u'rmix2' 237 | print rp.rmix2(x), u'\n' 238 | 239 | print u'xmass' 240 | prop = rp.xmass(x) 241 | print prop, u'\n' 242 | 243 | print u'xmole' 244 | print rp.xmole(prop[u'xkg']), u'\n' 245 | 246 | print u'limitx' 247 | print rp.limitx(x, u'eos', t, D, p), u'\n' 248 | 249 | print u'limitk' 250 | print rp.limitk(u'eos', 1, t, D, p), u'\n' 251 | 252 | print u'limits' 253 | print rp.limits(x), u'\n' 254 | 255 | print u'flsh, ts' 256 | prop = rp.flsh(u'ts', t, 40, x) 257 | print prop, u'\n' 258 | 259 | print u'flsh, te' 260 | print rp.flsh(u'te', t, prop[u'e'], x), u'\n' 261 | 262 | print u'flsh, pD' 263 | prop = rp.flsh(u'Pd', p, D, x) 264 | print prop, u'\n' 265 | 266 | print u'flsh, ph' 267 | prop = rp.flsh(u'ph', p, prop[u'h'], x) 268 | print prop, u'\n' 269 | 270 | print u'flsh, ps' 271 | prop = rp.flsh(u'ps', p, prop[u's'], x) 272 | print prop, u'\n' 273 | 274 | print u'flsh, pe' 275 | prop = rp.flsh(u'pE', p, prop[u'e'], x) 276 | print prop, u'\n' 277 | 278 | print u'flsh, es' 279 | prop = rp.flsh(u'es', prop[u'e'], prop[u's'], x) 280 | print prop, u'\n' 281 | 282 | print u'flsh, hs' 283 | prop = rp.flsh(u'hs', 40000, 100, x) 284 | print prop, u'\n' 285 | 286 | print u'flsh, es' 287 | print rp.flsh(u'es', 175, 13, x), u'\n' 288 | 289 | print u'flsh, Dh' 290 | print rp.flsh(u'DH', 20, 18000, x), u'\n' 291 | 292 | print u'flsh, Ds' 293 | prop = rp.flsh(u'Ds', 20, 50, x) 294 | print prop, u'\n' 295 | 296 | print u'flsh, De' 297 | prop = rp.flsh(u'DE', 20, prop[u'e'], x) 298 | print prop, u'\n' 299 | 300 | print u'flsh, tq' 301 | prop = rp.flsh(u'tq', t, prop[u'q'], x) 302 | print prop, u'\n' 303 | 304 | print u'flsh, pq' 305 | print rp.flsh(u'pq', 1200, prop[u'q'], x), u'\n' 306 | 307 | prop = rp.flsh(u'tp', 350, 1200, x) 308 | print u'flsh, tp' 309 | print prop, u'\n' 310 | s = prop[u's'] 311 | e = prop[u'e'] 312 | h = prop[u'h'] 313 | D = prop[u'D'] 314 | t = prop[u't'] 315 | p = prop[u'p'] 316 | Dmin = 40 317 | Dmax = 55 318 | 319 | print u'flsh1, liq, ph' 320 | print rp.flsh1(u'Ph', p, h, x, 1), u'\n' 321 | 322 | print u'getphase' 323 | print rp.getphase(prop), u'\n' 324 | 325 | print u'flsh1, liq, pD' 326 | print rp.flsh1(u'PD', p, D, x), u'\n' 327 | 328 | print u'flsh1, liq, ps' 329 | print rp.flsh1(u'Ps', p, s, x), u'\n' 330 | 331 | #unsupported in Windows 332 | if platform.system() == u'Linux': 333 | print u'flsh1, liq, th' 334 | print rp.flsh1(u'th', t, h, x, Dmin=Dmin, Dmax=Dmax), u'\n' 335 | 336 | #unsupported in Windows 337 | if platform.system() == u'Linux': 338 | print u'flsh1, liq, ts' 339 | print rp.flsh1(u'ts', t, s, x, Dmin=Dmin, Dmax=Dmax), u'\n' 340 | 341 | #unsupported in Windows 342 | if platform.system() == u'Linux': 343 | print u'flsh1, liq, te' 344 | print rp.flsh1(u'te', t, e, x, Dmin=Dmin, Dmax=Dmax), u'\n' 345 | 346 | #unsupported in Windows 347 | if platform.system() == u'Linux': 348 | print u'flsh1, liq, pe' 349 | print rp.flsh1(u'Pe', p, e, x), u'\n' 350 | 351 | #unsupported in Windows 352 | if platform.system() == u'Linux': 353 | print u'flsh1, liq, hs' 354 | print rp.flsh1(u'hs', h, s, x, Dmin=Dmin, Dmax=Dmax), u'\n' 355 | 356 | #unsupported in Windows 357 | if platform.system() == u'Linux': 358 | print u'flsh1, liq, Dh' 359 | print rp.flsh1(u'Dh', D, h, x), u'\n' 360 | 361 | #unsupported in Windows 362 | if platform.system() == u'Linux': 363 | print u'flsh1, liq, Ds' 364 | print rp.flsh1(u'Ds', D, s, x), u'\n' 365 | 366 | #unsupported in Windows 367 | if platform.system() == u'Linux': 368 | print u'flsh1, liq, De' 369 | print rp.flsh1(u'De', D, e, x), u'\n' 370 | 371 | prop = rp.flsh(u'tp', 400, 100, x) 372 | s = prop[u's'] 373 | e = prop[u'e'] 374 | h = prop[u'h'] 375 | D = prop[u'D'] 376 | Dmin = 0.01 377 | Dmax = 0.05 378 | t = prop[u't'] 379 | p = prop[u'p'] 380 | 381 | print u'flsh1, vap, ph' 382 | print rp.flsh1(u'Ph', p, h, x, 2), u'\n' 383 | 384 | print u'getphase' 385 | print rp.getphase(prop), u'\n' 386 | 387 | print u'flsh1, vap, pD' 388 | print rp.flsh1(u'PD', p, D, x, 2), u'\n' 389 | 390 | print u'flsh1, vap, ps' 391 | print rp.flsh1(u'Ps', p, s, x, 2), u'\n' 392 | 393 | #unsupported in Windows 394 | if platform.system() == u'Linux': 395 | print u'flsh1, vap, th' 396 | print rp.flsh1(u'th', t, h, x, Dmin=Dmin, Dmax=Dmax), u'\n' 397 | 398 | #unsupported in Windows 399 | if platform.system() == u'Linux': 400 | print u'flsh1, vap, ts' 401 | print rp.flsh1(u'ts', t, s, x, Dmin=Dmin, Dmax=Dmax), u'\n' 402 | 403 | #unsupported in Windows 404 | if platform.system() == u'Linux': 405 | print u'flsh1, vap, te' 406 | print rp.flsh1(u'te', t, e, x, Dmin=Dmin, Dmax=Dmax), u'\n' 407 | 408 | #unsupported in Windows 409 | if platform.system() == u'Linux': 410 | print u'flsh1, vap, pe' 411 | print rp.flsh1(u'Pe', p, e, x, 2), u'\n' 412 | 413 | #unsupported in Windows 414 | if platform.system() == u'Linux': 415 | print u'flsh1, vap, hs' 416 | print rp.flsh1(u'hs', h, s, x, Dmin=Dmin, Dmax=Dmax), u'\n' 417 | 418 | #unsupported in Windows 419 | if platform.system() == u'Linux': 420 | print u'flsh1, vap, Dh' 421 | print rp.flsh1(u'Dh', D, h, x), u'\n' 422 | 423 | #unsupported in Windows 424 | if platform.system() == u'Linux': 425 | print u'flsh1, vap, Ds' 426 | print rp.flsh1(u'Ds', D, s, x), u'\n' 427 | 428 | #unsupported in Windows 429 | if platform.system() == u'Linux': 430 | print u'flsh1, vap, De' 431 | print rp.flsh1(u'De', D, e, x), u'\n' 432 | 433 | print u'cstar' 434 | print rp.cstar(t, p, 8, x), u'\n' 435 | 436 | print u'fpv' 437 | print rp.fpv(t, D, p, x), u'\n' 438 | 439 | #function not supported in Windows 440 | if platform.system() == u'Linux': 441 | print u'excess' 442 | print rp.excess(t, p, x, kph=2), u'\n' 443 | 444 | prop = rp.flsh(u'pq', 1200, 0.65, x) 445 | D = prop[u'D'] 446 | Dliq = prop[u'Dliq'] 447 | Dvap = prop[u'Dvap'] 448 | xliq = prop[u'xliq'] 449 | xvap = prop[u'xvap'] 450 | e = prop[u'e'] 451 | h = prop[u'h'] 452 | s = prop[u's'] 453 | q = prop[u'q'] 454 | p = prop[u'p'] 455 | t = prop[u't'] 456 | 457 | #function not supported in Windows 458 | if platform.system() == u'Linux': 459 | print u'tpfl2' 460 | print rp.flsh2(u'tp', t, p, x), u'\n' 461 | 462 | #function not supported in Windows 463 | if platform.system() == u'Linux': 464 | print u'Dhfl2' 465 | print rp.flsh2(u'Dh', D, h, x), u'\n' 466 | 467 | #function not supported in Windows 468 | if platform.system() == u'Linux': 469 | print u'Dsfl2' 470 | print rp.flsh2(u'Ds', D, s, x), u'\n' 471 | 472 | #function not supported in Windows 473 | if platform.system() == u'Linux': 474 | print u'Defl2' 475 | print rp.flsh2(u'De', D, e, x), u'\n' 476 | 477 | #function not supported in Windows 478 | if platform.system() == u'Linux': 479 | print u'thfl2' 480 | print rp.flsh2(u'th', t, h, x, ksat=0), u'\n' 481 | 482 | #function not supported in Windows 483 | if platform.system() == u'Linux': 484 | print u'tsfl2' 485 | print rp.flsh2(u'ts', t, s, x, ksat=0), u'\n' 486 | 487 | #function not supported in Windows 488 | if platform.system() == u'Linux': 489 | print u'tefl2' 490 | print rp.flsh2(u'te', t, e, x, ksat=0), u'\n' 491 | 492 | #function not supported in Windows 493 | if platform.system() == u'Linux': 494 | print u'tDfl2' 495 | print rp.flsh2(u'tD', t, D, x, ksat=0), u'\n' 496 | 497 | #function not supported in Windows 498 | if platform.system() == u'Linux': 499 | print u'pDfl2' 500 | print rp.flsh2(u'pD', p, D, x, ksat=0), u'\n' 501 | 502 | #function not supported in Windows 503 | if platform.system() == u'Linux': 504 | print u'phfl2' 505 | print rp.flsh2(u'ph', p, h, x, ksat=0), u'\n' 506 | 507 | #function not supported in Windows 508 | if platform.system() == u'Linux': 509 | print u'psfl2' 510 | print rp.flsh2(u'ps', p, s, x, ksat=0), u'\n' 511 | 512 | #function not supported in Windows 513 | if platform.system() == u'Linux': 514 | print u'pefl2' 515 | print rp.flsh2(u'pe', p, e, x, ksat=0), u'\n' 516 | 517 | #function not supported in Windows 518 | if platform.system() == u'Linux': 519 | print u'tqfl2' 520 | print rp.flsh2(u'tq', t, q, x, ksat=0), u'\n' 521 | 522 | #function not supported in Windows 523 | if platform.system() == u'Linux': 524 | print u'pqfl2' 525 | print rp.flsh2(u'pq', p, q, x, ksat=0), u'\n' 526 | 527 | #function not supported in Windows 528 | #~ if platform.system() == 'Linux': 529 | #~ print('Dqfl2') 530 | #~ print(rp.flsh2('Dq', D, q, x), '\n') 531 | 532 | prop = rp.flsh(u'tp', 340, 100, x) 533 | t = prop[u't'] 534 | Dliq = prop[u'Dliq'] 535 | Dvap = prop[u'Dvap'] 536 | xliq = prop[u'xliq'] 537 | xvap = prop[u'xvap'] 538 | 539 | print u'qmass' 540 | prop = rp.qmass(prop[u'q'], xliq, xvap) 541 | print prop, u'\n' 542 | 543 | print u'qmole' 544 | print rp.qmole(prop[u'qkg'], prop[u'xlkg'], prop[u'xvkg']), u'\n' 545 | 546 | print u'wmol' 547 | print rp.wmol(x), u'\n' 548 | 549 | prop = rp.flsh(u'tp', 340, 100, x) 550 | 551 | print u'dielec' 552 | print rp.dielec(prop[u't'], prop[u'D'], x), u'\n' 553 | 554 | print u'surten' 555 | print rp.surten (t, Dliq, Dvap, xliq, xvap), u'\n' 556 | 557 | print u'surft' 558 | print rp.surft(240, x), u'\n' 559 | 560 | rp.setup(u'def', u'water') 561 | 562 | print u'meltt' 563 | print rp.meltt(273.15, [1]), u'\n' 564 | 565 | print u'meltp' 566 | print rp.meltp(100, [1]), u'\n' 567 | 568 | print u'sublt' 569 | print rp.sublt(273.15, [1]), u'\n' 570 | 571 | print u'sublp' 572 | print rp.sublp(0.1, [1]), u'\n' 573 | 574 | rp.setup(u'def', u'butane', u'ethane', u'propane', u'methane',) 575 | x = [0.5, 0.15, 0.3, 0.05] 576 | rp.setref(u'nbp') 577 | prop = rp.flsh(u'tp', 260, 150, x) 578 | D = prop[u'D'] 579 | print u'trnprp, setref' 580 | print rp.trnprp(260, D, x), u'\n' 581 | 582 | print u'B12' 583 | print rp.b12(260, x), u'\n' 584 | 585 | print u'chempot' 586 | print rp.chempot(260, D, x), u'\n' 587 | 588 | print u'fugcof' 589 | print rp.fugcof(260, D, x), u'\n' 590 | 591 | ###function not supported in Windows 592 | #if platform.system() == 'Linux': input values changed.............................. 593 | #print('phiderv') 594 | #print(rp.phiderv(2, 1, 260, D, x), '\n') 595 | 596 | #function not supported in Windows 597 | if platform.system() == u'Linux': 598 | print u'getmod' 599 | print rp.getmod(1, u'EOS'), u'\n' 600 | 601 | rp.setmod(u'tcx', u'ecs', [u'tc2', u'tc1', u'tc2', u'tc2']) 602 | rp.setup(u'def', u'butane', u'ethane', u'propane', u'methane',) 603 | x = [0.5, 0.15, 0.3, 0.05] 604 | prop = rp.flsh(u'tp', 260, 200, x) 605 | print u'trnprp, setref NBP, setmod [tcx, ecs, tc2, tc1, tc2, tc2]' 606 | print rp.trnprp(260, prop[u'D'], x), u'\n' 607 | 608 | #function not supported in Windows 609 | if platform.system() == u'Linux': 610 | print u'getmod' 611 | print rp.getmod(3, u'tcx'), u'\n' 612 | 613 | rp.setref(u'oth', 1, [1], 0, 0, 273, 100) 614 | print u'setref = OTH' 615 | prop = rp.flsh(u'tp', 260, 200, x) 616 | print prop, u'\n' 617 | 618 | resetup_test_prop_a = prop 619 | 620 | rp.setref(u'???', 1, [1], 0, 0, 373, 100) 621 | print u'setref = ???' 622 | prop = rp.flsh(u'tp', 260, 200, x) 623 | print prop, u'\n' 624 | 625 | resetup_test_prop_b = prop 626 | 627 | print u'name' 628 | print rp.name(1), u'\n' 629 | 630 | rp.setup(u'def', u'butane', u'ethane', u'propane', u'methane',) 631 | x = [0.5, 0.15, 0.3, 0.05] 632 | print u'getktv' 633 | prop = rp.getktv(1, 3) 634 | print prop, u'\n' 635 | 636 | print u'setktv' 637 | prop = rp.setktv(1, 3, u'lin', prop[u'fij'], prop[u'hfmix'],) 638 | print prop, u'\n' 639 | 640 | resetup_test_prop_c = prop 641 | 642 | print u'reset setktv' 643 | print rp.setktv(1, 2, u'rst'), u'\n' 644 | 645 | print u'getfij' 646 | print rp.getfij(u'LIN'), u'\n' 647 | 648 | print u'resetup_test_prop, setref, setmod' 649 | print resetup_test_prop_a, u'\n' 650 | 651 | print u'resetup' 652 | print rp.resetup(resetup_test_prop_a), u'\n' 653 | 654 | print u'resetup_test_prop, setref(???), setmod' 655 | print resetup_test_prop_b, u'\n' 656 | 657 | print u'resetup' 658 | print rp.resetup(resetup_test_prop_b), u'\n' 659 | 660 | print u'resetup_test_prop, setktv' 661 | print resetup_test_prop_c, u'\n' 662 | 663 | print u'resetup' 664 | print rp.resetup(resetup_test_prop_c), u'\n' 665 | 666 | print u'resetup_test_prop, purefld' 667 | print resetup_test_prop_d, u'\n' 668 | 669 | print u'resetup' 670 | print rp.resetup(resetup_test_prop_d), u'\n' 671 | 672 | #normalize([0.2, 0.2, 0.1, 0.1]) 673 | print u'normalize' 674 | print rp.normalize([0.2, 0.2, 0.1, 0.1]), u'\n' 675 | 676 | #setup_details 677 | print u'setup_details' 678 | print rp.setup_details({u'hfld': [u'BUTANE', u'ETHANE', u'PROPANE', u'METHANE'], 679 | u'D': 0.21683907260570098, 680 | u'Dvap': 0.09664613429889905, u'hfmix': u'HMX.BNC', 681 | u'setmod': {u'hcomp': [u'TC2', u'TC1', u'TC2', u'TC2'], 682 | u'htype': u'TCX', u'hmix': u'ECS'}, 683 | u'cp': -9999980.0, 684 | u'xliq': [Decimal(u'0.7125650648765283717349528049'), 685 | Decimal(u'0.04065955068790887177072495080'), 686 | Decimal(u'0.2449672538076863186375885862'), 687 | Decimal(u'0.001808130627876437856733658079')], 688 | u'xvap': [Decimal(u'0.2304027911956556081031262882'), 689 | Decimal(u'0.2886769748808782463382744488'), 690 | Decimal(u'0.3697982730402927396744896960'), 691 | Decimal(u'0.1111219608831734058841095670')], 692 | u'x': [0.5, 0.15, 0.3, 0.05], u'e': -13828.39837781548, 693 | u'h': -12906.055381248256, u'nc': 4, 694 | u'Dliq': 11.150114864150222, u'cv': -9999980.0, 695 | u'q': 0.4408579356823604, u'p': 200.0, 696 | u's': -44.047682476988044, u't': 260.0, u'w': -9999980.0, 697 | u'kph': 1, u'setref': {u'p0': 100, u'ixflag': 1, u'h0': 0, 698 | u's0': 0, u't0': 273, 699 | u'hrf': [u'OTH', u'???']}, 700 | u'hrf': u'DEF'}), u'\n' 701 | 702 | #gerg04 703 | print u'gerg04 = 1' 704 | rp.gerg04(1) 705 | print rp.setup(u'def', u'butane', u'ethane', u'propane'), u'\n' 706 | 707 | #reset gerg04 708 | print u'gerg04 = 0' 709 | rp.gerg04(0) 710 | print rp.setup(u'def', u'butane', u'ethane', u'propane'), u'\n' 711 | 712 | #preos 713 | print u'preos = 2' 714 | print rp.preos(2), u'\n' 715 | 716 | print u'preos = -1' 717 | print rp.preos(-1), u'\n' 718 | 719 | print u'preos = 0' 720 | print rp.preos(0), u'\n' 721 | 722 | print u'preos = -1' 723 | print rp.preos(-1), u'\n' 724 | 725 | #setaga 726 | print u'setaga' 727 | print rp.setaga(), u'\n' 728 | 729 | #unsetaga 730 | print u'unsetaga' 731 | print rp.unsetaga(), u'\n' 732 | 733 | #setup_settings 734 | print u'setup_setting' 735 | print rp.setup_setting(), u'\n' 736 | -------------------------------------------------------------------------------- /python3.2/multiRP.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | #Name: multiRP 3 | #Purpose: allowing multiple refprop calculations simultaneously with 4 | # multiple CPU support using python multiprocessing module 5 | # 6 | #Author: Thelen, B.J. 7 | # thelen_ben@yahoo.com 8 | #------------------------------------------------------------------------------- 9 | 10 | '''Multiprocessing can be done with refprop.py module provided that the setup 11 | details of each refprop routine called simultaneously is identical. 12 | 13 | This module manage and control call of various routines of different setup 14 | details such that only routines of identical setup details are being called 15 | simultanously. The no. cores and threads of cpu matches the the maximum multiple 16 | refprop calculations to be performed simultanously. 17 | 18 | The aim of this module is to gain time of fluid cycle calculations. 19 | 20 | All the same functions as found in the refprop module are available with 21 | additional input of the setup details and porting of the multiprocessing 22 | variables 23 | 24 | Note for windows users, initialtion of multirefprop does require some time 25 | which could render the time gain. On my system the initiation difference ratio 26 | between Linux and Windows is 14.04365604 times (in favour for Linux)''' 27 | 28 | ## to be implemented 29 | ## put _fldext in parent shared lib. for general access to all children this saves time.... 30 | 31 | 32 | 33 | import os 34 | import sys 35 | import refprop 36 | import time 37 | import multiprocessing as mp 38 | from decimal import Decimal 39 | 40 | #input declarations 41 | RefpropError = refprop.RefpropError 42 | RefpropdllError = refprop.RefpropdllError 43 | RefpropicompError = refprop.RefpropicompError 44 | RefpropinputError = refprop.RefpropinputError 45 | RefpropnormalizeError = refprop.RefpropnormalizeError 46 | RefproproutineError = refprop.RefproproutineError 47 | RefpropWarning = refprop.RefpropWarning 48 | RefpropdllWarning = refprop.RefpropdllWarning 49 | 50 | #Classes 51 | class _MultiRefProp(mp.Process): 52 | '''initiate multiprocessing for refprop, 53 | 54 | this function needs to be called prior to usage of multiRP and under 55 | "if __name__ == '__main__':" enable to function properly''' 56 | def __init__(self): 57 | self.process = mp.Process 58 | self.mgr = mp.Manager() 59 | self.sem = mp.Semaphore(mp.cpu_count()) 60 | self.result = self.mgr.dict() #result dict 61 | self.ppipe, self.cpipe = mp.Pipe() #parent pipe, #child pipe 62 | 63 | class MultiRPError(RefpropError): 64 | 'General error for multiRP' 65 | pass 66 | 67 | class SetupError(MultiRPError): 68 | 'Raise input error when Setups are blocked' 69 | def __init__(self, value): 70 | self.value = value 71 | def __str__(self): 72 | return repr(self.value) 73 | 74 | class MultiRPInputError(MultiRPError): 75 | 'Raise input error when Setups are blocked' 76 | def __init__(self, value): 77 | self.value = value 78 | def __str__(self): 79 | return repr(self.value) 80 | 81 | class MultiRPChildError(MultiRPError): 82 | 'Raise input error when Setups are blocked' 83 | def __init__(self, value): 84 | self.value = value 85 | def __str__(self): 86 | return repr(self.value) 87 | 88 | 89 | #Classes from refprop.py 90 | class FluidModel(refprop.FluidModel): 91 | '''return array of fluid model''' 92 | pass 93 | 94 | class SetWarning(): 95 | 'Return RefpropdllWarning status (on / off)' 96 | def __repr__(self): 97 | return str(refprop.SetWarning()) 98 | @staticmethod 99 | def on(prop=None, mRP=None): 100 | 'Sets RefpropdllWarning on, initiate Error on Refpropdll ierr value < 0' 101 | global _inhibt_setuperror 102 | _inhibt_setuperror = True 103 | def _rpfunc(): 104 | global _inhibt_setuperror, _setupprop 105 | _inhibt_setuperror = False 106 | prop = refprop.SetWarning.on() 107 | #adjust _setupprop 108 | _setupprop = setup_details(prop) 109 | return prop 110 | return _rpfunc_handler(prop, mRP, _rpfunc) 111 | @staticmethod 112 | def off(prop=None, mRP=None): 113 | 'Sets RefpropdllWarning off, no Error raised on Refpropdll ierr value < 0' 114 | global _inhibt_setuperror 115 | _inhibt_setuperror = True 116 | def _rpfunc(): 117 | global _inhibt_setuperror, _setupprop 118 | _inhibt_setuperror = False 119 | prop = refprop.SetWarning.off() 120 | #adjust _setupprop 121 | _setupprop = setup_details(prop) 122 | return prop 123 | return _rpfunc_handler(prop, mRP, _rpfunc) 124 | 125 | class SetError(): 126 | 'Return RefpropdllError status (on / off)' 127 | def __repr__(self): 128 | return str(refprop.SetError()) 129 | @staticmethod 130 | def on(prop=None, mRP=None): 131 | 'Sets RefpropdllError on, initiate Error on Refpropdll ierr value != 0' 132 | global _inhibt_setuperror 133 | _inhibt_setuperror = True 134 | def _rpfunc(): 135 | global _inhibt_setuperror, _setupprop 136 | _inhibt_setuperror = False 137 | prop = refprop.SetError.on() 138 | #adjust _setupprop 139 | _setupprop = setup_details(prop) 140 | return prop 141 | return _rpfunc_handler(prop, mRP, _rpfunc) 142 | @staticmethod 143 | def off(prop=None, mRP=None): 144 | 'Sets RefpropdllError off, no Error raised on Refpropdll ierr value != 0' 145 | global _inhibt_setuperror 146 | _inhibt_setuperror = True 147 | def _rpfunc(): 148 | global _inhibt_setuperror, _setupprop 149 | _inhibt_setuperror = False 150 | prop = refprop.SetError.off() 151 | #adjust _setupprop 152 | _setupprop = setup_details(prop) 153 | return prop 154 | return _rpfunc_handler(prop, mRP, _rpfunc) 155 | 156 | class SetErrorDebug(): 157 | 'Return SetErrorDebug status (on / off)' 158 | def __repr__(self): 159 | return str(refprop.SetErrorDebug()) 160 | @staticmethod 161 | def on(prop=None, mRP=None): 162 | 'Sets error debug mode on, displays error message only' 163 | global _inhibt_setuperror 164 | _inhibt_setuperror = True 165 | def _rpfunc(): 166 | global _inhibt_setuperror, _setupprop 167 | _inhibt_setuperror = False 168 | prop = refprop.SetErrorDebug.on() 169 | #adjust _setupprop 170 | _setupprop = setup_details(prop) 171 | return prop 172 | return _rpfunc_handler(prop, mRP, _rpfunc) 173 | @staticmethod 174 | def off(prop=None, mRP=None): 175 | 'Sets error debug mode off, displays error message only' 176 | global _inhibt_setuperror 177 | _inhibt_setuperror = True 178 | def _rpfunc(): 179 | global _inhibt_setuperror, _setupprop 180 | _inhibt_setuperror = False 181 | prop = refprop.SetErrorDebug.off() 182 | #adjust _setupprop 183 | _setupprop = setup_details(prop) 184 | return prop 185 | return _rpfunc_handler(prop, mRP, _rpfunc) 186 | 187 | 188 | #functions 189 | def multirefprop(): 190 | 'initiate multiprocessing variables' 191 | global mRP 192 | #identify parent process (only parent can call this) 193 | if mp.current_process()._parent_pid == None: 194 | #only call if never called 195 | if not 'mRP' in globals(): 196 | _mRP = _MultiRefProp() 197 | mRP = {'sem':_mRP.sem, 198 | 'process':_mRP.process, 199 | 'result':_mRP.result, 'ppipe':_mRP.ppipe, 200 | 'cpipe':_mRP.cpipe} 201 | else: 202 | raise MultiRPChildError( 203 | 'Only parent process can initiate mRP variables') 204 | 205 | return mRP 206 | 207 | def run_mRP(processlist): 208 | 'start, close and check child processes' 209 | #start child processes 210 | for each in processlist: 211 | each.start() 212 | #close child processes 213 | for each in processlist: 214 | each.join() 215 | #check for errors in child processes 216 | for each in processlist: 217 | if each.exitcode != 0: 218 | raise MultiRPChildError('child error in ' + each.name + 219 | ' exitcode = ' + str(each.exitcode)) 220 | 221 | 222 | def _multirefprop(_mRP): 223 | 'Set parent multiprocessing variables as globals' 224 | global sem, process, result, mRP, ppipe, cpipe 225 | sem = _mRP['sem'] 226 | result = _mRP['result'] 227 | process = _mRP['process'] 228 | mRP = _mRP 229 | cpipe = _mRP['cpipe'] 230 | ppipe = _mRP['ppipe'] 231 | 232 | def ppip(): 233 | 'return parent pipe' 234 | if 'mRP' in globals(): 235 | return mRP['pipe'] 236 | else: 237 | raise MultiRPInputError('parent pipe can not be return without a' + 238 | ' multirefprop() call') 239 | 240 | def _rpfunc_handler(prop, mRP, _rpfunc): 241 | global _setupprop 242 | #verify either prop has value or value has been set before' 243 | if prop == None \ 244 | and ('_setupprop' not in dir(refprop) \ 245 | or refprop._setupprop == {}) \ 246 | and '_inhibt_setuperror' in globals() \ 247 | and not _inhibt_setuperror: 248 | raise MultiRPInputError( 249 | 'First refprop function in child needs setup' + 250 | ' details in "prop" to be defined' + 251 | ' or parent process needs setup input first') 252 | if mRP != None: 253 | #set mRP values as globals 254 | _multirefprop(mRP) 255 | if prop != None: 256 | #store prop as global for continue function call in same child 257 | _setupprop = setup_details(prop) 258 | #identify child process 259 | if mp.current_process()._parent_pid != None: 260 | if prop == None: 261 | if '_setupprop' not in globals() or _setupprop == None: 262 | raise MultiRPInputError( 263 | 'child process needs "prop" input for first refprop function') 264 | #function call to inherite prop values from previous call 265 | prop = _setupprop 266 | #raise error if child process is initiated without mRP settings 267 | if not 'mRP' in globals(): 268 | raise MultiRPInputError( 269 | 'child process needs "mRP" input for first refprop function') 270 | #resetup fluid 271 | refprop.resetup(prop) 272 | with sem: 273 | #run function, this is where the refprop function is called 274 | prps = _rpfunc() 275 | #return result in result.dict (for child processes only) 276 | result[process().name.rsplit(':', 1)[0]] = prps 277 | return prps 278 | #identify parent process 279 | elif mp.current_process()._parent_pid == None: 280 | #confirm active children 281 | if len(mp.active_children()) > 1: 282 | #raise error if children are active 283 | raise MultiRPInputError( 284 | 'parent process can not proceed with ' + 285 | 'child processes being handled. Wait untill ' + 286 | 'child processes have joined. Use run_mRP ' + 287 | 'command to start and join child processes.') 288 | #resetup 289 | if prop != None: 290 | refprop.resetup(prop) 291 | #run function 292 | return _rpfunc() 293 | 294 | def _checksetupblock(name): ##################################################################perhaps this whole function can be ommitted, but carefully as settings are passed through 295 | if mp.current_process()._parent_pid != None: 296 | #raise error if child process request for setup 297 | raise SetupError('function "' + str(name) + 298 | '" is blocked for multiRP child processes') 299 | elif len(mp.active_children()) > 1: 300 | #raise error if parent process request for setup while child process(es) 301 | #are active. 302 | raise SetupError( 303 | 'function "' + str(name) + 304 | '" is blocked while multiRP child processes are active') 305 | 306 | 307 | #functions from refprop.py 308 | def setpath(path='c:/program files/refprop/'): 309 | '''Set Directory to refprop root containing fluids and mixtures.''' 310 | refprop.setpath(path) 311 | 312 | def fluidlib(): 313 | '''Displays all fluids and mixtures available on root directory.''' 314 | refprop.fluidlib() 315 | 316 | def normalize(x): 317 | '''Normalize the sum of list x value's to 1''' 318 | return refprop.normalize(x) 319 | 320 | def resetup(prop, force=False, mRP=None): 321 | """Resetup models and re-initialize arrays. 322 | Initiate child process with prop and mRP transfer""" 323 | #resetup only to be run in parent process, in child process the passed prop 324 | #value will be used for resetup 325 | def _rpfunc(): 326 | return refprop.resetup(prop, force) 327 | return _rpfunc_handler(prop, mRP, _rpfunc) 328 | 329 | def setup_details(prop): 330 | '''Returns basic setup details.''' 331 | return refprop.setup_details(prop) 332 | 333 | def getphase(prop, mRP=None): 334 | '''Return fluid phase''' 335 | def _rpfunc(): 336 | return refprop.getphase(prop) 337 | return _rpfunc_handler(prop, mRP, _rpfunc) 338 | 339 | def setup_setting(mRP=None): 340 | """Returns current setup settings""" 341 | #identify parent process and confirm no active children 342 | if (mp.current_process()._parent_pid == None and 343 | len(mp.active_children()) <= 1): 344 | return refprop.setup_setting() 345 | #else multiprocessing active 346 | else: 347 | #check if mRP is included 348 | if 'mRP' not in globals(): 349 | raise MultiRPInputError( 350 | '"mRP" input required when multiprocessing') 351 | #check if setup_prop is already populated (done through first call) 352 | if '_setupprop' not in globals() or _setupprop == None: 353 | raise MultiRPInputError( 354 | 'child process needs "prop" input for first refprop function') 355 | #return _Setupprop (which contains setup-properties). 356 | return _setupprop 357 | 358 | def _test(): 359 | """execute detailed test run of multiRP""" 360 | import rptest 361 | rptest.settest('multiRP') 362 | 363 | def test(criteria = 0.00001): 364 | '''verify that the user's computer is returning proper calculations''' 365 | global testresult 366 | refproptest = refprop.test(criteria) 367 | testresult = refprop.testresult 368 | return refproptest 369 | 370 | def psliq(p, s, x, prop=None, mRP=None): 371 | """flsh1 calculations with boundery check, raise RefpropinputError when 372 | input is outside bounderies""" 373 | def _rpfunc(): 374 | return refprop.psliq(p, s, x) 375 | return _rpfunc_handler(prop, mRP, _rpfunc) 376 | 377 | def psvap(p, s, x, prop=None, mRP=None): 378 | """flsh1 calculations with boundery check, raise RefpropinputError when 379 | input is outside bounderies""" 380 | def _rpfunc(): 381 | return refprop.psvap(p, s, x) 382 | return _rpfunc_handler(prop, mRP, _rpfunc) 383 | 384 | def ps2ph(p, s, x, prop=None, mRP=None): 385 | """flsh2 calculations with boundery check, raise RefpropinputError when 386 | input is outside bounderies""" 387 | def _rpfunc(): 388 | return refprop.ps2ph(p, s, x) 389 | return _rpfunc_handler(prop, mRP, _rpfunc) 390 | 391 | def phliq(p, h, x, prop=None, mRP=None): 392 | """flsh1 calculations with boundery check, raise RefpropinputError when 393 | input is outside bounderies""" 394 | def _rpfunc(): 395 | return refprop.phliq(p, h, x) 396 | return _rpfunc_handler(prop, mRP, _rpfunc) 397 | 398 | def phvap(p, h, x, prop=None, mRP=None): 399 | """flsh1 calculations with boundery check, raise RefpropinputError when 400 | input is outside bounderies""" 401 | def _rpfunc(): 402 | return refprop.phvap(p, h, x) 403 | return _rpfunc_handler(prop, mRP, _rpfunc) 404 | 405 | def ph2ph(p, h, x, prop=None, mRP=None): 406 | """flsh2 calculations with boundery check, raise RefpropinputError when 407 | input is outside bounderies""" 408 | def _rpfunc(): 409 | return refprop.ph2ph(p, h, x) 410 | return _rpfunc_handler(prop, mRP, _rpfunc) 411 | 412 | def setup(hrf, *hfld, hfmix='HMX.BNC'): 413 | '''Define models and initialize arrays.''' 414 | _checksetupblock('setup') 415 | return refprop.setup(hrf, *hfld, hfmix=hfmix) 416 | 417 | def setmod(htype, hmix, *hcomp): 418 | '''Set model(s) other than the NIST-recommended ('NBS') ones.''' 419 | _checksetupblock('setmod') 420 | refprop.setmod(htype, hmix, *hcomp) 421 | 422 | def gerg04(ixflag=0): 423 | '''set the pure model(s) to those used by the GERG 2004 formulation.''' 424 | _checksetupblock('gerg04') 425 | refprop.gerg04(ixflag) 426 | 427 | def setref(hrf='DEF', ixflag=1, x0=[1], h0=0, s0=0, t0=273, p0=100): 428 | '''set reference state enthalpy and entropy''' 429 | _checksetupblock('setref') 430 | return refprop.setref(hrf, ixflag, x0, h0, s0, t0, p0) 431 | 432 | def critp(x, prop=None, mRP=None): 433 | '''critical parameters as a function of composition''' 434 | def _rpfunc(): 435 | return refprop.critp(x) 436 | return _rpfunc_handler(prop, mRP, _rpfunc) 437 | 438 | def therm(t, D, x, prop=None, mRP=None): 439 | '''Compute thermal quantities as a function of temperature, density and 440 | compositions using core functions''' 441 | def _rpfunc(): 442 | return refprop.therm(t, D, x) 443 | return _rpfunc_handler(prop, mRP, _rpfunc) 444 | 445 | def therm0(t, D, x, prop=None, mRP=None): 446 | '''Compute ideal gas thermal quantities as a function of temperature, 447 | density and compositions using core functions.''' 448 | def _rpfunc(): 449 | return refprop.therm0(t, D, x) 450 | return _rpfunc_handler(prop, mRP, _rpfunc) 451 | 452 | def residual (t, D, x, prop=None, mRP=None): 453 | '''compute the residual quantities as a function of temperature, density, 454 | and compositions (where the residual is the property minus the ideal gas 455 | portion)''' 456 | def _rpfunc(): 457 | return refprop.residual (t, D, x) 458 | return _rpfunc_handler(prop, mRP, _rpfunc) 459 | 460 | def therm2(t, D, x, prop=None, mRP=None): 461 | '''Compute thermal quantities as a function of temperature, density and 462 | compositions using core functions''' 463 | def _rpfunc(): 464 | return refprop.therm2(t, D, x) 465 | return _rpfunc_handler(prop, mRP, _rpfunc) 466 | 467 | def therm3(t, D, x, prop=None, mRP=None): 468 | '''Compute miscellaneous thermodynamic properties''' 469 | def _rpfunc(): 470 | return refprop.therm3(t, D, x) 471 | return _rpfunc_handler(prop, mRP, _rpfunc) 472 | 473 | def purefld(icomp=0): 474 | '''Change the standard mixture setup so that the properties of one fluid 475 | can be calculated as if SETUP had been called for a pure fluid.''' 476 | _checksetupblock('purefld') 477 | return refprop.purefld(icomp) 478 | 479 | def name(icomp=1, prop=None, mRP=None): 480 | '''Provides name information for specified component''' 481 | def _rpfunc(): 482 | return refprop.name(icomp) 483 | return _rpfunc_handler(prop, mRP, _rpfunc) 484 | 485 | def entro(t, D, x, prop=None, mRP=None): 486 | '''Compute entropy as a function of temperature, density and composition 487 | using core functions''' 488 | def _rpfunc(): 489 | return refprop.entro(t, D, x) 490 | return _rpfunc_handler(prop, mRP, _rpfunc) 491 | 492 | def enthal(t, D, x, prop=None, mRP=None): 493 | '''Compute enthalpy as a function of temperature, density, and 494 | composition using core functions''' 495 | def _rpfunc(): 496 | return refprop.enthal(t, D, x) 497 | return _rpfunc_handler(prop, mRP, _rpfunc) 498 | 499 | def cvcp(t, D, x, prop=None, mRP=None): 500 | '''Compute isochoric (constant volume) and isobaric (constant pressure) 501 | heat capacity as functions of temperature, density, and composition 502 | using core functions''' 503 | def _rpfunc(): 504 | return refprop.cvcp(t, D, x) 505 | return _rpfunc_handler(prop, mRP, _rpfunc) 506 | 507 | def cvcpk(icomp, t, D, prop=None, mRP=None): 508 | '''Compute isochoric (constant volume) and isobaric (constant pressure) 509 | heat capacity as functions of temperature for a given component.''' 510 | def _rpfunc(): 511 | return refprop.cvcpk(icomp, t, D) 512 | return _rpfunc_handler(prop, mRP, _rpfunc) 513 | 514 | def gibbs(t, D, x, prop=None, mRP=None): 515 | '''Compute residual Helmholtz and Gibbs free energy as a function of 516 | temperature, density, and composition using core functions''' 517 | def _rpfunc(): 518 | return refprop.gibbs(t, D, x) 519 | return _rpfunc_handler(prop, mRP, _rpfunc) 520 | 521 | def ag(t, D, x, prop=None, mRP=None): 522 | '''Ccompute Helmholtz and Gibbs energies as a function of temperature, 523 | density, and composition.''' 524 | def _rpfunc(): 525 | return refprop.ag(t, D, x) 526 | return _rpfunc_handler(prop, mRP, _rpfunc) 527 | 528 | def press(t, D, x, prop=None, mRP=None): 529 | '''Compute pressure as a function of temperature, density, and 530 | composition using core functions''' 531 | def _rpfunc(): 532 | return refprop.press(t, D, x) 533 | return _rpfunc_handler(prop, mRP, _rpfunc) 534 | 535 | def dpdd(t, D, x, prop=None, mRP=None): 536 | '''Compute partial derivative of pressure w.r.t. density at constant 537 | temperature as a function of temperature, density, and composition''' 538 | def _rpfunc(): 539 | return refprop.dpdd(t, D, x) 540 | return _rpfunc_handler(prop, mRP, _rpfunc) 541 | 542 | def dpddk(icomp, t, D, prop=None, mRP=None): 543 | '''Compute partial derivative of pressure w.r.t. density at constant 544 | temperature as a function of temperature and density for a specified 545 | component''' 546 | def _rpfunc(): 547 | return refprop.dpddk(icomp, t, D) 548 | return _rpfunc_handler(prop, mRP, _rpfunc) 549 | 550 | def dpdd2(t, D, x, prop=None, mRP=None): 551 | '''Compute second partial derivative of pressure w.r.t. density at 552 | const. temperature as a function of temperature, density, and 553 | composition.''' 554 | def _rpfunc(): 555 | return refprop.dpdd2(t, D, x) 556 | return _rpfunc_handler(prop, mRP, _rpfunc) 557 | 558 | def dpdt(t, D, x, prop=None, mRP=None): 559 | '''Compute partial derivative of pressure w.r.t. temperature at constant 560 | density as a function of temperature, density, and composition.''' 561 | def _rpfunc(): 562 | return refprop.dpdt(t, D, x) 563 | return _rpfunc_handler(prop, mRP, _rpfunc) 564 | 565 | def dpdtk(icomp, t, D, prop=None, mRP=None): 566 | '''Compute partial derivative of pressure w.r.t. temperature at constant 567 | density as a function of temperature and density for a specified 568 | component''' 569 | def _rpfunc(): 570 | return refprop.dpdtk(icomp, t, D) 571 | return _rpfunc_handler(prop, mRP, _rpfunc) 572 | 573 | def dddp(t, D, x, prop=None, mRP=None): 574 | '''ompute partial derivative of density w.r.t. pressure at constant 575 | temperature as a function of temperature, density, and composition.''' 576 | def _rpfunc(): 577 | return refprop.dddp(t, D, x) 578 | return _rpfunc_handler(prop, mRP, _rpfunc) 579 | 580 | def dddt(t, D, x, prop=None, mRP=None): 581 | '''Compute partial derivative of density w.r.t. temperature at constant 582 | pressure as a function of temperature, density, and composition.''' 583 | def _rpfunc(): 584 | return refprop.dddt(t, D, x) 585 | return _rpfunc_handler(prop, mRP, _rpfunc) 586 | 587 | def dhd1(t, D, x, prop=None, mRP=None): 588 | '''Compute partial derivatives of enthalpy w.r.t. t, p, or D at constant 589 | t, p, or D as a function of temperature, density, and composition''' 590 | def _rpfunc(): 591 | return refprop.dhd1(t, D, x) 592 | return _rpfunc_handler(prop, mRP, _rpfunc) 593 | 594 | def fgcty(t, D, x, prop=None, mRP=None): 595 | '''Compute fugacity for each of the nc components of a mixture by 596 | numerical differentiation (using central differences) of the 597 | dimensionless residual Helmholtz energy''' 598 | def _rpfunc(): 599 | return refprop.fgcty(t, D, x) 600 | return _rpfunc_handler(prop, mRP, _rpfunc) 601 | 602 | #~ def fgcty2(t, D, x, prop=None, mRP=None): 603 | #~ '''Compute fugacity for each of the nc components of a mixture by 604 | #~ analytical differentiation of the dimensionless residual Helmholtz energy.''' 605 | #~ def _rpfunc(): 606 | #~ return refprop.fgcty2(t, D, x) 607 | #~ return _rpfunc_handler(prop, mRP, _rpfunc) 608 | 609 | def dbdt(t, x, prop=None, mRP=None): 610 | '''Compute the 2nd derivative of B (B is the second virial coefficient) 611 | with respect to T as a function of temperature and composition.''' 612 | def _rpfunc(): 613 | return refprop.dbdt(t, x) 614 | return _rpfunc_handler(prop, mRP, _rpfunc) 615 | 616 | def virb(t, x, prop=None, mRP=None): 617 | '''Compute second virial coefficient as a function of temperature and 618 | composition.''' 619 | def _rpfunc(): 620 | return refprop.virb(t, x) 621 | return _rpfunc_handler(prop, mRP, _rpfunc) 622 | 623 | def virc(t, x, prop=None, mRP=None): 624 | '''Compute the third virial coefficient as a function of temperature and 625 | composition.''' 626 | def _rpfunc(): 627 | return refprop.virc(t, x) 628 | return _rpfunc_handler(prop, mRP, _rpfunc) 629 | 630 | def vird(t, x, prop=None, mRP=None): 631 | '''Compute the fourth virial coefficient as a function of temperature 632 | and composition.''' 633 | def _rpfunc(): 634 | return refprop.vird(t, x) 635 | return _rpfunc_handler(prop, mRP, _rpfunc) 636 | 637 | def virba(t, x, prop=None, mRP=None): 638 | '''Compute second acoustic virial coefficient as a function of temperature 639 | and composition.''' 640 | def _rpfunc(): 641 | return refprop.virba(t, x) 642 | return _rpfunc_handler(prop, mRP, _rpfunc) 643 | 644 | def virca(t, x, prop=None, mRP=None): 645 | '''Compute third acoustic virial coefficient as a function of temperature 646 | and composition.''' 647 | def _rpfunc(): 648 | return refprop.virca(t, x) 649 | return _rpfunc_handler(prop, mRP, _rpfunc) 650 | 651 | def satt(t, x, kph=2, prop=None, mRP=None): 652 | '''Iterate for saturated liquid and vapor states given temperature and 653 | the composition of one phase''' 654 | def _rpfunc(): 655 | return refprop.satt(t, x, kph) 656 | return _rpfunc_handler(prop, mRP, _rpfunc) 657 | 658 | def satp(p, x, kph=2, prop=None, mRP=None): 659 | '''Iterate for saturated liquid and vapor states given pressure and the 660 | composition of one phase.''' 661 | def _rpfunc(): 662 | return refprop.satp(p, x, kph) 663 | return _rpfunc_handler(prop, mRP, _rpfunc) 664 | 665 | def satd(D, x, kph=2, prop=None, mRP=None): 666 | '''Iterate for temperature and pressure given a density along the 667 | saturation boundary and the composition.''' 668 | def _rpfunc(): 669 | return refprop.satd(D, x, kph) 670 | return _rpfunc_handler(prop, mRP, _rpfunc) 671 | 672 | def sath(h, x, kph=2, prop=None, mRP=None): 673 | '''Iterate for temperature, pressure, and density given enthalpy along 674 | the saturation boundary and the composition.''' 675 | def _rpfunc(): 676 | return refprop.sath(h, x, kph) 677 | return _rpfunc_handler(prop, mRP, _rpfunc) 678 | 679 | def sate(e, x, kph=2, prop=None, mRP=None): 680 | '''Iterate for temperature, pressure, and density given energy along the 681 | saturation boundary and the composition.''' 682 | def _rpfunc(): 683 | return refprop.sate(e, x, kph) 684 | return _rpfunc_handler(prop, mRP, _rpfunc) 685 | 686 | def sats(s, x, kph=2, prop=None, mRP=None): 687 | '''Iterate for temperature, pressure, and density given entropy along 688 | the saturation boundary and the composition.''' 689 | def _rpfunc(): 690 | return refprop.sats(s, x, kph) 691 | return _rpfunc_handler(prop, mRP, _rpfunc) 692 | 693 | def csatk(icomp, t, kph=2, prop=None, mRP=None): 694 | '''Compute the heat capacity along the saturation line as a function of 695 | temperature for a given component.''' 696 | def _rpfunc(): 697 | return refprop.csatk(icomp, t, kph) 698 | return _rpfunc_handler(prop, mRP, _rpfunc) 699 | 700 | def dptsatk(icomp, t, kph=2, prop=None, mRP=None): 701 | '''Compute the heat capacity and dP/dT along the saturation line as a 702 | function of temperature for a given component.''' 703 | def _rpfunc(): 704 | return refprop.dptsatk(icomp, t, kph) 705 | return _rpfunc_handler(prop, mRP, _rpfunc) 706 | 707 | def cv2pk(icomp, t, D=0, prop=None, mRP=None): 708 | '''Compute the isochoric heat capacity in the two phase (liquid+vapor) 709 | region.''' 710 | def _rpfunc(): 711 | return refprop.cv2pk(icomp, t, D) 712 | return _rpfunc_handler(prop, mRP, _rpfunc) 713 | 714 | def tprho(t, p, x, kph=2, kguess=0, D=0, prop=None, mRP=None): 715 | '''Iterate for density as a function of temperature, pressure, and 716 | composition for a specified phase.''' 717 | def _rpfunc(): 718 | return refprop.tprho(t, p, x, kph, kguess, D) 719 | return _rpfunc_handler(prop, mRP, _rpfunc) 720 | 721 | def flsh(routine, var1, var2, x, kph=1, prop=None, mRP=None): 722 | '''Flash calculation given two independent variables and bulk 723 | composition.''' 724 | def _rpfunc(): 725 | return refprop.flsh(routine, var1, var2, x, kph) 726 | return _rpfunc_handler(prop, mRP, _rpfunc) 727 | 728 | def flsh1(routine, var1, var2, x, kph=1, Dmin=0, Dmax=0, prop=None, mRP=None): 729 | '''Flash calculation given two independent variables and bulk 730 | composition.''' 731 | def _rpfunc(): 732 | return refprop.flsh1(routine, var1, var2, x, kph, Dmin, Dmax) 733 | return _rpfunc_handler(prop, mRP, _rpfunc) 734 | 735 | def flsh2(routine, var1, var2, x, kq=1, ksat=0, tbub=0, tdew=0, pbub=0, pdew=0, 736 | Dlbub=0, Dvdew=0, xbub=None, xdew=None, prop=None, mRP=None): 737 | '''Flash calculation given two independent variables and bulk composition''' 738 | def _rpfunc(): 739 | return refprop.flsh2( 740 | routine, var1, var2, x, kq, ksat, tbub, tdew, pbub, pdew, Dlbub, 741 | Dvdew, xbub, xdew) 742 | return _rpfunc_handler(prop, mRP, _rpfunc) 743 | 744 | def info(icomp=1, prop=None, mRP=None): 745 | '''Provides fluid constants for specified component.''' 746 | def _rpfunc(): 747 | return refprop.info(icomp) 748 | return _rpfunc_handler(prop, mRP, _rpfunc) 749 | 750 | def xmass(x, prop=None, mRP=None): 751 | '''Converts composition on a mole fraction basis to mass fraction.''' 752 | def _rpfunc(): 753 | return refprop.xmass(x) 754 | return _rpfunc_handler(prop, mRP, _rpfunc) 755 | 756 | def xmole(xkg, prop=None, mRP=None): 757 | '''Converts composition on a mass fraction basis to mole fraction.''' 758 | def _rpfunc(): 759 | return refprop.xmole(xkg) 760 | return _rpfunc_handler(prop, mRP, _rpfunc) 761 | 762 | def limitx(x, htype='EOS', t=0, D=0, p=0, prop=None, mRP=None): 763 | '''returns limits of a property model as a function of composition 764 | and/or checks input t, D, p against those limits.''' 765 | def _rpfunc(): 766 | return refprop.limitx(x, htype, t, D, p) 767 | return _rpfunc_handler(prop, mRP, _rpfunc) 768 | 769 | def limitk(htype='EOS', icomp=1, t='tnbp', D=0, p=0, prop=None, mRP=None): 770 | '''Returns limits of a property model (read in from the .fld files) for 771 | a mixture component and/or checks input t, D, p against those limits.''' 772 | def _rpfunc(): 773 | return refprop.limitk(htype, icomp, t, D, p) 774 | return _rpfunc_handler(prop, mRP, _rpfunc) 775 | 776 | def limits(x, htype = 'EOS', prop=None, mRP=None): 777 | '''Returns limits of a property model as a function of composition.''' 778 | def _rpfunc(): 779 | return refprop.limits(x, htype) 780 | return _rpfunc_handler(prop, mRP, _rpfunc) 781 | 782 | def qmass(q, xliq, xvap, prop=None, mRP=None): 783 | '''converts quality and composition on a mole basis to a mass basis.''' 784 | def _rpfunc(): 785 | return refprop.qmass(q, xliq, xvap) 786 | return _rpfunc_handler(prop, mRP, _rpfunc) 787 | 788 | def qmole(qkg, xlkg, xvkg, prop=None, mRP=None): 789 | '''Converts quality and composition on a mass basis to a molar basis.''' 790 | def _rpfunc(): 791 | return refprop.qmole(qkg, xlkg, xvkg) 792 | return _rpfunc_handler(prop, mRP, _rpfunc) 793 | 794 | def wmol(x, prop=None, mRP=None): 795 | '''Molecular weight for a mixture of specified composition.''' 796 | def _rpfunc(): 797 | return refprop.wmol(x) 798 | return _rpfunc_handler(prop, mRP, _rpfunc) 799 | 800 | def dielec(t, D, x, prop=None, mRP=None): 801 | '''Compute the dielectric constant as a function of temperature, 802 | density, and composition.''' 803 | def _rpfunc(): 804 | return refprop.dielec(t, D, x) 805 | return _rpfunc_handler(prop, mRP, _rpfunc) 806 | 807 | def surft(t, x, prop=None, mRP=None): 808 | '''Compute surface tension.''' 809 | def _rpfunc(): 810 | return refprop.surft(t, x) 811 | return _rpfunc_handler(prop, mRP, _rpfunc) 812 | 813 | def surten(t, Dliq, Dvap, xliq, xvap, prop=None, mRP=None): 814 | '''Compute surface tension.''' 815 | def _rpfunc(): 816 | return refprop.surten(t, Dliq, Dvap, xliq, xvap) 817 | return _rpfunc_handler(prop, mRP, _rpfunc) 818 | 819 | def meltt(t, x, prop=None, mRP=None): 820 | '''Compute the melting line pressure as a function of temperature and 821 | composition.''' 822 | def _rpfunc(): 823 | return refprop.meltt(t, x) 824 | return _rpfunc_handler(prop, mRP, _rpfunc) 825 | 826 | def meltp(p, x, prop=None, mRP=None): 827 | '''Compute the melting line temperature as a function of pressure and 828 | composition.''' 829 | def _rpfunc(): 830 | return refprop.meltp(p, x) 831 | return _rpfunc_handler(prop, mRP, _rpfunc) 832 | 833 | def sublt(t, x, prop=None, mRP=None): 834 | '''Compute the sublimation line pressure as a function of temperature 835 | and composition.''' 836 | def _rpfunc(): 837 | return refprop.sublt(t, x) 838 | return _rpfunc_handler(prop, mRP, _rpfunc) 839 | 840 | def sublp(p, x, prop=None, mRP=None): 841 | '''Compute the sublimation line temperature as a function of pressure 842 | and composition.''' 843 | def _rpfunc(): 844 | return refprop.sublp(p, x) 845 | return _rpfunc_handler(prop, mRP, _rpfunc) 846 | 847 | def trnprp(t, D, x, prop=None, mRP=None): 848 | '''Compute the transport properties of thermal conductivity and 849 | viscosity as functions of temperature, density, and composition.''' 850 | def _rpfunc(): 851 | return refprop.trnprp(t, D, x) 852 | return _rpfunc_handler(prop, mRP, _rpfunc) 853 | 854 | def getktv(icomp, jcomp, prop=None, mRP=None): 855 | '''Retrieve mixture model and parameter info for a specified binary.''' 856 | def _rpfunc(): 857 | return refprop.getktv(icomp, jcomp) 858 | return _rpfunc_handler(prop, mRP, _rpfunc) 859 | 860 | def setktv(icomp, jcomp, hmodij, fij=([0] * refprop._nmxpar), 861 | hfmix='hmx.bnc'): 862 | '''Set mixture model and/or parameters.''' 863 | _checksetupblock('setktv') 864 | return refprop.setktv(icomp, jcomp, hmodij, fij, hfmix) 865 | 866 | def setaga(): 867 | '''Set up working arrays for use with AGA8 equation of state.''' 868 | _checksetupblock('setaga') 869 | return refprop.setaga() 870 | 871 | def unsetaga(): 872 | '''Load original values into arrays changed in the call to SETAGA.''' 873 | _checksetupblock('unsetaga') 874 | return refprop.unsetaga() 875 | 876 | def preos(ixflag): 877 | '''Turn on or off the use of the PR cubic equation.''' 878 | _checksetupblock('preos') 879 | return refprop.preos(ixflag) 880 | 881 | def getfij(hmodij, prop=None, mRP=None): 882 | '''Retrieve parameter info for a specified mixing rule.''' 883 | def _rpfunc(): 884 | return refprop.getfij(hmodij) 885 | return _rpfunc_handler(prop, mRP, _rpfunc) 886 | 887 | def b12(t, x, prop=None, mRP=None): 888 | '''Compute b12 as a function of temperature and composition.''' 889 | def _rpfunc(): 890 | return refprop.b12(t, x) 891 | return _rpfunc_handler(prop, mRP, _rpfunc) 892 | 893 | def excess(t, p, x, kph=0, prop=None, mRP=None): 894 | '''Compute excess properties as a function of temperature, pressure, and 895 | composition.''' 896 | def _rpfunc(): 897 | return refprop.excess(t, p, x, kph) 898 | return _rpfunc_handler(prop, mRP, _rpfunc) 899 | 900 | def getmod(icomp, htype, prop=None, mRP=None): 901 | '''Retrieve citation information for the property models used''' 902 | def _rpfunc(): 903 | return refprop.getmod(icomp, htype) 904 | return _rpfunc_handler(prop, mRP, _rpfunc) 905 | 906 | def cstar(t, p, v, x, prop=None, mRP=None): 907 | '''Calculate the critical flow factor, C*, for nozzle flow of a gas 908 | (subroutine was originally named CCRIT)''' 909 | def _rpfunc(): 910 | return refprop.cstar(t, p, v, x) 911 | return _rpfunc_handler(prop, mRP, _rpfunc) 912 | 913 | def phiderv(icomp, jcomp, t, D, x, prop=None, mRP=None): 914 | '''Calculate various derivatives needed for VLE determination''' 915 | def _rpfunc(): 916 | return refprop.phiderv(icomp, jcomp, t, D, x) 917 | return _rpfunc_handler(prop, mRP, _rpfunc) 918 | 919 | def chempot(t, D, x, prop=None, mRP=None): 920 | '''Compute the chemical potentials for each of the nc components of a 921 | mixture.''' 922 | def _rpfunc(): 923 | return refprop.chempot(t, D, x) 924 | return _rpfunc_handler(prop, mRP, _rpfunc) 925 | 926 | def fugcof(t, D, x, prop=None, mRP=None): 927 | '''Compute the fugacity coefficient for each of the nc components of a 928 | mixture.''' 929 | def _rpfunc(): 930 | return refprop.fugcof(t, D, x) 931 | return _rpfunc_handler(prop, mRP, _rpfunc) 932 | 933 | def dcdt(t, x, prop=None, mRP=None): 934 | '''Compute the 1st derivative of C (C is the third virial coefficient) with 935 | respect to T as a function of temperature and composition.''' 936 | def _rpfunc(): 937 | return refprop.dcdt(t, x) 938 | return _rpfunc_handler(prop, mRP, _rpfunc) 939 | 940 | def dcdt2(t, x, prop=None, mRP=None): 941 | '''Compute the 2nd derivative of C (C is the third virial coefficient) with 942 | respect to T as a function of temperature and composition.''' 943 | def _rpfunc(): 944 | return refprop.dcdt2(t, x) 945 | return _rpfunc_handler(prop, mRP, _rpfunc) 946 | 947 | def fpv(t, D, p, x, prop=None, mRP=None): 948 | '''Compute the supercompressibility factor, Fpv.''' 949 | def _rpfunc(): 950 | return refprop.fpv(t, D, p, x) 951 | return _rpfunc_handler(prop, mRP, _rpfunc) 952 | 953 | def rmix2(x, prop=None, mRP=None): 954 | '''Return the gas "constant" as a combination of the gas constants for 955 | the pure fluids.''' 956 | def _rpfunc(): 957 | return refprop.rmix2(x) 958 | return _rpfunc_handler(prop, mRP, _rpfunc) 959 | 960 | #compilations 961 | 962 | #create function (to demonstrate pipe) 963 | def _mRPpipe(fluid, mRP): 964 | resetup(fluid, mRP=mRP) 965 | for each in range(100): 966 | #put value into pipe 967 | mRP['cpipe'].send( 968 | press(303 + each, 58, [0.4, 0.6])['p']) 969 | mRP['cpipe'].close() 970 | 971 | if __name__ == '__main__': 972 | #add module file path to python sys path 973 | import multiRP as _filename 974 | _filename = (os.path.dirname(_filename.__file__)) 975 | sys.path.append(_filename) 976 | 977 | #test multiRP without multiprocessing 978 | import rptest 979 | rptest.settest('multiRP') 980 | 981 | #initiate multirefprop, this will create global 'mRP' 982 | multirefprop() 983 | 984 | #create setup details 985 | H2O = setup('def', 'WATER') 986 | H2O_NH3 = setup('def', 'AMMONIA', 'WATER') 987 | CH4 = setup('def', 'METHANE') 988 | CH4_C2H6 = setup('def', 'METHANE', 'ETHANE') 989 | 990 | #various refprop functions named 991 | peen = mRP['process'](target=critp, args=([1], H2O, mRP)) 992 | ptwee = mRP['process'](target=critp, args=([0.4, 0.6],), 993 | kwargs={'prop':H2O_NH3, 'mRP':mRP})#alternative input 994 | pdrie = mRP['process'](target=critp, args=([1], CH4, mRP)) 995 | pvier = mRP['process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 996 | qeen = mRP['process'](target=critp, args=([1], H2O, mRP)) 997 | qtwee = mRP['process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 998 | qdrie = mRP['process'](target=critp, args=([1], CH4, mRP)) 999 | qvier = mRP['process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 1000 | ween = mRP['process'](target=critp, args=([1], H2O, mRP)) 1001 | wtwee = mRP['process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 1002 | wdrie = mRP['process'](target=critp, args=([1], CH4, mRP)) 1003 | wvier = mRP['process'](target=critp, args=([0.35, 0.65], CH4_C2H6, mRP)) 1004 | reen = mRP['process'](target=critp, args=([1], H2O, mRP)) 1005 | rtwee = mRP['process'](target=critp, args=([0.4, 0.6], H2O_NH3, mRP)) 1006 | rdrie = mRP['process'](target=critp, args=([1], CH4, mRP)) 1007 | rvier = mRP['process'](target=critp, args=([0.35, 0.65], 1008 | CH4_C2H6, mRP)) 1009 | sfun = mRP['process'](target=_mRPpipe, args=(H2O_NH3, mRP))#pipe 1010 | 1011 | #list refprop functions 1012 | processlist = [peen, ptwee, pdrie, pvier, qeen, qtwee, qdrie, qvier, 1013 | ween, wtwee, wdrie, wvier, reen, rtwee, rdrie, rvier, 1014 | sfun] 1015 | 1016 | #now run the functions 1017 | run_mRP(processlist) 1018 | 1019 | #print the results 1020 | for each in processlist: 1021 | if each.name in mRP['result']: 1022 | print(mRP['result'][each.name]) #only returns the last refprop function results unless tweaked at function call 1023 | 1024 | #loop untill pipe is empty 1025 | while mRP['ppipe'].poll():#parentpipe 1026 | #print value from pipe 1027 | print(mRP['ppipe'].recv()) 1028 | -------------------------------------------------------------------------------- /python3.2/rptest.py: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------- 2 | #Name: rptest 3 | #Purpose: test module for refprop and multiRP 4 | # 5 | #Author: Thelen, B.J. 6 | # thelen_ben@yahoo.com 7 | #------------------------------------------------------------------------------- 8 | '''Allow refprop and multiRP module functional test of all functions''' 9 | 10 | 11 | ####################################################### test if some windows functions are working now with rp9.1 12 | 13 | from decimal import Decimal 14 | import platform 15 | 16 | def settest(test): 17 | '''set test module 18 | 'refprop' or 'multiRP' 19 | and execute test run''' 20 | if test == 'refprop': 21 | import refprop as rp 22 | _maintest(rp) 23 | elif test == 'multiRP': 24 | import multiRP as rp 25 | _maintest(rp) 26 | 27 | #main test def. for usage at refprop and multiRP 28 | def _maintest(rp): 29 | #examples and test setup 30 | rp.SetErrorDebug.off() #turn on =>> for testing purpose 31 | 32 | if rp.test(): #if True; rptest =>>for testing purpose 33 | print('refprop installed correctely') 34 | 35 | print('test results') 36 | print(rp.testresult) 37 | 38 | print('fluidlib') 39 | rp.fluidlib() 40 | print('\n') 41 | 42 | prop = rp.setup('def', 'air',) 43 | print('setup air') 44 | print(prop, '\n') 45 | 46 | x = prop['x'] 47 | 48 | print('critp(x)') 49 | print(rp.critp(x), '\n') 50 | 51 | print('setup water ammonia') 52 | print(rp.setup('def', 'water', 'ammonia',), '\n') 53 | 54 | #alternative setup input 55 | rp.setup('def', ['water', 'ammonia'],) 56 | 57 | x = [0.5, 0.3] 58 | prop = rp.normalize(x) 59 | x = prop['x'] 60 | 61 | prop = rp.critp(x) 62 | prop = rp.therm(prop['tcrit'], prop['Dcrit'], x) 63 | print('therm') 64 | print(prop, '\n') 65 | 66 | p = prop['p'] 67 | 68 | print('therm2') 69 | print(rp.therm2(prop['t'], prop['D'], x), '\n') 70 | 71 | print('therm0') 72 | print(rp.therm0(prop['t'], prop['D'], x), '\n') 73 | 74 | print('residual') 75 | print(rp.residual(prop['t'], prop['D'], x), '\n') 76 | 77 | print('entro') 78 | print(rp.entro(prop['t'], prop['D'], x), '\n') 79 | 80 | print('enthal') 81 | print(rp.enthal(prop['t'], prop['D'], x), '\n') 82 | 83 | print('ag') 84 | print(rp.ag(prop['t'], prop['D'], x), '\n') 85 | 86 | print('cvcp') 87 | print(rp.cvcp(prop['t'], prop['D'], x), '\n') 88 | 89 | print('dddp') 90 | print(rp.dddp(prop['t'], prop['D'], x), '\n') 91 | 92 | print('dddt') 93 | print(rp.dddt(prop['t'], prop['D'], x), '\n') 94 | 95 | print('dhd1') 96 | print(rp.dhd1(prop['t'], prop['D'], x), '\n') 97 | 98 | print('dpdd') 99 | print(rp.dpdd(prop['t'], prop['D'], x), '\n') 100 | 101 | print('dpdd2') 102 | print(rp.dpdd2(prop['t'], prop['D'], x), '\n') 103 | 104 | print('dpdt') 105 | print(rp.dpdt(prop['t'], prop['D'], x), '\n') 106 | 107 | D = prop['D'] 108 | 109 | #function not supported in Windows 110 | if platform.system() == 'Linux': 111 | print('dcdt') 112 | print(rp.dcdt(prop['t'], x), '\n') 113 | 114 | #function not supported in Windows 115 | if platform.system() == 'Linux': 116 | print('dcdt2') 117 | print(rp.dcdt2(prop['t'], x), '\n') 118 | 119 | print('fgcty') 120 | print(rp.fgcty(prop['t'], D, x), '\n') 121 | 122 | print('gibbs') 123 | print(rp.gibbs(prop['t'], prop['D'], x), '\n') 124 | 125 | #~ print('fgcty2') 126 | #~ print(rp.fgcty2(prop['t'], prop['D'], x), '\n') 127 | 128 | prop = rp.therm3(prop['t'], prop['D'], x) 129 | print('therm3') 130 | print(prop, '\n') 131 | 132 | D = prop['D'] 133 | 134 | print('virb') 135 | print(rp.virb(prop['t'], x), '\n') 136 | 137 | print('virc') 138 | print(rp.virc(prop['t'], x), '\n') 139 | 140 | #function not supported in Windows 141 | if platform.system() == 'Linux': 142 | print('vird') 143 | print(rp.vird(prop['t'], x), '\n') 144 | 145 | print('virba') 146 | print(rp.virba(prop['t'], x), '\n') 147 | 148 | print('virca') 149 | print(rp.virca(prop['t'], x), '\n') 150 | 151 | print('cvcpk') 152 | print(rp.cvcpk(1, prop['t'], D), '\n') 153 | 154 | print('dbdt') 155 | print(rp.dbdt(prop['t'], x), '\n') 156 | 157 | print('dpddk') 158 | print(rp.dpddk(1, prop['t'], D), '\n') 159 | 160 | print('dpdtk') 161 | print(rp.dpdtk(2, prop['t'], D), '\n') 162 | 163 | D = 55 164 | t = 373 165 | 166 | prop = rp.press(t, D, x) 167 | print('press') 168 | print(prop, '\n') 169 | 170 | p = prop['p'] 171 | 172 | print('purefld(1)') 173 | prop = rp.purefld(1) 174 | print(prop, '\n') 175 | 176 | x = [1] 177 | 178 | resetup_test_prop_d = prop 179 | 180 | print('satt') 181 | prop = rp.satt(t, x) 182 | print(prop, '\n') 183 | 184 | print('satp') 185 | prop = rp.satp(prop['p'], x) 186 | print(prop, '\n') 187 | 188 | print('satd') 189 | print(rp.satd(prop['Dliq'], x), '\n') 190 | 191 | print('sath') 192 | print(rp.sath(47000, x, 0), '\n') 193 | 194 | print('sate') 195 | print(rp.sate(0.46047E-13, x), '\n') 196 | 197 | print('sats') 198 | print(rp.sats(50, x, 0), '\n') 199 | 200 | print('purefld(0)') 201 | print(rp.purefld(0), '\n') 202 | 203 | x = [0.5, 0.3] 204 | x = rp.normalize(x)['x'] 205 | 206 | print('csatk') 207 | print(rp.csatk(1, t), '\n') 208 | 209 | print('dptsatk') 210 | print(rp.dptsatk(1, t), '\n') 211 | 212 | print('cv2pk') 213 | print(rp.cv2pk(2, t, D), '\n') 214 | 215 | print('tprho') 216 | print(rp.tprho(t, p, x, 2, 1, 58), '\n') 217 | 218 | print('flsh, tp') 219 | prop = rp.flsh('tp', t, p, x) 220 | print(prop, '\n') 221 | 222 | print('flsh, th') 223 | print(rp.flsh('tH', 305, prop['h'], x, 1), '\n') 224 | 225 | print('flsh, tD') 226 | print(rp.flsh('tD', t, 30, x), '\n') 227 | 228 | print('info()') 229 | print(rp.info(), '\n') 230 | 231 | print('info(2)') 232 | print(rp.info(2), '\n') 233 | 234 | #unsupported in Windows 235 | if platform.system() == 'Linux': 236 | print('rmix2') 237 | print(rp.rmix2(x), '\n') 238 | 239 | print('xmass') 240 | prop = rp.xmass(x) 241 | print(prop, '\n') 242 | 243 | print('xmole') 244 | print(rp.xmole(prop['xkg']), '\n') 245 | 246 | print('limitx') 247 | print(rp.limitx(x, 'eos', t, D, p), '\n') 248 | 249 | print('limitk') 250 | print(rp.limitk('eos', 1, t, D, p), '\n') 251 | 252 | print('limits') 253 | print(rp.limits(x), '\n') 254 | 255 | print('flsh, ts') 256 | prop = rp.flsh('ts', t, 40, x) 257 | print(prop, '\n') 258 | 259 | print('flsh, te') 260 | print(rp.flsh('te', t, prop['e'], x), '\n') 261 | 262 | print('flsh, pD') 263 | prop = rp.flsh('Pd', p, D, x) 264 | print(prop, '\n') 265 | 266 | print('flsh, ph') 267 | prop = rp.flsh('ph', p, prop['h'], x) 268 | print(prop, '\n') 269 | 270 | print('flsh, ps') 271 | prop = rp.flsh('ps', p, prop['s'], x) 272 | print(prop, '\n') 273 | 274 | print('flsh, pe') 275 | prop = rp.flsh('pE', p, prop['e'], x) 276 | print(prop, '\n') 277 | 278 | print('flsh, es') 279 | prop = rp.flsh('es', prop['e'], prop['s'], x) 280 | print(prop, '\n') 281 | 282 | print('flsh, hs') 283 | prop = rp.flsh('hs', 40000, 100, x) 284 | print(prop, '\n') 285 | 286 | print('flsh, es') 287 | print(rp.flsh('es', 175, 13, x), '\n') 288 | 289 | print('flsh, Dh') 290 | print(rp.flsh('DH', 20, 18000, x), '\n') 291 | 292 | print('flsh, Ds') 293 | prop = rp.flsh('Ds', 20, 50, x) 294 | print(prop, '\n') 295 | 296 | print('flsh, De') 297 | prop = rp.flsh('DE', 20, prop['e'], x) 298 | print(prop, '\n') 299 | 300 | print('flsh, tq') 301 | prop = rp.flsh('tq', t, prop['q'], x) 302 | print(prop, '\n') 303 | 304 | print('flsh, pq') 305 | print(rp.flsh('pq', 1200, prop['q'], x), '\n') 306 | 307 | prop = rp.flsh('tp', 350, 1200, x) 308 | print('flsh, tp') 309 | print(prop, '\n') 310 | s = prop['s'] 311 | e = prop['e'] 312 | h = prop['h'] 313 | D = prop['D'] 314 | t = prop['t'] 315 | p = prop['p'] 316 | Dmin = 40 317 | Dmax = 55 318 | 319 | print('flsh1, liq, ph') 320 | print(rp.flsh1('Ph', p, h, x, 1), '\n') 321 | 322 | print('getphase') 323 | print(rp.getphase(prop), '\n') 324 | 325 | print('flsh1, liq, pD') 326 | print(rp.flsh1('PD', p, D, x), '\n') 327 | 328 | print('flsh1, liq, ps') 329 | print(rp.flsh1('Ps', p, s, x), '\n') 330 | 331 | #unsupported in Windows 332 | if platform.system() == 'Linux': 333 | print('flsh1, liq, th') 334 | print(rp.flsh1('th', t, h, x, Dmin=Dmin, Dmax=Dmax), '\n') 335 | 336 | #unsupported in Windows 337 | if platform.system() == 'Linux': 338 | print('flsh1, liq, ts') 339 | print(rp.flsh1('ts', t, s, x, Dmin=Dmin, Dmax=Dmax), '\n') 340 | 341 | #unsupported in Windows 342 | if platform.system() == 'Linux': 343 | print('flsh1, liq, te') 344 | print(rp.flsh1('te', t, e, x, Dmin=Dmin, Dmax=Dmax), '\n') 345 | 346 | #unsupported in Windows 347 | if platform.system() == 'Linux': 348 | print('flsh1, liq, pe') 349 | print(rp.flsh1('Pe', p, e, x), '\n') 350 | 351 | #unsupported in Windows 352 | if platform.system() == 'Linux': 353 | print('flsh1, liq, hs') 354 | print(rp.flsh1('hs', h, s, x, Dmin=Dmin, Dmax=Dmax), '\n') 355 | 356 | #unsupported in Windows 357 | if platform.system() == 'Linux': 358 | print('flsh1, liq, Dh') 359 | print(rp.flsh1('Dh', D, h, x), '\n') 360 | 361 | #unsupported in Windows 362 | if platform.system() == 'Linux': 363 | print('flsh1, liq, Ds') 364 | print(rp.flsh1('Ds', D, s, x), '\n') 365 | 366 | #unsupported in Windows 367 | if platform.system() == 'Linux': 368 | print('flsh1, liq, De') 369 | print(rp.flsh1('De', D, e, x), '\n') 370 | 371 | prop = rp.flsh('tp', 400, 100, x) 372 | s = prop['s'] 373 | e = prop['e'] 374 | h = prop['h'] 375 | D = prop['D'] 376 | Dmin = 0.01 377 | Dmax = 0.05 378 | t = prop['t'] 379 | p = prop['p'] 380 | 381 | print('flsh1, vap, ph') 382 | print(rp.flsh1('Ph', p, h, x, 2), '\n') 383 | 384 | print('getphase') 385 | print(rp.getphase(prop), '\n') 386 | 387 | print('flsh1, vap, pD') 388 | print(rp.flsh1('PD', p, D, x, 2), '\n') 389 | 390 | print('flsh1, vap, ps') 391 | print(rp.flsh1('Ps', p, s, x, 2), '\n') 392 | 393 | #unsupported in Windows 394 | if platform.system() == 'Linux': 395 | print('flsh1, vap, th') 396 | print(rp.flsh1('th', t, h, x, Dmin=Dmin, Dmax=Dmax), '\n') 397 | 398 | #unsupported in Windows 399 | if platform.system() == 'Linux': 400 | print('flsh1, vap, ts') 401 | print(rp.flsh1('ts', t, s, x, Dmin=Dmin, Dmax=Dmax), '\n') 402 | 403 | #unsupported in Windows 404 | if platform.system() == 'Linux': 405 | print('flsh1, vap, te') 406 | print(rp.flsh1('te', t, e, x, Dmin=Dmin, Dmax=Dmax), '\n') 407 | 408 | #unsupported in Windows 409 | if platform.system() == 'Linux': 410 | print('flsh1, vap, pe') 411 | print(rp.flsh1('Pe', p, e, x, 2), '\n') 412 | 413 | #unsupported in Windows 414 | if platform.system() == 'Linux': 415 | print('flsh1, vap, hs') 416 | print(rp.flsh1('hs', h, s, x, Dmin=Dmin, Dmax=Dmax), '\n') 417 | 418 | #unsupported in Windows 419 | if platform.system() == 'Linux': 420 | print('flsh1, vap, Dh') 421 | print(rp.flsh1('Dh', D, h, x), '\n') 422 | 423 | #unsupported in Windows 424 | if platform.system() == 'Linux': 425 | print('flsh1, vap, Ds') 426 | print(rp.flsh1('Ds', D, s, x), '\n') 427 | 428 | #unsupported in Windows 429 | if platform.system() == 'Linux': 430 | print('flsh1, vap, De') 431 | print(rp.flsh1('De', D, e, x), '\n') 432 | 433 | print('cstar') 434 | print(rp.cstar(t, p, 8, x), '\n') 435 | 436 | print('fpv') 437 | print(rp.fpv(t, D, p, x), '\n') 438 | 439 | #function not supported in Windows 440 | if platform.system() == 'Linux': 441 | print('excess') 442 | print(rp.excess(t, p, x, kph=2), '\n') 443 | 444 | prop = rp.flsh('pq', 1200, 0.65, x) 445 | D = prop['D'] 446 | Dliq = prop['Dliq'] 447 | Dvap = prop['Dvap'] 448 | xliq = prop['xliq'] 449 | xvap = prop['xvap'] 450 | e = prop['e'] 451 | h = prop['h'] 452 | s = prop['s'] 453 | q = prop['q'] 454 | p = prop['p'] 455 | t = prop['t'] 456 | 457 | #function not supported in Windows 458 | if platform.system() == 'Linux': 459 | print('tpfl2') 460 | print(rp.flsh2('tp', t, p, x), '\n') 461 | 462 | #function not supported in Windows 463 | if platform.system() == 'Linux': 464 | print('Dhfl2') 465 | print(rp.flsh2('Dh', D, h, x), '\n') 466 | 467 | #function not supported in Windows 468 | if platform.system() == 'Linux': 469 | print('Dsfl2') 470 | print(rp.flsh2('Ds', D, s, x), '\n') 471 | 472 | #function not supported in Windows 473 | if platform.system() == 'Linux': 474 | print('Defl2') 475 | print(rp.flsh2('De', D, e, x), '\n') 476 | 477 | #function not supported in Windows 478 | if platform.system() == 'Linux': 479 | print('thfl2') 480 | print(rp.flsh2('th', t, h, x, ksat=0), '\n') 481 | 482 | #function not supported in Windows 483 | if platform.system() == 'Linux': 484 | print('tsfl2') 485 | print(rp.flsh2('ts', t, s, x, ksat=0), '\n') 486 | 487 | #function not supported in Windows 488 | if platform.system() == 'Linux': 489 | print('tefl2') 490 | print(rp.flsh2('te', t, e, x, ksat=0), '\n') 491 | 492 | #function not supported in Windows 493 | if platform.system() == 'Linux': 494 | print('tDfl2') 495 | print(rp.flsh2('tD', t, D, x, ksat=0), '\n') 496 | 497 | #function not supported in Windows 498 | if platform.system() == 'Linux': 499 | print('pDfl2') 500 | print(rp.flsh2('pD', p, D, x, ksat=0), '\n') 501 | 502 | #function not supported in Windows 503 | if platform.system() == 'Linux': 504 | print('phfl2') 505 | print(rp.flsh2('ph', p, h, x, ksat=0), '\n') 506 | 507 | #function not supported in Windows 508 | if platform.system() == 'Linux': 509 | print('psfl2') 510 | print(rp.flsh2('ps', p, s, x, ksat=0), '\n') 511 | 512 | #function not supported in Windows 513 | if platform.system() == 'Linux': 514 | print('pefl2') 515 | print(rp.flsh2('pe', p, e, x, ksat=0), '\n') 516 | 517 | #function not supported in Windows 518 | if platform.system() == 'Linux': 519 | print('tqfl2') 520 | print(rp.flsh2('tq', t, q, x, ksat=0), '\n') 521 | 522 | #function not supported in Windows 523 | if platform.system() == 'Linux': 524 | print('pqfl2') 525 | print(rp.flsh2('pq', p, q, x, ksat=0), '\n') 526 | 527 | #function not supported in Windows 528 | #~ if platform.system() == 'Linux': 529 | #~ print('Dqfl2') 530 | #~ print(rp.flsh2('Dq', D, q, x), '\n') 531 | 532 | prop = rp.flsh('tp', 340, 100, x) 533 | t = prop['t'] 534 | Dliq = prop['Dliq'] 535 | Dvap = prop['Dvap'] 536 | xliq = prop['xliq'] 537 | xvap = prop['xvap'] 538 | 539 | print('qmass') 540 | prop = rp.qmass(prop['q'], xliq, xvap) 541 | print(prop, '\n') 542 | 543 | print('qmole') 544 | print(rp.qmole(prop['qkg'], prop['xlkg'], prop['xvkg']), '\n') 545 | 546 | print('wmol') 547 | print(rp.wmol(x), '\n') 548 | 549 | prop = rp.flsh('tp', 340, 100, x) 550 | 551 | print('dielec') 552 | print(rp.dielec(prop['t'], prop['D'], x), '\n') 553 | 554 | print('surten') 555 | print(rp.surten (t, Dliq, Dvap, xliq, xvap), '\n') 556 | 557 | print('surft') 558 | print(rp.surft(240, x), '\n') 559 | 560 | rp.setup('def', 'water') 561 | 562 | print('meltt') 563 | print(rp.meltt(273.15, [1]), '\n') 564 | 565 | print('meltp') 566 | print(rp.meltp(100, [1]), '\n') 567 | 568 | print('sublt') 569 | print(rp.sublt(273.15, [1]), '\n') 570 | 571 | print('sublp') 572 | print(rp.sublp(0.1, [1]), '\n') 573 | 574 | rp.setup('def', 'butane', 'ethane', 'propane', 'methane',) 575 | x = [0.5, 0.15, 0.3, 0.05] 576 | rp.setref('nbp') 577 | prop = rp.flsh('tp', 260, 150, x) 578 | D = prop['D'] 579 | print('trnprp, setref') 580 | print(rp.trnprp(260, D, x), '\n') 581 | 582 | print('B12') 583 | print(rp.b12(260, x), '\n') 584 | 585 | print('chempot') 586 | print(rp.chempot(260, D, x), '\n') 587 | 588 | print('fugcof') 589 | print(rp.fugcof(260, D, x), '\n') 590 | 591 | #function not supported in Windows 592 | if platform.system() == 'Linux': 593 | print('phiderv') 594 | print(rp.phiderv(1, 260, D, x), '\n') 595 | 596 | #function not supported in Windows 597 | if platform.system() == 'Linux': 598 | print('getmod') 599 | print(rp.getmod(1, 'EOS'), '\n') 600 | 601 | rp.setmod('tcx', 'ecs', ['tc2', 'tc1', 'tc2', 'tc2']) 602 | rp.setup('def', 'butane', 'ethane', 'propane', 'methane',) 603 | x = [0.5, 0.15, 0.3, 0.05] 604 | prop = rp.flsh('tp', 260, 200, x) 605 | print('trnprp, setref NBP, setmod [tcx, ecs, tc2, tc1, tc2, tc2]') 606 | print(rp.trnprp(260, prop['D'], x), '\n') 607 | 608 | #function not supported in Windows 609 | if platform.system() == 'Linux': 610 | print('getmod') 611 | print(rp.getmod(3, 'tcx'), '\n') 612 | 613 | rp.setref('oth', 1, [1], 0, 0, 273, 100) 614 | print('setref = OTH') 615 | prop = rp.flsh('tp', 260, 200, x) 616 | print(prop, '\n') 617 | 618 | resetup_test_prop_a = prop 619 | 620 | rp.setref('???', 1, [1], 0, 0, 373, 100) 621 | print('setref = ???') 622 | prop = rp.flsh('tp', 260, 200, x) 623 | print(prop, '\n') 624 | 625 | resetup_test_prop_b = prop 626 | 627 | print('name') 628 | print(rp.name(1), '\n') 629 | 630 | rp.setup('def', 'butane', 'ethane', 'propane', 'methane',) 631 | x = [0.5, 0.15, 0.3, 0.05] 632 | print('getktv') 633 | prop = rp.getktv(1, 3) 634 | print(prop, '\n') 635 | 636 | print('setktv') 637 | prop = rp.setktv(1, 3, 'lin', prop['fij'], prop['hfmix'],) 638 | print(prop, '\n') 639 | 640 | resetup_test_prop_c = prop 641 | 642 | print('reset setktv') 643 | print(rp.setktv(1, 2, 'rst'), '\n') 644 | 645 | print('getfij') 646 | print(rp.getfij('LIN'), '\n') 647 | 648 | print('resetup_test_prop, setref, setmod') 649 | print(resetup_test_prop_a, '\n') 650 | 651 | print('resetup') 652 | print(rp.resetup(resetup_test_prop_a), '\n') 653 | 654 | print('resetup_test_prop, setref(???), setmod') 655 | print(resetup_test_prop_b, '\n') 656 | 657 | print('resetup') 658 | print(rp.resetup(resetup_test_prop_b), '\n') 659 | 660 | print('resetup_test_prop, setktv') 661 | print(resetup_test_prop_c, '\n') 662 | 663 | print('resetup') 664 | print(rp.resetup(resetup_test_prop_c), '\n') 665 | 666 | print('resetup_test_prop, purefld') 667 | print(resetup_test_prop_d, '\n') 668 | 669 | print('resetup') 670 | print(rp.resetup(resetup_test_prop_d), '\n') 671 | 672 | #normalize([0.2, 0.2, 0.1, 0.1]) 673 | print('normalize') 674 | print(rp.normalize([0.2, 0.2, 0.1, 0.1]), '\n') 675 | 676 | #setup_details 677 | print('setup_details') 678 | print(rp.setup_details({'hfld': ['BUTANE', 'ETHANE', 'PROPANE', 'METHANE'], 679 | 'D': 0.21683907260570098, 680 | 'Dvap': 0.09664613429889905, 'hfmix': 'HMX.BNC', 681 | 'setmod': {'hcomp': ['TC2', 'TC1', 'TC2', 'TC2'], 682 | 'htype': 'TCX', 'hmix': 'ECS'}, 683 | 'cp': -9999980.0, 684 | 'xliq': [Decimal('0.7125650648765283717349528049'), 685 | Decimal('0.04065955068790887177072495080'), 686 | Decimal('0.2449672538076863186375885862'), 687 | Decimal('0.001808130627876437856733658079')], 688 | 'xvap': [Decimal('0.2304027911956556081031262882'), 689 | Decimal('0.2886769748808782463382744488'), 690 | Decimal('0.3697982730402927396744896960'), 691 | Decimal('0.1111219608831734058841095670')], 692 | 'x': [0.5, 0.15, 0.3, 0.05], 'e': -13828.39837781548, 693 | 'h': -12906.055381248256, 'nc': 4, 694 | 'Dliq': 11.150114864150222, 'cv': -9999980.0, 695 | 'q': 0.4408579356823604, 'p': 200.0, 696 | 's': -44.047682476988044, 't': 260.0, 'w': -9999980.0, 697 | 'kph': 1, 'setref': {'p0': 100, 'ixflag': 1, 'h0': 0, 698 | 's0': 0, 't0': 273, 699 | 'hrf': ['OTH', '???']}, 700 | 'hrf': 'DEF'}), '\n') 701 | 702 | #gerg04 703 | print('gerg04 = 1') 704 | rp.gerg04(1) 705 | print(rp.setup('def', 'butane', 'ethane', 'propane'), '\n') 706 | 707 | #reset gerg04 708 | print('gerg04 = 0') 709 | rp.gerg04(0) 710 | print(rp.setup('def', 'butane', 'ethane', 'propane'), '\n') 711 | 712 | #preos 713 | print('preos = 2') 714 | print(rp.preos(2), '\n') 715 | 716 | print('preos = -1') 717 | print(rp.preos(-1), '\n') 718 | 719 | print('preos = 0') 720 | print(rp.preos(0), '\n') 721 | 722 | print('preos = -1') 723 | print(rp.preos(-1), '\n') 724 | 725 | #setaga 726 | print('setaga') 727 | print(rp.setaga(), '\n') 728 | 729 | #unsetaga 730 | print('unsetaga') 731 | print(rp.unsetaga(), '\n') 732 | 733 | #setup_settings 734 | print('setup_setting') 735 | print(rp.setup_setting(), '\n') 736 | -------------------------------------------------------------------------------- /rp2so: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #update 26 april comments from Andy 3 | 4 | #first use WINE to install refprop.exe in the C:\Program Files\REFPROP\ directory (or virtual box if WINE doesn't work for you) 5 | #then execute this shell script 6 | #note, you will need to have the following installed on Linux: 7 | # gfortran 8 | # sed 9 | # dos2unix 10 | #finally, you can then use the refprop.py interface to call the librefprop.so 11 | 12 | #cause the script to abort immediately on error instead of trying to continue 13 | #an error could for example be caused by not running this script as superuser (sudo), if installing to a path that requires superuser permissions 14 | set -e 15 | 16 | #set the default paths. don't use relative paths 17 | DefaultREFPROPSourcePath=~/.wine/drive_c/Program\ Files/REFPROP 18 | Defaultpath=/usr/local/lib/refprop 19 | 20 | #now ask the user if they want to change from the default paths 21 | echo "Enter the path where the REFPROP source files were installed to (relative paths not allowed)." 22 | echo "Hit Enter to accept the default of $DefaultREFPROPSourcePath" 23 | read REFPROPSourcePath; 24 | if [ "$REFPROPSourcePath" == "" ]; then 25 | REFPROPSourcePath=${DefaultREFPROPSourcePath} 26 | fi; 27 | echo 28 | echo "Enter base path where the compiled REFPROP files will be installed to (relative paths not allowed)" 29 | echo "Hit Enter to accept the default of $Defaultpath" 30 | echo "Warning: You may need to be running this script as superuser (i.e. 'sudo ./rp2so') for $Defaultpath" 31 | echo "You can press Control-C to stop the script now." 32 | read path; 33 | if [ "$path" == "" ]; then 34 | path=${Defaultpath} 35 | fi; 36 | echo 37 | 38 | #delete previous installation 39 | echo "Are you sure you want to delete $path ?" 40 | echo "Enter 'y' for yes, Control-C to stop the script now, or anything else for no" 41 | read yess; 42 | echo 43 | if [ "$yess" == "y" ]; then 44 | echo "--- Deleting $path ---" 45 | rm -rf ${path} 46 | else 47 | echo "--- Not deleting $path ---" 48 | fi; 49 | 50 | #create directories 51 | echo "--- Creating directories ---" 52 | mkdir -p ${path}/FOR/ 53 | mkdir -p ${path}/fluids/ 54 | mkdir -p ${path}/mixtures/ 55 | 56 | #copy fortran / refprop files to ${path} 57 | echo "--- Copying source files ---" 58 | cp -r "${REFPROPSourcePath}"/fortran/*.FOR ${path}/FOR/ 59 | cp -r "${REFPROPSourcePath}"/fluids/* ${path}/fluids/ 60 | cp -r "${REFPROPSourcePath}"/mixtures/* ${path}/mixtures/ 61 | 62 | #allow read permission all 63 | echo "--- Changing file permissions ---" 64 | chmod -R a+r ${path}/fluids/ 65 | chmod -R a+r ${path}/mixtures/ 66 | 67 | #rename all filenames to UPPERCASE and correct fortran extension (*.FOR > *.f) 68 | echo "--- Renaming lowercase to UPPERCASE filenames and correct extension---" 69 | cd ${path}/fluids/ 70 | rename 'y/a-z/A-Z/' * 71 | cd ${path}/mixtures/ 72 | rename 'y/a-z/A-Z/' * 73 | cd ${path}/FOR/ 74 | rename 'y/a-z/A-Z/' * 75 | rename -f 's/\.FOR/\.f/' ${path}/FOR/*.FOR 76 | 77 | #modify PASS_FTN.f 78 | #remove windows specific command 79 | echo "--- Applying a linux specific fix to PASS_FTN.f ---" 80 | sed -i 's/ dll_export/c dll_export/' ${path}/FOR/PASS_FTN.f 81 | 82 | #process files (dos to unix) 83 | echo "--- Converting source file line endings from dos to unix ---" 84 | for files in ${path}/FOR/*.f ${path}/fluids/* ${path}/mixtures/* 85 | do 86 | { 87 | echo "processing ${files}" 88 | #change *.f files from dos to unix 89 | dos2unix -q ${files} 90 | } & 91 | done 92 | #wait for multiprocessing to complete 93 | wait 94 | 95 | #modify *.f 96 | echo "--- Applying common file fix ---" 97 | for files in ${path}/FOR/*.f 98 | do 99 | { 100 | sudo sed -i "s/'commons.for'/'COMMONS.include'/" ${files} 101 | sudo sed -i "s/'comtrn.for'/'COMTRN.include'/" ${files} 102 | } & 103 | done 104 | wait 105 | #rename COMMONS.f and COMTRN.f to *.include 106 | rename -f 's/\.f/\.include/' ${path}/FOR/COMMONS.f ${path}/FOR/COMTRN.f 107 | 108 | #create the dynamically link "shared objects" (so) library 109 | echo "--- Creating shared object file ---" 110 | #option -fopenmp is possible but at present does not have any speed gains on the contrary 111 | #option -lc, does nothing? 112 | gfortran -shared -fpic -Ofast ${path}/FOR/*.f -Wl,-soname,librefprop.so.9 -o ${path}/librefprop.so.9.1 #-lc -fopenmp 113 | 114 | #install the object file 115 | echo "--- Installing object file ---" 116 | rm -rf ${path%/refprop}/librefprop.so 117 | ldconfig -n ${path} 118 | ln -s ${path}/librefprop.so.9 ${path%/refprop}/librefprop.so 119 | 120 | echo 121 | echo "Note: If you want to display ported commands, type:" 122 | echo "nm ${path%/refprop}/librefprop.so" 123 | --------------------------------------------------------------------------------