Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mixture calculations with starting value of 0 K #477

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/tespy/components/heat_exchangers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ def calculate_td_log(self):
o2 = self.outl[1]

# temperature value manipulation for convergence stability
T_i1 = i1.calc_T(T0=i1.T.val_SI)
T_i2 = i2.calc_T(T0=i2.T.val_SI)
T_o1 = o1.calc_T(T0=o1.T.val_SI)
T_o2 = o2.calc_T(T0=o2.T.val_SI)
T_i1 = i1.calc_T()
T_i2 = i2.calc_T()
T_o1 = o1.calc_T()
T_o2 = o2.calc_T()

if T_i1 <= T_o2:
T_i1 = T_o2 + 0.01
Expand Down Expand Up @@ -581,8 +581,8 @@ def ttd_u_func(self):
"""
i = self.inl[0]
o = self.outl[1]
T_i1 = i.calc_T(T0=i.T.val_SI)
T_o2 = o.calc_T(T0=o.T.val_SI)
T_i1 = i.calc_T()
T_o2 = o.calc_T()
return self.ttd_u.val - T_i1 + T_o2

def ttd_u_func_doc(self, label):
Expand Down Expand Up @@ -636,8 +636,8 @@ def ttd_l_func(self):
"""
i = self.inl[1]
o = self.outl[0]
T_i2 = i.calc_T(T0=i.T.val_SI)
T_o1 = o.calc_T(T0=o.T.val_SI)
T_i2 = i.calc_T()
T_o1 = o.calc_T()
return self.ttd_l.val - T_o1 + T_i2

def ttd_l_func_doc(self, label):
Expand Down
8 changes: 4 additions & 4 deletions src/tespy/components/heat_exchangers/condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ def calculate_td_log(self):
o2 = self.outl[1]

T_i1 = i1.calc_T_sat()
T_i2 = i2.calc_T(T0=i2.T.val_SI)
T_o1 = o1.calc_T(T0=o1.T.val_SI)
T_o2 = o2.calc_T(T0=o2.T.val_SI)
T_i2 = i2.calc_T()
T_o1 = o1.calc_T()
T_o2 = o2.calc_T()

if T_i1 <= T_o2 and not i1.T.is_set:
T_i1 = T_o2 + 0.5
Expand Down Expand Up @@ -452,7 +452,7 @@ def ttd_u_func(self):
i = self.inl[0]
o = self.outl[1]
T_i1 = i.calc_T_sat()
T_o2 = o.calc_T(T0=self.outl[1].T.val_SI)
T_o2 = o.calc_T()
return self.ttd_u.val - T_i1 + T_o2

def ttd_u_func_doc(self, label):
Expand Down
2 changes: 1 addition & 1 deletion src/tespy/components/heat_exchangers/parabolic_trough.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def energy_group_func(self):
i = self.inl[0]
o = self.outl[0]

T_m = 0.5 * (i.calc_T(T0=i.T.val_SI) + o.calc_T(T0=o.T.val_SI))
T_m = 0.5 * (i.calc_T() + o.calc_T())

iam = (
1 - self.iam_1.val * abs(self.aoi.val)
Expand Down
8 changes: 4 additions & 4 deletions src/tespy/components/heat_exchangers/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ def kA_group_func(self):
i = self.inl[0]
o = self.outl[0]

ttd_1 = i.calc_T(T0=i.T.val_SI) - self.Tamb.val_SI
ttd_2 = o.calc_T(T0=o.T.val_SI) - self.Tamb.val_SI
ttd_1 = i.calc_T() - self.Tamb.val_SI
ttd_2 = o.calc_T() - self.Tamb.val_SI

# For numerical stability: If temperature differences have
# different sign use mean difference to avoid negative logarithm.
Expand Down Expand Up @@ -651,8 +651,8 @@ def kA_char_group_func(self):
# For numerical stability: If temperature differences have
# different sign use mean difference to avoid negative logarithm.

ttd_1 = i.calc_T(T0=i.T.val_SI) - self.Tamb.val_SI
ttd_2 = o.calc_T(T0=o.T.val_SI) - self.Tamb.val_SI
ttd_1 = i.calc_T() - self.Tamb.val_SI
ttd_2 = o.calc_T() - self.Tamb.val_SI

if (ttd_1 / ttd_2) < 0:
td_log = (ttd_2 + ttd_1) / 2
Expand Down
2 changes: 1 addition & 1 deletion src/tespy/components/heat_exchangers/solar_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def energy_group_func(self):
i = self.inl[0]
o = self.outl[0]

T_m = 0.5 * (i.calc_T(T0=i.T.val_SI) + o.calc_T(T0=o.T.val_SI))
T_m = 0.5 * (i.calc_T() + o.calc_T())

return (
i.m.val_SI * (o.h.val_SI - i.h.val_SI)
Expand Down
4 changes: 2 additions & 2 deletions src/tespy/components/nodes/separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ def energy_balance_func(self):
\forall j \in \text{outlets}
"""
residual = []
T_in = self.inl[0].calc_T(T0=300)
T_in = self.inl[0].calc_T()
for o in self.outl:
residual += [T_in - o.calc_T(T0=300)]
residual += [T_in - o.calc_T()]
return residual

def energy_balance_func_doc(self, label):
Expand Down
4 changes: 2 additions & 2 deletions src/tespy/components/turbomachinery/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def char_map_pr_func(self):
i = self.inl[0]
o = self.outl[0]

x = np.sqrt(i.T.design / i.calc_T(T0=i.T.val_SI))
x = np.sqrt(i.T.design / i.calc_T())
y = (i.m.val_SI * i.p.design) / (i.m.design * i.p.val_SI * x)

yarr, zarr = self.char_map_pr.char_func.evaluate_x(x)
Expand Down Expand Up @@ -477,7 +477,7 @@ def char_map_eta_s_func(self):
i = self.inl[0]
o = self.outl[0]

x = np.sqrt(i.T.design / i.calc_T(T0=i.T.val_SI))
x = np.sqrt(i.T.design / i.calc_T())
y = (i.m.val_SI * i.p.design) / (i.m.design * i.p.val_SI * x)

yarr, zarr = self.char_map_eta_s.char_func.evaluate_x(x)
Expand Down
2 changes: 2 additions & 0 deletions src/tespy/connections/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ def primary_ref_deriv(self, k, **kwargs):
self.jacobian[k, ref.obj.get_attr(variable).J_col] = -ref.factor

def calc_T(self, T0=None):
if T0 is None:
T0 = self.T.val_SI
return T_mix_ph(self.p.val_SI, self.h.val_SI, self.fluid_data, self.mixing_rule, T0=T0)

def T_func(self, k, **kwargs):
Expand Down
2 changes: 0 additions & 2 deletions src/tespy/tools/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

SPDX-License-Identifier: MIT
"""
import collections

import numpy as np

from tespy.tools import logger
Expand Down
2 changes: 1 addition & 1 deletion src/tespy/tools/fluid_properties/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_molar_fractions(fluid_data):
def inverse_temperature_mixture(p=None, target_value=None, fluid_data=None, T0=None, f=None):
# calculate the fluid properties for fluid mixtures
valmin, valmax = get_mixture_temperature_range(fluid_data)
if T0 is None:
if T0 is None or T0 == 0 or np.isnan(T0):
T0 = (valmin + valmax) / 2.0

function_kwargs = {
Expand Down
Loading