Exemple #1
0
def calcs():
    T0 = 26.1  #C average temp in June @ NM, Assume N2O @daily mean temp
    vessel_radius = 0.1397  #m | inner radius of vessel
    thickness = 0.00635  #m | vessel wall thickness
    P = 6.895e+6  #Pa | vessel pressure
    m0 = 20  #kg initial mass
    #Calculates N2O density at given temperature and pressure
    rho_N2O = PropsSI('D', 'T', T0 + 273.15, 'P', P, 'N2O')
    print("N2O Density {:.3f} kg/m^3".format(rho_N2O))

    CheckStress = True
    if CheckStress == True:
        PressureVessel(P, vessel_radius, thickness)

    N2OPhase = CP.PhaseSI('P', P, 'T', T0 + 273.15, 'N2O')

    U_0 = PropsSI('Q', 'T', T0 + 273.15, 'P', P, 'N2O')
    print("Initial Internal Energy {} J".format(U_0))

    print(N2OPhase)
    m_dot = .234  #kg/s

    t = 0.04  #s

    test = [[], []]

    m_tank = m0
    m_out = 0  #no mass out initially
    while abs(m_out) < m_tank:
        m_out += -m_dot * t
        print(m_out)

    test.append(t)
    test.append(m_tank)
def enth_sh(fluid, temperature, pressure):
    # return enthalpy of superheated vapor at compressor inlet for fluid at
    # pressure and temperature from CoolProp
    phase = CP.PhaseSI('P', pressure, 'T', temperature, fluid)
    if phase == 'gas':
        h_sh = CP.PropsSI('H', 'T', temperature, 'P', pressure, fluid)
    else:
        h_sh = CP.PropsSI('H', 'P', pressure, 'Q', 1, fluid)
        # print('Warning: Values set to saturation (h_sh)')

    return h_sh
def compressor_inlet_state_reci(enthalpy, pressure, fluid):
    # return isentropic coefficient and specific volume for fluid at enthalpy
    # and pressure from CoolProp
    phase = CP.PhaseSI('P', pressure, 'H', enthalpy, fluid)

    if phase == 'gas':
        v_suc = 1 / CP.PropsSI('D', 'H', enthalpy, 'P', pressure, fluid)
        gamma_calc = CP.PropsSI('ISENTROPIC_EXPANSION_COEFFICIENT', 'H',
                                enthalpy, 'P', pressure, fluid)
    else:  # if enthalpy below saturated vapor enthalpy at pressure, assume
        # saturated state
        v_suc = 1 / CP.PropsSI('D', 'P', pressure, 'Q', 1, fluid)
        gamma_calc = CP.PropsSI('ISENTROPIC_EXPANSION_COEFFICIENT', 'P',
                                pressure, 'Q', 1, fluid)
        # print('Warning: Values set to saturation (compressor inlet state reci)')
    return [v_suc, gamma_calc]
