def generate_values(TR,P=101325):
    """ Starting with T,R as inputs, generate all other values """
    T,R = TR
    psi_w = CP.HAPropsSI('psi_w','T',T,'R',R,'P',P)
    other_output_keys = ['T_wb','T_dp','Hda','Sda','Vda','Omega']
    outputs = {'psi_w':psi_w,'T':T,'P':P,'R':R}
    for k in other_output_keys:
        outputs[k] = CP.HAPropsSI(k,'T',T,'R',R,'P',P)
    return outputs
Exemple #2
0
 def HAPropsSI(self, output, name1, prop1, name2, prop2, name3, prop3):
     """Calculate properties of humid air from SI inputs."""
     try:
         return CoolProp.HAPropsSI(output, name1, prop1, name2, prop2,
                                   name3, prop3)
     except Exception as e:
         return str(e)
Exemple #3
0
    def __init__(self, temp, pressure, rel_Humid, dryair_massfrac):

        self._temp = temp
        self._pressure = pressure
        self._rel_Humid = rel_Humid
        self._dryair_massfrac = dryair_massfrac
        #---------------------------------------------------------------------------------------
        comp_names = [
            'CarbonDioxide', 'Water', 'Nitrogen', 'Argon', 'Oxygen',
            'SulfurDioxide', 'CarbonMonoxide', 'Hydrogen', 'Methane',
            'HydrogenSulfide', 'Ethane', 'n-Propane'
        ]

        #---------------------------------------------------------------------------------------
        import CoolProp.CoolProp as prop_HA
        import numpy as np
        #---------------------------------------------------------------------------------------
        if temp < 0 or pressure < 0 or temp == 0 or pressure == 0:
            print('pressure[Pa] and Temperature[K] must be greater than zero')
            raise ValueError
        elif rel_Humid > 1 or rel_Humid < 0:
            print('Relative Humidity must be between 0 and 1')
            raise ValueError
        else:
            for value in dryair_massfrac:
                a = dryair_massfrac.index(value)
                if dryair_massfrac[a] < 0:
                    print('Component less than zero!')
                    raise ValueError

        burnables = dryair_massfrac[comp_names.index('CarbonMonoxide'):]
        if dryair_massfrac[comp_names.index('Water')] != 0:
            print('Dry air must not contain Water')
            raise ValueError
        elif np.sum(burnables) != 0:
            print('Air must not contain burnable components')
            raise ValueError
        elif dryair_massfrac[comp_names.index('Oxygen')] == 0:
            print('Air must contain Oxygen')
            raise ValueError
#---------------------------------------------------------------------------------------
        if rel_Humid == 0:
            massfrac_H2O = 0
        else:
            load_H2O = prop_HA.HAPropsSI('W', 'T', temp, 'P', pressure, 'R',
                                         rel_Humid)
            massfrac_H2O = 1 / ((1 / load_H2O) + 1)

        index_H2O = comp_names.index('Water')
        temp_vek = (1 - massfrac_H2O) * np.array(dryair_massfrac)
        temp_vek[index_H2O] = massfrac_H2O
        self.__wetair_massfrac = list(temp_vek)
        #----------------------------------------------------------------------------------------
        super().__init__('massfrac', self.__wetair_massfrac, 'none', 'none')
def calculate(inputs):
    """ For a given input, try all possible input pairs """
    errors = []
    supported_pairs = get_supported_input_pairs()
    for k1, k2 in supported_pairs:
        psi_w_input = inputs['psi_w']
        args = 'psi_w',k1,inputs[k1],k2,inputs[k2],'P',inputs['P']
        try:
            psi_w_new = CP.HAPropsSI(*args)
        except BaseException as BE:
            errors.append((str(BE),args, inputs))
    return errors
def plot_psychrometrics(ti, Wi, to, Wo):

    fig, ax = plt.subplots(1, 1, figsize=(10, 8))
    Tdbvec = np.linspace(-10, 55) + 273.15

    plt.plot([ti - 273.15, to - 273.15], [Wi, Wo],
             color='g',
             lw=5,
             marker='o',
             ms=10,
             mfc='y')

    # Lines of constant relative humidity
    for RH in np.arange(0.1, 1, 0.1):
        W = CP.HAPropsSI("W", "R", RH, "P", 101325, "T", Tdbvec)
        plt.plot(Tdbvec - 273.15, W, color='k', lw=0.5)

    # Saturation curve
    W = CP.HAPropsSI("W", "R", 1, "P", 101325, "T", Tdbvec)
    plt.plot(Tdbvec - 273.15, W, color='k', lw=1.5)

    plt.plot([10, 20], [0.05, 0.1], color='k', lw=1.5)
    # Lines of constant Vda
    for Vda in np.arange(0.69, 0.961, 0.01):
        R = np.linspace(0, 1)
        W = CP.HAPropsSI("W", "R", R, "P", 101325, "Vda", Vda)
        Tdb = CP.HAPropsSI("Tdb", "R", R, "P", 101325, "Vda", Vda)
        plt.plot(Tdb - 273.15,
                 W,
                 color='b',
                 lw=1.5 if abs(Vda % 0.05) < 0.001 else 0.5)

    # Lines of constant wetbulb
    for Twb_C in np.arange(-16, 33, 2):
        if Twb_C == 0:
            continue
        R = np.linspace(0.0, 1)
        #print(Twb_C)
        Tdb = CP.HAPropsSI("Tdb", "R", R, "P", 101325, "Twb", Twb_C + 273.15)
        W = CP.HAPropsSI("W", "R", R, "P", 101325, "Tdb", Tdb)
        plt.plot(Tdb - 273.15,
                 W,
                 color='r',
                 lw=1.5 if abs(Twb_C % 10) < 0.001 else 0.5)
        plt.plot([10, 20], label="Line 1")

    plt.xlabel(r'Dry bulb temperature $T_{\rm db}$ ($^{\circ}$ C)')
    plt.ylabel(r'Humidity Ratio $W$ (kg/kg)')
    plt.ylim(0, 0.030)
    plt.xlim(-10, 55)
    plt.savefig('Psychrometric Process.svg')
    plt.show()
