/
test_busses.py
250 lines (210 loc) · 9.94 KB
/
test_busses.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# -*- coding: utf-8
"""Module for testing busses.
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_busses.py
SPDX-License-Identifier: MIT
"""
import shutil
import numpy as np
from tespy.components.basics import sink
from tespy.components.basics import source
from tespy.components.combustion import combustion_chamber
from tespy.components.turbomachinery import compressor
from tespy.components.turbomachinery import turbine
from tespy.connections import bus
from tespy.connections import connection
from tespy.networks.networks import network
from tespy.tools.characteristics import char_line
class TestBusses:
def setup(self):
"""Set up the model."""
# %% network setup
fluid_list = ['Ar', 'N2', 'O2', 'CO2', 'CH4', 'H2O']
self.nw = network(
fluids=fluid_list, p_unit='bar', T_unit='C',
p_range=[0.5, 20], T_range=[10, 2000])
# %% components
amb = source('ambient')
sf = source('fuel')
cc = combustion_chamber('combustion')
cp = compressor('compressor')
gt = turbine('turbine')
fg = sink('flue gas outlet')
# %% connections
amb_cp = connection(amb, 'out1', cp, 'in1', label='ambient air flow')
cp_cc = connection(cp, 'out1', cc, 'in1')
sf_cc = connection(sf, 'out1', cc, 'in2')
cc_gt = connection(cc, 'out1', gt, 'in1')
gt_fg = connection(gt, 'out1', fg, 'in1')
self.nw.add_conns(amb_cp, cp_cc, sf_cc, cc_gt, gt_fg)
# %% component parameters
cc.set_attr(lamb=3)
cp.set_attr(eta_s=0.9, pr=15)
gt.set_attr(eta_s=0.9)
# %% connection parameters
amb_cp.set_attr(
T=20, p=1, m=100,
fluid={'Ar': 0.0129, 'N2': 0.7553, 'H2O': 0, 'CH4': 0,
'CO2': 0.0004, 'O2': 0.2314})
sf_cc.set_attr(
T=20, fluid={'CO2': 0.04, 'Ar': 0, 'N2': 0,
'O2': 0, 'H2O': 0, 'CH4': 0.96})
gt_fg.set_attr(p=1)
# motor efficiency
x = np.array(
[0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55,
0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15,
1.2, 10])
y = np.array(
[0.01, 0.3148, 0.5346, 0.6843, 0.7835, 0.8477, 0.8885, 0.9145,
0.9318, 0.9443, 0.9546, 0.9638, 0.9724, 0.9806, 0.9878, 0.9938,
0.9982, 0.999, 0.9995, 0.9999, 1, 0.9977, 0.9947, 0.9909, 0.9853,
0.9644]) * 0.975
self.motor_bus_based = char_line(x=x, y=y)
self.motor_comp_based = char_line(x=x, y=1 / y)
# generator efficiency
x = np.array(
[0.100, 0.345, 0.359, 0.383, 0.410, 0.432, 0.451, 0.504, 0.541,
0.600, 0.684, 0.805, 1.000, 1.700, 10])
y = np.array(
[0.976, 0.989, 0.990, 0.991, 0.992, 0.993, 0.994, 0.995, 0.996,
0.997, 0.998, 0.999, 1.000, 0.999, 0.99]) * 0.975
self.generator = char_line(x=x, y=y)
power_bus_total = bus('total power output')
power_bus_total.add_comps(
{'comp': cp, 'char': self.motor_bus_based, 'base': 'bus'},
{'comp': gt, 'char': self.generator})
thermal_input = bus('thermal input')
thermal_input.add_comps({'comp': cc})
compressor_power_comp = bus('compressor power input')
compressor_power_comp.add_comps(
{'comp': cp, 'char': self.motor_comp_based})
compressor_power_bus = bus('compressor power input bus based')
compressor_power_bus.add_comps(
{'comp': cp, 'char': self.motor_bus_based, 'base': 'bus'})
self.nw.add_busses(
power_bus_total, thermal_input, compressor_power_comp,
compressor_power_bus)
# %% solving
self.nw.solve('design')
self.nw.save('tmp')
def test_model(self):
"""Test the bus functionalities in a gas turbine model."""
tpo = self.nw.busses['total power output']
ti = self.nw.busses['thermal input']
cpi = self.nw.busses['compressor power input']
cpibb = self.nw.busses['compressor power input bus based']
cp = self.nw.components['compressor']
gt = self.nw.components['turbine']
cc = self.nw.components['combustion']
# test results of design case
eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6)
eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6)
msg = (
'The efficiency value of the compressor on the bus ' + tpo.label +
' (' + str(eta_cp_tpo) + ') must be identical to the efficiency '
'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').')
assert eta_cp_tpo == eta_cpi, msg
P_cp_tpo = cp.calc_bus_value(tpo)
eta_cp_tpo = cp.calc_bus_efficiency(tpo)
P_cp = round(P_cp_tpo * eta_cp_tpo, 0)
msg = (
'The compressor power must be ' + str(round(cp.P.val, 0)) + ' on '
'the bus ' + tpo.label + ' but is ' + str(P_cp) + ').')
assert round(cp.P.val, 0) == P_cp, msg
P_cp_tpo = round(
cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0)
P_cp_cpi = round(
cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0)
P_cp_cpibb = round(
cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0)
msg = (
'The busses\' component power value for the compressor on bus ' +
tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the '
'component power on all other busses. Bus ' + cpi.label + ' (' +
str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' +
str(P_cp_cpibb) + ').')
assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg
eta_gt_tpo = gt.calc_bus_efficiency(tpo)
msg = (
'The efficiency value of the turbine on the bus ' + tpo.label +
' (' + str(eta_gt_tpo) + ') must be equal to 0.975.')
assert eta_gt_tpo == 0.975, msg
eta_ti = cc.calc_bus_efficiency(ti)
msg = (
'The efficiency value of the combustion chamber on the bus ' +
ti.label + ' (' + str(eta_ti) + ') must be equal to 1.0.')
assert eta_ti == 1.0, msg
# test partload for bus functions
# first test in identical conditions
self.nw.connections['ambient air flow'].set_attr(m=None)
P_design = cpibb.P.val
cpibb.set_attr(P=P_design)
self.nw.solve('offdesign', design_path='tmp')
eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6)
eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6)
msg = (
'The efficiency value of the compressor on the bus ' + tpo.label +
' (' + str(eta_cp_tpo) + ') must be identical to the efficiency '
'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').')
assert eta_cp_tpo == eta_cpi, msg
eta_gt_tpo = gt.calc_bus_efficiency(tpo)
msg = (
'The efficiency value of the turbine on the bus ' + tpo.label +
' (' + str(eta_gt_tpo) + ') must be equal to 0.975.')
assert eta_gt_tpo == 0.975, msg
P_cp_tpo = round(
cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0)
P_cp_cpi = round(
cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0)
P_cp_cpibb = round(
cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0)
msg = (
'The busses\' component power value for the compressor on bus ' +
tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the '
'component power on all other busses. Bus ' + cpi.label + ' (' +
str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' +
str(P_cp_cpibb) + ').')
assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg
# 60 % load
load = 0.6
cpibb.set_attr(P=P_design * load)
self.nw.solve('offdesign', design_path='tmp')
eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6)
eta_cp_char = self.motor_bus_based.evaluate(load)
msg = (
'The efficiency value of the compressor on the bus ' + tpo.label +
' (' + str(eta_cp_tpo) + ') must be identical to the efficiency '
'on the characteristic line (' + str(eta_cp_char) + ').')
assert eta_cp_tpo == eta_cp_char, msg
load_frac = round(
cp.calc_bus_value(tpo) / tpo.comps.loc[cp, 'P_ref'], 6)
msg = (
'The load fraction value of the compressor on the bus ' +
tpo.label + ' (' + str(load_frac) + ') must be identical to the '
'load fraction value on the bus ' + cpibb.label + ' (' +
str(load) + ').')
assert load == load_frac, msg
eta_cpi = round(1 / cp.calc_bus_efficiency(cpi), 6)
eta_cp_tpo = round(cp.calc_bus_efficiency(tpo), 6)
msg = (
'The efficiency value of the compressor on the bus ' + tpo.label +
' (' + str(eta_cp_tpo) + ') must be higher than the efficiency '
'on the bus ' + cpi.label + ' (' + str(eta_cpi) + ').')
assert eta_cp_tpo > eta_cpi, msg
P_cp_tpo = round(
cp.calc_bus_value(tpo) * cp.calc_bus_efficiency(tpo), 0)
P_cp_cpi = round(
cp.calc_bus_value(cpi) / cp.calc_bus_efficiency(cpi), 0)
P_cp_cpibb = round(
cp.calc_bus_value(cpibb) * cp.calc_bus_efficiency(cpibb), 0)
msg = (
'The busses\' component power value for the compressor on bus ' +
tpo.label + ' (' + str(P_cp_tpo) + ') must be equal to the '
'component power on all other busses. Bus ' + cpi.label + ' (' +
str(P_cp_cpi) + ') and bus ' + cpibb.label + ' (' +
str(P_cp_cpibb) + ').')
assert P_cp_tpo == P_cp_cpi and P_cp_tpo == P_cp_cpibb, msg
shutil.rmtree('tmp', ignore_errors=True)