Skip to content

Commit

Permalink
Update desuperheater implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Sep 5, 2023
1 parent e48af86 commit faafbe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
26 changes: 9 additions & 17 deletions src/tespy/components/heat_exchangers/desuperheater.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class Desuperheater(HeatExchanger):
**Mandatory Equations**
- :py:meth:`tespy.components.component.Component.fluid_func`
- :py:meth:`tespy.components.component.Component.mass_flow_func`
- :py:meth:`tespy.components.heat_exchangers.base.HeatExchanger.energy_balance_func`
- :py:meth:`tespy.components.heat_exchangers.desuperheater.Desuperheater.saturated_gas_func`
Expand Down Expand Up @@ -129,9 +127,8 @@ class Desuperheater(HeatExchanger):
>>> from tespy.components import Sink, Source, Desuperheater
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> from tespy.tools.fluid_properties import T_bp_p
>>> import shutil
>>> nw = Network(fluids=['water', 'ethanol'], T_unit='C', p_unit='bar',
>>> nw = Network(T_unit='C', p_unit='bar',
... h_unit='kJ / kg', v_unit='l / s', m_range=[0.001, 10], iterinfo=False)
>>> et_in = Source('ethanol inlet')
>>> et_out = Sink('ethanol outlet')
Expand Down Expand Up @@ -171,7 +168,7 @@ class Desuperheater(HeatExchanger):
>>> round(cw_de.v.val, 2)
1.94
>>> et_de.set_attr(v=7)
>>> nw.solve('offdesign', design_path='tmp', init_path='tmp')
>>> nw.solve('offdesign', design_path='tmp')
>>> round(cw_de.v.val, 2)
0.41
>>> shutil.rmtree('./tmp', ignore_errors=True)
Expand All @@ -183,14 +180,6 @@ def component():

def get_mandatory_constraints(self):
return {
'mass_flow_constraints': {
'func': self.mass_flow_func, 'deriv': self.mass_flow_deriv,
'constant_deriv': True, 'latex': self.mass_flow_func_doc,
'num_eq': 2},
'fluid_constraints': {
'func': self.fluid_func, 'deriv': self.fluid_deriv,
'constant_deriv': True, 'latex': self.fluid_func_doc,
'num_eq': self.num_nw_fluids * 2},
'energy_balance_constraints': {
'func': self.energy_balance_func,
'deriv': self.energy_balance_deriv,
Expand All @@ -216,7 +205,8 @@ def saturated_gas_func(self):
0 = h_{out,1} - h\left(p_{out,1}, x=1 \right)
"""
return self.outl[0].h.val_SI - h_mix_pQ(self.outl[0].get_flow(), 1)
o = self.outl[0]
return o.h.val_SI - h_mix_pQ(o.p.val_SI, 1, o.fluid_data)

def saturated_gas_func_doc(self, label):
r"""
Expand Down Expand Up @@ -247,6 +237,8 @@ def saturated_gas_deriv(self, increment_filter, k):
k : int
Position of derivatives in Jacobian matrix (k-th equation).
"""
o1 = self.outl[0].get_flow()
self.jacobian[k, 2, 1] = -dh_mix_dpQ(o1, 1)
self.jacobian[k, 2, 2] = 1
o = self.outl[0]
if self.is_variable(o.p):
self.jacobian[k, o.p.J_col] = -dh_mix_dpQ(o, 1, o.fluid_data)
if self.is_variable(o.h):
self.jacobian[k, o.h.J_col] = 1
4 changes: 2 additions & 2 deletions src/tespy/networks/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2250,11 +2250,11 @@ def check_connection_properties(self, c):
# mass flow
if c.m.val_SI <= self.m_range_SI[0] and not c.m.is_set:
c.m.val_SI = self.m_range_SI[0]
logger.debug(self._property_range_message(c, 'm'))
logger.debug(c._property_range_message('m'))

elif c.m.val_SI >= self.m_range_SI[1] and not c.m.is_set:
c.m.val_SI = self.m_range_SI[1]
logger.debug(self._property_range_message(c, 'm'))
logger.debug(c._property_range_message('m'))

def solve_components(self):
r"""
Expand Down

0 comments on commit faafbe8

Please sign in to comment.