def get_supported_input_pairs():
    """ Determine which input pairs are supported """
    good_ones = []
    inputs = generate_values((300, 0.5))
    for k1, k2 in itertools.product(inputs.keys(), inputs.keys()):
        if 'P' in [k1,k2] or k1==k2:
            continue
        args = ('psi_w', k1, inputs[k1], k2, inputs[k2], 'P', inputs['P'])
        try:
            psi_w_new = CP.HAPropsSI(*args)
            good_ones.append((k1,k2))
        except BaseException as BE:
            pass
            if 'currently at least one of' in str(BE) or 'cannot provide two inputs' in str(BE):
                pass
            else:
                print(BE)
                good_ones.append((k1,k2))
    return good_ones
Exemple #7
0
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] = []

    calculation_option = doc['input']['calculation_option']['_val']
    Tdb = parseFloat(doc['input']['Tdb']['_val'])
    P = parseFloat(doc['input']['P']['_val'])

    try:
        if (calculation_option == 'Tdb_RH_P'):
            RH = parseFloat(doc['input']['RH']['_val'])
        if (calculation_option == 'Tdb_Twb_P'):
            Twb = parseFloat(doc['input']['Twb']['_val'])
            RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Twb', Twb)
        if (calculation_option == 'Tdb_Tdp_P'):
            Tdp = parseFloat(doc['input']['Tdp']['_val'])
            RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Tdp', Tdp)
        if (calculation_option == 'Tdb_Tdp_P'):
            Tdp = parseFloat(doc['input']['Tdp']['_val'])
            RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'Tdp', Tdp)
        if (calculation_option == 'Tdb_W_P'):
            W = parseFloat(doc['input']['W']['_val'])
            RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'W', W)
        if (calculation_option == 'Tdb_h_P'):
            h = parseFloat(doc['input']['h']['_val'])
            RH = CP.HAPropsSI('R', 'Tdb', Tdb, 'P', P, 'H', h)
    except Exception:
        RH = math.nan

    try:
        Twb = CP.HAPropsSI('Twb', 'Tdb', Tdb, 'P', P, 'R', RH)
        Tdp = CP.HAPropsSI('Tdp', 'Tdb', Tdb, 'P', P, 'R', RH)
    except Exception:
        Twb = math.nan
        Tdp = math.nan

    try:
        v = CP.HAPropsSI('Vha', 'Tdb', Tdb, 'P', P, 'R', RH)
        rho = 1 / v
    except Exception:
        v = math.nan
        rho = math.nan

    try:
        W = CP.HAPropsSI('W', 'Tdb', Tdb, 'P', P, 'R', RH)
    except Exception:
        W = math.nan

    try:
        h = CP.HAPropsSI('H', 'Tdb', Tdb, 'P', P, 'R', RH)
        u = CP.HAPropsSI('U', 'Tdb', Tdb, 'P', P, 'R', RH)
        s = CP.HAPropsSI('S', 'Tdb', Tdb, 'P', P, 'R', RH)
    except Exception:
        h = math.nan
        u = math.nan
        s = math.nan

    try:
        Cp = CP.HAPropsSI('cp', 'Tdb', Tdb, 'P', P, 'R', RH)
        Cp_ha = CP.HAPropsSI('cp_ha', 'Tdb', Tdb, 'P', P, 'R', RH)
    except Exception:
        Cp = math.nan
        Cp_ha = math.nan

    RH = roundit(RH, 4)
    Twb = roundit(Twb, 1)
    Tdp = roundit(Tdp, 1)
    W = roundit(W, 4)
    rho = roundit(rho, 4)
    v = roundit(v, 4)
    h = roundit(h, 4)
    u = roundit(u, 4)
    s = roundit(s, 4)
    Cp = roundit(Cp, 4)
    Cp_ha = roundit(Cp_ha, 4)

    doc['result'].update({'RH': {'_val': str(RH)}})
    doc['result'].update({'Twb': {'_val': str(Twb), '_dim': 'temperature'}})
    doc['result'].update({'Tdp': {'_val': str(Tdp), '_dim': 'temperature'}})
    doc['result'].update({'W': {'_val': str(W)}})
    doc['result'].update({'rho': {'_val': str(rho), '_dim': 'density'}})
    doc['result'].update({'v': {'_val': str(v), '_dim': 'specificVolume'}})
    doc['result'].update({'h': {'_val': str(h), '_dim': 'specificEnergy'}})
    doc['result'].update({'u': {'_val': str(u), '_dim': 'specificEnergy'}})
    doc['result'].update({'s': {'_val': str(s), '_dim': 'specificHeat'}})
    doc['result'].update({'Cp': {'_val': str(Cp), '_dim': 'specificHeat'}})
    doc['result'].update(
        {'Cp_ha': {
            '_val': str(Cp_ha),
            '_dim': 'specificHeat'
        }})

    treeUnitConvert(doc, SI_UNITS, doc['units'], autoRoundOff=True)
    doc_original['result'].update(doc['result'])
    doc_original['errors'] = doc['errors']

    return True
Exemple #8
0
 def get_result(args):
     result = cp.HAPropsSI(args.output_type, args.intype1,
                           args.invalue1, args.intype2, args.invalue2,
                           args.intype3, args.invalue3)
     return result