def return_expression(b, cobj, T): # Specific heat capacity T = pyunits.convert(T, to_units=pyunits.K) cp = (cobj.cp_mol_ig_comp_coeff_D*T**3 + cobj.cp_mol_ig_comp_coeff_C*T**2 + cobj.cp_mol_ig_comp_coeff_B*T + cobj.cp_mol_ig_comp_coeff_A) units = b.params.get_metadata().derived_units return pyunits.convert(cp, units["heat_capacity_mole"])
def density_mol_calculation(self, p): if p == "Vap": return self.pressure == ( self.density_mol[p] * pyunits.convert(Constants.gas_constant, pyunits.MJ / pyunits.kmol / pyunits.K) * pyunits.convert(self.temperature, pyunits.K)) elif p == "Liq": # dummy value return self.density_mol[ p] == 11.1 * pyunits.kmol / pyunits.m**3
def delta_temperature_out_equation(b, t): if b.config.flow_pattern == HeatExchangerFlowPattern.cocurrent: return (b.delta_temperature_out[t] == b.side_1.properties_out[t].temperature - pyunits.convert(b.side_2.properties_out[t].temperature, to_units=t_units)) else: return (b.delta_temperature_out[t] == b.side_1.properties_out[t].temperature - pyunits.convert(b.side_2.properties_in[t].temperature, to_units=t_units))
def return_expression(b, cobj, T, dT=False): if dT: return pressure_sat_comp.dT_expression(b, cobj, T) psat = (exp(cobj.pressure_sat_comp_coeff_A - cobj.pressure_sat_comp_coeff_B / (pyunits.convert(T, to_units=pyunits.K) + cobj.pressure_sat_comp_coeff_C)))*pyunits.mmHg units = b.params.get_metadata().derived_units return pyunits.convert(psat, to_units=units["pressure"])
def cationic_polymer_demand_equation(b, t): return b.cationic_polymer_demand[t] == pyunits.convert( b.cationic_polymer_parameter_a * pyunits.convert( b.properties_in[t].flow_vol / (pyunits.m**3 / pyunits.hour), to_units=pyunits.dimensionless, ) ** b.cationic_polymer_parameter_b * b.properties_in[t].flow_vol, to_units=pyunits.kg / pyunits.hr, )
def return_expression(b, cobj, T): # pg. 2-98 T = pyunits.convert(T, to_units=pyunits.K) rho = (cobj.dens_mol_liq_comp_coeff_1 / cobj.dens_mol_liq_comp_coeff_2 **(1 + (1 - T / cobj.dens_mol_liq_comp_coeff_3)** cobj.dens_mol_liq_comp_coeff_4)) units = b.params.get_metadata().derived_units return pyunits.convert(rho, units["density_mole"])
def return_expression(b, cobj, T): T = pyunits.convert(T, to_units=pyunits.K) rho = (cobj.dens_mol_liq_comp_coeff_1 * T**2 + cobj.dens_mol_liq_comp_coeff_2 * T + cobj.dens_mol_liq_comp_coeff_3) vol_mol = cobj.mw / rho units = b.params.get_metadata().derived_units return pyunits.convert(vol_mol, units["volume"] / units["amount"])
def activated_carbon_demand_equation(b, t): return b.activated_carbon_demand[t] == pyunits.convert( b.activated_carbon_parameter_a * pyunits.convert( b.properties_in[t].flow_vol / (pyunits.m**3 / pyunits.hour), to_units=pyunits.dimensionless, ) ** b.activated_carbon_parameter_b * b.properties_in[t].flow_vol, to_units=pyunits.kg / pyunits.hr, )
def total_operating_cost(b): return ( pyunits.convert( m.fs.zo_costing.total_fixed_operating_cost, to_units=pyunits.USD_2018 / pyunits.year, ) + pyunits.convert( m.fs.zo_costing.total_variable_operating_cost, to_units=pyunits.USD_2018 / pyunits.year, ) + m.fs.ro_costing.total_operating_cost )
def return_expression(b, cobj, T): # Specific heat capacity # Need to convert K to C - fake units for now. T = pyunits.convert(T, to_units=pyunits.K) - 273.15 * pyunits.K cp = cobj.mw * (cobj.cp_mass_liq_comp_coeff_5 * T**4 + cobj.cp_mass_liq_comp_coeff_4 * T**3 + cobj.cp_mass_liq_comp_coeff_3 * T**2 + cobj.cp_mass_liq_comp_coeff_2 * T + cobj.cp_mass_liq_comp_coeff_1) units = b.params.get_metadata().derived_units return pyunits.convert(cp, units["heat_capacity_mole"])
def return_expression(b, cobj, T, dT=False): if dT: return pressure_sat_comp.dT_expression(b, cobj, T) psat = (exp(cobj.pressure_sat_comp_coeff_A - cobj.pressure_sat_comp_coeff_B / (pyunits.convert(T, to_units=pyunits.K) + cobj.pressure_sat_comp_coeff_C))) * pyunits.mmHg base_units = b.params.get_metadata().default_units p_units = (base_units["mass"] * base_units["length"]**-1 * base_units["time"]**-2) return pyunits.convert(psat, to_units=p_units)
def return_expression(b, cobj, T): # Specific enthalpy via the Shomate equation t = pyunits.convert(T, to_units=pyunits.kiloK) h = (cobj.cp_mol_ig_comp_coeff_A * (t) + (cobj.cp_mol_ig_comp_coeff_B / 2) * (t**2) + (cobj.cp_mol_ig_comp_coeff_C / 3) * (t**3) + (cobj.cp_mol_ig_comp_coeff_D / 4) * (t**4) - cobj.cp_mol_ig_comp_coeff_E * (1 / t) + cobj.cp_mol_ig_comp_coeff_F) units = b.params.get_metadata().derived_units return pyunits.convert(h, units["energy_mole"])
def enthalpy_correlation(b): ft = sum(self.flow_mol_comp[j] for j in self.params.component_list) t = pyunits.convert(self.temperature, to_units=pyunits.kK) return self.enth_mol * ft == sum( self.flow_mol_comp[j] * pyunits.convert( self.params.cp_mol_ig_comp_coeff_A[j] * t + self.params.cp_mol_ig_comp_coeff_B[j] * t**2 / 2 + self.params.cp_mol_ig_comp_coeff_C[j] * t**3 / 3 + self.params.cp_mol_ig_comp_coeff_D[j] * t**4 / 4 - self.params.cp_mol_ig_comp_coeff_E[j] / t + self.params.cp_mol_ig_comp_coeff_F[j], to_units=pyunits.J/pyunits.mol) for j in self.params.component_list)
def return_expression(b, cobj, T): # Specific heat capacity T = pyunits.convert(T, to_units=pyunits.K) cp = ( (cobj.cp_mol_ig_comp_coeff_a4 * T**4 + cobj.cp_mol_ig_comp_coeff_a3 * T**3 + cobj.cp_mol_ig_comp_coeff_a2 * T**2 + cobj.cp_mol_ig_comp_coeff_a1 * T + cobj.cp_mol_ig_comp_coeff_a0) * const.gas_constant) units = b.params.get_metadata().derived_units return pyunits.convert(cp, units["heat_capacity_mole"])
def return_expression(b, cobj, T): # Specific heat capacity T = pyunits.convert(T, to_units=pyunits.K) cp = (cobj.cp_mol_ig_comp_coeff_D * T**3 + cobj.cp_mol_ig_comp_coeff_C * T**2 + cobj.cp_mol_ig_comp_coeff_B * T + cobj.cp_mol_ig_comp_coeff_A) base_units = b.params.get_metadata().default_units cp_units = (base_units["mass"] * base_units["length"]**2 * base_units["time"]**-2 * base_units["amount"]**-1 * base_units["temperature"]**-1) return pyunits.convert(cp, cp_units)
def D_bin(i, j): return (((1.43e-3 * param_units) * (self.temperature**1.75) * ( (pyunits.convert(self._params.mw_comp[i], to_units=pyunits.kg / pyunits.kmol) + pyunits.convert(self._params.mw_comp[j], to_units=pyunits.kg / pyunits.kmol)) / (2 * (pyunits.convert(self._params.mw_comp[i], to_units=pyunits.kg / pyunits.kmol)) * (pyunits.convert(self._params.mw_comp[j], to_units=pyunits.kg / pyunits.kmol))))**0.5) / ((pyunits.convert(self.pressure, to_units=pyunits.atm)) * ((self._params.diff_vol_param[i]**(1 / 3)) + (self._params.diff_vol_param[j]**(1 / 3)))**2))
def display_costing(m): m.fs.costing.total_capital_cost.display() m.fs.costing.total_operating_cost.display() m.fs.costing.LCOW.display() print("\nUnit Capital Costs\n") for u in m.fs.costing._registered_unit_costing: print( u.name, " : ", value(pyunits.convert(u.capital_cost, to_units=pyunits.USD_2018)), ) print("\nUtility Costs\n") for f in m.fs.costing.flow_types: print( f, " : ", value( pyunits.convert( m.fs.costing.aggregate_flow_costs[f], to_units=pyunits.USD_2018 / pyunits.year, )), ) print("") total_capital_cost = value( pyunits.convert(m.fs.costing.total_capital_cost, to_units=pyunits.MUSD_2018)) print(f"Total Capital Costs: {total_capital_cost:.4f} M$") total_operating_cost = value( pyunits.convert(m.fs.costing.total_operating_cost, to_units=pyunits.MUSD_2018 / pyunits.year)) print(f"Total Operating Costs: {total_operating_cost:.4f} M$/year") electricity_intensity = value( pyunits.convert(m.fs.costing.electricity_intensity, to_units=pyunits.kWh / pyunits.m**3)) print(f"Electricity Intensity: {electricity_intensity:.4f} kWh/m^3") LCOW = value( pyunits.convert(m.fs.costing.LCOW, to_units=m.fs.costing.base_currency / pyunits.m**3)) print(f"Levelized Cost of Water: {LCOW:.4f} $/m^3") LCOCR = value( pyunits.convert(m.fs.costing.LCOCR, to_units=m.fs.costing.base_currency / pyunits.kg)) print(f"Levelized Cost of COD Removal: {LCOCR:.4f} $/kg") LCOH = value( pyunits.convert(m.fs.costing.LCOH, to_units=m.fs.costing.base_currency / pyunits.kg)) print(f"Levelized Cost of Hydrogen: {LCOH:.4f} $/kg") LCOM = value( pyunits.convert(m.fs.costing.LCOM, to_units=m.fs.costing.base_currency / pyunits.kg)) print(f"Levelized Cost of Methane: {LCOM:.4f} $/kg")
def pure_comp_enthalpy(b, j): t = pyunits.convert(b.temperature, to_units=pyunits.kK) return b.enth_mol_comp[j] == pyunits.convert( # parameters 1-5 are defined in J b._params.cp_param_1[j]*t + b._params.cp_param_2[j]*(t**2)/2 + b._params.cp_param_3[j]*(t**3)/3 + b._params.cp_param_4[j]*(t**4)/4 - b._params.cp_param_5[j]/(t), to_units=units_enth_mol) + \ pyunits.convert( # parameters 6 and 8 are defined in kJ, and must be added # after converting to the enthalpy units set b._params.cp_param_6[j] - b._params.cp_param_8[j], to_units=units_enth_mol)
def eq_total_boron(self, t): inlet_Boron = self.control_volume.properties_in[ t].conc_mol_phase_comp["Liq", self.boron_name_id] inlet_Borate = self.control_volume.properties_in[ t].conc_mol_phase_comp["Liq", self.borate_name_id] conc_mol_Borate = pyunits.convert( self.conc_mol_Borate[t], to_units=units_meta("amount") * units_meta("length")**-3, ) conc_mol_Boron = pyunits.convert( self.conc_mol_Boron[t], to_units=units_meta("amount") * units_meta("length")**-3, ) return inlet_Boron + inlet_Borate == conc_mol_Borate + conc_mol_Boron
def return_expression(b, cobj, T): # Specific entropy via the Shomate equation t = pyunits.convert(T, to_units=pyunits.kiloK) s = ( cobj.cp_mol_ig_comp_coeff_A * log(t / pyunits.kiloK) + # need to make unitless cobj.cp_mol_ig_comp_coeff_B * t + (cobj.cp_mol_ig_comp_coeff_C / 2) * t**2 + (cobj.cp_mol_ig_comp_coeff_D / 3) * t**3 - (cobj.cp_mol_ig_comp_coeff_E / 2) * t**-2 + cobj.cp_mol_ig_comp_coeff_G) units = b.params.get_metadata().derived_units return pyunits.convert(s, units["entropy_mole"])
def return_expression(b, cobj, T): # Specific entropy T = pyunits.convert(T, to_units=pyunits.K) Tr = pyunits.convert(b.params.temperature_ref, to_units=pyunits.K) units = b.params.get_metadata().derived_units s = (pyunits.convert( (cobj.cp_mol_ig_comp_coeff_D/3)*(T**3-Tr**3) + (cobj.cp_mol_ig_comp_coeff_C/2)*(T**2-Tr**2) + cobj.cp_mol_ig_comp_coeff_B*(T-Tr) + cobj.cp_mol_ig_comp_coeff_A*log(T/Tr), units["entropy_mole"]) + cobj.entr_mol_form_vap_comp_ref) return s
def electricity_intensity_constraint(b, t): q_in = pyunits.convert( b.properties_in[t].flow_vol, to_units=pyunits.m**3 / pyunits.hour ) tds_in = pyunits.convert( b.properties_in[t].conc_mass_comp["tds"], to_units=pyunits.mg / pyunits.L, ) return ( b.electricity_intensity[t] == b.elec_coeff_1 + b.elec_coeff_2 * tds_in + b.elec_coeff_3 * b.recovery_frac_mass_H2O[t] + b.elec_coeff_4 * q_in )
def eq_tss_loss_rate(self, t): tss_out = pyunits.convert(self.slope[t]*self.final_turbidity_ntu[t] + self.intercept[t], to_units=units_meta('mass')*units_meta('length')**-3) input_rate = self.control_volume.properties_in[t].flow_mass_phase_comp['Liq','TSS'] exit_rate = self.control_volume.properties_out[t].flow_vol_phase['Liq']*tss_out return (self.tss_loss_rate[t] == input_rate - exit_rate)
def evap_rate_salt_constraint(b, t): evap_rate_gal_min_acre = pyunits.convert( b.evaporation_rate_pure[t], to_units=(pyunits.gallons / pyunits.minute / pyunits.acre), ) return (b.evaporation_rate_salt[t] == evap_rate_gal_min_acre * b.evaporation_rate_adj_factor[t])
def return_expression(b, cobj, T): # Specific enthalpy T = pyunits.convert(T, to_units=pyunits.K) Tr = pyunits.convert(b.params.temperature_ref, to_units=pyunits.K) units = b.params.get_metadata().derived_units h = (pyunits.convert( (cobj.cp_mol_liq_comp_coeff_5 / 5) * (T**5 - Tr**5) + (cobj.cp_mol_liq_comp_coeff_4 / 4) * (T**4 - Tr**4) + (cobj.cp_mol_liq_comp_coeff_3 / 3) * (T**3 - Tr**3) + (cobj.cp_mol_liq_comp_coeff_2 / 2) * (T**2 - Tr**2) + cobj.cp_mol_liq_comp_coeff_1 * (T - Tr), units["energy_mole"]) + cobj.enth_mol_form_liq_comp_ref) return h
def hpool_eqn(b, t): return (1e-4*b.hpool[t]*sqrt(pyunits.convert( b.control_volume.properties_in[0].mw, to_units=pyunits.g/pyunits.mol)) * (-log10(b.reduced_pressure[t]))**(0.55) == 1e-4*55.0*b.reduced_pressure[t]**0.12 * b.heat_flux_conv[t]**0.67)
def test_chem_addition_costing(self, model): model.fs.unit2 = ChemicalAdditionZO(default={ "property_package": model.fs.params, "process_subtype": "alum", "database": model.db}) model.fs.unit2.inlet.flow_mass_comp[0, "H2O"].fix(1000) model.fs.unit2.inlet.flow_mass_comp[0, "sulfur"].fix(1) model.fs.unit2.inlet.flow_mass_comp[0, "toc"].fix(2) model.fs.unit2.inlet.flow_mass_comp[0, "tss"].fix(3) model.fs.unit2.load_parameters_from_database() assert degrees_of_freedom(model.fs.unit2) == 0 model.fs.unit2.costing = UnitModelCostingBlock(default={ "flowsheet_costing_block": model.fs.costing}) assert isinstance( model.fs.costing.chemical_addition, Block) assert isinstance( model.fs.costing.chemical_addition.capital_a_parameter, Var) assert isinstance( model.fs.costing.chemical_addition.capital_b_parameter, Var) assert isinstance(model.fs.unit2.costing.capital_cost, Var) assert isinstance(model.fs.unit2.costing.capital_cost_constraint, Constraint) assert_units_consistent(model.fs) assert degrees_of_freedom(model.fs.unit2) == 0 assert model.fs.unit2.electricity[0] is \ model.fs.costing._registered_flows["electricity"][1] assert pytest.approx(1.006e3*10/0.5, rel=1e-8) == value(pyunits.convert( model.fs.costing._registered_flows["alum"][0], to_units=pyunits.mg/pyunits.s))
def energy_internal_mol_ig_comp_pure(b, j): # Method for calculating pure component U from H for ideal gases units = b.params.get_metadata().derived_units R = pyunits.convert(const.gas_constant, to_units=units["heat_capacity_mole"]) if cobj(b, j).parent_block().config.include_enthalpy_of_formation: # First, need to determine correction between U_form and H_form # U_form = H_form - delta_n*R*T ele_comp = cobj(b, j).config.elemental_composition if ele_comp is None: raise ConfigurationError( "{} calculation of internal energy requires elemental " "composition of all species. Please set this using the " "elemental_composition argument in the component " "declaration ({}).".format(b.name, j)) delta_n = 0 for e, s in ele_comp.items(): # Check for any element which is vapor at standard state if e in ["He", "Ne", "Ar", "Kr", "Xe", "Ra"]: delta_n += -s elif e in ["F", "Cl", "H", "N", "O"]: delta_n += -s/2 # These are diatomic at standard state delta_n += 1 # One mole of gaseous compound is formed dU_form = delta_n*R*b.params.temperature_ref else: dU_form = 0 # No heat of formation to correct # For ideal gases, U = H - R(T-T_ref) + dU_form return (get_method(b, "enth_mol_ig_comp", j)( b, cobj(b, j), b.temperature) - R*(b.temperature-b.params.temperature_ref) + dU_form)
def return_expression(b, rblock, r_idx, T): units = rblock.parent_block().get_metadata().derived_units return rblock.arrhenius_const * exp( -rblock.energy_activation / (pyunits.convert(c.gas_constant, to_units=units["gas_constant"]) * T))
def rule_coldside_dP(blk, t): return blk.cold_side.deltaP[t] == -( (2 * blk.friction_factor_cold[t] * (blk.plate_length + blk.port_diameter) * blk.number_of_passes * blk.cold_channel_velocity[t]**2 * pyunits.convert(blk.cold_side.properties_in[t].dens_mass, to_units=units_meta("density_mass")) / blk.channel_diameter) + (0.7 * blk.number_of_passes * blk.cold_port_velocity[t]**2 * pyunits.convert(blk.cold_side.properties_in[t].dens_mass, to_units=units_meta("density_mass"))) + (pyunits.convert(blk.cold_side.properties_in[t].dens_mass, to_units=units_meta("density_mass")) * pyunits.convert(Constants.acceleration_gravity, to_units=units_meta("acceleration")) * (blk.plate_length + blk.port_diameter)))