Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif c.h.val_SI > hmax and not c.h.val_set:
c.h.val_SI = hmax * 0.9999
logging.debug(self.property_range_message(c, 'h'))
if ((c.Td_bp.val_set is True or c.state.is_set is True) and
c.h.val_set is False and self.iter < 3):
if (c.Td_bp.val_SI > 0 or
(c.state.val == 'g' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 1)
if c.h.val_SI < h:
c.h.val_SI = h * 1.01
logging.debug(self.property_range_message(c, 'h'))
elif (c.Td_bp.val_SI < 0 or
(c.state.val == 'l' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 0)
if c.h.val_SI > h:
c.h.val_SI = h * 0.99
logging.debug(self.property_range_message(c, 'h'))
elif self.iter < 4 and c.good_starting_values is False:
# pressure
if c.p.val_SI <= self.p_range_SI[0] and not c.p.val_set:
c.p.val_SI = self.p_range_SI[0]
logging.debug(self.property_range_message(c, 'p'))
elif c.p.val_SI >= self.p_range_SI[1] and not c.p.val_set:
c.p.val_SI = self.p_range_SI[1]
logging.debug(self.property_range_message(c, 'p'))
# enthalpy
if c.h.val_SI < self.h_range_SI[0] and not c.h.val_set:
self.residual[k] = p - c.p.val_SI
k += 1
######################################################################
# eqations for enthalpy
val = 0
for i in self.inl:
val += i.m.val_SI * i.h.val_SI
for o in self.outl:
val -= o.m.val_SI * o.h.val_SI
self.residual[k] = val
k += 1
######################################################################
# eqations for staturated fluid state at outlets
self.residual[k] = h_mix_pQ(
self.outl[0].to_flow(), 0) - self.outl[0].h.val_SI
k += 1
self.residual[k] = h_mix_pQ(
self.outl[1].to_flow(), 1) - self.outl[1].h.val_SI
k += 1
Calculate results of additional equations.
Equations
**mandatory equations**
.. math::
0 = h_{1,out} - h\left(p, x=0 \right)\\
x: \text{vapour mass fraction}
"""
######################################################################
# equation for saturated liquid at hot side outlet
if self.subcooling.val is False:
o1 = self.outl[0].to_flow()
self.residual[k] = o1[2] - h_mix_pQ(o1, 0)
k += 1
if c.x.val_set and not c.h.val_set:
c.h.val_SI = fp.h_mix_pQ(c.to_flow(), c.x.val_SI)
if c.T.val_set and not c.h.val_set:
try:
c.h.val_SI = fp.h_mix_pT(c.to_flow(), c.T.val_SI)
except ValueError:
pass
# starting values for specified subcooling/overheating
# and state specification
if ((c.Td_bp.val_set is True or c.state.is_set is True) and
c.h.val_set is False):
if ((c.Td_bp.val_SI > 0 and c.Td_bp.val_set is True) or
(c.state.val == 'g' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 1)
if c.h.val_SI < h:
c.h.val_SI = h * 1.001
elif ((c.Td_bp.val_SI < 0 and c.Td_bp.val_set is True) or
(c.state.val == 'l' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 0)
if c.h.val_SI > h:
c.h.val_SI = h * 0.999
msg = 'Generic fluid property specification complete.'
logging.debug(msg)
except ValueError:
pass
if c.T.val_set and not c.h.val_set:
try:
c.h.val_SI = fp.h_mix_pT(c.to_flow(), c.T.val_SI)
except ValueError:
pass
# starting values for specified subcooling/overheating
# and state specification
if ((c.Td_bp.val_set is True or c.state.is_set is True) and
c.h.val_set is False):
if ((c.Td_bp.val_SI > 0 and c.Td_bp.val_set is True) or
(c.state.val == 'g' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 1)
if c.h.val_SI < h:
c.h.val_SI = h * 1.001
elif ((c.Td_bp.val_SI < 0 and c.Td_bp.val_set is True) or
(c.state.val == 'l' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 0)
if c.h.val_SI > h:
c.h.val_SI = h * 0.999
msg = 'Generic fluid property specification complete.'
logging.debug(msg)
ref_col_s = ref.obj.conn_loc * self.num_conn_vars + 3
ref_col_e = (ref.obj.conn_loc + 1) * self.num_conn_vars
if not all(self.increment_filter[col_s:col_e]):
self.jacobian[k, col_s:col_e] = (
fp.dT_mix_ph_dfluid(flow, T0=c.T.val_SI))
if not all(self.increment_filter[ref_col_s:ref_col_e]):
self.jacobian[k, ref_col_s:ref_col_e] = -(
fp.dT_mix_ph_dfluid(flow_ref, T0=ref.obj.T.val_SI))
k += 1
# saturated steam fraction
if c.x.val_set is True:
if (np.absolute(self.residual[k]) > err ** 2 or
self.iter % 2 == 0):
self.residual[k] = c.h.val_SI - (
fp.h_mix_pQ(flow, c.x.val_SI))
if not self.increment_filter[col + 1]:
self.jacobian[k, col + 1] = -(
fp.dh_mix_dpQ(flow, c.x.val_SI))
self.jacobian[k, col + 2] = 1
k += 1
# volumetric flow
if c.v.val_set is True:
if (np.absolute(self.residual[k]) > err ** 2 or
self.iter % 2 == 0):
self.residual[k] = (
c.v.val_SI - fp.v_mix_ph(flow, T0=c.T.val_SI) *
c.m.val_SI)
self.jacobian[k, col] = -fp.v_mix_ph(flow, T0=c.T.val_SI)
self.jacobian[k, col + 1] = -(
fp.dv_mix_dph(flow, T0=c.T.val_SI) * c.m.val_SI)
self.residual[k] = self.zeta_func(
zeta='zeta3', inconn=2, outconn=2)
k += 1
######################################################################
# equation for saturated liquid at hot side 1 outlet
if self.subcooling.val is False:
o1 = self.outl[0].to_flow()
self.residual[k] = o1[2] - h_mix_pQ(o1, 0)
k += 1
######################################################################
# equation for saturated gas at cold side outlet
if self.overheating.val is False:
o3 = self.outl[2].to_flow()
self.residual[k] = o3[2] - h_mix_pQ(o3, 1)
k += 1
self.residual[k] = self.zeta_func(
zeta='zeta2', inconn=1, outconn=1)
k += 1
######################################################################
# equations for specified zeta at cold side
if self.zeta3.is_set:
self.residual[k] = self.zeta_func(
zeta='zeta3', inconn=2, outconn=2)
k += 1
######################################################################
# equation for saturated liquid at hot side 1 outlet
if self.subcooling.val is False:
o1 = self.outl[0].to_flow()
self.residual[k] = o1[2] - h_mix_pQ(o1, 0)
k += 1
######################################################################
# equation for saturated gas at cold side outlet
if self.overheating.val is False:
o3 = self.outl[2].to_flow()
self.residual[k] = o3[2] - h_mix_pQ(o3, 1)
k += 1
# improved starting values for referenced connections,
# specified vapour content values, temperature values as well as
# subccooling/overheating and state specification
for c in self.conns.index:
# starting values for fluid properties with referenced objects
for key in ['m', 'p', 'h', 'T']:
if (c.get_attr(key).ref_set and
c.get_attr(key).val_set is False):
c.get_attr(key).val_SI = (
c.get_attr(key).ref.obj.get_attr(key).val_SI *
c.get_attr(key).ref.f + c.get_attr(key).ref.d)
# starting values for specified vapour content or temperature
if c.x.val_set and not c.h.val_set:
try:
c.h.val_SI = fp.h_mix_pQ(c.to_flow(), c.x.val_SI)
except ValueError:
pass
if c.T.val_set and not c.h.val_set:
try:
c.h.val_SI = fp.h_mix_pT(c.to_flow(), c.T.val_SI)
except ValueError:
pass
# starting values for specified subcooling/overheating
# and state specification
if ((c.Td_bp.val_set is True or c.state.is_set is True) and
c.h.val_set is False):
if ((c.Td_bp.val_SI > 0 and c.Td_bp.val_set is True) or
(c.state.val == 'g' and c.state.is_set is True)):
h = fp.h_mix_pQ(c.to_flow(), 1)