Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
----
For standard functions f\ :subscript:`1` \ and f\ :subscript:`2` \ see
module :func:`tespy.data`.
- Calculate temperatures at inlets and outlets.
- Perform value manipulation, if temperature levels are not physically
feasible.
"""
i1 = self.inl[0].to_flow()
i2 = self.inl[1].to_flow()
o1 = self.outl[0].to_flow()
o2 = self.outl[1].to_flow()
T_i1 = T_mix_ph(i1, T0=self.inl[0].T.val_SI)
T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
if T_i1 <= T_o2:
T_i1 = T_o2 + 0.01
if T_i1 <= T_o2:
T_o2 = T_i1 - 0.01
if T_i1 <= T_o2:
T_o1 = T_i2 + 0.02
if T_o1 <= T_i2:
T_i2 = T_o1 - 0.02
td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
return i1[0] * (o1[2] - i1[2]) + self.kA.val * td_log
Note
----
For standard functions f\ :subscript:`1` \ and f\ :subscript:`2` \ see
module :func:`tespy.data`.
- Calculate temperatures at inlets and outlets.
- Perform value manipulation, if temperature levels are not physically
feasible.
"""
i1 = self.inl[0].to_flow()
i2 = self.inl[1].to_flow()
o1 = self.outl[0].to_flow()
o2 = self.outl[1].to_flow()
T_i1 = T_mix_ph(i1, T0=self.inl[0].T.val_SI)
T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
if T_i1 <= T_o2:
T_i1 = T_o2 + 0.01
if T_i1 <= T_o2:
T_o2 = T_i1 - 0.01
if T_i1 <= T_o2:
T_o1 = T_i2 + 0.02
if T_o1 <= T_i2:
T_i2 = T_o1 - 0.02
td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
Z1 = \frac{p_2 \cdot p_\mathrm{1,ref}}
{p_1 \cdot p_\mathrm{2,ref}}-
pr_{c}(char(m, igva))
Z2 = \frac{\eta_\mathrm{s,c}}{\eta_\mathrm{s,c,ref}} -
\eta_{s,c}(char(m, igva))
"""
# actual values
i = self.inl[0].to_flow()
o = self.outl[0].to_flow()
# design values
i_d = self.inl[0].to_flow_design()
o_d = self.outl[0].to_flow_design()
T_i = T_mix_ph(i, T0=self.inl[0].T.val_SI)
x = np.sqrt(T_mix_ph(i_d) / T_i)
y = (i[0] * i_d[1]) / (i_d[0] * i[1] * x)
pr, eta = self.char_map.func.evaluate(x, y, igva=self.igva.val)
z1 = o[1] * i_d[1] / (i[1] * o_d[1]) - pr
z2 = ((self.h_os('post') - i[2]) / (o[2] - i[2]) /
self.eta_s.design - eta)
return np.array([z1, z2])
def ttd_l_func(self):
r"""
Equation for upper terminal temperature difference.
Returns
-------
res : float
Residual value of equation.
.. math::
res = ttd_{l} - T_{1,out} + T_{2,in}
"""
i2 = self.inl[1].to_flow()
o1 = self.outl[0].to_flow()
return (self.ttd_l.val - T_mix_ph(o1, T0=self.outl[0].T.val_SI) +
T_mix_ph(i2, T0=self.inl[1].T.val_SI))
# busses
for b in self.busses.values():
b.P.val = 0
for cp in b.comps.index:
# get components bus func value
val = cp.bus_func(b.comps.loc[cp])
# save as reference value
if self.mode == 'design':
b.comps.loc[cp].P_ref = (
cp.bus_func(b.comps.loc[cp]) /
abs(b.comps.loc[cp].char.evaluate(1)))
b.P.val += val
# connections
for c in self.conns.index:
c.T.val_SI = fp.T_mix_ph(c.to_flow(), T0=c.T.val_SI)
c.v.val_SI = fp.v_mix_ph(c.to_flow(), T0=c.T.val_SI) * c.m.val_SI
c.T.val = (c.T.val_SI / self.T[c.T.unit][1] - self.T[c.T.unit][0])
c.m.val = c.m.val_SI / self.m[c.m.unit]
c.p.val = c.p.val_SI / self.p[c.p.unit]
c.h.val = c.h.val_SI / self.h[c.h.unit]
c.v.val = c.v.val_SI / self.v[c.v.unit]
fluid = hlp.single_fluid(c.fluid.val)
if isinstance(fluid, str) and not c.x.val_set:
c.x.val_SI = fp.Q_ph(c.p.val_SI, c.h.val_SI, fluid)
c.x.val = c.x.val_SI
c.T.val0 = c.T.val
c.m.val0 = c.m.val
c.p.val0 = c.p.val
c.h.val0 = c.h.val
c.fluid.val0 = c.fluid.val.copy()
def ttd_u_func(self):
r"""
Equation for upper terminal temperature difference.
Returns
-------
res : float
Residual value of equation.
.. math::
res = ttd_{u} - T_{1,in} + T_{2,out}
"""
T_i1 = T_mix_ph(self.inl[0].to_flow(), T0=self.inl[0].T.val_SI)
T_o2 = T_mix_ph(self.outl[1].to_flow(), T0=self.outl[1].T.val_SI)
return self.ttd_u.val - T_i1 + T_o2
self.jacobian[k, col + 2] = (
-fp.dT_mix_pdh(flow, T0=c.T.val_SI))
if len(self.fluids) != 1:
col_s = c.conn_loc * self.num_conn_vars + 3
col_e = (c.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)
k += 1
# referenced temperature
if c.T.ref_set is True:
ref = c.T.ref
flow_ref = ref.obj.to_flow()
ref_col = ref.obj.conn_loc * self.num_conn_vars
self.residual[k] = fp.T_mix_ph(flow, T0=c.T.val_SI) - (
fp.T_mix_ph(flow_ref, T0=ref.obj.T.val_SI) *
ref.f + ref.d)
self.jacobian[k, col + 1] = (
fp.dT_mix_dph(flow, T0=c.T.val_SI))
self.jacobian[k, col + 2] = (
fp.dT_mix_pdh(flow, T0=c.T.val_SI))
self.jacobian[k, ref_col + 1] = -(
fp.dT_mix_dph(flow_ref, T0=ref.obj.T.val_SI) * ref.f)
self.jacobian[k, ref_col + 2] = -(
fp.dT_mix_pdh(flow_ref, T0=ref.obj.T.val_SI) * ref.f)
# dT / dFluid
if len(self.fluids) != 1:
col_s = c.conn_loc * self.num_conn_vars + 3
{\ln{\frac{ttd_u}{ttd_l}}}
f_{kA} = \frac{2}{1 + \frac{1}
{f\left(\frac{m_1}{m_{1,ref}}\right)}}
T_{amb}: \text{ambient temperature}
Note
----
For standard function of f\ :subscript:`1` \ see module
:func:`tespy.data`.
"""
i, o = self.inl[0].to_flow(), self.outl[0].to_flow()
ttd_1 = T_mix_ph(i, T0=self.inl[0].T.val_SI) - self.Tamb.val_SI
ttd_2 = T_mix_ph(o, T0=self.outl[0].T.val_SI) - self.Tamb.val_SI
if ttd_1 > ttd_2:
td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
elif ttd_1 < ttd_2:
td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
else:
td_log = 0
f = 1
if not np.isnan(self.inl[0].m.design):
if self.kA_char.param == 'm':
f = self.kA_char.func.evaluate(i[0] / self.inl[0].m.design)
fkA = 2 / (1 + 1 / f)
return i[0] * (o[2] - i[2]) + self.kA.design * fkA * td_log
\begin{split}
T_m = & \frac{T_{out} + T_{in}}{2}\\
0 = & \dot{m} \cdot \left( h_{out} - h_{in} \right)\\
& - A \cdot \left[E \cdot \eta_{opt} - \alpha_1 \cdot
\left(T_m - T_{amb} \right) - \alpha_2 \cdot
\left(T_m - T_{amb}\right)^2 \right]
\end{split}
Reference: :cite:`Quaschning2013`.
"""
i = self.inl[0].to_flow()
o = self.outl[0].to_flow()
T_m = (T_mix_ph(i, T0=self.inl[0].T.val_SI) +
T_mix_ph(o, T0=self.outl[0].T.val_SI)) / 2
return (i[0] * (o[2] - i[2]) -
self.A.val * (
self.E.val * self.eta_opt.val -
(T_m - self.Tamb.val_SI) * self.lkf_lin.val -
self.lkf_quad.val * (T_m - self.Tamb.val_SI) ** 2))