Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Jan 21, 2024
2 parents 6d36940 + 70654a8 commit 3cc6027
Show file tree
Hide file tree
Showing 35 changed files with 200 additions and 184 deletions.
6 changes: 3 additions & 3 deletions docs/api/_images/DropletSeparator.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/api/_images/DropletSeparator_darkmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@
r'https://doi.org/20.500.12738/6561', # 08.01.2023: does not resolve anymore
r'https://doi.org/10.1021/ie4033999', # 28.02.2023: does not resolve anymore for some reason
r'https://doi.org/10.1002/bbpc.19900940121', # 13.03.2023 ...?
r' http://www.coolprop.org/fluid_properties/Incompressibles.html', # 02.12.2023 ...?
r'http://www\.coolprop\.org/.*', # 02.12.2023 ...?
r'https://github\.com/oemof/tespy/.*', # 08.01.2024 ...?
]
17 changes: 12 additions & 5 deletions docs/modules/fluid_properties.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ Incompressible fluids
If you are looking for heat transfer fluids, the list of incompressible
`fluids <http://www.coolprop.org/fluid_properties/Incompressibles.html>`__
might be interesting for you. In contrast to the pure fluids, the properties
cover liquid state only. TESPy supports using pure incompressibles as well as
the predefined mixtures.
cover liquid state only.

Fluid mixtures
++++++++++++++
CoolProp provides a back end for predefined mixtures, which is rather instable
using HEOS. If you want to use the mixture feature of CoolProp we recommend
using the REFPROP back end instead.
TESPy provides support for three types of mixtures:

- ideal: Mixtures for gases only.
- ideal-cond: Mixture for gases with condensation calculation for water share.
- incompressible: Mixtures for incompressible fluids.

Furthermore, CoolProp provides a back end for predefined mixtures, which is
rather instable using HEOS. Using the CoolProp mixture back-end is not tested,
reach out if you would like to support us in adopting the TESPy implementation.
In general, to use the mixture feature of CoolProp we recommend using the
REFPROP back end instead of HEOS.

Using other engines
-------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ude.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ derivatives to mass flow are not zero.
... c0 = self.conns[0]
... c1 = self.conns[1]
... if c0.m.is_var:
... ude.jacobian[c0.m.J_col] = 1
... self.jacobian[c0.m.J_col] = 1
... if c1.m.is_var:
... self.jacobian[c1.m.J_col] = -2 * self.conns[1].m.val_SI
Expand Down
1 change: 1 addition & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ What's New

Discover noteable new features and improvements in each release

.. include:: whats_new/v0-7-2.rst
.. include:: whats_new/v0-7-1.rst
.. include:: whats_new/v0-7-0.rst
.. include:: whats_new/v0-6-3.rst
Expand Down
18 changes: 18 additions & 0 deletions docs/whats_new/v0-7-2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
v0.7.1 - Newton's Nature (January, 21, 2024)
++++++++++++++++++++++++++++++++++++++++++++

Bug Fixes
#########
- The `delta` value of the :py:class:`tespy.connections.connection.Ref` class
was oriented with the wrong sign. A positive delta lead to a negative value.
Fixed in (`PR #459 <https://github.com/oemof/tespy/pull/459>`__).
- In initial simulations the temperature value of mixtures is 0 by default.
For calculating temperatures of the mixtures during that initial simulation,
that value was used as starting value causing CoolProp to raise an error and
the calculation to crash. This is now prevented by checking if the starting
value is reasonable or not
(`PR #477 <https://github.com/oemof/tespy/pull/477>`__).

Contributors
############
- Francesco Witte (`@fwitte <https://github.com/fwitte>`__)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exclude = ["docs/_build"]