def compressor_inlet_state(temperature, pressure, fluid):
    # return isentropic coefficient ad specific volume for fluid at temperature
    # and pressure from CoolProp
    phase = CP.PhaseSI('P', pressure, 'T', temperature, fluid)

    if phase == 'gas':
        v_suc = 1 / CP.PropsSI('D', 'T', temperature, 'P', pressure, fluid)
        gamma_calc = CP.PropsSI('ISENTROPIC_EXPANSION_COEFFICIENT', 'T',
                                temperature, 'P', pressure, fluid)
    else:  #if temperature below saturation temperature at pressure, assume
        # saturated state
        v_suc = 1 / CP.PropsSI('D', 'P', pressure, 'Q', 1, fluid)
        gamma_calc = CP.PropsSI('ISENTROPIC_EXPANSION_COEFFICIENT', 'P',
                                pressure, 'Q', 1, fluid)
        # print('Warning: Values set to saturation (compressor inlet state)')
    return [v_suc, gamma_calc]
 def get_property_from_coolprop(self, coolprop_property_name: str):
     if coolprop_property_name in [
             'T_critical', 'p_critical', 'rhomass_critical',
             'rhomolar_critical', 'T_triple', 'p_triple'
     ]:  # todo: add reducing point?
         return PropsSI(coolprop_property_name, self.fluid_name)
     pns = list(self.cp_inputs.keys())
     values = list(self.cp_inputs.values())
     try:
         if coolprop_property_name == 'phase':
             return CP.PhaseSI(pns[0], values[0].magnitude, pns[1],
                               values[1].magnitude, self.fluid_name)
         else:
             return PropsSI(coolprop_property_name, pns[0],
                            values[0].magnitude, pns[1],
                            values[1].magnitude, self.fluid_name)
     except Exception as e:
         return np.nan
    def N2O_Unsat(self, T, P):
        """
        Method calculates and returns thermodynamic properties of N2O at the input temperature and pressure.
        Only valid for unsaturated conditions between the triple point and critical points.
        The maximum allowed temperature input is the critical temperature, if any temperature
        """
        phase_Check = CP.PhaseSI('P', P, 'T', T, 'N2O')
        print('Phase :: {}'.format(phase_Check))
        T_r = T / 309.52  #reduced Temp
        Cp = float(PropsSI('C', 'T', T, 'P', P,
                           'N2O'))  # J/kg/K      | Heat Capacity
        rho = float(PropsSI('D', 'T', T, 'P', P,
                            'N2O'))  # kg/m^3      | Density
        beta = float(
            PropsSI('ISOBARIC_EXPANSION_COEFFICIENT', 'T', T, 'P', P,
                    'N2O'))  # 1/K   | Expansion Coefficient

        if phase_Check == 'liquid':
            # Dynamic Viscosity
            # EQ 4.9 | kg/(m s)
            theta = (309.52 - 5.24) / (T - 5.24)
            mu = (0.0293423 * e(1.6089 * (theta - 1)**(1/3) + 2.0439*(theta - 1)**(4/3)) ) * \
                    10**(-6)
            # Thermal Conductivity
            # EQ 4.11 | W/mK
            k = (72.35 * (1 + 1.5 * (1 - T_r)**(1 / 3) + -3.5 *
                          (1 - T_r)**(2 / 3) + 4.5 * (1 - T_r))) * 10**(-3)
        elif phase_Check == 'gas':
            # Dynamic Viscosity
            # EQ 4.10 | kg/(m s)
            mu = e(3.3281 + -1.18237 * (1 / T_r - 1)**(1 / 3) + -0.055155 *
                   (1 / T_r - 1)**(4 / 3)) * 10**(-3)
            # Thermal Conductivity
            # EQ 4.12 | W/mK
            k = e(\
                -7.08870 + -0.276962*(1-T_r)**(-2/3) + 2.88672*(1-T_r)**(-1/3) + \
                16.6116*(1 - T_r)**(1/3) + -11.8221*(1 - T_r)**(2/3)) * 10**(-3)

        return Cp, rho, mu, k, beta
Exemple #7
0
def CO2State(temp: float, pres: float) -> str:
    temp_kelvin = temp + 273.15
    pres_pa = 100000 * pres
    return CP.PhaseSI('P', pres_pa, 'T', temp_kelvin, 'CarbonDioxide')
