def build(self): """ Add model equations to the unit model. This is called by a default block construnction rule when the unit model is created. """ super().build() # Basic unit model build/read config config = self.config # shorter config pointer # The thermodynamic expression writer object, te, writes expressions # including external function calls to calculate thermodynamic quantities # from a set of state variables. _assert_properties(config.property_package) te = ThermoExpr(blk=self, parameters=config.property_package) eff = self.efficiency_isentropic = pyo.Var(self.flowsheet().time, initialize=0.9, doc="Isentropic efficiency") eff.fix() pratio = self.ratioP = pyo.Var(self.flowsheet().time, initialize=0.7, doc="Ratio of outlet to inlet pressure") # Some shorter refernces to property blocks properties_in = self.control_volume.properties_in properties_out = self.control_volume.properties_out @self.Expression(self.flowsheet().time, doc="Outlet isentropic enthalpy") def h_is(b, t): return te.h(s=properties_in[t].entr_mol, p=properties_out[t].pressure) @self.Expression(self.flowsheet().time, doc="Isentropic enthalpy change") def delta_enth_isentropic(b, t): return self.h_is[t] - properties_in[t].enth_mol @self.Expression(self.flowsheet().time, doc="Isentropic work") def work_isentropic(b, t): return properties_in[t].flow_mol * (properties_in[t].enth_mol - self.h_is[t]) @self.Expression(self.flowsheet().time, doc="Outlet enthalpy") def h_o(b, t): # Early access to the outlet enthalpy and work return properties_in[t].enth_mol - eff[t] * ( properties_in[t].enth_mol - self.h_is[t]) @self.Constraint(self.flowsheet().time) def eq_work(b, t): # Work from energy balance return properties_out[t].enth_mol == self.h_o[t] @self.Constraint(self.flowsheet().time) def eq_pressure_ratio(b, t): return (pratio[t] * properties_in[t].pressure == properties_out[t].pressure) @self.Expression(self.flowsheet().time) def work_mechanical(b, t): return b.control_volume.work[t]
def build(self): """ Add model equations to the unit model. This is called by a default block construnction rule when the unit model is created. """ super().build() # Basic unit model build/read config config = self.config # shorter config pointer # The thermodynamic expression writer object, te, writes expressions # including external function calls to calculate thermodynamic quantities # from a set of state variables. _assert_properties(config.property_package) te = ThermoExpr(blk=self, parameters=config.property_package) self.valve_opening = pyo.Var( self.flowsheet().config.time, initialize=1, doc="Fraction open for valve from 0 to 1", ) self.Cv = pyo.Var( initialize=0.1, doc="Valve flow coefficent, for vapor " "[mol/s/Pa] for liquid [mol/s/Pa]", units=pyo.units.mol/pyo.units.s/pyo.units.Pa ) #self.Cv.fix() # set up the valve function rule. I'm not sure these matter too much # for us, but the options are easy enough to provide. vfcb = self.config.valve_function_callback vfselect = self.config.valve_function if vfselect is not ValveFunctionType.custom and vfcb is not None: _log.warning(f"A valve function callback was provided but the valve " "function type is not custom.") if vfselect == ValveFunctionType.linear: _linear_callback(self) elif vfselect == ValveFunctionType.quick_opening: _quick_open_callback(self) elif vfselect == ValveFunctionType.equal_percentage: _equal_percentage_callback(self) else: if vfcb is None: raise ConfigurationError( "No custom valve function callback provided") vfcb(self) if self.config.phase == "Liq": rule = _liquid_pressure_flow_rule else: rule = _vapor_pressure_flow_rule self.pressure_flow_equation = pyo.Constraint( self.flowsheet().config.time, rule=rule )
def build(self): """ Add model equations to the unit model. This is called by a default block construnction rule when the unit model is created. """ super().build() # Basic unit model build/read config config = self.config # shorter config pointer # The thermodynamic expression writer object, te, writes expressions # including external function calls to calculate thermodynamic quantities # from a set of state variables. _assert_properties(config.property_package) te = ThermoExpr(blk=self, parameters=config.property_package) eff = self.efficiency_pump = pyo.Var(self.flowsheet().config.time, initialize=0.9, doc="Pump efficiency") self.efficiency_isentropic = pyo.Reference(self.efficiency_pump[:]) pratio = self.ratioP = pyo.Var(self.flowsheet().config.time, initialize=0.7, doc="Ratio of outlet to inlet pressure") # Some shorter refernces to property blocks properties_in = self.control_volume.properties_in properties_out = self.control_volume.properties_out @self.Expression(self.flowsheet().config.time, doc="Thermodynamic work") def work_fluid(b, t): return properties_out[t].flow_vol * (self.deltaP[t]) @self.Expression(self.flowsheet().config.time, doc="Work required to drive the pump.") def shaft_work(b, t): # Early access to the outlet enthalpy and work return self.work_fluid[t] / eff[t] @self.Constraint(self.flowsheet().config.time) def eq_work(b, t): # outlet enthalpy coens from energy balance return self.control_volume.work[t] == self.shaft_work[t] @self.Constraint(self.flowsheet().config.time) def eq_pressure_ratio(b, t): return (pratio[t] * properties_in[t].pressure == properties_out[t].pressure)