[project]
name = "tespy"
version = "0.7.1.post1"
version = "0.7.2"
description = "Thermal Engineering Systems in Python (TESPy)"
readme = "README.rst"
authors = [
Expand All @@ -47,7 +47,7 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"CoolProp>=6.4,<7",
"CoolProp>=6.6,<7",
"jinja2",
"matplotlib>=3.2.1,<4",
"numpy>=1.13.3,<2",
Expand Down
2 changes: 1 addition & 1 deletion src/tespy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

__datapath__ = os.path.join(importlib.resources.files("tespy"), "data")
__version__ = '0.7.1.post1 - Newton\'s Nature'
__version__ = '0.7.2 - Newton\'s Nature'

# tespy data and connections import
from . import connections # noqa: F401
Expand Down
8 changes: 3 additions & 5 deletions src/tespy/components/combustion/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,11 +1302,9 @@ def calc_parameters(self):
self.outl[i].h.val_SI - self.inl[i].h.val_SI)
self.get_attr('pr' + str(i + 1)).val = (
self.outl[i].p.val_SI / self.inl[i].p.val_SI)
self.get_attr('zeta' + str(i + 1)).val = (
(self.inl[i].p.val_SI - self.outl[i].p.val_SI) * np.pi ** 2 / (
4 * self.inl[i].m.val_SI ** 2 *
(self.inl[i].vol.val_SI + self.outl[i].vol.val_SI)
))
self.get_attr('zeta' + str(i + 1)).val = self.calc_zeta(
self.inl[i], self.outl[i]
)

self.P.val = self.calc_P()
self.Qloss.val = self.calc_Qloss()
Expand Down
39 changes: 23 additions & 16 deletions src/tespy/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
SPDX-License-Identifier: MIT
"""

from collections import OrderedDict

import numpy as np

from tespy.tools import logger
Expand Down Expand Up @@ -122,7 +120,7 @@ def __init__(self, label, **kwargs):
self.fkt_group = self.label

# add container for components attributes
self.parameters = OrderedDict(self.get_parameters().copy())
self.parameters = self.get_parameters().copy()
self.__dict__.update(self.parameters)
self.set_attr(**kwargs)

Expand Down Expand Up @@ -342,7 +340,7 @@ def preprocess(self, num_nw_vars):
self.num_eq = 0
self.vars = {}
self.num_vars = 0
self.constraints = OrderedDict(self.get_mandatory_constraints().copy())
self.constraints = self.get_mandatory_constraints().copy()
self.prop_specifications = {}
self.var_specifications = {}
self.group_specifications = {}
Expand Down Expand Up @@ -415,7 +413,7 @@ def preprocess(self, num_nw_vars):
if data.is_set and data.func is not None:
self.num_eq += data.num_eq

self.jacobian = OrderedDict()
self.jacobian = {}
self.residual = np.zeros(self.num_eq)

sum_eq = 0
Expand Down Expand Up @@ -813,18 +811,18 @@ def check_parameter_bounds(self):
if isinstance(data, dc_cp):
if data.val > data.max_val + ERR :
msg = (
'Invalid value for ' + p + ': ' + p + ' = ' +
str(data.val) + ' above maximum value (' +
str(data.max_val) + ') at component ' + self.label +
'.')
f"Invalid value for {p}: {p} = {data.val} above "
f"maximum value ({data.max_val}) at component "
f"{self.label}."
)
logger.warning(msg)

elif data.val < data.min_val - ERR :
msg = (
'Invalid value for ' + p + ': ' + p + ' = ' +
str(data.val) + ' below minimum value (' +
str(data.min_val) + ') at component ' + self.label +
'.')
f"Invalid value for {p}: {p} = {data.val} below "
f"minimum value ({data.max_val}) at component "
f"{self.label}."
)
logger.warning(msg)

elif isinstance(data, dc_cc) and data.is_set:
Expand Down Expand Up @@ -968,7 +966,8 @@ def enthalpy_equality_func_doc(self, label):
indices = str(indices[0])
latex = (
r'0=h_{\mathrm{in,}i}-h_{\mathrm{out,}i}'
r'\; \forall i \in [' + indices + r']')
r'\; \forall i \in [' + indices + r']'
)
return generate_latex_eq(self, latex, label)

def enthalpy_equality_deriv(self, k):
Expand Down Expand Up @@ -1021,8 +1020,7 @@ def pr_func(self, pr='', inconn=0, outconn=0):
0 = p_{in} \cdot pr - p_{out}
"""
pr = self.get_attr(pr)
return (self.inl[inconn].p.val_SI * pr.val -
self.outl[outconn].p.val_SI)
return self.inl[inconn].p.val_SI * pr.val - self.outl[outconn].p.val_SI