Exemple #8
0
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] =[]

    fluid = doc['input']['fluid']['_val']
    P = float(doc['input']['P']['_val'])
    T = float(doc['input']['T']['_val'])
    result = {}


    try:
        phase = CP.PhaseSI('T',T, 'P',P, fluid)
    except Exception as e:
        phase = ""
        doc['errors'].append("Failed to calculate 'phase' . Check Inputs")
    finally:
        doc['result'].update({'phase':{'_val' : phase}})

    try:
        MW = round(CP.PropsSI('M', fluid),5)
    except Exception as e:
        MW = math.nan
        doc['errors'].append("Failed to calculate 'MW' . Check Inputs")
    finally:
        doc['result'].update({'MW':{'_val' : str(MW), '_dim':'molecularMass'}})

    try:
        Pcritical = round(CP.PropsSI('Pcrit', 'T',T, 'P',P, fluid),1)
    except:
        Pcritical = math.nan
        doc['errors'].append("Failed to calculate 'Pcritical' . Check Inputs")
    finally:
        doc['result'].update({'Pcritical':{'_val' : str(Pcritical), '_dim':'pressure'}})

    try:
        Tcritical = round(CP.PropsSI('Tcrit', 'T',T, 'P',P, fluid),1)
    except:
        Tcritical = math.nan
        doc['errors'].append("Failed to calculate 'Tcritical' . Check Inputs")
    finally:
        doc['result'].update({'Tcritical':{'_val' : str(Tcritical), '_dim':'temperature'}})

    try:
        Ptriple = round(CP.PropsSI('P_TRIPLE', 'T',T, 'P',P, fluid),1)
    except:
        Ptriple = math.nan
        doc['errors'].append("Failed to calculate 'Ptriple' . Check Inputs")
    finally:
        doc['result'].update({'Ptriple':{'_val' : str(Ptriple), '_dim':'pressure'}})


    try:
        Ttriple = round(CP.PropsSI('T_TRIPLE', 'T',T, 'P',P, fluid),1)
    except:
        Ttriple = math.nan
        doc['errors'].append("Failed to calculate 'Ttriple' . Check Inputs")
    finally:
        doc['result'].update({'Ttriple':{'_val' : str(Ttriple), '_dim':'temperature'}})


    try:
        acentric = round(CP.PropsSI('acentric', 'T',T, 'P',P, fluid),4)
    except:
        acentric = math.nan
        doc['errors'].append("Failed to calculate 'acentric' . Check Inputs")
    finally:
        doc['result'].update({'acentric':{'_val' : str(acentric)}})

    try:
        Z = round(CP.PropsSI('Z', 'T',T, 'P',P, fluid),4)
    except:
        Z = math.nan
        doc['errors'].append("Failed to calculate 'Z' . Check Inputs")
    finally:
        doc['result'].update({'Z':{'_val' : str(Z)}})

    try:
        rho = round(CP.PropsSI('D', 'T',T, 'P',P, fluid),4)
        v = round(1/rho,4)
    except:
        rho = math.nan
        v = math.nan
        doc['errors'].append("Failed to calculate 'Density' and 'Specific Volume' . Check Inputs")

    finally:
        doc['result'].update({'rho':{'_val' : str(rho), '_dim':'density'}})
        doc['result'].update({'v':{'_val' : str(v), '_dim':'specificVolume'}})


    try:
        h =  round(CP.PropsSI('H', 'T',T, 'P',P, fluid),1)
    except:
        h = math.nan
        doc['errors'].append("Failed to calculate 'Enthalphy' . Check Inputs")

    finally:
        doc['result'].update({'h':{'_val' : str(h), '_dim':'specificEnergy'}})



    try:
        u = round(CP.PropsSI('U', 'T',T, 'P',P, fluid),1)
    except:
        u = math.nan
        doc['errors'].append("Failed to calculate 'Specific Internal Energy' . Check Inputs")
    finally:
        doc['result'].update({'u':{'_val' : str(u), '_dim':'specificEnergy'}})

    try:
        s = round(CP.PropsSI('S', 'T',T, 'P',P, fluid),1)
    except:
        s = math.nan
        doc['errors'].append("Failed to calculate 'Specific Entropy' . Check Inputs")
    finally:
        doc['result'].update({'s':{'_val' : str(s), '_dim':'specificHeat'}})


    try:
        gibbs = round(CP.PropsSI('G', 'T',T, 'P',P, fluid),1)
    except:
        gibbs = math.nan
        doc['errors'].append("Failed to calculate 'Gibbs Free Energy' . Check Inputs")

    finally:
        doc['result'].update({'gibbs':{'_val' : str(gibbs), '_dim':'specificEnergy'}})

    try:
        helmholtz = round(CP.PropsSI('Helmholtzmass', 'T',T, 'P',P, fluid),1)
    except:
        helmholtz = math.nan
        doc['errors'].append("Failed to calculate 'Helmholtz Energy' . Check Inputs")

    finally:
        doc['result'].update({'helmholtz':{'_val' : str(helmholtz), '_dim':'specificEnergy'}})


    try:
        Cp = round(CP.PropsSI('Cpmass', 'T',T, 'P',P, fluid),1)
    except:
        Cp = math.nan
        doc['errors'].append("Failed to calculate 'Cp' . Check Inputs")

    finally:
        doc['result'].update({'Cp':{'_val' : str(Cp), '_dim':'specificHeat'}})


    try:
        Cv = round(CP.PropsSI('Cvmass', 'T',T, 'P',P, fluid),1)
    except:
        Cv = math.nan
        doc['errors'].append("Failed to calculate 'Cv' . Check Inputs")

    finally:
        doc['result'].update({'Cv':{'_val' : str(Cv), '_dim':'specificHeat'}})

    try:
        Cp_molar = round(CP.PropsSI('Cpmolar', 'T',T, 'P',P, fluid),1)
    except:
        Cp_molar = math.nan
        doc['errors'].append("Failed to calculate 'Cp_molar' . Check Inputs")

    finally:
        doc['result'].update({'Cp_molar':{'_val' : str(Cp_molar), '_dim':'specificHeatMolar'}})


    try:
        Cv_molar = round(CP.PropsSI('Cvmolar', 'T',T, 'P',P, fluid),1)
    except:
        Cv_molar = math.nan
        doc['errors'].append("Failed to calculate 'Cv_molar' . Check Inputs")

    finally:
        doc['result'].update({'Cv_molar':{'_val' : str(Cv_molar), '_dim':'specificHeatMolar'}})


    try:
        Cp0 = round(CP.PropsSI('Cp0mass', 'T',T, 'P',P, fluid),1)
    except:
        Cp0 = math.nan
        doc['errors'].append("Failed to calculate 'Cp0' . Check Inputs")
    finally:
        doc['result'].update({'Cp0':{'_val' : str(Cp0), '_dim':'specificHeat'}})


    try:
        Prandtl = round(CP.PropsSI('Prandtl', 'T',T, 'P',P, fluid),4)
    except:
        Prandtl = math.nan
        doc['errors'].append("Failed to calculate 'Prandtl' . Check Inputs")

    finally:
        doc['result'].update({'Prandtl':{'_val' : str(Prandtl)}})


    try:
        dynViscosity = round(CP.PropsSI('viscosity', 'T',T, 'P',P, fluid),8)
    except:
        dynViscosity = math.nan
        doc['errors'].append("Failed to calculate 'Dynamic Viscosity' . Check Inputs")

    finally:
        doc['result'].update({'dynViscosity':{'_val' : str(dynViscosity), '_dim':'dynViscosity'}})


    try:
        conductivity  = round(CP.PropsSI('conductivity', 'T',T, 'P',P, fluid),8)
    except:
        conductivity = math.nan
        doc['errors'].append("Failed to calculate 'Thermal Conductivity' . Check Inputs")

    finally:
        doc['result'].update({'conductivity':{'_val' : str(conductivity), '_dim':'thermalConductivity'}})

    try:
        HH = CP.PropsSI('HH', 'T',T, 'P',P, fluid)
    except:
        HH=""
    finally:
        doc['result'].update({'HH':{'_val' : str(HH)}})


    try:
        PH = CP.PropsSI('PH', 'T',T, 'P',P, fluid)
    except:
        PH = ""
    finally:
        doc['result'].update({'PH':{'_val' : str(PH)}})


    try:
        GWP = CP.PropsSI('GWP100', 'T',T, 'P',P, fluid)
    except:
        GWP = ""
    finally:
        doc['result'].update({'GWP':{'_val' : str(GWP)}})

    try:
        ODP = CP.PropsSI('ODP', 'T',T, 'P',P, fluid)
    except:
        ODP = ""
    finally:
        doc['result'].update({'ODP':{'_val' : str(ODP)}})


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

    doc_original['errors'] = doc['errors']

    return True
