Skip to content

Meeting 2022 11 21

Francesco Witte edited this page Dec 4, 2022 · 1 revision

There was an interesting little HVAC example with cooling humid air using a refrigeration machine. We polished the code a little bit, here is how you can set relative humidity etc. and calculate condensation of water inside air water mixture.

from tespy.networks import Network
from tespy.components import HeatExchanger, CycleCloser, Source, Sink, Compressor, Valve, HeatExchangerSimple
from tespy.connections import Connection
from tespy.tools.fluid_properties import cond_check
from tespy.tools.helpers import molar_mass_flow, molar_masses

from CoolProp.CoolProp import PropsSI


def get_water_mass_fraction_at_relative_humidity(rh, T, p):
    """Get

    Parameters
    ----------
    rh : float
        Relative humidity
    T : float
        Temperature in °C
    p : float
        Pressure in bar

    Returns
    -------
    float
        water mass fraction in water, air mixture given relative humidity
    """
    p *= 1e5
    psatH2O = PropsSI("P", "Q", 0, "T", T + 273.15, "water")
    pH2O = rh * psatH2O
    xH20 = PropsSI("M", "water") * (pH2O / p) / (pH2O / p * PropsSI("M", "water") + (1 - pH2O / p) * PropsSI("M", "Air"))
    return xH20


def HVAC_cooling_mode(fluid):
    """
    Gernerate a HVAC in cooling mode

    Parameters
    ----------
    fluid : str
        fluid for refrigerant cycle

    Returns
    -------
    tespy.networks.network.Network
        TESPy model
    """
    nw = Network(
        fluids=[fluid, "Air", "water"],
        T_unit="C", p_unit="bar", h_unit="J / kg", m_unit="kg / s"
    )

    ev = HeatExchanger("evaporator")
    source = Source("air source")
    sink = Sink("air sink")

    # cooling cycle
    cc = CycleCloser("CycleCloser")
    cp = Compressor("compressor")
    co = HeatExchangerSimple("condenser")
    va = Valve("valve")

    c0 = Connection(ev, "out2", cc, "in1", label="0")
    c1 = Connection(cc, "out1", cp, "in1", label="1")
    c2 = Connection(cp, "out1", co, "in1", label="2")
    c3 = Connection(co, "out1", va, "in1", label="3")
    c4 = Connection(va, "out1", ev, "in2", label="4")

    nw.add_conns(c0, c1, c2, c3, c4)

    c11 = Connection(source, "out1", ev, "in1", label="11")
    c12 = Connection(ev, "out1", sink, "in1", label="12")
    nw.add_conns(c11, c12)

    return nw


def print_humid_air_info(conn):
    # this is a list containing mass flow, pressure, enthalpy and fluid composition
    flow = conn.get_flow()
    # calculate the flow in molar units (mol/s)
    n = molar_mass_flow(flow[3])
    # calculate the molar composition of the air at connection 12
    x_i = {
        fluid: y / (molar_masses[fluid] * n)
        for fluid, y in flow[3].items()
    }
    # calculate gaseous and liquid parts of water air mixture
    y_i_gas, x_i_gas, y_water_liq, x_water_liq = (
        cond_check(conn.fluid.val, x_i, flow[1], n, conn.T.val_SI)
    )

    print(f"Water mass fraction liquid: {y_water_liq * 100:.2f}, % mass fraction gaseous: {(1 - y_water_liq) * y_i_gas['water'] * 100:.2f} %")

    print(f"Composition of humid air (g). water (g): {y_i_gas['water'] * 100:.2f} %, dry (air): {y_i_gas['Air'] * 100:.2f} %")
    print(f"Composition of humid air (g, l). water (g): {y_i_gas['water'] * 100 * (1 - y_water_liq):.2f} %, water (l): {y_water_liq * 100:.2f} %, dry air: {y_i_gas['Air'] * 100 * (1 - y_water_liq):.2f} %")


fluid = "R290"
hvac = HVAC_cooling_mode(fluid)

T_cond = 40
T_evap = 0
p_amb = 1.01325
m_air = 1
T_air_in = 30
T_air_out = 5
rh = 0.8

x_water = get_water_mass_fraction_at_relative_humidity(rh, T_air_in, p_amb)

hvac.get_conn("1").set_attr(x=1, T=T_evap, fluid={fluid: 1, "Air": 0, "water": 0})
hvac.get_conn("3").set_attr(x=0, T=T_cond)

c11 = hvac.get_conn("11")
c12 = hvac.get_conn("12")
c11.set_attr(fluid={'Air': 1 - x_water, 'water': x_water, fluid: 0}, T=T_air_in, p=p_amb, m=m_air)
c12.set_attr(T=T_air_out)

hvac.get_comp("condenser").set_attr(pr=1)

cp = hvac.get_comp("compressor")
cp.set_attr(eta_s=1)

ev = hvac.get_comp("evaporator")
ev.set_attr(pr1=1, pr2=1)

hvac.solve("design")
hvac.print_results()

print(f"Compression power: {cp.P.val:.2f} W")
print(f"Evaporator heat: {ev.Q.val:.2f} W")
print(f"COP = {abs(ev.Q.val) / cp.P.val:.2f}")


print("#" * 5, "air inlet", "#" * 5)
print_humid_air_info(c11)
print("#" * 5, "air outlet", "#" * 5)
print_humid_air_info(c12)
Clone this wiki locally