def pr_func_doc(self, label, pr='', inconn=0, outconn=0):
r"""
Expand Down Expand Up @@ -1083,6 +1081,15 @@ def pr_deriv(self, increment_filter, k, pr='', inconn=0, outconn=0):
if pr.is_var:
self.jacobian[k, self.pr.J_col] = i.p.val_SI

def calc_zeta(self, i, o):
if abs(i.m.val_SI) <= 1e-4:
return 0
else:
return (
(i.p.val_SI - o.p.val_SI) * np.pi ** 2
/ (4 * i.m.val_SI ** 2 * (i.vol.val_SI + o.vol.val_SI))
)

def zeta_func(self, zeta='', inconn=0, outconn=0):
r"""
Calculate residual value of :math:`\zeta`-function.
Expand Down
30 changes: 15 additions & 15 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 Expand Up @@ -830,20 +830,20 @@ def calc_parameters(self):
for i in range(2):
self.get_attr('pr' + str(i + 1)).val = (
self.outl[i].p.val_SI / self.inl[i].p.val_SI)
self.get_attr('zeta' + str(i + 1)).val = (
(self.inl[i].p.val_SI - self.outl[i].p.val_SI) * np.pi ** 2 / (
4 * self.inl[i].m.val_SI ** 2 *
(self.inl[i].vol.val_SI + self.outl[i].vol.val_SI)
))
self.get_attr('zeta' + str(i + 1)).val = self.calc_zeta(
self.inl[i], self.outl[i]
)

# kA and logarithmic temperature difference
if self.ttd_u.val < 0 or self.ttd_l.val < 0:
self.td_log.val = np.nan
elif self.ttd_l.val == self.ttd_u.val:
self.td_log.val = self.ttd_l.val
else:
self.td_log.val = ((self.ttd_l.val - self.ttd_u.val) /
np.log(self.ttd_l.val / self.ttd_u.val))
self.td_log.val = (
(self.ttd_l.val - self.ttd_u.val)
/ np.log(self.ttd_l.val / self.ttd_u.val)
)
self.kA.val = -self.Q.val / self.td_log.val

def entropy_balance(self):
Expand Down
10 changes: 4 additions & 6 deletions src/tespy/components/heat_exchangers/condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
from tespy.tools.data_containers import GroupedComponentCharacteristics as dc_gcc
from tespy.tools.data_containers import SimpleDataContainer as dc_simple
from tespy.tools.document_models import generate_latex_eq
from tespy.tools.fluid_properties import T_mix_ph
from tespy.tools.fluid_properties import T_sat_p
from tespy.tools.fluid_properties import dh_mix_dpQ
from tespy.tools.fluid_properties import h_mix_pQ

Expand Down Expand Up @@ -329,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 @@ -454,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
8 changes: 3 additions & 5 deletions 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 Expand Up @@ -361,10 +361,8 @@ def calc_parameters(self):

self.Q.val = i.m.val_SI * (o.h.val_SI - i.h.val_SI)
self.pr.val = o.p.val_SI / i.p.val_SI
self.zeta.val = (
(i.p.val_SI - o.p.val_SI) * np.pi ** 2
/ (4 * i.m.val_SI ** 2 * (i.vol.val_SI + o.vol.val_SI))
)
self.zeta.val = self.calc_zeta(i, o)

if self.energy_group.is_set:
self.Q_loss.val = - self.E.val * self.A.val + self.Q.val
self.Q_loss.is_result = True
Expand Down
Loading

0 comments on commit 3cc6027

Please sign in to comment.