Exemple #9
0
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] =[]


    state = doc['input']['state']['_val']

    try:
        if (state=='Saturated_P'):
            P = float(doc['input']['P']['_val'])
            Q = float(doc['input']['Q']['_val'])
            phase = CP.PhaseSI('P', P, 'Q', Q, 'Water')
            Tsat = round(CP.PropsSI('T','P', P, 'Q', Q, 'Water'),1)
            rho = round(CP.PropsSI('D','P', P, 'Q', Q, 'Water'),4)
            v = round(1/rho,4)
            h = round(CP.PropsSI('H','P', P, 'Q', Q, 'Water'),1)
            u = round(CP.PropsSI('U','P', P, 'Q', Q, 'Water'),1)
            s = round(CP.PropsSI('S','P', P, 'Q', Q, 'Water'),1)
            doc['result'].update({'Psat':{'_val' : '', '_dim':'pressure'}})
            doc['result'].update({'Tsat':{'_val' : str(Tsat), '_dim':'temperature'}})

        if (state=='Saturated_T'):
            T = float(doc['input']['T']['_val'])
            Q = float(doc['input']['Q']['_val'])
            phase = CP.PhaseSI('T', T, 'Q', Q, 'Water')
            Psat = round(CP.PropsSI('P','T', T, 'Q', Q, 'Water'),1)
            rho = round(CP.PropsSI('D','T', T, 'Q', Q, 'Water'),4)
            v = round(1/rho,4)
            h = round(CP.PropsSI('H','T', T, 'Q', Q, 'Water'),1)
            u = round(CP.PropsSI('U','T', T, 'Q', Q, 'Water'),1)
            s = round(CP.PropsSI('S','T', T, 'Q', Q, 'Water'),1)
            doc['result'].update({'Psat':{'_val' : str(Psat), '_dim':'pressure'}})
            doc['result'].update({'Tsat':{'_val' : '', '_dim':'temperature'}})

        if (state=='Superheated_or_Compressed'):
            T = float(doc['input']['T']['_val'])
            P = float(doc['input']['P']['_val'])
            phase = CP.PhaseSI('T', T, 'P', P, 'Water')
            rho = round(CP.PropsSI('D','T', T, 'P', P, 'Water'),4)
            v = round(1/rho,1)
            h = round(CP.PropsSI('H','T', T, 'P', P, 'Water'),1)
            u = round(CP.PropsSI('U','T', T, 'P', P, 'Water'),1)
            s = round(CP.PropsSI('S','T', T, 'P', P, 'Water'),1)
            doc['result'].update({'Psat':{'_val' : '', '_dim':'pressure'}})
            doc['result'].update({'Tsat':{'_val' : '', '_dim':'temperature'}})
    except Exception as e:
        raise e
        doc['errors'].append(str(e))
        doc['errors'].append('Failed to calculate Water/Steam Properties. Check Inputs')
        phase = ""
        Psat = math.nan
        Tsat = math.nan
        rho = math.nan
        v = math.nan
        h = math.nan
        u = math.nan
        s = math.nan


    doc['result'].update({'phase':{'_val' : str(phase)}})
    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'}})

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

    return True
