Skip to content

Commit

Permalink
Merge branch 'fix/numpy-2-compatibility' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fwitte committed Jul 8, 2024
2 parents 78fa8d1 + a582d8a commit 3df1909
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 113 deletions.
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
The developer rules can be found in the chapter
[developing TESPy](https://tespy.readthedocs.io/en/dev/developing_tespy.html)
of the tespy.documentation.
The developer rules can be found in the
[online documentation](https://tespy.readthedocs.io/).
2 changes: 1 addition & 1 deletion docs/modules/networks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ be at 10 bar, use it as upper boundary.
>>> my_plant.set_attr(p_range=[0.05, 10], h_range=[15, 2000])
>>> my_plant.p_unit
'bar'
>>> my_plant.p_range_SI.tolist()
>>> my_plant.p_range_SI
[5000.0, 1000000.0]
.. _printout_logging_label:
Expand Down
2 changes: 2 additions & 0 deletions docs/whats_new/v0-7-5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Other Changes
(`PR #524 <https://github.com/oemof/tespy/pull/524>`__).
- Update various parts of the source code to implement more maintainer-friendly
features (`PR #525 <https://github.com/oemof/tespy/pull/525>`__).
- Create :code:`numpy` 2.0 compatibility
(`PR #527 <https://github.com/oemof/tespy/pull/527>`__).

Contributors
############
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"CoolProp>=6.6,<7",
"CoolProp>=6.6",
"jinja2",
"matplotlib>=3.2.1,<4",
"numpy>=1.13.3,<2",
"pandas>=1.3.0,<3",
"tabulate>=0.8.2,<0.9",
"matplotlib>=3.2.1",
"numpy>=1.13.3",
"pandas>=1.3.0",
"tabulate>=0.8.2",
]
license = {text = "MIT"}

Expand Down
5 changes: 3 additions & 2 deletions src/tespy/components/basics/cycle_closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def preprocess(self, num_nw_vars):
def calc_parameters(self):
r"""Postprocessing parameter calculation."""
# calculate deviation in mass flow
self.mass_deviation.val = np.abs(
self.inl[0].m.val_SI - self.outl[0].m.val_SI)
self.mass_deviation.val = abs(
self.inl[0].m.val_SI - self.outl[0].m.val_SI
)

# calculate deviation in fluid composition
d1 = self.inl[0].fluid.val
Expand Down
1 change: 0 additions & 1 deletion src/tespy/components/combustion/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class CombustionEngine(CombustionChamber):
... Splitter)
>>> from tespy.connections import Connection, Ref
>>> from tespy.networks import Network
>>> import numpy as np
>>> import shutil
>>> nw = Network(p_unit='bar', T_unit='C', iterinfo=False)
>>> amb = Source('ambient')
Expand Down
8 changes: 5 additions & 3 deletions src/tespy/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
SPDX-License-Identifier: MIT
"""

import math

import numpy as np

from tespy.tools import logger
Expand Down Expand Up @@ -801,7 +803,7 @@ def set_parameters(self, mode, data):
if isinstance(dc, dc_cp):
if ((mode == 'offdesign' and not self.local_design) or
(mode == 'design' and self.local_offdesign)):
self.get_attr(key).design = data[key]
self.get_attr(key).design = float(data[key])

else:
self.get_attr(key).design = np.nan
Expand Down Expand Up @@ -1092,7 +1094,7 @@ def calc_zeta(self, i, o):
return 0
else:
return (
(i.p.val_SI - o.p.val_SI) * np.pi ** 2
(i.p.val_SI - o.p.val_SI) * math.pi ** 2
/ (4 * i.m.val_SI ** 2 * (i.vol.val_SI + o.vol.val_SI))
)

Expand Down Expand Up @@ -1149,7 +1151,7 @@ def zeta_func(self, zeta='', inconn=0, outconn=0):
v_i = v_mix_ph(i.p.val_SI, i.h.val_SI, i.fluid_data, i.mixing_rule, T0=i.T.val_SI)
v_o = v_mix_ph(o.p.val_SI, o.h.val_SI, o.fluid_data, o.mixing_rule, T0=o.T.val_SI)
return (
data.val - (i.p.val_SI - o.p.val_SI) * np.pi ** 2
data.val - (i.p.val_SI - o.p.val_SI) * math.pi ** 2
/ (8 * abs(i.m.val_SI) * i.m.val_SI * (v_i + v_o) / 2)
)

Expand Down
6 changes: 4 additions & 2 deletions src/tespy/components/heat_exchangers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
SPDX-License-Identifier: MIT
"""
import math

