matplotlib

Table Of Contents

Previous topic

Examples

Next topic

Example Code for MATLAB

This Page

Example Code for C++

Code

#include "CoolProp.h"
#include "HumidAirProp.h"
#include "CPState.h"
#include <iostream>
#include <stdlib.h>

#pragma GCC diagnostic ignored "-Wwrite-strings" //Ignore char* warnings

int main() {
    double T, h, p, D;

    printf("CoolProp version:\t%s\n",     get_global_param_string("version").c_str());
    printf("CoolProp gitrevision:\t%s\n", get_global_param_string("gitrevision").c_str());
    printf("CoolProp fluids:\t%s\n",      get_global_param_string("FluidsList").c_str());

    printf("\n************ USING EOS *************\n");

    printf("FLUID STATE INDEPENDENT INPUTS\n");
    printf("Critical Density Propane: %f kg/m^3\n", Props1("Propane", "rhocrit"));

    printf("\nTWO PHASE INPUTS (Pressure)\n");
    printf("Density of saturated liquid Propane at 101325 Pa: %f kg/m^3\n",   PropsSI("D", "P", 101325, "Q", 0, "Propane"));
    printf("Density of saturated vapor R290 at 101325 Pa:     %f kg/m^3\n",   PropsSI("D", "P", 101325, "Q", 1, "R290"));

    printf("\nTWO PHASE INPUTS (Temperature)\n");
    printf("Density of saturated liquid Propane at 300 K: %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 0, "Propane"));
    printf("Density of saturated vapor R290 at 300 K:     %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 1, "R290"));

    printf("\nSINGLE PHASE CYCLE (Propane)\n");
    p = PropsSI("P", "T", 300, "D", 1, "Propane");
    h = PropsSI("H", "T", 300, "D", 1, "Propane");
    printf("T,D -> P,H : 300,1 -> %f,%f\n", p, h);

    T = PropsSI("T", "P", p, "H", h, "Propane");
    D = PropsSI("D", "P", p, "H", h, "Propane");
    printf("P,H -> T,D : %f, %f -> %f, %f\n", p, h, T, D);

    printf("\n************ USING TTSE ***************\n");
    enable_TTSE_LUT("Propane");

    printf("TWO PHASE INPUTS (Pressure)\n");
    printf("Density of saturated liquid Propane at 101325 Pa: %f kg/m^3\n", PropsSI("D", "P", 101325, "Q", 0, "Propane"));
    printf("Density of saturated vapor R290 at 101325 Pa:     %f kg/m^3\n", PropsSI("D", "P", 101325, "Q", 1, "R290"));

    printf("\nTWO PHASE INPUTS (Temperature)");
    printf("Density of saturated liquid Propane at 300 K: %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 0, "Propane"));
    printf("Density of saturated vapor R290 at 300 K:     %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 1, "R290"));

    printf("\nSINGLE PHASE CYCLE (propane)\n");
    p = PropsSI("P", "T", 300, "D", 1, "Propane");
    h = PropsSI("H", "T", 300, "D", 1, "Propane");
    printf("T,D -> P,H : 300,1 -> %f,%f", p, h);

    T = PropsSI("T", "P", p, "H", h, "Propane");
    D = PropsSI("D", "P", p, "H", h, "Propane");
    printf("P,H -> T,D : %f, %f -> %f, %f\n", p, h, T, D);

    disable_TTSE_LUT("Propane");

    try
    {
        printf("\n************ USING REFPROP ***************\n");
        std::string RPName = std::string("REFPROP-")+get_fluid_param_string("Propane","REFPROPname");
        printf("TWO PHASE INPUTS (Pressure)");
        printf("Density of saturated liquid Propane at 101325 Pa: %f kg/m^3\n", PropsSI("D", "P", 101325, "Q", 0, RPName));
        printf("Density of saturated vapor R290 at 101325 Pa:     %f kg/m^3\n", PropsSI("D", "P", 101325, "Q", 1, RPName));

        printf("\nTWO PHASE INPUTS (Temperature)");
        printf("Density of saturated liquid Propane at 300 K: %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 0, RPName));
        printf("Density of saturated vapor R290 at 300 K:     %f kg/m^3\n", PropsSI("D", "T", 300, "Q", 1, RPName));

        printf("\nSINGLE PHASE CYCLE (propane)\n");
        p = PropsSI("P", "T", 300, "D", 1, RPName);
        h = PropsSI("H", "T", 300, "D", 1, RPName);
        printf("T,D -> P,H : 300,1 -> %f,%f\n", p, h);

        T = PropsSI("T", "P", p, "H", h, RPName);
        D = PropsSI("D", "P", p, "H", h, RPName);
        printf("P,H -> T,D : %f, %f -> %f, %f\n", p, h, T, D);
    }
    catch (std::exception &e)
    {
        printf("\n************ CANT USE REFPROP ************\n");
    }

    printf("\n************ BRINES AND SECONDARY WORKING FLUIDS *************\n");
    printf("Density of 50%% (mass) ethylene glycol/water at 300 K, 101325 Pa: %f kg/m^3\n", PropsSI("D", "T", 300, "P", 101325, "EG-50%"));
    printf("Viscosity of Therminol D12 at 350 K, 101325 Pa: %f Pa-s\n",  PropsSI("V", "T", 350, "P", 101325, "TD12"));

    printf("\n************ HUMID AIR PROPERTIES *************\n");
    printf("Humidity ratio of 50%% rel. hum. air at 300 K, 101.325 kPa: %f kg_w/kg_da\n", HAProps("W", "T", 300, "P", 101.325, "R", 0.5));
    printf("Relative humidity from last calculation: %f (fractional)\n",   HAProps("R", "T", 300, "P", 101.325, "W", HAProps("W", "T", 300, "P", 101.325, "R", 0.5)));
    return 0;
}

Output

CoolProp version:	4.2.5
CoolProp gitrevision:	b'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.478100 kg/m^3

TWO PHASE INPUTS (Pressure)
Density of saturated liquid Propane at 101325 Pa: 580.882952 kg/m^3
Density of saturated vapor R290 at 101325 Pa:     2.416136 kg/m^3

TWO PHASE INPUTS (Temperature)
Density of saturated liquid Propane at 300 K: 489.447375 kg/m^3
Density of saturated vapor R290 at 300 K:     21.629532 kg/m^3

SINGLE PHASE CYCLE (Propane)
T,D -> P,H : 300,1 -> 56072.762748,634733.625928
P,H -> T,D : 56072.762748, 634733.625928 -> 300.000000, 1.000000

************ USING TTSE ***************
TWO PHASE INPUTS (Pressure)
0.177 to build both two phase tables
2.328 to build single phase table with p,h
11.065 to build single phase table for T,rho
write time: 0.053
Density of saturated liquid Propane at 101325 Pa: 580.882952 kg/m^3
Density of saturated vapor R290 at 101325 Pa:     2.416136 kg/m^3

TWO PHASE INPUTS (Temperature)Density of saturated liquid Propane at 300 K: 489.447377 kg/m^3
Density of saturated vapor R290 at 300 K:     21.629532 kg/m^3

SINGLE PHASE CYCLE (propane)
T,D -> P,H : 300,1 -> 56072.764406,634733.625854P,H -> T,D : 56072.764406, 634733.625854 -> 300.000000, 1.000000

************ USING REFPROP ***************
TWO PHASE INPUTS (Pressure)Density of saturated liquid Propane at 101325 Pa: 580.882952 kg/m^3
Density of saturated vapor R290 at 101325 Pa:     2.416136 kg/m^3

TWO PHASE INPUTS (Temperature)Density of saturated liquid Propane at 300 K: 489.447375 kg/m^3
Density of saturated vapor R290 at 300 K:     21.629532 kg/m^3

SINGLE PHASE CYCLE (propane)
T,D -> P,H : 300,1 -> 56072.762748,634733.629700
P,H -> T,D : 56072.762748, 634733.629700 -> 300.000000, 1.000000

************ BRINES AND SECONDARY WORKING FLUIDS *************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: 1061.179308 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 0.000523 Pa-s

************ HUMID AIR PROPERTIES *************
Humidity ratio of 50% rel. hum. air at 300 K, 101.325 kPa: 0.011096 kg_w/kg_da
Relative humidity from last calculation: 0.500000 (fractional)