Skip to content

Commit 9a329ed

Browse files
committed
Merge branch 'dev'
2 parents 064858f + 51f9194 commit 9a329ed

File tree

14 files changed

+105
-31
lines changed

14 files changed

+105
-31
lines changed

docs/conf.py

+1
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@
148148
r'https://doi.org/20.500.12738/6561', # 08.01.2023: does not resolve anymore
149149
r'https://doi.org/10.1021/ie4033999', # 28.02.2023: does not resolve anymore for some reason
150150
r'https://doi.org/10.1002/bbpc.19900940121', # 13.03.2023 ...?
151+
r' http://www.coolprop.org/fluid_properties/Incompressibles.html', # 02.12.2023 ...?
151152
]

docs/whats_new.rst

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ What's New
33

44
Discover noteable new features and improvements in each release
55

6+
.. include:: whats_new/v0-7-1.rst
67
.. include:: whats_new/v0-7-0.rst
78
.. include:: whats_new/v0-6-3.rst
89
.. include:: whats_new/v0-6-2.rst

docs/whats_new/v0-7-1.rst

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
v0.7.1 - Newton's Nature (December, 2, 2023)
2+
++++++++++++++++++++++++++++++++++++++++++++
3+
4+
Bug Fixes
5+
#########
6+
- Several bugs introduced by the restructuring of the package in version 0.7.0
7+
have been fixed:
8+
9+
- `PR #451 <https://github.com/oemof/tespy/pull/451>`__
10+
- `PR #453 <https://github.com/oemof/tespy/pull/453>`__
11+
12+
Contributors
13+
############
14+
- Francesco Witte (`@fwitte <https://github.com/fwitte>`__)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exclude = ["docs/_build"]
2525