import numpy as np

from tespy.components.component import Component
Expand Down Expand Up @@ -404,7 +406,7 @@ def calculate_td_log(self):
if ttd_u == ttd_l:
td_log = ttd_l
else:
td_log = (ttd_l - ttd_u) / np.log((ttd_l) / (ttd_u))
td_log = (ttd_l - ttd_u) / math.log((ttd_l) / (ttd_u))

return td_log

Expand Down Expand Up @@ -845,7 +847,7 @@ def calc_parameters(self):
else:
self.td_log.val = (
(self.ttd_l.val - self.ttd_u.val)
/ np.log(self.ttd_l.val / self.ttd_u.val)
/ math.log(self.ttd_l.val / self.ttd_u.val)
)
self.kA.val = -self.Q.val / self.td_log.val

Expand Down
8 changes: 5 additions & 3 deletions src/tespy/components/heat_exchangers/condenser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
SPDX-License-Identifier: MIT
"""

import math

import numpy as np

from tespy.components.component import component_registry
Expand Down Expand Up @@ -347,7 +349,7 @@ def calculate_td_log(self):
if ttd_u == ttd_l:
td_log = ttd_l
else:
td_log = (ttd_l - ttd_u) / np.log((ttd_l) / (ttd_u))
td_log = (ttd_l - ttd_u) / math.log((ttd_l) / (ttd_u))

return td_log

Expand Down Expand Up @@ -491,7 +493,7 @@ def calc_parameters(self):
for num, (i, o) in enumerate(zip(self.inl, self.outl)):
self.get_attr(f"pr{num + 1}").val = o.p.val_SI / i.p.val_SI
self.get_attr(f"zeta{num + 1}").val = (
(i.p.val_SI - o.p.val_SI) * np.pi ** 2
(i.p.val_SI - o.p.val_SI) * math.pi ** 2
/ (4 * i.m.val_SI ** 2 * (i.vol.val_SI + o.vol.val_SI))
)

Expand All @@ -503,6 +505,6 @@ def calc_parameters(self):
else:
self.td_log.val = (
(self.ttd_l.val - self.ttd_u.val)
/ np.log(self.ttd_l.val / self.ttd_u.val)
/ math.log(self.ttd_l.val / self.ttd_u.val)
)
self.kA.val = -self.Q.val / self.td_log.val
6 changes: 3 additions & 3 deletions src/tespy/components/heat_exchangers/parabolic_trough.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ParabolicTrough(SimpleHeatExchanger):
>>> from tespy.components import Sink, Source, ParabolicTrough
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> import numpy as np
>>> import math
>>> import shutil
>>> nw = Network()
>>> nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False)
Expand All @@ -182,7 +182,7 @@ class ParabolicTrough(SimpleHeatExchanger):
:math:`\text{m}^2` for simplicity reasons.
>>> aoi = 20
>>> E = 1000 * np.cos(aoi / 180 * np.pi)
>>> E = 1000 * math.cos(aoi / 180 * math.pi)
>>> pt.set_attr(pr=1, aoi=aoi, doc=1,
... Tamb=20, A=1, eta_opt=0.816, c_1=0.0622, c_2=0.00023, E=E,
... iam_1=-1.59e-3, iam_2=9.77e-5)
Expand All @@ -208,7 +208,7 @@ class ParabolicTrough(SimpleHeatExchanger):
well as the heat transfer at different operating points.
>>> aoi = 30
>>> E = 800 * np.cos(aoi / 180 * np.pi)
>>> E = 800 * math.cos(aoi / 180 * math.pi)
>>> pt.set_attr(A=pt.A.val, aoi=aoi, Q=None, E=E)
>>> inc.set_attr(T=150)
>>> outg.set_attr(T=None)
Expand Down
27 changes: 15 additions & 12 deletions src/tespy/components/heat_exchangers/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SPDX-License-Identifier: MIT
"""

