/
test_merge.py
121 lines (88 loc) · 3.82 KB
/
test_merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8
"""Module for testing components of type merge.
This file is part of project TESPy (github.com/oemof/tespy). It's copyrighted
by the contributors recorded in the version control history of the file,
available from its original location
tests/test_components/test_merge.py
SPDX-License-Identifier: MIT
"""
from pytest import approx
from tespy.components import Merge
from tespy.components import SimpleHeatExchanger
from tespy.components import Sink
from tespy.components import Source
from tespy.components import Splitter
from tespy.connections import Connection
from tespy.networks import Network
class TestMerge:
def setup_method(self):
self.nwk = Network(T_unit="C", p_unit="bar", h_unit="kJ / kg")
so1 = Source("Source1")
so2 = Source("Source2")
me = Merge("Merge")
si = Sink("Sink")
c1 = Connection(so1, "out1", me, "in1", label="1")
c2 = Connection(so2, "out1", me, "in2", label="2")
c3 = Connection(me, "out1", si, "in1", label="3")
self.nwk.add_conns(c1, c2, c3)
def test_single_fluid_at_outlet(self):
c1, c2, c3 = self.nwk.get_conn(["1", "2", "3"])
c1.set_attr(m=5, p=10, h=200)
c2.set_attr(m=5, h=200)
c3.set_attr(fluid={"water": 1})
self.nwk.solve("design")
self.nwk._convergence_check()
target = c1.m.val_SI + c2.m.val_SI
msg = f"Target value for mass flow at connection 3 must be {target}."
assert c3.m.val_SI == approx(target), msg
def test_massflows_from_two_fluid_fractions(self):
c1, c2, c3 = self.nwk.get_conn(["1", "2", "3"])
c1.set_attr(m=5, p=10, h=200, fluid={"N2": 1})
c2.set_attr(h=200, fluid={"O2": 1})
c3.set_attr(fluid={"N2": 0.3, "O2": 0.7})
self.nwk.solve("design")
self.nwk._convergence_check()
target = c1.m.val / c3.fluid.val["N2"]
msg = f"Target value for mass flow at connection 3 is {target}"
assert c3.m.val_SI == approx(target), msg
class TestCyclicMerging:
"""
Testing issue raised in https://github.com/oemof/tespy/issues/424
"""
def setup_method(self):
self.nwk = Network(T_unit="C", p_unit="bar", h_unit="kJ / kg")
source = Source("source1")
merge = Merge("merge")
component1 = SimpleHeatExchanger("comp1", pr=1)
splitter = Splitter("splitter")
component2 = SimpleHeatExchanger("comp2")
sink = Sink("sink")
c1 = Connection(source, "out1", merge, "in1", label="1")
c2 = Connection(merge, "out1", component1, "in1", label="2")
c3 = Connection(component1, "out1", splitter, "in1", label="3")
c4 = Connection(splitter, "out1", component2, "in1", label="4")
c5 = Connection(component2, "out1", merge, "in2", label="5")
c6 = Connection(splitter, "out2", sink, "in1", label="6")
self.nwk.add_conns(c1, c2, c3, c4, c5, c6)
def test_single_fluid_setup(self):
c1, c3, c4, c5, c6 = self.nwk.get_conn(["1", "3", "4", "5", "6"])
c1.set_attr(p=1, h=200, m=10, fluid={"R134a": 1})
c3.set_attr(h=180)
c4.set_attr(m=1)
c5.set_attr(h=170)
self.nwk.solve("design")
self.nwk._convergence_check()
target = c1.m.val_SI
msg = f"Target value for mass flow at connection 3 is {target}"
assert c6.m.val_SI == approx(target), msg
def test_two_fluid_setup(self):
c1, c3, c4, c5, c6 = self.nwk.get_conn(["1", "3", "4", "5", "6"])
c1.set_attr(p=1, h=200, m=10, fluid={"R134a": 1})
c3.set_attr(h=180)
c4.set_attr(m=1)
c5.set_attr(h=170)
self.nwk.solve("design")
self.nwk._convergence_check()
target = c1.m.val_SI
msg = f"Target value for mass flow at connection 3 is {target}"
assert c6.m.val_SI == approx(target), msg