matplotlib

Table Of Contents

Previous topic

Example Code for Java

Next topic

Python Plotting

This Page

Example Code for Python

Code

# Example of CoolProp for Python
# Ian Bell, 2013

from __future__ import print_function

import CoolProp
import CoolProp.CoolProp as CP

print('CoolProp version: ', CoolProp.__version__)
print('CoolProp gitrevision: ', CoolProp.__gitrevision__)
print('CoolProp fluids: ', CoolProp.__fluids__)


print(' ')
print('************ USING EOS *************')
print(' ')
print('FLUID STATE INDEPENDENT INPUTS')
print('Critical Density Propane:', CP.Props('Propane', 'rhocrit'), 'kg/m^3')
print('TWO PHASE INPUTS (Pressure)')
print('Density of saturated liquid Propane at 101.325 kPa:',
       CP.Props('D', 'P', 101.325, 'Q', 0, 'Propane'), 'kg/m^3')
print('Density of saturated vapor R290 at 101.325 kPa:',
       CP.Props('D', 'P', 101.325, 'Q', 1, 'R290'), 'kg/m^3')
print('TWO PHASE INPUTS (Temperature)')
print('Density of saturated liquid Propane at 300 K:',
       CP.Props('D', 'T', 300, 'Q', 0, 'Propane'), 'kg/m^3')
print('Density of saturated vapor R290 at 300 K:',
       CP.Props('D', 'T', 300, 'Q', 1, 'R290'), 'kg/m^3')

p = CP.Props('P', 'T', 300, 'D', 1, 'Propane')
h = CP.Props('H', 'T', 300, 'D', 1, 'Propane')
T = CP.Props('T', 'P', p, 'H', h, 'Propane')
D = CP.Props('D', 'P', p, 'H', h, 'Propane')
print('SINGLE PHASE CYCLE (propane)')
print('T,D -> P,H', 300, ',', 1, '-->', p, ',', h)
print('P,H -> T,D', p, ',', h, '-->', T, ',', D)


CP.enable_TTSE_LUT('Propane')
print(' ')
print('************ USING TTSE ***************')
print(' ')
print('TWO PHASE INPUTS (Pressure)')
print('Density of saturated liquid Propane at 101.325 kPa:',
       CP.Props('D', 'P', 101.325, 'Q', 0, 'Propane'), 'kg/m^3')
print('Density of saturated vapor R290 at 101.325 kPa:',
       CP.Props('D', 'P', 101.325, 'Q', 1, 'R290'), 'kg/m^3')
print('TWO PHASE INPUTS (Temperature)')
print('Density of saturated liquid Propane at 300 K:',
       CP.Props('D', 'T', 300, 'Q', 0, 'Propane'), 'kg/m^3')
print('Density of saturated vapor R290 at 300 K:',
       CP.Props('D', 'T', 300, 'Q', 1, 'R290'), 'kg/m^3')

p = CP.Props('P', 'T', 300, 'D', 1, 'Propane')
h = CP.Props('H', 'T', 300, 'D', 1, 'Propane')
T = CP.Props('T', 'P', p, 'H', h, 'Propane')
D = CP.Props('D', 'P', p, 'H', h, 'Propane')
print('SINGLE PHASE CYCLE (propane)')
print('T,D -> P,H', 300, ',', 1, '-->', p, ',', h)
print('P,H -> T,D', p, ',', h, '-->', T, ',', D)
CP.disable_TTSE_LUT('Propane')

try:
    print(' ')
    print('************ USING REFPROP ***************')
    print(' ')
    print('TWO PHASE INPUTS (Pressure)')
    print('Density of saturated liquid Propane at 101.325 kPa:',
           CP.Props('D', 'P', 101.325, 'Q', 0, 'REFPROP-Propane'), 'kg/m^3')
    print('Density of saturated vapor Propane at 101.325 kPa:',
           CP.Props('D', 'P', 101.325, 'Q', 1, 'REFPROP-propane'), 'kg/m^3')
    print('TWO PHASE INPUTS (Temperature)')
    print('Density of saturated liquid Propane at 300 K:',
           CP.Props('D', 'T', 300, 'Q', 0, 'REFPROP-propane'), 'kg/m^3')
    print('Density of saturated vapor Propane at 300 K:',
           CP.Props('D', 'T', 300, 'Q', 1, 'REFPROP-propane'), 'kg/m^3')

    p = CP.Props('P', 'T', 300, 'D', 1, 'Propane')
    h = CP.Props('H', 'T', 300, 'D', 1, 'Propane')
    T = CP.Props('T', 'P', p, 'H', h, 'Propane')
    D = CP.Props('D', 'P', p, 'H', h, 'Propane')
    print('SINGLE PHASE CYCLE (propane)')
    print('T,D -> P,H', 300, ',', 1, '-->', p, ',', h)
    print('P,H -> T,D', p, ',', h, '-->', T, ',', D)
except:
    print(' ')
    print('************ CANT USE REFPROP ************')
    print(' ')

print(' ')
print('************ CHANGE UNIT SYSTEM (default is kSI) *************')
print(' ')
CP.set_standard_unit_system(CoolProp.UNIT_SYSTEM_SI)
print('Vapor pressure of water at 373.15 K in SI units (Pa):',
       CP.Props('P', 'T', 373.15, 'Q', 0, 'Water'))
CP.set_standard_unit_system(CoolProp.UNIT_SYSTEM_KSI)
print('Vapor pressure of water at 373.15 K in kSI units (kPa):',
       CP.Props('P', 'T', 373.15, 'Q', 0, 'Water'))

