-
Notifications
You must be signed in to change notification settings - Fork 89
/
rankine.py
executable file
·237 lines (191 loc) · 6.29 KB
/
rankine.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
# %%[sec_1]
from tespy.networks import Network
# create a network object with R134a as fluid
my_plant = Network()
my_plant.set_attr(T_unit='C', p_unit='bar', h_unit='kJ / kg')
# %%[sec_2]
from tespy.components import (
CycleCloser, Pump, Condenser, Turbine, SimpleHeatExchanger, Source, Sink
)
cc = CycleCloser('cycle closer')
sg = SimpleHeatExchanger('steam generator')
mc = Condenser('main condenser')
tu = Turbine('steam turbine')
fp = Pump('feed pump')
cwso = Source('cooling water source')
cwsi = Sink('cooling water sink')
from tespy.connections import Connection
c1 = Connection(cc, 'out1', tu, 'in1', label='1')
c2 = Connection(tu, 'out1', mc, 'in1', label='2')
c3 = Connection(mc, 'out1', fp, 'in1', label='3')
c4 = Connection(fp, 'out1', sg, 'in1', label='4')
c0 = Connection(sg, 'out1', cc, 'in1', label='0')
my_plant.add_conns(c1, c2, c3, c4, c0)
c11 = Connection(cwso, 'out1', mc, 'in2', label='11')
c12 = Connection(mc, 'out2', cwsi, 'in1', label='12')
my_plant.add_conns(c11, c12)
# %%[sec_3]
mc.set_attr(pr1=1, pr2=0.98)
sg.set_attr(pr=0.9)
tu.set_attr(eta_s=0.9)
fp.set_attr(eta_s=0.75)
c11.set_attr(T=20, p=1.2, fluid={'water': 1})
c12.set_attr(T=30)
c1.set_attr(T=600, p=150, m=10, fluid={'water': 1})
c2.set_attr(p=0.1)
my_plant.solve(mode='design')
my_plant.print_results()
# %%[sec_4]
mc.set_attr(ttd_u=4)
c2.set_attr(p=None)
my_plant.solve(mode='design')
my_plant.print_results()
# %%[sec_5]
# Adding feature to plot the T-s Diagram using fluprodia library
# Importing necessary library
import matplotlib.pyplot as plt
import numpy as np
from fluprodia import FluidPropertyDiagram
# Initial Setup
diagram = FluidPropertyDiagram('water')
diagram.set_unit_system(T='°C', p='bar', h='kJ/kg')
# Storing the model result in the dictionary
result_dict = {}
result_dict.update(
{cp.label: cp.get_plotting_data()[1] for cp in my_plant.comps['object']
if cp.get_plotting_data() is not None})
# Iterate over the results obtained from TESPy simulation
for key, data in result_dict.items():
# Calculate individual isolines for T-s diagram
result_dict[key]['datapoints'] = diagram.calc_individual_isoline(**data)
# Create a figure and axis for plotting T-s diagram
fig, ax = plt.subplots(1, figsize=(20, 10))
isolines = {
'Q': np.linspace(0, 1, 2),
'p': np.array([1, 2, 5, 10, 20, 50, 100, 300]),
'v': np.array([]),
'h': np.arange(500, 3501, 500)
}
# Set isolines for T-s diagram
diagram.set_isolines(**isolines)
diagram.calc_isolines()
# Draw isolines on the T-s diagram
diagram.draw_isolines(fig, ax, 'Ts', x_min=0, x_max=7500, y_min=0, y_max=650)
# Adjust the font size of the isoline labels
for text in ax.texts:
text.set_fontsize(10)
# Plot T-s curves for each component
for key in result_dict.keys():
datapoints = result_dict[key]['datapoints']
_ = ax.plot(datapoints['s'], datapoints['T'], color='#ff0000', linewidth=2)
_ = ax.scatter(datapoints['s'][0], datapoints['T'][0], color='#ff0000')
# Set labels and title for the T-s diagram
ax.set_xlabel('Entropy, s in J/kgK', fontsize=16)
ax.set_ylabel('Temperature, T in °C', fontsize=16)
ax.set_title('T-s Diagram of Rankine Cycle', fontsize=20)
# Set font size for the x-axis and y-axis ticks
ax.tick_params(axis='x', labelsize=12)
ax.tick_params(axis='y', labelsize=12)
plt.tight_layout()
# Save the T-s diagram plot as an SVG file
fig.savefig('rankine_ts_diagram.svg')
# %%[sec_6]
from tespy.connections import Bus
powergen = Bus("electrical power output")
powergen.add_comps(
{"comp": tu, "char": 0.97, "base": "component"},
{"comp": fp, "char": 0.97, "base": "bus"},
)
my_plant.add_busses(powergen)
my_plant.solve(mode='design')
my_plant.print_results()
# %%[sec_7]
powergen.set_attr(P=-10e6)
c1.set_attr(m=None)
my_plant.solve(mode='design')
my_plant.print_results()
# %%[sec_8]
my_plant.set_attr(iterinfo=False)
c1.set_attr(m=20)
powergen.set_attr(P=None)
# make text reasonably sized
plt.rc('font', **{'size': 18})
data = {
'T_livesteam': np.linspace(450, 750, 7),
'T_cooling': np.linspace(15, 45, 7),
'p_livesteam': np.linspace(75, 225, 7)
}
eta = {
'T_livesteam': [],
'T_cooling': [],
'p_livesteam': []
}
power = {
'T_livesteam': [],
'T_cooling': [],
'p_livesteam': []
}
for T in data['T_livesteam']:
c1.set_attr(T=T)
my_plant.solve('design')
eta['T_livesteam'] += [abs(powergen.P.val) / sg.Q.val * 100]
power['T_livesteam'] += [abs(powergen.P.val) / 1e6]
# reset to base temperature
c1.set_attr(T=600)
for T in data['T_cooling']:
c12.set_attr(T=T)
c11.set_attr(T=T - 10)
my_plant.solve('design')
eta['T_cooling'] += [abs(powergen.P.val) / sg.Q.val * 100]
power['T_cooling'] += [abs(powergen.P.val) / 1e6]
# reset to base temperature
c12.set_attr(T=30)
c11.set_attr(T=20)
for p in data['p_livesteam']:
c1.set_attr(p=p)
my_plant.solve('design')
eta['p_livesteam'] += [abs(powergen.P.val) / sg.Q.val * 100]
power['p_livesteam'] += [abs(powergen.P.val) / 1e6]
# reset to base pressure
c1.set_attr(p=150)
fig, ax = plt.subplots(2, 3, figsize=(16, 8), sharex='col', sharey='row')
ax = ax.flatten()
[a.grid() for a in ax]
i = 0
for key in data:
ax[i].scatter(data[key], eta[key], s=100, color="#1f567d")
ax[i + 3].scatter(data[key], power[key], s=100, color="#18a999")
i += 1
ax[0].set_ylabel('Efficiency in %')
ax[3].set_ylabel('Power in MW')
ax[3].set_xlabel('Live steam temperature in °C')
ax[4].set_xlabel('Feed water temperature in °C')
ax[5].set_xlabel('Live steam pressure in bar')
plt.tight_layout()
fig.savefig('rankine_parametric-darkmode.svg')
plt.close()
# %%[sec_9]
mc.set_attr(design=["ttd_u"], offdesign=["kA"])
c11.set_attr(offdesign=["v"])
c12.set_attr(design=["T"])
c1.set_attr(design=["p"])
tu.set_attr(offdesign=["cone"])
# %%[sec_10]
my_plant.solve("design")
my_plant.save("rankine_design")
# %%[sec_11]
partload_efficiency = []
partload_m_range = np.linspace(20, 10, 11)
for m in partload_m_range:
c1.set_attr(m=m)
my_plant.solve("offdesign", design_path="rankine_design")
partload_efficiency += [abs(powergen.P.val) / sg.Q.val * 100]
fig, ax = plt.subplots(1, figsize=(16, 8))
ax.grid()
ax.scatter(partload_m_range, partload_efficiency, s=100, color="#1f567d")
ax.set_xlabel("Mass flow in kg/s")
ax.set_ylabel("Plant electrical efficiency in %")
plt.tight_layout()
fig.savefig('rankine_partload.svg')
plt.close()
# %%[sec_12]