2626
[project]
2727
name = "tespy"
28-
version = "0.7.1"
28+
version = "0.7.1.post1"
2929
description = "Thermal Engineering Systems in Python (TESPy)"
3030
readme = "README.rst"
3131
authors = [

src/tespy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

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

88
# tespy data and connections import
99
from . import connections # noqa: F401

src/tespy/components/heat_exchangers/desuperheater.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,6 @@ def saturated_gas_deriv(self, increment_filter, k):
239239
"""
240240
o = self.outl[0]
241241
if self.is_variable(o.p):
242-
self.jacobian[k, o.p.J_col] = -dh_mix_dpQ(o, 1, o.fluid_data)
242+
self.jacobian[k, o.p.J_col] = -dh_mix_dpQ(o.p.val_SI, 1, o.fluid_data)
243243
if self.is_variable(o.h):
244244
self.jacobian[k, o.h.J_col] = 1

src/tespy/components/nodes/drum.py

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def outlets():
170170
return ['out1', 'out2']
171171

172172
def get_mandatory_constraints(self):
173+
num_mass_eq = 1
173174
if self.inl[1].m == self.outl[0].m:
174175
num_mass_eq = 0
175176
return {
@@ -217,6 +218,7 @@ def mass_flow_func(self):
217218
if self.inl[1].m == self.outl[0].m:
218219
return self.inl[0].m.val_SI - self.outl[1].m.val_SI
219220
else:
221+
res = 0
220222
for i in self.inl:
221223
res += i.m.val_SI
222224
for o in self.outl:

src/tespy/networks/network.py

+15
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,21 @@ def initialise(self):
847847
self.num_conn_vars = 0
848848
self.variables_dict = {}
849849

850+
# in multiprocessing copies are made of all connections
851+
# the mass flow branches and fluid branches hold references to
852+
# connections from the original run (where network.checked is False)
853+
# The assignment of variable spaces etc. is however made on the
854+
# copies of the connections which do not correspond to the mass flow
855+
# branches and fluid branches anymore. So the topology simplification
856+
# does not actually apply to the copied network, therefore the
857+
# branches have to be recreated for this case. We can detect that by
858+
# checking whether a network holds a massflow branch with some
859+
# connections and compare that with the connection object actually
860+
# present in the network
861+
first_conn = self.massflow_branches[0]["connections"][0]
862+
if self.conns.loc[first_conn.label, "object"] != first_conn:
863+
self.create_massflow_and_fluid_branches()
864+
self.create_fluid_wrapper_branches()
850865
self.propagate_fluid_wrappers()
851866
self.presolve_massflow_topology()
852867
self.presolve_fluid_topology()

src/tespy/tools/fluid_properties/wrappers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
from tespy.tools.global_vars import ERR
1717

1818

19+
class SerializableAbstractState(CP.AbstractState):
20+
21+
def __init__(self, back_end, fluid_name):
22+
self.back_end = back_end
23+
self.fluid_name = fluid_name
24+
25+
def __reduce__(self):
26+
return (self.__class__, (self.back_end, self.fluid_name))
27+
28+
1929
class FluidPropertyWrapper:
2030

2131
def __init__(self, fluid, back_end=None) -> None:
@@ -112,7 +122,7 @@ def __init__(self, fluid, back_end=None) -> None:
112122
back_end = "HEOS"
113123

114124
super().__init__(fluid, back_end)
115-
self.AS = CP.CoolProp.AbstractState(self.back_end, self.fluid)
125+
self.AS = SerializableAbstractState(self.back_end, self.fluid)
116126
self._set_constants()
117127

118128
def _set_constants(self):

tests/test_components/test_combustion.py

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import shutil
1414

15-
import numpy as np
16-
1715
from tespy.components import CombustionChamber
1816
from tespy.components import CombustionEngine
1917
from tespy.components import DiabaticCombustionChamber

tests/test_components/test_drum.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8
2+
3+
"""Module for testing components of type merge.
4+
This file is part of project TESPy (github.com/oemof/tespy). It's copyrighted
5+
by the contributors recorded in the version control history of the file,
6+
available from its original location
7+
tests/test_components/test_merge.py
8+
SPDX-License-Identifier: MIT
9+
"""
10+
from pytest import approx
11+
from pytest import fixture
12+
13+
from tespy.components import Drum
14+
from tespy.components import SimpleHeatExchanger
15+
from tespy.components import Sink
16+
from tespy.components import Source
17+
from tespy.components import Splitter
18+
from tespy.connections import Connection
19+
from tespy.networks import Network
20+
21+
22+
@fixture()
23+
def drum_network_setup():
24+
nw = Network(T_unit="C", p_unit="bar")
25+
dr = Drum("drum")
26+
so = Source("liquid")
27+
si = Sink("vapor")
28+
c1 = Connection(so, "out1", dr, "in1", label="1")
29+
c2 = Connection(dr, "out2", si, "in1", label="2")
30+
nw.add_conns(c1, c2)
31+
c1.set_attr(fluid={"R290": 1}, m=10, Td_bp=-10, T=50)
32+
yield nw
33+
34+
35+
def test_drum_with_blowdown(drum_network_setup):
36+
nw = drum_network_setup
37+
sp = Splitter("blowdown splitter")
38+
si = Sink("blowdown sink")
39+
eva = SimpleHeatExchanger("evaporator")
40+
dr = nw.get_comp("drum")
41+
c3 = Connection(dr, "out1", sp, "in1", label="3")
42+
c4 = Connection(sp, "out1", si, "in1", label="4")
43+
c5 = Connection(sp, "out2", eva, "in1", label="5")
44+
c6 = Connection(eva, "out1", dr, "in2", label="6")
45+
46+
c6.set_attr(x=0.7, m=15)
47+
48+
nw.add_conns(c3, c4, c5, c6)
49+
50+
nw.solve("design")
51+
52+
assert 0.72728 == approx(c4.m.val_SI)

tests/test_components/test_merge.py

-14
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,3 @@ def test_two_fluid_setup(self):
119119
target = c1.m.val_SI
120120
msg = f"Target value for mass flow at connection 3 is {target}"
121121
assert c6.m.val_SI == approx(target), msg
122-
123-
124-
test = TestMerge()
125-
test.setup_method()
126-
test.test_single_fluid_at_outlet()
127-
test.setup_method()
128-
test.test_massflows_from_two_fluid_fractions()
129-
130-
131-
test2 = TestCyclicMerging()
132-
test2.setup_method()
133-
test2.test_single_fluid_setup()
134-
test2.setup_method()
135-
test2.test_two_fluid_setup()

tests/test_components/test_reactors.py

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import shutil
1414

15-
import numpy as np
16-
1715
from tespy.components import Sink
1816
from tespy.components import Source
1917
from tespy.components import WaterElectrolyzer

tutorial/advanced/optimization_example.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from tespy.components import SimpleHeatExchanger
1111
from tespy.components import Merge
1212
from tespy.components import Splitter
13-
from tespy.components import Valve
1413
from tespy.components import Pump
1514
from tespy.components import Turbine
1615
from tespy.connections import Bus
@@ -82,10 +81,7 @@ def __init__(self):
8281
c32 = Connection(fwh1, "out1", pu3, "in1", label="32")
8382
c33 = Connection(pu3, "out1", me, "in2", label="33")
8483

85-
self.nw.add_conns(
86-
c21, c22, c23, c24,
87-
c31, c32, c33
88-
)
84+
self.nw.add_conns(c21, c22, c23, c24, c31, c32, c33)
8985

9086
# cooling water
9187
c41 = Connection(cwi, "out1", con, "in2", label="41")
@@ -108,8 +104,6 @@ def __init__(self):
108104

109105
self.nw.add_busses(self.power, self.heat)
110106

111-
# parametrization
112-
# components
113107
hpt.set_attr(eta_s=0.9)
114108
mpt.set_attr(eta_s=0.9)
115109
lpt.set_attr(eta_s=0.9)
@@ -129,13 +123,16 @@ def __init__(self):
129123
c2.set_attr(p=20)
130124
c4.set_attr(p=3)
131125

132-
c41.set_attr(T=20, p=3, fluid={"water": 1})
133-
c42.set_attr(T=28)
126+
c41.set_attr(T=20, p=3, fluid={"INCOMP::Water": 1})
127+
c42.set_attr(T=28, p0=3, h0=100)
134128

129+
# parametrization
130+
# components
135131
self.nw.solve("design")
136132
self.stable = "_stable"
137133
self.nw.save(self.stable)
138134
self.solved = True
135+
self.nw.print_results()
139136

140137
# %%[sec_2]
141138

0 commit comments

Comments
 (0)