def get_global_param_string(self, param_name, split=False): """Get global parameter string from CoolProp. The split option was added for convenience and can be used to output comma separated values as a column vector in Calc. Thus, the function can be directly used as input for dropdown fields. """ try: param_str = CoolProp.get_global_param_string(param_name) if split: return zip(param_str.split(',')) else: return [[param_str]] except Exception as e: return [[str(e)]]
"""Module to organize fluids.""" from warnings import warn import CoolProp.CoolProp as CP class Fluid: def __init__(self, name): self.name = name self.possible_names = [] def __repr__(self): return f"{type(self).__name__}({self.__dict__}" _fluid_list = CP.get_global_param_string("fluids_list").split(",") fluid_list = {name: Fluid(name) for name in _fluid_list} # define possible names fluid_list["IsoButane"].possible_names.extend( ["isobutane", "i-butane", "ibutane", "isobutan", "iso-butane"]) fluid_list["n-Butane"].possible_names.extend(["butane", "n-butane", "nbutane"]) fluid_list["trans-2-Butene"].possible_names.extend( ["trans-butene", "trans-butene-2"]) fluid_list["IsoButene"].possible_names.extend( ["i-butene", "ibutene", "iso-butene"]) fluid_list["cis-2-Butene"].possible_names.extend( ["cis-butene", "cis-butene-2"]) fluid_list["n-Pentane"].possible_names.extend( ["pentane", "n-pentane", "npentane"]) fluid_list["Isopentane"].possible_names.extend(
RPdata = CP.PropsSI(key, 'T', T, 'Dmolar', rho, RPfluid) - CP.PropsSI(key, 'T', T, 'Dmolar', 1, RPfluid) CPdata = CP.PropsSI(key, 'T', T, 'Dmolar', rho, fluid) - CP.PropsSI(key, 'T', T, 'Dmolar', 1, fluid) plt.plot(rho/rhoc, np.abs(RPdata/CPdata-1)*100, lw = 0, label = key, marker = symbols[(i+len(normalkeys))%len(symbols)]) ax.legend(loc='best', ncol = 2) plt.xlabel(r'Reduced density [$\\rho/\\rho_c$]') plt.ylabel(r'Relative deviation $(y_{{CP}}/y_{{RP}}-1)\\times 100$ [%]') ax.set_yscale('log') plt.title('Comparison between CoolProp and REFPROP({rpv:s}) along T = 1.01*Tc') plt.savefig(fluid+'.png', dpi = 100) plt.savefig(fluid+'.pdf') plt.close('all') """ if not os.path.exists(plots_path): os.makedirs(plots_path) with open(os.path.join(plots_path, 'matplotlibrc'), 'w') as fp: fp.write("backend : agg\n") for fluid in CoolProp.__fluids__: print('fluid:', fluid) file_string = template.format(fluid = fluid, rpv = CP.get_global_param_string("REFPROP_version")) file_path = os.path.join(plots_path, fluid + '.py') print('Writing to', file_path) with open(file_path, 'w') as fp: fp.write(file_string) subprocess.check_call('python "' + fluid + '.py"', cwd = plots_path, stdout = sys.stdout, stderr = sys.stderr, shell = True)
# raise err # Check external optional modules from tools.dependences import optional_modules # noqa for module, use in optional_modules: try: __import__(module) os.environ[module] = "True" except ImportError: print("%s could not be found, %s" % (module, use)) os.environ[module] = "" else: # Check required version if module == "CoolProp": import CoolProp.CoolProp as CP version = CP.get_global_param_string("version") mayor, minor, rev = map(int, version.split(".")) if mayor < 6: print("Find CoolProp %s but CoolProp 6 required" % version) os.environ[module] = "" # Logging configuration if args.debug: loglevel = "DEBUG" else: loglevel = args.loglevel loglevel = getattr(logging, loglevel.upper()) # Checking config folder if not os.path.isdir(conf_dir): os.mkdir(conf_dir)
def check_global(p): CP.get_global_param_string(p)
# Check external optional modules from tools.dependences import optional_modules # noqa for module, use in optional_modules: try: __import__(module) os.environ[module] = "True" except ImportError: print("%s could not be found, %s" % (module, use)) os.environ[module] = "" else: # Check required version if module == "CoolProp": import CoolProp.CoolProp as CP version = CP.get_global_param_string("version") mayor, minor, rev = map(int, version.split(".")) if mayor < 6: print("Find CoolProp %s but CoolProp 6 required" % version) os.environ[module] = "" # Logging configuration if args.debug: loglevel = "DEBUG" else: loglevel = args.loglevel loglevel = getattr(logging, loglevel.upper()) # Checking config folder if not os.path.isdir(conf_dir):
# -*- coding: utf-8 -*- """ Created on Fri Apr 20 22:25:34 2018 @author: Zihao.MAI """ PATH_TO_REFPROP_LIB = 'D:\\REFPROP' from common.postimport import when_imported @when_imported('CoolProp.CoolProp') def test1(mod): print('hello cp') @when_imported('CoolProp.CoolProp') def test2(mod): try: mod.set_config_string(mod.ALTERNATIVE_REFPROP_PATH, PATH_TO_REFPROP_LIB) print(mod.get_global_param_string('REFPROP_version')) except: print('oops') import CoolProp.CoolProp as cp print(cp.get_global_param_string('REFPROP_version'))
plt.xlabel(r'Reduced density [$\\rho/\\rho_c$]') plt.ylabel(r'Relative deviation $(y_{{CP}}/y_{{RP}}-1)\\times 100$ [%]') ax.set_yscale('log') plt.title('Comparison between CoolProp and REFPROP({rpv:s}) along T = 1.01*Tc') plt.savefig(fluid+'.png', dpi = 100) plt.savefig(fluid+'.pdf') plt.close('all') """ if not os.path.exists(plots_path): os.makedirs(plots_path) with open(os.path.join(plots_path, 'matplotlibrc'), 'w') as fp: fp.write("backend : agg\n") for fluid in CoolProp.__fluids__: print('fluid:', fluid) file_string = template.format( fluid=fluid, rpv=CP.get_global_param_string("REFPROP_version")) file_path = os.path.join(plots_path, fluid + '.py') print('Writing to', file_path) with open(file_path, 'w') as fp: fp.write(file_string) subprocess.check_call('python "' + fluid + '.py"', cwd=plots_path, stdout=sys.stdout, stderr=sys.stderr, shell=True)
CPdata = CP.PropsSI(key, 'T', T, 'Dmolar', rho, fluid) - CP.PropsSI(key, 'T', T, 'Dmolar', 1, fluid) plt.plot(rho/rhoc, np.abs(RPdata/CPdata-1)*100, lw = 0, label = key, marker = symbols[(i+len(normalkeys))%len(symbols)]) ax.legend(loc='best', ncol = 2) plt.xlabel(r'Reduced density [$\\rho/\\rho_c$]') plt.ylabel(r'Relative deviation $(y_{{CP}}/y_{{RP}}-1)\\times 100$ [%]') ax.set_yscale('log') plt.title('Comparison between CoolProp and REFPROP({rpv:s}) along T = 1.01*Tc') plt.savefig(fluid+'.png', dpi = 100) plt.savefig(fluid+'.pdf') plt.close('all') """ if not os.path.exists(plots_path): os.makedirs(plots_path) with open(os.path.join(plots_path, 'matplotlibrc'), 'w') as fp: fp.write("backend : agg\n") for fluid in CoolProp.__fluids__: print('fluid:', fluid) file_string = template.format(fluid = fluid, rpv = CP.get_global_param_string("REFPROP_version")) file_path = os.path.join(plots_path, fluid + '.py') print('Writing to', file_path) with open(file_path, 'w') as fp: fp.write(file_string) subprocess.check_call('python "' + fluid + '.py"', cwd = plots_path, stdout = sys.stdout, stderr = sys.stderr, shell = True)
from CoolProp.Plots import PropertyPlot, SimpleCompressionCycle, SimpleCycles import CoolProp import CoolProp.CoolProp as CP import math print("CoolProp version:", CP.get_global_param_string("version")) # P1 = 0.25*10**6 # P2 = 1 * 10**6 # T1 = 250 # gas = 'Air' # # h1 = CP.PropsSI('H', 'P',P1, 'T', T1, gas) # print("h1 = ", h1) # # h2 = CP.PropsSI('H', 'P',P2, 'T', T1, gas) # print("h2 = ", h2) # # plot = PropertyPlot('Air', 'TS', unit_system='SI', tp_limits='ACHP') # plot.calc_isolines(CoolProp.iP, iso_range=[P1,P2], num=5, rounding=True) # plot.calc_isolines(CoolProp.iHmass, iso_range=[h1,h2], num = 5 ) # plot.show() # print(CP.PropsSI('S', ))