print(' ')
print('************ BRINES AND SECONDARY WORKING FLUIDS *************')
print(' ')
print('Density of 50% (mass) ethylene glycol/water at 300 K, 101.325 kPa:',
       CP.Props('D', 'T', 300, 'P', 101.325, 'EG-50%'), 'kg/m^3')
print('Viscosity of Therminol D12 at 350 K, 101.325 kPa:',
       CP.Props('V', 'T', 350, 'P', 101.325, 'TD12'), 'Pa-s')

print(' ')
print('************ HUMID AIR PROPERTIES *************')
print(' ')
print('Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa:',
       CP.HAProps('W', 'T', 300, 'P', 101.325, 'R', 0.5), 'kg_w/kg_da')
print('Relative humidity from last calculation:',
       CP.HAProps('R', 'T', 300, 'P', 101.325, 'W',
                   CP.HAProps('W', 'T', 300, 'P', 101.325, 'R', 0.5)),
       '(fractional)')

Output

CoolProp version:  4.2.5
CoolProp gitrevision:  7fd51d2f3821338fb4c27d2cd1ffad52d3efc23e
CoolProp fluids:  ['Water', 'R134a', 'Helium', 'Oxygen', 'Hydrogen', 'ParaHydrogen', 'OrthoHydrogen', 'Argon', 'CarbonDioxide', 'Nitrogen', 'n-Propane', 'Ammonia', 'R1234yf', 'R1234ze(E)', 'R32', 'R22', 'SES36', 'Ethylene', 'SulfurHexafluoride', 'Ethanol', 'DimethylEther', 'DimethylCarbonate', 'R143a', 'R23', 'n-Dodecane', 'Propylene', 'Cyclopentane', 'R236FA', 'R236EA', 'R227EA', 'R365MFC', 'R161', 'HFE143m', 'Benzene', 'n-Undecane', 'R125', 'CycloPropane', 'Neon', 'R124', 'Propyne', 'Fluorine', 'Methanol', 'RC318', 'R21', 'R114', 'R13', 'R14', 'R12', 'R113', 'R1234ze(Z)', 'R1233zd(E)', 'AceticAcid', 'R245fa', 'R41', 'CarbonMonoxide', 'CarbonylSulfide', 'n-Decane', 'HydrogenSulfide', 'Isopentane', 'Neopentane', 'Isohexane', 'Krypton', 'n-Nonane', 'Toluene', 'Xenon', 'R116', 'Acetone', 'NitrousOxide', 'SulfurDioxide', 'R141b', 'R142b', 'R218', 'Methane', 'Ethane', 'n-Butane', 'IsoButane', 'n-Pentane', 'n-Hexane', 'n-Heptane', 'n-Octane', 'CycloHexane', 'R152A', 'R123', 'R11', 'MDM', 'MD2M', 'MD3M', 'D6', 'MM', 'MD4M', 'D4', 'D5', '1-Butene', 'IsoButene', 'cis-2-Butene', 'trans-2-Butene', 'MethylPalmitate', 'MethylStearate', 'MethylOleate', 'MethylLinoleate', 'MethylLinolenate', 'o-Xylene', 'm-Xylene', 'p-Xylene', 'EthylBenzene', 'Deuterium', 'ParaDeuterium', 'OrthoDeuterium', 'Air', 'R404A', 'R410A', 'R407C', 'R507A', 'R407F']
 
************ USING EOS *************
 
FLUID STATE INDEPENDENT INPUTS
Critical Density Propane: 220.4781 kg/m^3
TWO PHASE INPUTS (Pressure)
Density of saturated liquid Propane at 101.325 kPa: 580.882951955 kg/m^3
Density of saturated vapor R290 at 101.325 kPa: 2.41613600879 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.447375252 kg/m^3
Density of saturated vapor R290 at 300 K: 21.6295320185 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300 , 1 --> 56.0727627483 , 634.733625928
P,H -> T,D 56.0727627483 , 634.733625928 --> 300.0 , 1.0
 
************ USING TTSE ***************
 
TWO PHASE INPUTS (Pressure)
0.149 to build both two phase tables
Density of saturated liquid Propane at 101.325 kPa: 580.893699557 kg/m^3
Density of saturated vapor R290 at 101.325 kPa: 2.41629622838 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.447377441 kg/m^3
Density of saturated vapor R290 at 300 K: 21.6295318773 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300 , 1 --> 56.0727644058 , 634.733625854
P,H -> T,D 56.0727644058 , 634.733625854 --> 299.999999907 , 0.999999979733
 
************ USING REFPROP ***************
 
TWO PHASE INPUTS (Pressure)
Density of saturated liquid Propane at 101.325 kPa: 580.882951955 kg/m^3
Density of saturated vapor Propane at 101.325 kPa: 2.41613600879 kg/m^3
TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.447375252 kg/m^3
Density of saturated vapor Propane at 300 K: 21.6295320185 kg/m^3
SINGLE PHASE CYCLE (propane)
T,D -> P,H 300 , 1 --> 56.0727627483 , 634.733625928
P,H -> T,D 56.0727627483 , 634.733625928 --> 300.0 , 1.0
 
************ CHANGE UNIT SYSTEM (default is kSI) *************
 
Vapor pressure of water at 373.15 K in SI units (Pa): 101417.99666
Vapor pressure of water at 373.15 K in kSI units (kPa): 101.41799666
 
************ BRINES AND SECONDARY WORKING FLUIDS *************
 
Density of 50% (mass) ethylene glycol/water at 300 K, 101.325 kPa: 1061.17930772 kg/m^3
Viscosity of Therminol D12 at 350 K, 101.325 kPa: 0.000522884941051 Pa-s
 
************ HUMID AIR PROPERTIES *************
 
Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: 0.0110962237501 kg_w/kg_da
Relative humidity from last calculation: 0.5 (fractional)