import math
import warnings

import numpy as np
Expand Down Expand Up @@ -347,13 +348,13 @@ def darcy_func(self):
v_i = i.calc_vol(T0=i.T.val_SI)
v_o = o.calc_vol(T0=o.T.val_SI)

Re = 4 * abs(i.m.val_SI) / (np.pi * self.D.val * (visc_i + visc_o) / 2)
Re = 4 * abs(i.m.val_SI) / (math.pi * self.D.val * (visc_i + visc_o) / 2)

return (
(i.p.val_SI - o.p.val_SI)
- 8 * abs(i.m.val_SI) * i.m.val_SI * (v_i + v_o)
/ 2 * self.L.val * dff(Re, self.ks.val, self.D.val)
/ (np.pi ** 2 * self.D.val ** 5)
/ (math.pi ** 2 * self.D.val ** 5)
)

def darcy_func_doc(self, label):
Expand Down Expand Up @@ -450,10 +451,12 @@ def hazen_williams_func(self):
v_o = o.calc_vol(T0=o.T.val_SI)

return (
(i.p.val_SI - o.p.val_SI) * np.sign(i.m.val_SI) -
(10.67 * abs(i.m.val_SI) ** 1.852 * self.L.val /
(self.ks_HW.val ** 1.852 * self.D.val ** 4.871)) *
(9.81 * ((v_i + v_o) / 2) ** 0.852))
math.copysign(i.p.val_SI - o.p.val_SI, i.m.val_SI)
- (
10.67 * abs(i.m.val_SI) ** 1.852 * self.L.val /
(self.ks_HW.val ** 1.852 * self.D.val ** 4.871)
) * (9.81 * ((v_i + v_o) / 2) ** 0.852)
)