Exemple #10
0
def calculate(doc_original):
    doc = deepcopy(doc_original)
    treeUnitConvert(doc, doc['units'], SI_UNITS)
    doc['errors'] = []

    solve_for = doc['input']['solve_for']['_val']
    inlet_definition = doc['input']['inlet_definition']['_val']
    P_inlet = float(doc['input']['P_inlet']['_val'])

    # Determine Inlet Properties
    if (inlet_definition == "P-T"):
        T_inlet = float(doc['input']['T_inlet']['_val'])
        try:
            h_inlet = round(
                CP.PropsSI('H', 'P', P_inlet, 'T', T_inlet, 'Water'), 1)
            s_inlet = round(
                CP.PropsSI('S', 'P', P_inlet, 'T', T_inlet, 'Water'), 1)
            phase_inlet = CP.PhaseSI('P', P_inlet, 'T', T_inlet, 'Water')
        except Exception as e:
            doc['errors'].append(
                'Failed to calculate steam inlet conditions, check inputs')
            h_inlet = math.nan
            s_inlet = math.nan
            phase_inlet = ""

    elif (inlet_definition == 'P-h'):
        h_inlet = float(doc['input']['h_inlet']['_val'])
        try:
            T_inlet = round(
                CP.PropsSI('T', 'P', P_inlet, 'H', h_inlet, 'Water'), 1)
            s_inlet = round(
                CP.PropsSI('S', 'P', P_inlet, 'H', h_inlet, 'Water'), 1)
            phase_inlet = CP.PhaseSI('P', P_inlet, 'H', h_inlet, 'Water')
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate steam inlet conditions, check inputs')
            T_inlet = math.nan
            s_inlet = math.nan
            phase_inlet = ""

    elif (inlet_definition == 'P-s'):
        s_inlet = float(doc['input']['s_inlet']['_val'])
        try:
            T_inlet = round(
                CP.PropsSI('T', 'P', P_inlet, 'S', s_inlet, 'Water'), 1)
            h_inlet = round(
                CP.PropsSI('H', 'P', P_inlet, 'S', s_inlet, 'Water'), 1)
            phase_inlet = CP.PhaseSI('P', P_inlet, 'S', s_inlet, 'Water')
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate steam inlet conditions, check inputs')
            T_inlet = math.nan
            h_inlet = math.nan
            phase_inlet = ""

    elif (inlet_definition == 'P-Q'):
        Q_inlet = float(doc['input']['Q_inlet']['_val'])
        try:
            T_inlet = round(
                CP.PropsSI('T', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1)
            s_inlet = round(
                CP.PropsSI('S', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1)
            h_inlet = round(
                CP.PropsSI('H', 'P', P_inlet, 'Q', Q_inlet, 'Water'), 1)
            phase_inlet = CP.PhaseSI('P', P_inlet, 'Q', Q_inlet, 'Water')
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate steam inlet conditions, check inputs')
            T_inlet = math.nan
            s_inlet = math.nan
            phase_inlet = ""

    outlet_definition = doc['input']['outlet_definition']['_val']
    P_outlet = float(doc['input']['P_outlet']['_val'])
    s_outlet_ideal = s_inlet

    try:
        h_outlet_ideal = round(
            CP.PropsSI('H', 'P', P_outlet, 'S', s_outlet_ideal, 'Water'), 1)
    except Exception as e:
        #        doc['errors'].append(str(e))
        doc['errors'].append(
            'Failed to calculate steam ideal outlet conditions, check inputs')
        h_outlet_ideal = math.nan

    if (solve_for == 'outlet_properties'):
        isentropic_efficiency = float(
            doc['input']['isentropic_efficiency']['_val'])
        try:
            h_outlet = h_inlet - (isentropic_efficiency /
                                  100) * (h_inlet - h_outlet_ideal)
            h_outlet = round(h_outlet, 1)
            T_outlet = round(
                CP.PropsSI('T', 'P', P_outlet, 'H', h_outlet, 'Water'), 1)
            s_outlet = round(
                CP.PropsSI('S', 'P', P_outlet, 'H', h_outlet, 'Water'), 1)
            phase_outlet = CP.PhaseSI('P', P_outlet, 'H', h_outlet, 'Water')
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate steam outlet conditions, check inputs')
            h_outlet = math.nan
            T_outlet = math.nan
            s_outlet = math.nan
            phase_outlet = ""

    else:

        try:
            if (outlet_definition == "P-T"):
                T_outlet = float(doc['input']['T_outlet']['_val'])
                h_outlet = round(
                    CP.PropsSI('H', 'P', P_outlet, 'T', T_outlet, 'Water'), 1)
                s_outlet = round(
                    CP.PropsSI('S', 'P', P_outlet, 'T', T_outlet, 'Water'), 1)

            elif (outlet_definition == 'P-h'):
                h_outlet = float(doc['input']['h_outlet']['_val'])
                T_outlet = round(
                    CP.PropsSI('H', 'P', P_outlet, 'H', h_outlet, 'Water'), 1)
                s_outlet = round(
                    CP.PropsSI('S', 'P', P_outlet, 'H', h_outlet, 'Water'), 1)

            elif (outlet_definition == 'P-s'):
                s_outlet = float(doc['input']['s_outlet']['_val'])
                h_outlet = float(doc['input']['h_outlet']['_val'])
                T_outlet = round(
                    CP.PropsSI('H', 'P', P_outlet, 'H', h_outlet, 'Water'), 1)

            elif (outlet_definition == 'P-Q'):
                Q_outlet = float(doc['input']['Q_outlet']['_val'])
                T_outlet = round(
                    CP.PropsSI('T', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1)
                h_outlet = round(
                    CP.PropsSI('H', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1)
                s_outlet = round(
                    CP.PropsSI('S', 'P', P_outlet, 'Q', Q_outlet, 'Water'), 1)

        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate steam outlet conditions, check inputs')
            h_outlet = math.nan
            T_outlet = math.nan
            s_outlet = math.nan

        try:
            isentropic_efficiency = (h_inlet - h_outlet) * 100 / (
                h_inlet - h_outlet_ideal)
            isentropic_efficiency = round(isentropic_efficiency, 1)
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to Isentropic Efficiency, check inputs')
            isentropic_efficiency = math.nan

    phase_outlet = CP.PhaseSI('P', P_outlet, 'H', h_outlet, 'Water')

    turbine_definition = doc['input']['turbine_definition']['_val']
    generator_efficiency = float(doc['input']['generator_efficiency']['_val'])
    if (turbine_definition == 'mass_flow'):
        mass_flow = float(doc['input']['mass_flow']['_val'])
        try:
            energy_output = (h_inlet - h_outlet) * mass_flow
            energy_output = roundit(energy_output)
            power_output = energy_output * generator_efficiency / 100
            power_output = roundit(power_output)
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate Turbine Parameters, check inputs')
            energy_output = math.nan
            power_output = math.nan
    else:
        try:
            power_output = float(doc['input']['power_output']['_val'])
            energy_output = power_output * 100 / generator_efficiency
            mass_flow = energy_output / (h_inlet - h_outlet)
            mass_flow = roundit(mass_flow)
        except Exception as e:
            #            doc['errors'].append(str(e))
            doc['errors'].append(
                'Failed to calculate Turbine Parameters, check inputs')
            energy_output = math.nan
            mass_flow = math.nan

    doc['result'].update(
        {'P_inlet': {
            '_val': str(P_inlet),
            '_dim': 'pressure'
        }})
    doc['result'].update(
        {'T_inlet': {
            '_val': str(T_inlet),
            '_dim': 'temperature'
        }})
    doc['result'].update(
        {'h_inlet': {
            '_val': str(h_inlet),
            '_dim': 'specificEnergy'
        }})
    doc['result'].update(
        {'s_inlet': {
            '_val': str(s_inlet),
            '_dim': 'specificHeat'
        }})
    doc['result'].update({'phase_inlet': {'_val': str(phase_inlet)}})
    doc['result'].update({
        'h_outlet_ideal': {
            '_val': str(h_outlet_ideal),
            '_dim': 'specificEnergy'
        }
    })

    doc['result'].update(
        {'P_outlet': {
            '_val': str(P_outlet),
            '_dim': 'pressure'
        }})
    doc['result'].update(
        {'T_outlet': {
            '_val': str(T_outlet),
            '_dim': 'temperature'
        }})
    doc['result'].update(
        {'h_outlet': {
            '_val': str(h_outlet),
            '_dim': 'specificEnergy'
        }})
    doc['result'].update(
        {'s_outlet': {
            '_val': str(s_outlet),
            '_dim': 'specificHeat'
        }})
    doc['result'].update({'phase_outlet': {'_val': str(phase_outlet)}})

    doc['result'].update(
        {'isentropic_efficiency': {
            '_val': str(isentropic_efficiency)
        }})
    doc['result'].update(
        {'generator_efficiency': {
            '_val': str(generator_efficiency)
        }})
    doc['result'].update(
        {'mass_flow': {
            '_val': str(mass_flow),
            '_dim': 'massflow'
        }})
    doc['result'].update(
        {'energy_output': {
            '_val': str(energy_output),
            '_dim': 'power'
        }})
    doc['result'].update(
        {'power_output': {
            '_val': str(power_output),
            '_dim': 'power'
        }})

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

    return True
Exemple #11
0
print(Tmax)

# What's the temperature at which it solidifies?

#p=101325

state = CP.AbstractState("", "Deuterium")
print(state.has_melting_line())
# Conclusion:  seems like CoolProp does not have this information.

p_psi = 20.  # PSI
p = p_psi * 6894.76  # Pa
T = 23.0  # K

h1 = CP.PropsSI('H', 'T', T, 'P', p, fluid)
phase = CP.PhaseSI('T', T, 'P', p, fluid)
print(T, p, h1, phase)

T = 24.0  # K
h2 = CP.PropsSI('H', 'T', T, 'P', p, fluid)
density = CP.PropsSI('D', 'T', T, 'P', p, fluid)
phase = CP.PhaseSI('T', T, 'P', p, fluid)
print(T, p, h2, phase)

qdot = 50  # W
delta_t = 0.125 * density * (h2 - h1) / qdot
print(delta_t / 60)

mdot = qdot / (h2 - h1)  # kg/s
print(mdot)
Exemple #12
0
def get_phase(state: dict, fluid):
    arguments = map_properties(state)
    return CP.PhaseSI(arguments[0], arguments[1], arguments[2], arguments[3],
                      fluid)
Exemple #13
0
 def PhaseSI(self, name1, prop1, name2, prop2, fluid_name):
     """Return the phase of a given state from SI inputs"""
     try:
         return CoolProp.PhaseSI(name1, prop1, name2, prop2, fluid_name)
     except Exception as e:
         return str(e)