2021年10月9日 星期六

Introduction of CoolProp for Excel

CoolProp provides functions for thermophysical properties of fluids. It is open-source, free, and licensed under the MIT License. Basically, you can do anything you like with the MIT license. It is very permissive and not copy-left. You can use CoolProp in commercial code.


0.0 General

CoolProp supports lots of programming languages, 122 pure and pseudo-pure fluids, and some mixtures.

Download address:

https://sourceforge.net/projects/coolprop/files/CoolProp/

Detailed document:

http://www.coolprop.org

After installation, we need to activate CoolProp. In Excel, please activate "CoolProp" in Excel Add-ins dialog box. In VBA Editor, please activate "CoolProp" in References dialog box.

For a string literal in Excel or VBA, use double-quotation-marks ( " ) instead of single-quotation-marks ( ' ).

This article is tested per CoolProp Version 6.4.


1.0 High-Level Functions

CoolProp for Excel provides four high-level functions: PropsSI, Props1SI, PhaseSI, HAPropsSI.


1.1 PropsSI

Function PropsSI(ByVal output As String, ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String)

The parameter output is the name of output property that will be returned. Parameters Name1 and Value1 are the name and value of the first input property. Parameters Name2 and Value2 are the name and value of the second input property. The parameter fluid is the name of fluid for which the output property will be calculated.

Per State Postulate in thermodynamics, the state of a pure substance will be determined when two independent, intensive properties are given. That is why two properties are required as function input.

For the name of properties, please refer to Section 2.1 in this article.

CoolProp only uses SI units for input/output properties, other systems of units are not supported. For the unit of properties, please refer to Section 2.1 in this article.

VBA Example:

Private Sub Test1_1()

'density of Nitrogen at 101325 Pa & 300 K

D1 = PropsSI("D", "P", 101325, "T", 300, "Nitrogen")

Debug.Print D1 & " kg/m^3"     '1.13816468646245 kg/m^3

'order of input properties is irrelevant

D2 = PropsSI("D", "T", 300, "P", 101325, "Nitrogen")

Debug.Print D2 & " kg/m^3"     '1.13816468646245 kg/m^3

End Sub


1.2 Props1SI

Function Props1SI(ByVal fluid As String, ByVal output As String)

Some fluid information (e.g.,  pressure at the critical point) is not related to the state of the fluid, so only fluid name (parameter fluid) and output property name (parameter output) are required.

For the name and unit of parameter output in function Props1SI, please refer to Section 2.2 in this article.

VBA Example:

Private Sub Test1_2()

'call Props1SI function

Tcrit1 = Props1SI(“Tcrit”,”Water”)

Debug.Print Tcrit1 & " K"    '647.096 K

'call PropsSI function using dummy arguments for the unused parameters

Tcrit2 = PropsSI("Tcrit","",0,"",0,"Water")

Debug.Print Tcrit2 & " K"    '647.096 K

End Sub


1.3 PhaseSI 

Function PhaseSI(ByVal Name1 As String, ByVal Value1 As Double, ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String)

PhaseSI function only returns the name of the phase, therefore there is no parameter output.

VBA Example:

Private Sub Test1_3()

'PhaseSI function returns name of phase (as string)

phase1 = PhaseSI('P',101325,'Q',0,'Water')

Debug.Print phase1    'twophase

'PropsSI function returns phase index (as floating point number)

phase2 = PropsSI('Phase','P',101325,'Q',0,'Water')

Debug.Print phase2    '6.0

End Sub


1.4 HAPropsSI

Function HAPropsSI(ByVal output As String, ByVal Input1Name As String, ByVal Value1 As Double, ByVal Input2Name As String, ByVal Value2 As Double, ByVal Input3name As String, ByVal Value3 As Double)

HAPropsSI function returns the property of humid air. It requires three properties as function input, and one of them should be humidity. HAPropsSI function is based on ASHREA-RP1485. It is applicable for pressure from 0.01 kPa up to 10 MPa, in a temperature range from -143.15 °C up to 350 °C with a humidity ratio from 0 kg of water up to 10 kg of water per kg of dry air.

For the name and unit of parameters in function HAPropsSI, please refer to Section 2.3 in this article.

VBA Example:

Private Sub Test1_4()

'Enthalpy at dry bulb temperature T of 25C, 

'pressure P of one atmosphere, relative humidity R of 50%

h = HAPropsSI('H','T',298.15,'P',101325,'R',0.5)

Debug.Print h & " J per kg dry air"    '50423.45039076901

#Temperature of saturated air

T1 = HAPropsSI('T','P',101325,'H',h,'R',1.0)

Debug.Print T1 & " K"    '290.96209246907983 K

'order of input properties doesn't matter

T2 = HAPropsSI('T','H',h,'R',1.0,'P',101325)

Debug.Print T2 & " K"    '290.96209246907983 K

End Sub


2.0 Table of String Inputs


2.1 Inputs/Outputs to PropsSI Function

Common properties for PropsSI function are listed in the following table. For a complete list, please refer to:

http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function

Parameter

Units

Input/Output

Description

DMOLARDmolar

mol/m^3

IO

Molar density

DDMASSDmass

kg/m^3

IO

Mass density

HMOLARHmolar

J/mol

IO

Molar specific enthalpy

HHMASSHmass

J/kg

IO

Mass specific enthalpy

P

Pa

IO

Pressure

Q

mol/mol

IO

Mass vapor quality

SMOLARSmolar

J/mol/K

IO

Molar specific entropy

SSMASSSmass

J/kg/K

IO

Mass specific entropy

T

K

IO

Temperature

UMOLARUmolar

J/mol

IO

Molar specific internal energy

UUMASSUmass

J/kg

IO

Mass specific internal energy

CONDUCTIVITYLconductivity

W/m/K

O

Thermal conductivity

CP0MASSCp0mass

J/kg/K

O

Ideal gas mass specific constant pressure specific heat

CP0MOLARCp0molar

J/mol/K

O

Ideal gas molar specific constant pressure specific heat

CPMOLARCpmolar

J/mol/K

O

Molar specific constant pressure specific heat

CVMASSCvmassO

J/kg/K

O

Mass specific constant volume specific heat

CVMOLARCvmolar

J/mol/K

O

Molar specific constant volume specific heat

CCPMASSCpmass

J/kg/K

O

Mass specific constant pressure specific heat

PHASEPhase

 

O

Phase index as a float

PRANDTLPrandtl

 

O

Prandtl number

VVISCOSITYviscosity

Pa s

O

Viscosity

Z

 

O

Compressibility factor

In Input/Output column, I indicates properties for parameters Name1Name2; O indicates properties for parameters output.


2.2 Trivial Inputs for Props1SI Function

Common properties for Props1SI function are listed in the following table. For a complete list, please refer to:

http://www.coolprop.org/coolprop/HighLevelAPI.html#trivial-inputs

Parameter

Units

Description

GAS_CONSTANTgas_constant

J/mol/K

Molar gas constant

MMOLARMASSMOLAR_MASSmolar_massmolarmass

kg/mol

Molar mass

PCRITP_CRITICALPcritp_criticalpcrit

Pa

Pressure at the critical point

RHOCRITRHOMASS_CRITICALrhocritrhomass_critical

kg/m^3

Mass density at critical point

RHOMOLAR_CRITICALrhomolar_critical

mol/m^3

Molar density at critical point

TCRITT_CRITICALT_criticalTcrit

K

Temperature at the critical point

PTRIPLEP_TRIPLEp_tripleptriple

Pa

Pressure at the triple point (pure only)

TTRIPLET_TRIPLET_tripleTtriple

K

Temperature at the triple point

FRACTION_MAXfraction_max

 

Fraction (mole, mass, volume) maximum value for incompressible solutions

FRACTION_MINfraction_min

 

Fraction (mole, mass, volume) minimum value for incompressible solutions

T_FREEZET_freeze

K

Freezing temperature for incompressible solutions

PMAXP_MAXP_maxpmax

Pa

Maximum pressure limit

PMINP_MINP_minpmin

Pa

Minimum pressure limit

TMAXT_MAXT_maxTmax

K

Maximum temperature limit

TMINT_MINT_minTmin

K

Minimum temperature limit


2.3 Inputs/Outputs to HAPropsSI Function

Complete properties for HAPropsSI function are listed in the following table:

Parameter

Units

Input/Output

Description

P

Pa

Input

Pressure

P_w

Pa

Input

Partial pressure of water vapor

TTdbT_db

K

Input/Output

Dry-Bulb Temperature

BTwbT_wbWetBulb

K

Input/Output

Wet-Bulb Temperature

DTdpDewPointT_dp

K

Input/Output

Dew-Point Temperature

psi_wY

mol water/mol humid air

Input/Output

Water mole fraction

RRHRelHum

 

Input/Output

Relative humidity in [0, 1]

WOmegaHumRat

kg water/kg dry air

Input/Output

Humidity Ratio

HHdaEnthalpy

J/kg dry air

Input/Output

Mixture enthalpy per dry air

Hha

J/kg humid air

Input/Output

Mixture enthalpy per humid air

SSdaEntropy

J/kg dry air/K

Input/Output

Mixture entropy per unit dry air

Sha

J/kg humid air/K

Input/Output

Mixture entropy per unit humid air

VVda

m^3 /kg dry air

Input/Output

Mixture volume per unit dry air

Vha

m^3 /kg humid air

Input/Output

Mixture volume per unit humid air

Ccp

J/kg dry air/K

Output

Mixture specific heat per unit dry air

Chacp_ha

J/kg humid air/K

Output

Mixture specific heat per unit humid air

CV

J/kg dry air/K

Output

Mixture specific heat at constant volume per unit dry air

CVhacv_ha

J/kg humid air/K

Output

Mixture specific heat at constant volume per unit humid air

KkConductivity

W/m/K

Output

Mixture thermal conductivity

MViscmu

Pa-s

Output

Mixture viscosity

Z

 

Output

Compressibility factor Z=pv/(RT)

In Input/Output column, Input indicates properties for parameters Name1,  Name2,  Name3; Output indicates properties for parameters output.


3.0 Fluids

3.1 Pure and Pseudo-Pure Fluids

Common pure and pseudo-pure fluids are listed in the following table. For a complete list, please refer to:

http://www.coolprop.org/fluid_properties/PurePseudoPure.html#list-of-fluids

Name

Thermal

Conductivity

Viscosity

Melting

Line

Surface

Tension

Air

Ammonia

Argon

CarbonDioxide

CarbonMonoxide

Ethane

Ethanol

Hydrogen

IsoButane

Isopentane

Methane

Methanol

Nitrogen

Oxygen

Water

n-Butane

n-Hexane

n-Pentane

n-Propane

For Thermal Conductivity, Viscosity, Melting Line, Surface Tension, not all of these properties are supported for a given fluid.


3.2 IAPWS-IF97

The International Association for the Properties of Water and Steam released IAPWS-IF97 for fast computation of water properties. The IF97 backend can be accessed in function PropsSI and function Props1SI. However, water is the only fluid name that can be specified, as "IF97::Water". The following figure is the valid range of temperature and pressure. Temperature and pressure outside of these regions will result in an “Out of Range” error.


VBA Example:

Private Sub Test3_2()

T_init = 500#

P_init = 101325

S_init = PropsSI("S", "T", T_init, "P", P_init, "IF97::Water")  '7938.58736435735

H_init = PropsSI("H", "S", S_init, "P", P_init, "IF97::Water")  '2928535.50133066

T_final = PropsSI("T", "H", H_init, "P", P_init, "IF97::Water") '499.998052904717


Debug.Print S_init & " J/kg/K"

Debug.Print H_init & " J/kg"

Debug.Print T_final & " K"

End Sub


3.3 Incompressible Fluids

In CoolProp, the incompressible fluids are divided into three major groups.

  • Pure fluids
  • Mass-based binary mixtures
  • Volume-based binary mixtures

The incompressible pure fluids implemented in CoolProp cover secondary refrigerants, heat transfer oils, and molten salt mixture. For a complete list of incompressible pure fluids and temperature range, please refer to:

http://www.coolprop.org/fluid_properties/Incompressibles.html#pure

For mass-based binary mixtures and volume-based binary mixtures. Most of them are secondary heat transfer fluids, but there are also aqueous ammonia (MAM) and lithium bromide (LiBr). The concentration always refers to the added component ranging from 0.0 for pure water to 1.0 for no water at all. For a complete list of mass-based and volume-based binary mixtures, temperature range and concentration range, please refer to:

http://www.coolprop.org/fluid_properties/Incompressibles.html#massmix

http://www.coolprop.org/fluid_properties/Incompressibles.html#volumix

VBA Example:

Private Sub Test3_3()

'Incompressible, Pure fluid

T_init = 500#

P_init = 101325

H_init = PropsSI("H", "T", T_init, "P", P_init, "INCOMP::DowQ") '408385.32146991

Debug.Print H_init & " J/kg"

'Incompressible, Mass-based binary mixture

'The fraction notation can be in the form of percent, LiBr-23%, or as a fraction between 0 and 1, LiBr[0.23]

D1 = PropsSI("D", "T", 300, "P", 101325, "INCOMP::LiBr[0.23]")  '1187.54382436172

D2 = PropsSI("D", "T", 300, "P", 101325, "INCOMP::LiBr-23%")    '1187.54382436172

Debug.Print "D1 = " & D1 & " kg/m^3" & vbNewLine & _

            "D2 = " & D2 & " kg/m^3"

'Incompressible, MITSW  (MIT Seawater)

Dsea = PropsSI("D", "T", 300, "P", 101325, "INCOMP::MITSW-3.5%")    '1022.97856743166

Debug.Print Dsea & " kg/m^3"

End Sub


3.4 Mixture

The only types of inputs that are allowed for mixtures right now are:

  • Pressure/quality
  • Temperature/quality
  • Temperature/pressure

The format of mixture name is:

"Name1[Frac1]&Name2[Frac2]&Name3[Frac3]"

Components are separated by ("&"); the fraction of the component is in ("[") and ("]") brackets; the fraction of mixture adopts mole fractions; space (" ") is not allowed in mixture name.

CoolProp provides MixtureString function for Excel:

Function MixtureString(names As Range, fractions As Range) As String

The parameter names is the Excel cells for component names of the mixture. The parameter fractions is the Excel cells for component fractions of the mixture. A string for mixture name will be returned.

Mixture calculations require binary interaction parameters for each pair in the mixture. While many binary interaction parameters are available in the CoolProp library, sadly, many are not. For a complete list of binary pairs, please refer to:

http://www.coolprop.org/fluid_properties/Mixtures.html#binary-pairs


沒有留言:

張貼留言