def hazen_williams_func_doc(self, label):
r"""
Expand Down Expand Up @@ -545,9 +548,9 @@ def kA_group_func(self):
if (ttd_1 / ttd_2) < 0:
td_log = (ttd_2 + ttd_1) / 2
elif ttd_1 > ttd_2:
td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
td_log = (ttd_1 - ttd_2) / math.log(ttd_1 / ttd_2)
elif ttd_1 < ttd_2:
td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
td_log = (ttd_2 - ttd_1) / math.log(ttd_2 / ttd_1)
else:
# both values are equal
td_log = ttd_2
Expand Down Expand Up @@ -659,9 +662,9 @@ def kA_char_group_func(self):
if (ttd_1 / ttd_2) < 0:
td_log = (ttd_2 + ttd_1) / 2
elif ttd_1 > ttd_2:
td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
td_log = (ttd_1 - ttd_2) / math.log(ttd_1 / ttd_2)
elif ttd_1 < ttd_2:
td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
td_log = (ttd_2 - ttd_1) / math.log(ttd_2 / ttd_1)
else:
# both values are equal
td_log = ttd_2
Expand Down Expand Up @@ -895,9 +898,9 @@ def calc_parameters(self):
if (ttd_1 / ttd_2) < 0:
td_log = np.nan
if ttd_1 > ttd_2:
td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
td_log = (ttd_1 - ttd_2) / math.log(ttd_1 / ttd_2)
elif ttd_1 < ttd_2:
td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
td_log = (ttd_2 - ttd_1) / math.log(ttd_2 / ttd_1)
else:
# both values are equal
td_log = ttd_1
Expand Down
1 change: 0 additions & 1 deletion src/tespy/components/nodes/drum.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class Drum(DropletSeparator):
>>> from tespy.tools.characteristics import CharLine
>>> from tespy.tools.characteristics import load_default_char as ldc
>>> import shutil
>>> import numpy as np
>>> nw = Network(T_unit='C', p_unit='bar', h_unit='kJ / kg', iterinfo=False)
>>> fa = Source('feed ammonia')
>>> amb_in = Source('air inlet')
Expand Down
1 change: 0 additions & 1 deletion src/tespy/components/nodes/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class Merge(NodeBase):
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> import shutil
>>> import numpy as np
>>> nw = Network(p_unit='bar', iterinfo=False)
>>> so1 = Source('source1')
>>> so2 = Source('source2')
Expand Down
4 changes: 1 addition & 3 deletions src/tespy/components/nodes/separator.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ class Separator(NodeBase):
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> import shutil
>>> import numpy as np
>>> nw = Network(p_unit='bar', T_unit='C',
... iterinfo=False)
>>> nw = Network(p_unit='bar', T_unit='C', iterinfo=False)
>>> so = Source('source')
>>> si1 = Sink('sink1')
>>> si2 = Sink('sink2')
Expand Down
4 changes: 1 addition & 3 deletions src/tespy/components/nodes/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class Splitter(NodeBase):
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> import shutil
>>> import numpy as np
>>> nw = Network(p_unit='bar', T_unit='C',
... iterinfo=False)
>>> nw = Network(p_unit='bar', T_unit='C', iterinfo=False)
>>> so = Source('source')
>>> si1 = Sink('sink1')
>>> si2 = Sink('sink2')
Expand Down
1 change: 0 additions & 1 deletion src/tespy/components/turbomachinery/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class Pump(Turbomachine):
>>> from tespy.connections import Connection
>>> from tespy.networks import Network
>>> from tespy.tools.characteristics import CharLine
>>> import numpy as np
>>> import shutil
>>> nw = Network(p_unit='bar', T_unit='C', h_unit='kJ / kg', v_unit='l / s',
... iterinfo=False)
Expand Down
8 changes: 3 additions & 5 deletions src/tespy/components/turbomachinery/turbine.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,11 @@ def cone_func(self):
vol = i.calc_vol(T0=i.T.val_SI)
return (
- i.m.val_SI + i.m.design * i.p.val_SI / i.p.design
* np.sqrt(i.p.design * i.vol.design / (i.p.val_SI * vol))
* np.sqrt(
abs(
* (i.p.design * i.vol.design / (i.p.val_SI * vol)) ** 0.5
* abs(
(1 - (o.p.val_SI / i.p.val_SI) ** ((n + 1) / n))
/ (1 - (self.pr.design) ** ((n + 1) / n))
)
)
) ** 0.5
)

def cone_func_doc(self, label):
Expand Down
1 change: 0 additions & 1 deletion src/tespy/connections/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Bus:
>>> from tespy.connections import Connection, Ref, Bus
>>> from tespy.networks import Network
>>> from tespy.tools import CharLine
>>> import numpy as np
>>> import shutil
>>> nw = Network(p_unit='bar', T_unit='C', p_range=[0.5, 10], iterinfo=False)
>>> amb = Source('ambient')
Expand Down
1 change: 0 additions & 1 deletion src/tespy/connections/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class Connection:
>>> from tespy.components import Sink, Source
>>> from tespy.connections import Connection, Ref
>>> import numpy as np
>>> so1 = Source('source1')
>>> so2 = Source('source2')
>>> si1 = Sink('sink1')
Expand Down
Loading

0 comments on commit 3df1909

Please sign in to comment.