def tabulate_solid(chemical, Tmin=None, Tmax=None, pts=10): chem = Chemical(chemical) (rhos, Cps) = [[] for i in range(2)] if not Tmin: # pragma: no cover if chem.Tm: Tmin = chem.Tm-100 else: Tmin = 150. if not Tmax: # pragma: no cover if chem.Tm: Tmax = chem.Tm else: Tmax = 350 Ts = np.linspace(Tmin, Tmax, pts) for T in Ts: chem = Chemical(chemical, T=T) rhos.append(chem.rhos) Cps.append(chem.Cps) data = OrderedDict() data['Density, kg/m^3'] = rhos data['Constant-pressure heat capacity, J/kg/K'] = Cps df = pd.DataFrame(data, index=Ts) df.index.name = 'T, K' return df
def tabulate_liq(chemical, Tmin=None, Tmax=None, pts=10): pd = pandas() chem = Chemical(chemical) (rhos, Cps, mugs, kgs, Prs, alphas, isobarics, JTs, Psats, sigmas, Hvaps, permittivities) = [[] for i in range(12)] if not Tmin: # pragma: no cover if chem.Tm: Tmin = chem.Tm else: Tmin = 273.15 if not Tmax: # pragma: no cover if chem.Tc: Tmax = chem.Tc else: Tmax = 450 Ts = np.linspace(Tmin, Tmax, pts) for T in Ts: chem = Chemical(chemical, T=T) rhos.append(chem.rhol) Cps.append(chem.Cpl) mugs.append(chem.mul) kgs.append(chem.kl) Prs.append(chem.Prl) alphas.append(chem.alphal) isobarics.append(chem.isobaric_expansion_l) JTs.append(chem.JTg) Psats.append(chem.Psat) Hvaps.append(chem.Hvap) sigmas.append(chem.sigma) permittivities.append(chem.permittivity) data = OrderedDict() data['Saturation pressure, Pa'] = Psats data['Density, kg/m^3'] = rhos data['Constant-pressure heat capacity, J/kg/K'] = Cps data['Heat of vaporization, J/kg'] = Hvaps data['Viscosity, Pa*s'] = mugs data['Thermal conductivity, W/m/K'] = kgs data['Surface tension, N/m'] = sigmas data['Prandtl number'] = Prs data['Thermal diffusivity, m^2/s'] = alphas data['Isobaric expansion, 1/K'] = isobarics data['Joule-Thompson expansion coefficient, K/Pa'] = JTs data['PermittivityLiquid'] = permittivities df = pd.DataFrame(data, index=Ts) df.index.name = 'T, K' return df
def __init__( self, p_nom_kw, load_init=1.0, fluid=Chemical("water", P=2E5, T=273.15 + 60), start="1/1/2000", ): super().__init__(start) self.p_nom_kw = p_nom_kw self.fluid = fluid self.tau_up_s = 20 * 60 self.tau_do_s = 10 * 60 self.load = load_init self.load_min = 0.65 self.eff_el = 0.37 self.eff_th = 0.52 self.m_dot = 3.5 / 3600 # m3/s self.t_ret = 50 self.p_el_kw = self.p_nom_kw * self.load * self.eff_el self.p_th_kw = self.p_nom_kw * self.load * self.eff_th self.p_fu_kw = self.p_nom_kw * self.load self.t_sup = round( self.t_ret + self.p_th_kw / self.m_dot / self.fluid.Cp, 2)
def test_create_a(simple_network): gas = Chemical("natural gas", T=10 + 273.15, P=1.022e5) net = simple_network g = top.graphs_by_level_as_dict(net) graph = g["BP"] a = sim.create_a(graph, gas) assert a.shape == (20, 20)
def __init__(self, mixture, name=IDEAL_PKG, **kwargs): if isinstance(mixture, list): self.CASs = IDs_to_CASs(mixture) self.Chemicals = [Chemical(CAS) for CAS in self.CASs] elif isinstance(mixture, Mixture): self.Chemicals = mixture.Chemicals self.name = name if name not in property_packages_cubic: eos_mix = PRMIX eos = PR else: eos_mix = property_package_to_eos[name] eos = property_package_to_eos_pures[name] self.eos = eos self.eos_mix = eos_mix self.eos_in_a_box = [eos_mix] self.pkg_obj = property_package_names_to_objs[self.name] self.set_chemical_constants() self.set_Chemical_property_objects() self.set_TP_sources() self.kwargs = kwargs self.pkg = self.new_package()
def run_one_level(net, level): """ """ g = top.graphs_by_level_as_dict(net)[level] gas = Chemical("natural gas", T=net.T_GRND, P=net.LEVELS[level]) loads = _scaled_loads_as_dict(net) p_ops = _operating_pressures_as_dict(net) p_nodes_i, m_dot_pipes_i, m_dot_nodes_i, gas = run_linear(net, level) x0 = np.concatenate((p_nodes_i, m_dot_pipes_i, m_dot_nodes_i)) x0 = np.clip(x0, a_min=1e-1, a_max=None) x0 *= np.random.normal(loc=1, scale=0.1, size=len(x0)) i_mat = create_incidence(g) leng = np.array([data["L_m"] for _, _, data in g.edges(data=True)]) diam = np.array([data["D_m"] for _, _, data in g.edges(data=True)]) materials = np.array([data["mat"] for _, _, data in g.edges(data=True)]) eps = np.array([fluids.material_roughness(m) for m in materials]) res = fsolve(_eq_model, x0, args=(i_mat, g, leng, diam, eps, gas, loads, p_ops, gas.P)) p_nodes = res[:len(g.nodes)] * gas.P m_dot_pipes = res[len(g.nodes):len(g.nodes) + len(g.edges)] * M_DOT_REF m_dot_nodes = res[len(g.nodes) + len(g.edges):] * M_DOT_REF return p_nodes, m_dot_pipes, m_dot_nodes, gas
def tabulate_gas(chemical, Tmin=None, Tmax=None, pts=10): chem = Chemical(chemical) pd = pandas() (rhos, Cps, Cvs, mugs, kgs, Prs, alphas, isobarics, isentropics, JTs) = [[] for i in range(10)] if not Tmin: # pragma: no cover if chem.Tm: Tmin = chem.Tm else: Tmin = 273.15 if not Tmax: # pragma: no cover if chem.Tc: Tmax = chem.Tc else: Tmax = 450 Ts = np.linspace(Tmin, Tmax, pts) for T in Ts: chem = Chemical(chemical, T=T) rhos.append(chem.rhog) Cps.append(chem.Cpg) Cvs.append(chem.Cvg) mugs.append(chem.mug) kgs.append(chem.kg) Prs.append(chem.Prg) alphas.append(chem.alphag) isobarics.append(chem.isobaric_expansion_g) isentropics.append(chem.isentropic_exponent) JTs.append(chem.JTg) data = OrderedDict() data['Density, kg/m^3'] = rhos data['Constant-pressure heat capacity, J/kg/K'] = Cps data['Constant-volume heat capacity, J/kg/K'] = Cvs data['Viscosity, Pa*s'] = mugs data['Thermal conductivity, W/m/K'] = kgs data['Prandtl number'] = Prs data['Thermal diffusivity, m^2/s'] = alphas data['Isobaric expansion, 1/K'] = isobarics data['Isentropic exponent'] = isentropics data['Joule-Thompson expansion coefficient, K/Pa'] = JTs df = pd.DataFrame(data, index=Ts) # add orient='index' df.index.name = 'T, K' return df
def test_create_k(simple_network): gas = Chemical("natural gas", T=10 + 273.15, P=1.022e5) net = simple_network g = top.graphs_by_level_as_dict(net) graph = g["BP"] k = sim.create_k(graph, gas) assert k.shape == (len(graph.edges), ) for ik in k: assert int(ik) == 49975
def __init__( self, p_max, # [W] t_snk, t_src, m_dot_snk, m_dot_src, n_th=0.4, tau=60.0, io_init=0.0, fluid_src="water", fluid_snk="water", start="1/1/2000", ): super().__init__(start) assert t_snk > t_src self.fluid_src = Chemical(fluid_src, T=273.15 + t_src, P=3E5) self.fluid_snk = Chemical(fluid_snk, T=273.15 + t_snk, P=3E5) self.p_max = p_max self.t_src = t_src self.t_snk = t_snk self.t_i_snk = t_snk - 10.0 self.m_dot_snk = m_dot_snk self.m_dot_src = m_dot_src self.n_th = n_th self.tau = tau self.io = io_init self.cop = self.n_th * ((self.t_snk + 273.15) / (self.t_snk - self.t_src)) self.p_sink = self.io * self.p_max self.p_elec = self.p_sink / self.cop self.p_srce = self.p_sink - self.p_elec self.t_o_snk = self.t_i_snk + self.p_sink / self.m_dot_snk / self.fluid_snk.Cp self.t_o_src = self.t_src - self.p_srce / self.m_dot_src / self.fluid_src.Cp
def getChemicalPropertiesForAGivenGasAtGivenTempandPressure( chemical, Temp, Pressure): if chemical == 'LPG': chemical = 'propane' chemicalObject = Chemical(chemical, T=Temp, P=Pressure) liquidHeatCapacity = chemicalObject.Cpl Hvap = chemicalObject.Hvap boilingTemprature = chemicalObject.Tb criticalTemprature = chemicalObject.Tc criticalPressure = chemicalObject.Pc liquidDensity = chemicalObject.rhol gasDensity = chemicalObject.rhog #obj = chemicalObject.EnthalpyVaporization return liquidHeatCapacity, Hvap, boilingTemprature, liquidDensity, gasDensity, criticalTemprature, criticalPressure
def test_reactor_loop(): elec_power = 50000.0 species = 'nitrogen' gas = Chemical(species) heat_eff = 0.90 turb_eff = 0.90 comp_rat_guess = 1.18 comp_eff = 0.90 conv_eff = 0.25 inlet_stat_temp = 800.0 # Kelvins inlet_stat_pres = 6000000.0 # Pascals gas.calculate(T=inlet_stat_temp, P=inlet_stat_pres) mw = gas.MW gamma1 = gas.Cp / gas.Cvg cp = gas.Cp inlet_mach_number = 0.1 inlet_stag_temp = Stagnation.stagnation_temperature(inlet_stat_temp, inlet_mach_number, gamma1) inlet_stag_pres = Stagnation.stagnation_pressure(inlet_stat_pres, inlet_mach_number, gamma1) deltat = 50.0 # Kelvins mdot = (elec_power / conv_eff) / (cp * deltat) reac = ReactorLoop(heat_eff, turb_eff, species) dicts = reac.performance(inlet_stag_temp, inlet_stag_pres, inlet_mach_number, inlet_stat_temp, inlet_stat_pres, elec_power, comp_rat_guess, comp_eff, conv_eff, mdot) print('Compressor') print(dicts[0]) print('Heat') print(dicts[1]) print('Turbine') print(dicts[2]) print('Rejection') print(dicts[3])
def compute(self, inputs, outputs): hp_fluid = Chemical('water') Q_hp = inputs['Q_hp'] A_cond = inputs['A_cond'] h_c = inputs['h_c'] T_coolant = inputs['T_coolant'] outputs['T_cond'] = Q_hp/(A_cond*h_c)+T_coolant outputs['T_hp'] = outputs['T_cond'] outputs['hp_fluid_T_hp'] = hp_fluid.calculate(outputs['T_hp']) outputs['P_v'] = hp_fluid.Psat outputs['hp_fluid_T_hp__P_v'] = hp_fluid.calculate(outputs['T_hp'],outputs['P_v']) outputs['h_fg'] = hp_fluid.Hvap outputs['mu_v'] = hp_fluid.mug outputs['rho_v'] = hp_fluid.rhog outputs['R_g'] = outputs['P_v']/(outputs['T_hp']*outputs['rho_v']) # def compute_partials(self, inputs, J):
class ThermProps: def __init__(self, species: str): """ :param species: The species of gas to be modeled """ self.chem = Chemical(species) # ---------------------------------------------------------------------------- def spec_heat_const_pressure(self, temperature: float, pressure: float) -> float: """ :param temperature: The static temperature in units of Kelvins :param pressure: The static pressure in units of Pascals :return cp: The specific heat at constant pressure in units of J/kg-k """ self.chem.calculate(T=temperature, P=pressure) return self.chem.Cp # ---------------------------------------------------------------------------- def spec_heat_const_volume(self, temperature: float, pressure: float) -> float: """ :param temperature: The static temperature in units of Kelvins :param pressure: The static pressure in units of Pascals :return cv: The specific heat at constant volume in units of J/kg-k """ self.chem.calculate(T=temperature, P=pressure) return self.chem.Cvg # ---------------------------------------------------------------------------- def ratio_specific_heats(self, temperature: float, pressure: float) -> float: """ :param temperature: The static temperature in units of Kelvins :param pressure: The static pressure in units of Pascals :return gamma: The ratio of specific heats """ cp = self.spec_heat_const_pressure(temperature, pressure) cv = self.spec_heat_const_volume(temperature, pressure) return cp / cv # ---------------------------------------------------------------------------- def molar_mass(self, temperature: float, pressure: float) -> float: """ :param temperature: The static temperature in units of Kelvins :param pressure: The static pressure in units of Pascals :return mw: THe molecular weight in units of g/mol """ self.chem.calculate(T=temperature, P=pressure) return self.chem.MW
def multiply_pressure_matrix_to_check(self): self.res_check = 0 # check for pressure conservation for each level sorted_levels = sorted(self.net.levels.items(), key=operator.itemgetter(1)) for level, value in sorted_levels: if level in self.net.bus["level"].unique(): # get network self.level = level netnx = self.net.netnx_all[level] level_value = self.net.levels[level] fluid_type = Chemical("natural gas", T=self.net.temperature, P=level_value + self.net.p_atm) # get network component for this level (not all component just part of it) self._compute_i_mat() self.bus_level = self.net.bus.loc[self.net.bus['level'] == level, :] self.load_level = self.net.load.loc[ self.net.load["bus"].isin(self.bus_level.index), :] self._scaled_loads() self._create_node_mass() # get data for this level materials = self.net.get_data_by_edge(level, "mat") roughness = np.array( [fluids.material_roughness(m) for m in materials]) leng = self.net.get_data_by_edge(level, "L_m") diam = self.net.get_data_by_edge(level, "D_m") name_pipe = self.net.get_data_by_edge(level, "name") m_dot_pipes = self.net.res_pipe.loc[name_pipe, "m_dot_kg/s"].values p_nodes = self.net.res_bus.loc[np.array(netnx.nodes), "p_Pa"].values # make the matrix multiplication (should be null) self._i_mat_for_pressure() p_loss = _dp_from_m_dot_vec(m_dot_pipes, leng, diam, roughness, fluid_type) * (-1) p_loss = np.append(p_loss, [level_value] * len(self.ind_feeder)) self.res_check += sum(self.mat_pres.dot(p_nodes) - p_loss)
def __init__(self, vol, area, k=200.0, t_bath_init=50.0, fluid="water", start="1/1/2000"): super().__init__(start) self.vol = vol # [m3] self.A = area # [m2] self.k = k # [W/m2/K] self.fluid = Chemical(fluid) self.fluid.T = t_bath_init self.t_bath = t_bath_init self.p_heat = 0.0 # [W] self.m_dot_fresh = 0.02 * vol / 3600 * self.fluid.rho # [kg/s] self.t_fresh = 12.0 self.t_amb = 20.0
def run_one_level(net, level): """ """ g = top.graphs_by_level_as_dict(net)[level] gas = Chemical("natural gas", T=net.T_GRND, P=net.LEVELS[level]) loads = _scaled_loads_as_dict(net) p_ops = _operating_pressures_as_dict(net) a = create_a(g, gas) b = create_b(g, loads, p_ops) x = solve(a, b) p_nodes = x[: len(g.nodes)] m_dot_pipes = x[len(g.nodes) : len(g.nodes) + len(g.edges)] m_dot_nodes = x[len(g.nodes) + len(g.edges) :] return p_nodes, m_dot_pipes, m_dot_nodes, gas
def _run_sim(net, level="BP", t_grnd=10 + 273.15): g = top.graphs_by_level_as_dict(net)[level] gas = Chemical('natural gas', T=t_grnd, P=net.LEVELS[level]) material = fluids.nearest_material_roughness('steel', clean=True) eps = fluids.material_roughness(material) x0 = _init_variables(g, net.LEVELS[level]) i_mat = _i_mat(g) leng = np.array([data["L_m"] for _, _, data in g.edges(data=True)]) diam = np.array([data["D_m"] for _, _, data in g.edges(data=True)]) load = _scaled_loads_as_dict(net) p_nom = _p_nom_feed_as_dict(net) logging.debug("SIM {}".format(level)) logging.debug("LOADS {}".format(load)) logging.debug("P_NOM {}".format(p_nom)) res = fsolve(_eq_model, x0, args=(i_mat, g, leng, diam, eps, gas, load, p_nom)) p_nodes = np.round(res[:len(g.nodes)], 1) m_dot_pipes = np.round(res[len(g.nodes):len(g.nodes) + len(g.edges)], 6) m_dot_nodes = np.round(res[len(g.nodes) + len(g.edges):], 6) p_nodes = {n: p_nodes[i] for i, n in enumerate(g.nodes)} m_dot_pipes = { data["name"]: m_dot_pipes[i] for i, (_, _, data) in enumerate(g.edges(data=True)) } m_dot_nodes = {n: m_dot_nodes[i] for i, n in enumerate(g.nodes)} return p_nodes, m_dot_pipes, m_dot_nodes, gas
def test_turbo_jet(): species = 'nitrogen' gas = Chemical(species) dif_eff = 0.95 diff_inlet_area = 0.0729 diff_outlet_area = 0.462 comp_ratio = 1.2 comp_eff = 0.9 heat_eff = 0.98 nozzle_eff = 0.95 turb_eff = 0.95 turb_work = 89286.33 nozzle_inlet_area = 0.462 nozzle_outlet_area = 0.12 temp = 81.05 # Kelvins pres = 49300.0 # Pascals gas.calculate(T=temp, P=pres) density = gas.rho gamma1 = gas.Cp / gas.Cvg mw = gas.MW sos = (gamma1 * ((1000.0 * 8.314) / mw) * temp) ** 0.5 velocity = 50.0 # m/s mach = velocity / sos mdot = density * velocity * diff_inlet_area # kg/s jet = TurboJet(dif_eff, diff_inlet_area, diff_outlet_area, comp_ratio, comp_eff, heat_eff, turb_eff, nozzle_eff, nozzle_inlet_area, nozzle_outlet_area, species) dif, comp, heat, turb, noz = jet.performance(temp, pres, mach, mdot, velocity, 10000.0, turb_work) assert isclose(dif['static_temperature'], 82.163, rel_tol=1.0e-3) assert isclose(dif['stagnation_pressure'], 51777.00, rel_tol=1.0e-3) assert isclose(dif['static_pressure'], 51710.97, rel_tol=1.0e-3) assert isclose(dif['stagnation_temperature'], 82.193, rel_tol=1.0e-3) assert isclose(dif['velocity'], 7.889, rel_tol=1.0e-3) assert isclose(dif['mach_number'], 0.0427, rel_tol=1.0e-3) assert isclose(dif['density'], 2.0858, rel_tol=1.0e-3) assert isclose(comp['static_temperature'], 87.042, rel_tol=1.0e-3) assert isclose(comp['stagnation_pressure'], 62132.40, rel_tol=1.0e-3) assert isclose(comp['static_pressure'], 62048.22, rel_tol=1.0e-3) assert isclose(comp['stagnation_temperature'], 87.07, rel_tol=1.0e-3) assert isclose(comp['velocity'], 8.359, rel_tol=1.0e-3) assert isclose(comp['mach_number'], 0.043956, rel_tol=1.0e-3) assert isclose(comp['work'], 42854.99, rel_tol=1.0e-3) assert isclose(heat['static_temperature'], 88.308, rel_tol=1.0e-3) assert isclose(heat['stagnation_pressure'], 62131.186, rel_tol=1.0e-3) assert isclose(heat['static_pressure'], 62047.22, rel_tol=1.0e-3) assert isclose(heat['stagnation_temperature'], 88.342, rel_tol=1.0e-3) assert isclose(heat['velocity'], 8.481, rel_tol=1.0e-3) assert isclose(heat['mach_number'], 0.044267, rel_tol=1.0e-3) assert isclose(heat['power'], 10204.081, rel_tol=1.0e-3) assert isclose(turb['static_temperature'], 76.416, rel_tol=1.0e-3) assert isclose(turb['stagnation_pressure'], 36381.49, rel_tol=1.0e-3) assert isclose(turb['static_pressure'], 36338.84, rel_tol=1.0e-3) assert isclose(turb['stagnation_temperature'], 76.442, rel_tol=1.0e-3) assert isclose(turb['velocity'], 7.336, rel_tol=1.0e-3) assert isclose(turb['mach_number'], 0.04117, rel_tol=1.0e-3) assert isclose(turb['extracted_work'], 93985.61, rel_tol=1.0e-3) assert isclose(noz['static_temperature'], 76.057, rel_tol=1.0e-3) assert isclose(noz['stagnation_pressure'], 36379.82, rel_tol=1.0e-3) assert isclose(noz['static_pressure'], 35744.16, rel_tol=1.0e-3) assert isclose(noz['stagnation_temperature'], 76.44, rel_tol=1.0e-3) assert isclose(noz['velocity'], 28.24, rel_tol=1.0e-3) assert isclose(noz['mach_number'], 0.1588, rel_tol=1.0e-3) assert isclose(noz['density'], 2.243, rel_tol=1.0e-3)
def test_IdealPPThermodynamic_single_component_H(): w = Chemical('water') EnthalpyVaporization = w.EnthalpyVaporization HeatCapacityGas = w.HeatCapacityGas VaporPressure = w.VaporPressure m = Mixture(['water'], zs=[1], T=298.15) pkg = IdealPPThermodynamic(VaporPressures=m.VaporPressures, Tms=m.Tms, Tbs=m.Tbs, Tcs=m.Tcs, Pcs=m.Pcs, HeatCapacityLiquids=m.HeatCapacityLiquids, HeatCapacityGases=m.HeatCapacityGases, EnthalpyVaporizations=m.EnthalpyVaporizations) # Check the enthalpy of vaporization matches at the reference temperature pkg.flash(T=298.15, P=1E5, zs=m.zs) H_pp = pkg.enthalpy_Cpg_Hvap() assert_allclose(H_pp, -EnthalpyVaporization(298.15)) # Check it's pressure independent for the gas (at ref T) kw_options = [{'P': w.Psat}, {'P': 100}, {'P': 1E-10}, {'VF': 1}] for kw in kw_options: pkg.flash(T=298.15, zs=m.zs, **kw) H_pp = pkg.enthalpy_Cpg_Hvap() assert_allclose(H_pp, 0) # Check it's pressure is independent (so long as it stays liquid) kw_options = [{'P': w.Psat+1E-4}, {'P': 1E4}, {'P': 1E10}, {'VF': 0}] for kw in kw_options: pkg.flash(T=298.15, zs=m.zs, **kw) H_pp = pkg.enthalpy_Cpg_Hvap() assert_allclose(H_pp, -EnthalpyVaporization(298.15)) # Gas heat capacity along the vapor curve (and above it) for T in np.linspace(w.Tm, w.Tc-1): for kw in [{'VF': 1}, {'P': VaporPressure(T)*0.5}]: pkg.flash(T=T, zs=m.zs, **kw) H_pp = pkg.enthalpy_Cpg_Hvap() assert_allclose(H_pp, HeatCapacityGas.T_dependent_property_integral(298.15, T)) # Gas heat capacity plus enthalpy of vaporization along the liquid for T in np.linspace(w.Tm, w.Tc-1): for kw in [{'VF': 0}, {'P': VaporPressure(T)*1.1}]: pkg.flash(T=T, zs=m.zs, **kw) H_pp = pkg.enthalpy_Cpg_Hvap() H_recalc = (HeatCapacityGas.T_dependent_property_integral(298.15, T) -EnthalpyVaporization(T)) assert_allclose(H_pp, H_recalc) # Just one basic case at VF = 0.5 T = 298.15 pkg.flash(T=T, zs=m.zs, VF=0.5) assert_allclose(pkg.enthalpy_Cpg_Hvap(), -0.5*EnthalpyVaporization(T)) # For a variety of vapor fractions and temperatures, check the enthapy is correctly described for VF in np.linspace(0., 1, 20): for T in np.linspace(w.Tm, w.Tc, 5): pkg.flash(T=T, zs=m.zs, VF=VF) pkg_calc = pkg.enthalpy_Cpg_Hvap() hand_calc = -(1 - VF)*EnthalpyVaporization(T) + HeatCapacityGas.T_dependent_property_integral(298.15, T) assert_allclose(pkg_calc, hand_calc) # Check the liquid and vapor enthalpies are equal at the critical point T = w.Tc pkg.flash(T=w.Tc, zs=m.zs, VF=1) Hvap_Tc_1 = pkg.enthalpy_Cpg_Hvap() pkg.flash(T=w.Tc, zs=m.zs, VF=0) Hvap_Tc_0 = pkg.enthalpy_Cpg_Hvap() assert_allclose(Hvap_Tc_0, Hvap_Tc_1) pkg.flash(T=w.Tc, zs=m.zs, VF=0.5) Hvap_Tc_half = pkg.enthalpy_Cpg_Hvap() assert_allclose(Hvap_Tc_0, Hvap_Tc_half)
def tabulate_constants(chemical, full=False, vertical=False): pd.set_option('display.max_rows', 100000) pd.set_option('display.max_columns', 100000) all_chemicals = OrderedDict() if isinstance(chemical, str): cs = [chemical] else: cs = chemical for chemical in cs: chem = Chemical(chemical) data = OrderedDict() data['CAS'] = chem.CAS data['Formula'] = chem.formula data['MW, g/mol'] = chem.MW data['Tm, K'] = chem.Tm data['Tb, K'] = chem.Tb data['Tc, K'] = chem.Tc data['Pc, Pa'] = chem.Pc data['Vc, m^3/mol'] = chem.Vc data['Zc'] = chem.Zc data['rhoc, kg/m^3'] = chem.rhoc data['Acentric factor'] = chem.omega data['Triple temperature, K'] = chem.Tt data['Triple pressure, Pa'] = chem.Pt data['Heat of vaporization at Tb, J/mol'] = chem.Hvap_Tbm data['Heat of fusion, J/mol'] = chem.Hfusm data['Heat of sublimation, J/mol'] = chem.Hsubm data['Heat of formation, J/mol'] = chem.Hf data['Dipole moment, debye'] = chem.dipole data['Molecular Diameter, Angstrom'] = chem.molecular_diameter data['Stockmayer parameter, K'] = chem.Stockmayer data['Refractive index'] = chem.RI data['Lower flammability limit, fraction'] = chem.LFL data['Upper flammability limit, fraction'] = chem.UFL data['Flash temperature, K'] = chem.Tflash data['Autoignition temperature, K'] = chem.Tautoignition data['Time-weighted average exposure limit'] = str(chem.TWA) data['Short-term exposure limit'] = str(chem.STEL) data['logP'] = chem.logP if full: data['smiles'] = chem.smiles data['InChI'] = chem.InChI data['InChI key'] = chem.InChI_Key data['IUPAC name'] = chem.IUPAC_name data['solubility parameter, Pa^0.5'] = chem.solubility_parameter data['Parachor'] = chem.Parachor data['Global warming potential'] = chem.GWP data['Ozone depletion potential'] = chem.ODP data['Electrical conductivity, S/m'] = chem.conductivity all_chemicals[chem.name] = data if vertical: df = pd.DataFrame.from_dict(all_chemicals) else: df = pd.DataFrame.from_dict(all_chemicals, orient='index') return df #chemicals = ['Sodium Hydroxide', 'sodium chloride', 'methanol', #'hydrogen sulfide', 'methyl mercaptan', 'Dimethyl disulfide', 'dimethyl sulfide', # 'alpha-pinene', 'chlorine dioxide', 'sulfuric acid', 'SODIUM CHLORATE', 'carbon dioxide', 'Cl2', 'formic acid', # 'sodium sulfate'] #for i in chemicals: # print tabulate_solid(i) # print tabulate_liq(i) # print tabulate_gas(i) # tabulate_constants(i) #tabulate_constants('Methylene blue')
def test_IdealPPThermodynamic_enthalpy_Cpl_Cpg_Hvap_binary_Tb_ref(): w = Chemical('water') MeOH = Chemical('methanol') m = Mixture(['water', 'methanol'], zs=[0.3, 0.7], T=298.15) pkg = IdealPPThermodynamic(VaporPressures=m.VaporPressures, Tms=m.Tms, Tbs=m.Tbs, Tcs=m.Tcs, Pcs=m.Pcs, HeatCapacityLiquids=m.HeatCapacityLiquids, HeatCapacityGases=m.HeatCapacityGases, EnthalpyVaporizations=m.EnthalpyVaporizations) pkg.set_T_transitions('Tb') # Full vapor flash, high T pkg.flash(T=1200, P=1E7, zs=m.zs) dH = pkg.enthalpy_Cpl_Cpg_Hvap() liq_w_dH = 0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, w.Tb) liq_MeOH_dH = 0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, MeOH.Tb) dH_w_vapor = 0.3*w.HeatCapacityGas.T_dependent_property_integral(w.Tb, 1200) dH_MeOH_vapor = 0.7*MeOH.HeatCapacityGas.T_dependent_property_integral(MeOH.Tb, 1200) liq_w_vap = 0.3*w.EnthalpyVaporization(w.Tb) liq_MeOH_vap = 0.7*MeOH.EnthalpyVaporization(MeOH.Tb) dH_hand = liq_w_dH + liq_MeOH_dH + liq_w_vap + liq_MeOH_vap + dH_w_vapor + dH_MeOH_vapor assert_allclose(dH_hand, dH) # Liquid change only, but to the phase change barrier pkg.flash(T=298.15+200, VF=0, zs=m.zs) dH = pkg.enthalpy_Cpl_Cpg_Hvap() dH_hand = (0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, 298.15+200) +0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, 298.15+200)) assert_allclose(dH, dH_hand) # Flash a minute amount - check the calc still works and the value is the same pkg.flash(T=298.15+200, VF=1E-7, zs=m.zs) dH = pkg.enthalpy_Cpl_Cpg_Hvap() assert_allclose(dH, dH_hand, rtol=1E-6) # Flash to vapor at methanol's boiling point pkg.flash(T=MeOH.Tb, VF=1, zs=m.zs) dH = pkg.enthalpy_Cpl_Cpg_Hvap() dH_hand = (0.7*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, MeOH.Tb) +0.3*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, w.Tb) + 0.3*w.HeatCapacityGas.T_dependent_property_integral(w.Tb, MeOH.Tb) + 0.3*w.EnthalpyVaporization(w.Tb) + 0.7*MeOH.EnthalpyVaporization(MeOH.Tb)) assert_allclose(dH, dH_hand) # Flash a minute amount more - check the calc still works and the value is the same pkg.flash(T=MeOH.Tb, P=pkg.P*.9999999, zs=m.zs) dH_minute_diff = pkg.enthalpy_Cpl_Cpg_Hvap() assert_allclose(dH, dH_minute_diff) # Again pkg.flash(T=MeOH.Tb, VF=0.99999999, zs=m.zs) dH_minute_diff = pkg.enthalpy_Cpl_Cpg_Hvap() assert_allclose(dH, dH_minute_diff) # Do a test with 65% liquid T = 320 pkg.flash(T=T, VF=0.35, zs=m.zs) dH = pkg.enthalpy_Cpl_Cpg_Hvap() liq_w_dH = pkg.xs[0]*0.65*w.HeatCapacityLiquid.T_dependent_property_integral(298.15, T) liq_MeOH_dH = pkg.xs[1]*0.65*MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, T) dH_w_vapor = 0.35*pkg.ys[0]*(w.HeatCapacityLiquid.T_dependent_property_integral(298.15, w.Tb) + w.HeatCapacityGas.T_dependent_property_integral(w.Tb, T)) dH_MeOH_vapor = 0.35*pkg.ys[1]*(MeOH.HeatCapacityLiquid.T_dependent_property_integral(298.15, MeOH.Tb) + MeOH.HeatCapacityGas.T_dependent_property_integral(MeOH.Tb, T)) liq_w_vap = pkg.ys[0]*0.35*w.EnthalpyVaporization(w.Tb) liq_MeOH_vap = pkg.ys[1]*0.35*MeOH.EnthalpyVaporization(MeOH.Tb) dH_hand = dH_MeOH_vapor + dH_w_vapor + liq_MeOH_dH + liq_w_dH + liq_MeOH_vap +liq_w_vap assert_allclose(dH, dH_hand)
# called Chemical was imported from the library, thermo.chemical . This module allows the program to access a # library of chemical properties, including critical properties, heat capacities, and phase change. import matplotlib.pyplot as plt from openpyxl import load_workbook from openpyxl.chart import (LineChart) from FindZ import FindDen from thermo.chemical import Chemical import numpy as np #Rename filepath to location of Excel Worksheet Project 3 PREoS Solver1.xlsx filepath = r"C:\Users\Nathan Lisech\.spyder-py3\Project 3 PREoS Solver1.xlsx" wb = load_workbook(filepath) worksheet = wb.active CompoundName = input('What is the compound name? ') Chem = Chemical(CompoundName) print(Chem) worksheet.title = CompoundName + " Peng-Robinson EoS" #Adds CompoundName to title worksheet['B7'] = CompoundName #Inputted Compound Name #The following block of code places values into the worksheet table # Parameters for pure component NoIsoT = int( input('What is the desired number of isotherms? ')) #Enter '5' Isotherms worksheet['B4'] = NoIsoT #Number of inputted isotherms Tstart = int(x=100) #Starting temperature in Celsius start = str(Tstart) worksheet['B2'] = Tstart Tstep = int(x=0) #Change in Temperature (K) worksheet['B3'] = Tstep Tstop = int(Tstart + (Tstep * NoIsoT)) # Ending Temperature in Celsius
def test_round_cond_outputs(self): use_poly = True if not use_poly: # use thermo package from thermo.chemical import Chemical ######################################## Solid and Wick Properties ######################################################## k_w = 11.4 epsilon = 0.46 ######################################## Overall Geometry ######################################################## L_evap = 0.01 L_cond = 0.02 L_adiabatic = 0.03 L_eff = (L_evap + L_cond) / 2 + L_adiabatic t_w = 0.0005 t_wk = 0.00069 D_od = 0.006 D_v = 0.00362 # make this a calculation r_i = (D_od / 2 - t_w) A_cond = np.pi * D_od * L_cond # Karsten A_evap = np.pi * D_od * L_evap # Karsten ######################################## Heat Pipe Core Geometry ######################################################## A_w = np.pi * ((D_od / 2)**2 - (D_od / 2 - t_w)**2) # Dustin A_wk = np.pi * ((D_od / 2 - t_w)**2 - (D_v / 2)**2) # Dustin A_interc = np.pi * D_v * L_cond # Dustin A_intere = np.pi * D_v * L_evap # Dustin ######################################## External Convection at Condenser ######################################################## h_c = 1200 T_coolant = 285 def f(T, a_0, a_1, a_2, a_3, a_4, a_5): poly = np.exp(a_0 + a_1 * T + a_2 * T**2 + a_3 * T**3 + a_4 * T**4 + a_5 * T**5) return poly alpha_array = [] h_fg_array = [] T_hp_array = [] v_fg_array = [] R_g_array = [] P_v_array = [] D_od_array = [] r_i_array = [] k_w_array = [] L_cond_array = [] D_v_array = [] k_wk_array = [] A_interc_array = [] h_interc_array = [] R_wc_array = [] R_wkc_array = [] R_interc_array = [] i = 1 for Q_hp in range(10, 50, 1): T_cond = Q_hp / (A_cond * h_c) + T_coolant T_hp = T_cond T_hpfp = T_hp - 273.15 ######################################## Fluid Properties for Water. From Faghri's book, Table C.70, page 909 ######################################################## if use_poly: P_v = f(T_hpfp, -5.0945, 7.2280e-2, -2.8625e-4, 9.2341e-7, -2.0295e-9, 2.1645e-12) * 1e5 # Ezra h_fg = f(T_hpfp, 7.8201, -5.8906e-4, -9.1355e-6, 8.4738e-8, -3.9635e-10, 5.9150e-13) * 1e3 # Ezra rho_l = f(T_hpfp, 6.9094, -2.0146e-5, -5.9868e-6, 2.5921e-8, -9.3244e-11, 1.2103e-13) # Ezra rho_v = f(T_hpfp, -5.3225, 6.8366e-2, -2.7243e-4, 8.4522e-7, -1.6558e-9, 1.5514e-12) # Ezra mu_l = f(T_hpfp, -6.3530, -3.1540e-2, 2.1670e-4, -1.1559e-6, 3.7470e-9, -5.2189e-12) # Ezra mu_v = f(T_hpfp, -11.596, 2.6382e-3, 6.9205e-6, -6.1035e-8, 1.6844e-10, -1.5910e-13) # Ezra k_l = f(T_hpfp, -5.8220e-1, 4.1177e-3, -2.7932e-5, 6.5617e-8, 4.1100e-11, -3.8220e-13) # Ezra k_v = f(T_hpfp, -4.0722, 3.2364e-3, 6.3860e-6, 8.5114e-9, -1.0464e-10, 1.6481e-13) # Ezra sigma_l = f(T_hpfp, 4.3438, -3.0664e-3, 2.0743e-5, -2.5499e-7, 1.0377e-9, -1.7156e-12) / 1e3 # Ezra cp_l = f(T_hpfp, 1.4350, -3.2231e-4, 6.1633e-6, -4.4099e-8, 2.0968e-10, -3.040e-13) * 1e3 # Ezra cp_v = f(T_hpfp, 6.3198e-1, 6.7903e-4, -2.5923e-6, 4.4936e-8, 2.2606e-10, -9.0694e-13) * 1e3 # Ezra else: hp_fluid = Chemical('water') hp_fluid.calculate(T_hp) P_v = hp_fluid.Psat hp_fluid.calculate(T_hp, P_v) rho_v = hp_fluid.rhog mu_v = hp_fluid.mug rho_l = hp_fluid.rhol mu_l = hp_fluid.mul k_l = hp_fluid.kl cp_l = hp_fluid.Cpl cp_v = hp_fluid.Cpg cv = hp_fluid.Cvg Pr_l = cp_l * mu_l / k_l h_fg = hp_fluid.Hvap sigma_l = hp_fluid.sigma v_fg = 1 / rho_v - 1 / rho_l R_g = P_v / (T_hp * rho_v) cv_v = cp_v - R_g gamma = cp_v / cv_v ######################################## Axial Thermal Resistances ######################################################## k_wk = (1 - epsilon) * k_w + epsilon * k_l # Dustin ######################################## Condenser Section Thermal Resistances ######################################################## alpha = 1 # Look into this, need better way to determine this rather than referencing papers. h_interc = 2 * alpha / (2 - alpha) * ( h_fg**2 / (T_hp * v_fg)) * np.sqrt( 1 / (2 * np.pi * R_g * T_hp)) * (1 - P_v * v_fg / (2 * h_fg)) # Sydney R_wc = np.log( (D_od / 2) / (r_i)) / (2 * np.pi * k_w * L_cond) # Sydney R_wkc = np.log( (r_i) / (D_v / 2)) / (2 * np.pi * k_wk * L_cond) # Sydney R_interc = 1 / (h_interc * A_interc) # Sydney alpha_array.append(alpha) h_fg_array.append(h_fg) T_hp_array.append(T_hp) v_fg_array.append(v_fg) R_g_array.append(R_g) P_v_array.append(P_v) D_od_array.append(D_od) r_i_array.append(r_i) k_w_array.append(k_w) L_cond_array.append(L_cond) D_v_array.append(D_v) k_wk_array.append(k_wk) A_interc_array.append(A_interc) h_interc_array.append(h_interc) R_wc_array.append(R_wc) R_wkc_array.append(R_wkc) R_interc_array.append(R_interc) self.prob.set_val('alpha', alpha_array) self.prob.set_val('L_flux', L_cond_array) self.prob.set_val('h_fg', h_fg_array) self.prob.set_val('T_hp', T_hp_array) self.prob.set_val('v_fg', v_fg_array) self.prob.set_val('R_g', R_g_array) self.prob.set_val('P_v', P_v_array) self.prob.set_val('D_od', D_od_array) self.prob.set_val('r_i', r_i_array) self.prob.set_val('k_w', k_w_array) self.prob.set_val('D_v', D_v_array) self.prob.set_val('k_wk', k_wk_array) self.prob.set_val('A_inter', A_interc_array) self.prob.run_model() assert_near_equal(self.prob.get_val('h_inter'), h_interc_array, tolerance=1.0E-5) assert_near_equal(self.prob.get_val('R_w'), R_wc_array, tolerance=1.0E-5) assert_near_equal(self.prob.get_val('R_wk'), R_wkc_array, tolerance=1.0E-5) assert_near_equal(self.prob.get_val('R_inter'), R_interc_array, tolerance=1.0E-5)
mu_l = f(T_hpfp, -6.3530, -3.1540e-2, 2.1670e-4, -1.1559e-6, 3.7470e-9, -5.2189e-12) # Ezra mu_v = f(T_hpfp, -11.596, 2.6382e-3, 6.9205e-6, -6.1035e-8, 1.6844e-10, -1.5910e-13) # Ezra k_l = f(T_hpfp, -5.8220e-1, 4.1177e-3, -2.7932e-5, 6.5617e-8, 4.1100e-11, -3.8220e-13) # Ezra k_v = f(T_hpfp, -4.0722, 3.2364e-3, 6.3860e-6, 8.5114e-9, -1.0464e-10, 1.6481e-13) # Ezra sigma_l = f(T_hpfp, 4.3438, -3.0664e-3, 2.0743e-5, -2.5499e-7, 1.0377e-9, -1.7156e-12) / 1e3 # Ezra cp_l = f(T_hpfp, 1.4350, -3.2231e-4, 6.1633e-6, -4.4099e-8, 2.0968e-10, -3.040e-13) * 1e3 # Ezra cp_v = f(T_hpfp, 6.3198e-1, 6.7903e-4, -2.5923e-6, 4.4936e-8, 2.2606e-10, -9.0694e-13) * 1e3 # Ezra else: hp_fluid = Chemical('water') hp_fluid.calculate(T_hp) P_v = hp_fluid.Psat hp_fluid.calculate(T_hp, P_v) rho_v = hp_fluid.rhog mu_v = hp_fluid.mug rho_l = hp_fluid.rhol mu_l = hp_fluid.mul k_l = hp_fluid.kl cp_l = hp_fluid.Cpl cp_v = hp_fluid.Cpg cv = hp_fluid.Cvg Pr_l = cp_l * mu_l / k_l h_fg = hp_fluid.Hvap sigma_l = hp_fluid.sigma
def test_all_chemicals(): for i in pubchem_dict.keys(): Chemical(i)
def process(): # loading variables from JSON json_data = request.form pipe_unit = "in" #NPS in by default # Diameter in meters (Pipe ID) Pressure in Pascal , Flow in m3-seg and T in Kelvin for Cv computation valid_data = True min_exist = (json_data['check_Min'] == 'true') max_exist = (json_data['check_Max'] == 'true') if valid_data: P1, P2 = P_to_Pascal(json_data, 'Op') T = T_to_K(json_data, 'Op') # liquid = Chemical(json_data['liquid'], P=(P1+P2)/2, T=T) #check P Max ?? liquid = Chemical(json_data['liquid'], P=(P1 + P2) / 2, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Op', rho / 1000) result = { 'rhoOp': round(liquid.rho / 1000, 4), 'PsatOp': round(liquid.Psat * 0.000145, 2), 'PcOp': round(liquid.Pc * 0.000145, 2), 'muOp': round(liquid.mu * 1000, 4), } sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, FL=0.9, Fd=1, full_output=True) print('All data Output: ', sizing) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Op = round(Kv_to_Cv(sizing['Kv']), 4) result['Cv_Op'] = Cv_Op result['CavIndexOp'] = Cav_index #Critical FL FL_Pvc = ((P1 - P2) / (P1 - (0.96 - 0.28 * (Psat / Pc)**0.5)))**0.5 result['FL_Pvc_Op'] = round(FL_Pvc, 4) # print('Cavitation index: ', Cav_index) # print('Rev: ', sizing['Rev']) # print('Laminar: ', sizing['laminar']) # print('Calculation FL with Pvc: ', FL_Pvc) if min_exist: print('Tambien debo calcular y retornar para Min') P1, P2 = P_to_Pascal(json_data, 'Min') T = T_to_K(json_data, 'Min') print('Ya tengo la data en formato ... para los calculos') liquid = Chemical(json_data['liquid'], P=P1, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Min', rho / 1000) result['rhoMin'] = round(liquid.rho / 1000, 4) result['PsatMin'] = round(liquid.Psat * 0.000145, 2) result['PcMin'] = round(liquid.Pc * 0.000145, 2) result['muMin'] = round(liquid.mu * 1000, 4) sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, Fd=1, full_output=True) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Min = round(Kv_to_Cv(sizing['Kv']), 4) result['Cv_Min'] = Cv_Min result['CavIndexMin'] = Cav_index #Critical FL FL_Pvc = ((P1 - P2) / (P1 - (0.96 - 0.28 * (Psat / Pc)**0.5)))**0.5 result['FL_Pvc_Min'] = round(FL_Pvc, 4) else: print('No hace falta preparar data for Min') if max_exist: print('Tambien debo calcular y retornar para Max') P1, P2 = P_to_Pascal(json_data, 'Max') T = T_to_K(json_data, 'Max') print('Ya tengo la data en formato ... para los calculos') liquid = Chemical(json_data['liquid'], P=P1, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Max', rho / 1000) result['rhoMax'] = round(liquid.rho / 1000, 4) result['PsatMax'] = round(liquid.Psat * 0.000145, 2) result['PcMax'] = round(liquid.Pc * 0.000145, 2) result['muMax'] = round(liquid.mu * 1000, 4) sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, Fd=1, full_output=True) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Max = round(Kv_to_Cv(sizing['Kv']), 4) result['Cv_Max'] = Cv_Max result['CavIndexMax'] = Cav_index #Critical FL FL_Pvc = ((P1 - P2) / (P1 - (0.96 - 0.28 * (Psat / Pc)**0.5)))**0.5 result['FL_Pvc_Max'] = round(FL_Pvc, 4) else: print('No hace falta preparar data for Max') return jsonify(result) # return jsonify({'Cv':Cv_Op, # 'Cav_index':Cav_index, # 'rho' : round(liquid.rho/1000,4), # 'Psat' : round(liquid.Psat*0.000145,2), # 'Pc' : round(liquid.Pc*0.000145,2), # 'mu' : round(liquid.mu*1000,4), # 'Cv_min' : # }) return jsonify({'error': 'Missing data!'})
def valve_sizing(): global data_return global df json_data = request.form pipe_unit = "in" #NPS inch by default print('server has received data from Valve Sizing **********************') print(json_data['ratedCv']) line = json_data['Cv_required'].replace("[", "") line = line.replace("]", "") print(line) Cv_required = np.fromstring(line, dtype=float, sep=',') print(Cv_required[0]) # from table get proper row where to iterate for RatedCv calculations table = df[df['Valve_Size_in'] == float(json_data['valve_size'])] selected = table.loc[table['100%'] == float(json_data['ratedCv'])] array_ratedCv = np.array(selected.iloc[0].values[7:17], dtype=np.float) array_FL = np.array(df.iloc[0].values[7:17], dtype=np.float) d_valve_orifice = selected.iloc[0][3] array_PTravel = [ 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0 ] # Cv_required = float(json_data['Cv_required'][0]) # % of Travel & % Cv interpolation for 3 cases if exists or at least Op in 0 PTravel = [0.0, 0.0, 0.0] P_Cv = [0.0, 0.0, 0.0] FL_Cv = [0.0, 0.0, 0.0] CavIndex = [-1.0, -1.0, -1.0] PTravel[0] = round(np.interp(Cv_required[0], array_ratedCv, array_PTravel), 2) P_Cv[0] = round((Cv_required[0] / array_ratedCv[-1]) * 100, 2) FL_Cv[0] = round(np.interp(Cv_required[0], array_ratedCv, array_FL), 2) print('PTravel: ', PTravel[0], 'PCv: ', P_Cv[0], 'FL_Cv: ', FL_Cv[0]) #New calculations for Cv now this time with D1, D2 and d, FL valid_data = True min_exist = (json_data['check_Min'] == 'true') max_exist = (json_data['check_Max'] == 'true') fig = plt.figure() # ax = fig.add_subplot(311) # bx = fig.add_subplot(312) graph = fig.add_subplot(111) if valid_data: P1, P2 = P_to_Pascal(json_data, 'Op') T = T_to_K(json_data, 'Op') print('OD Pipe & Valve check (in): ') print(json_data['inletD']) print(json_data['outletD']) print(json_data['valve_size']) print('Wall Thickness for ID calculation: ', json_data['wallThick']) D1, D2, d = D_to_meter(json_data, d_valve_orifice, pipe_unit) liquid = Chemical(json_data['liquid'], P=(P1 + P2) / 2, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Op', rho / 1000) FL = FL_Cv[0] print('FL before: ', array_FL[-1]) # for item in array_FL : # print('FL from array: ', item) # d=25.4/1000 print('D1,D2,d for sizing calculations in mm: ', D1 * 1000, D2 * 1000, d * 1000) print('Cv to K: ', Cv_to_K(Cv=6, D=12.7 / 1000)) #Sizing calculation considering D, Valve (d) and FL - Fd = 1 FLow to Close sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, Q=F, D1=D1, D2=D2, d=d, FL=array_FL[-1], Fd=1, full_output=True) print('All data Output: ', sizing) print('Cv: ', round(Kv_to_Cv(sizing['Kv']), 4)) print('Cv of 5.4385: ', Kv_to_Cv(5.4385)) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Op = round(Kv_to_Cv(sizing['Kv']), 4) # TESTTTTT NOW I HAVE DETERMINED FL APPROX Cv to this value # sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, D1=D1, D2=D2, # d=d, FL=0.7576, Fd=1, full_output=True) # print('Cv now with FL=0.7676: ', round(Kv_to_Cv(sizing['Kv']), 4)) Cv_required[0] = Cv_Op CavIndex[0] = Cav_index PTravel[0] = round( np.interp(Cv_required[0], array_ratedCv, array_PTravel), 2) P_Cv[0] = round((Cv_required[0] / array_ratedCv[-1]) * 100, 2) FL_Cv[0] = round(np.interp(Cv_required[0], array_ratedCv, array_FL), 4) # new calculation this time corrected with FL from valve # sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, D1=D1, D2=D2, # d=d, FL=0.9, Fd=1, full_output=True) # Cv_Op = round(Kv_to_Cv(sizing['Kv']), 4) # print('Cv con FL: ', Cv_Op, FL_Cv[0] ) # ax.scatter(PTravel[0], Cv_required[0], color='red', marker='+', linewidth=5) # bx.scatter(PTravel[0], FL_Cv[0], color='red', marker='+', linewidth=5) graph.scatter(PTravel[0], P_Cv[0], color='red', marker='+', linewidth=5) graph.scatter(PTravel[0], FL_Cv[0] * 100, color='red', marker='+', linewidth=5) # if (Cv_required[1] != 0) : if (min_exist): P1, P2 = P_to_Pascal(json_data, 'Min') T = T_to_K(json_data, 'Min') D1, D2, d = D_to_meter(json_data, d_valve_orifice, pipe_unit) liquid = Chemical(json_data['liquid'], P=P1, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Min', rho / 1000) PTravel[1] = round( np.interp(Cv_required[1], array_ratedCv, array_PTravel), 2) P_Cv[1] = round((Cv_required[1] / array_ratedCv[-1]) * 100, 2) FL_Cv[1] = round(np.interp(Cv_required[1], array_ratedCv, array_FL), 2) FL = FL_Cv[1] #Sizing calculation considering D, Valve and FL sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, D1=D1, D2=D2, d=d, FL=0.9, Fd=1, full_output=True) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Min = round(Kv_to_Cv(sizing['Kv']), 4) print('Cv Min: ', Cv_Min) print('Cavitation index: ', Cav_index) Cv_required[1] = Cv_Min CavIndex[1] = Cav_index PTravel[1] = round( np.interp(Cv_required[1], array_ratedCv, array_PTravel), 2) P_Cv[1] = round((Cv_required[1] / array_ratedCv[-1]) * 100, 2) FL_Cv[1] = round(np.interp(Cv_required[1], array_ratedCv, array_FL), 2) # ax.scatter(PTravel[1], Cv_required[1], color='red', marker='+', linewidth=5) # bx.scatter(PTravel[1], FL_Cv[1], color='red', marker='+', linewidth=5) graph.scatter(PTravel[1], P_Cv[1], color='red', marker='+', linewidth=5) graph.scatter(PTravel[1], FL_Cv[1] * 100, color='red', marker='+', linewidth=5) # if (Cv_required[2] != 0) : if (max_exist): P1, P2 = P_to_Pascal(json_data, 'Max') T = T_to_K(json_data, 'Max') D1, D2, d = D_to_meter(json_data, d_valve_orifice, pipe_unit) liquid = Chemical(json_data['liquid'], P=P1, T=T) rho = liquid.rho Psat = liquid.Psat Pc = liquid.Pc mu = liquid.mu F = F_to_m3_seg(json_data, 'Max', rho / 1000) PTravel[2] = round( np.interp(Cv_required[2], array_ratedCv, array_PTravel), 2) P_Cv[2] = round((Cv_required[2] / array_ratedCv[-1]) * 100, 2) FL_Cv[2] = round(np.interp(Cv_required[2], array_ratedCv, array_FL), 2) FL = FL_Cv[2] #Sizing calculation considering D, Valve and FL sizing = size_control_valve_l(rho, Psat, Pc, mu, P1, P2, F, D1=D1, D2=D2, d=d, FL=0.9, Fd=1, full_output=True) Cav_index = round(cavitation_index(P1=P1, P2=P2, Psat=Psat), 2) Cv_Max = round(Kv_to_Cv(sizing['Kv']), 4) print('Cv Max: ', Cv_Max) print('Cavitation index: ', Cav_index) Cv_required[2] = Cv_Max CavIndex[2] = Cav_index PTravel[2] = round( np.interp(Cv_required[2], array_ratedCv, array_PTravel), 2) P_Cv[2] = round((Cv_required[2] / array_ratedCv[-1]) * 100, 2) FL_Cv[2] = round(np.interp(Cv_required[2], array_ratedCv, array_FL), 2) # ax.scatter(PTravel[2], Cv_required[2], color='red', marker='+', linewidth=5) # bx.scatter(PTravel[2], FL_Cv[2], color='red', marker='+', linewidth=5) graph.scatter(PTravel[2], P_Cv[2], color='red', marker='+', linewidth=5) graph.scatter(PTravel[2], FL_Cv[2] * 100, color='red', marker='+', linewidth=5) # percentage_to_plot = np.delete(PTravel, 0.0) # FL_to_plot = np.delete(FL_Cv, 0.0) n # Display Plot Flow Valve & procces data # bx.plot(array_PTravel, array_FL, color='green', linewidth=1) # ax.plot(array_PTravel, array_ratedCv, color='black', linewidth=1) Cv_percent = array_ratedCv / array_ratedCv[-1] * 100 print('array percentage Cv:', Cv_percent) graph.plot(array_PTravel, array_FL * 100, color='blue', linewidth=2) graph.plot(array_PTravel, Cv_percent, color='green', linewidth=2) graph.set_ylabel('% Cv , FL') graph.set_xlabel('Travel - %') graph.grid() graph.legend(['FL', '% Cv']) plt.title('Cv and FL versus Travel - Valve Profile') plt.savefig('./static/docs/grafico.png') plt.close() return jsonify({ 'CvOp': Cv_required[0], 'CvMin': Cv_required[1] if (Cv_required[1] != 0) else '-', 'CvMax': Cv_required[2] if (Cv_required[1] != 0) else '-', 'CavIndexOp': CavIndex[0], 'CavIndexMin': CavIndex[1] if (CavIndex[1] != -1.0) else '-', 'CavIndexMax': CavIndex[2] if (CavIndex[2] != -1.0) else '-', 'travelOp': PTravel[0], 'travelMin': PTravel[1] if (Cv_required[1] != 0) else '-', 'travelMax': PTravel[2] if (Cv_required[2] != 0) else '-', 'percentageCvOp': P_Cv[0], 'percentageCvMin': P_Cv[1] if (Cv_required[1] != 0) else '-', 'percentageCvMax': P_Cv[2] if (Cv_required[2] != 0) else '-', 'FLOp': FL_Cv[0], 'FLMin': FL_Cv[1] if (Cv_required[1] != 0) else '-', 'FLMax': FL_Cv[2] if (Cv_required[2] != 0) else '-' })
inlet_stag_pressure, gamma, inlet_mach_number, molar_mass) assert isclose(exit_cond['total_work'], 1111.11, rel_tol=1.0e-3) assert isclose(exit_cond['static_temperature'], 355.37, rel_tol=1.0e-3) assert isclose(exit_cond['static_pressure'], 91050.91, rel_tol=1.0e-3) assert isclose(exit_cond['stagnation_pressure'], 91711.0, rel_tol=1.0e-3) assert isclose(exit_cond['stagnation_temperature'], 356.11, rel_tol=1.0e-3) assert isclose(exit_cond['velocity'], 206.719, rel_tol=1.0e-3) assert isclose(exit_cond['mach_number'], 0.1016405, rel_tol=1.0e-3) # ============================================================================== # ============================================================================== # Test RamJet species = 'nitrogen' gas = Chemical(species) dif_eff = 0.95 diff_inlet_area = 0.0729 diff_outlet_area = 0.462 heat_eff = 0.98 nozzle_eff = 0.95 nozzle_inlet_area = 0.462 nozzle_outlet_area = 0.074 temp = 81.05 # Kelvins pres = 49300.0 # Pascals gas.calculate(T=temp, P=pres) density = gas.rho gamma1 = gas.Cp / gas.Cvg mw = gas.MW sos = (gamma1 * ((1000.0 * 8.314) / mw) * temp) ** 0.5
loss at the external surface of the condenser. Author: Ezra McNichols NASA Glenn Research Center Turbomachinery and Turboelectric Systems """ import numpy as np import matplotlib.pyplot as plt from thermo.chemical import Chemical plt.rc('font', family='serif') ######################################## Solid and Wick Properties ######################################################## k_w = 11.4 epsilon = 0.46 roomtemp_fluid = Chemical('water') roomtemp_fluid.calculate(293.15) k_rtl = roomtemp_fluid.kl k_wk = (1 - epsilon) * k_w + epsilon * k_rtl ######################################## Overall Geometry ######################################################## L_evap = 0.01 L_cond = 0.02 L_adiabatic = 0.03 L_eff = (L_evap + L_cond) / 2 + L_adiabatic t_w = 0.0005 t_wk = 0.00069 D_od = 0.006 D_v = 0.00362 r_i = (D_od / 2 - t_w) A_cond = np.pi * D_od * L_cond A_evap = np.pi * D_od * L_evap
def test_turbo_prop(): species = 'nitrogen' gas = Chemical(species) prop_eff = 0.98 prop_work = 200000.0 dif_eff = 0.95 diff_inlet_area = 0.0729 diff_outlet_area = 0.2 comp_ratio = 2.5 comp_eff = 0.9 heat_eff = 0.98 nozzle_eff = 0.95 turb_eff = 0.95 turb_work = 89286.33 nozzle_inlet_area = 0.462 nozzle_outlet_area = 0.23 temp = 81.05 # Kelvins pres = 49300.0 # Pascals gas.calculate(T=temp, P=pres) density = gas.rho gamma1 = gas.Cp / gas.Cvg mw = gas.MW sos = (gamma1 * ((1000.0 * 8.314) / mw) * temp) ** 0.5 velocity = 100.0 # m/s mach = velocity / sos mdot = density * velocity * diff_inlet_area # kg/s stat_temp = Stagnation.static_temperature(temp, mach, gamma1) stat_pres = Stagnation.static_pressure(pres, mach, gamma1) jet = TurboProp(dif_eff, diff_inlet_area, diff_outlet_area, comp_ratio, comp_eff, heat_eff, turb_eff, nozzle_eff, nozzle_inlet_area, nozzle_outlet_area, prop_eff, species) prop, dif, comp, heat, turb, noz = jet.performance(prop_work, temp, mdot, pres, mach, stat_temp, stat_pres, 10000.0, turb_work) assert isclose(prop['static_temperature'], 86.526, rel_tol=1.0e-3) assert isclose(prop['static_pressure'], 22255.00, rel_tol=1.0e-3) assert isclose(prop['stagnation_temperature'], 93.969, rel_tol=1.0e-3) assert isclose(prop['stagnation_pressure'], 29707.25, rel_tol=1.0e-3) assert isclose(prop['velocity'], 124.35, rel_tol=1.0e-3) assert isclose(prop['mach_number'], 0.6558, rel_tol=1.0e-3) assert isclose(prop['total_work'], 204081.63, rel_tol= 1.0e-3) assert isclose(dif['static_temperature'], 92.608, rel_tol=1.0e-3) assert isclose(dif['stagnation_pressure'], 29297.508, rel_tol=1.0e-3) assert isclose(dif['static_pressure'], 28228.34, rel_tol=1.0e-3) assert isclose(dif['stagnation_temperature'], 93.597, rel_tol=1.0e-3) assert isclose(dif['velocity'], 45.326, rel_tol=1.0e-3) assert isclose(dif['mach_number'], 0.2310, rel_tol=1.0e-3) assert isclose(dif['density'], 1.6773, rel_tol=1.0e-3) assert isclose(comp['static_temperature'], 122.88, rel_tol=1.0e-3) assert isclose(comp['stagnation_pressure'], 73243.77, rel_tol=1.0e-3) assert isclose(comp['static_pressure'], 69531.38, rel_tol=1.0e-3) assert isclose(comp['stagnation_temperature'], 124.72, rel_tol=1.0e-3) assert isclose(comp['velocity'], 61.82, rel_tol=1.0e-3) assert isclose(comp['mach_number'], 0.2736, rel_tol=1.0e-3) assert isclose(comp['work'], 546239.28, rel_tol=1.0e-3) assert isclose(heat['static_temperature'], 123.49, rel_tol=1.0e-3) assert isclose(heat['stagnation_pressure'], 73224.28, rel_tol=1.0e-3) assert isclose(heat['static_pressure'], 69509.28, rel_tol=1.0e-3) assert isclose(heat['stagnation_temperature'], 125.35, rel_tol=1.0e-3) assert isclose(heat['velocity'], 62.16, rel_tol=1.0e-3) assert isclose(heat['mach_number'], 0.2744, rel_tol=1.0e-3) assert isclose(heat['power'], 10204.08, rel_tol=1.0e-3) assert isclose(turb['static_temperature'], 117.73, rel_tol=1.0e-3) assert isclose(turb['stagnation_pressure'], 61199.27, rel_tol=1.0e-3) assert isclose(turb['static_pressure'], 58251.17, rel_tol=1.0e-3) assert isclose(turb['stagnation_temperature'], 119.40, rel_tol=1.0e-3) assert isclose(turb['velocity'], 58.94, rel_tol=1.0e-3) assert isclose(turb['mach_number'], 0.2665, rel_tol=1.0e-3) assert isclose(turb['extracted_work'], 93985.61, rel_tol=1.0e-3) assert isclose(noz['static_temperature'], 112.57, rel_tol=1.0e-3) assert isclose(noz['stagnation_pressure'], 61049.38, rel_tol=1.0e-3) assert isclose(noz['static_pressure'], 49795.29, rel_tol=1.0e-3) assert isclose(noz['stagnation_temperature'], 119.31, rel_tol=1.0e-3) assert isclose(noz['velocity'], 118.40, rel_tol=1.0e-3) assert isclose(noz['mach_number'], 0.5474, rel_tol=1.0e-3) assert isclose(noz['density'], 0.5583, rel_tol=1.0e-3)