tespy 0.3.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3116 @@
1
+ # -*- coding: utf-8
2
+
3
+ """Module for components of type heat exchanger.
4
+
5
+ Components in this module:
6
+
7
+ - :func:`tespy.components.heat_exchangers.condenser`
8
+ - :func:`tespy.components.heat_exchangers.desuperheater`
9
+ - :func:`tespy.components.heat_exchangers.heat_exchanger`
10
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple`
11
+ - :func:`tespy.components.heat_exchangers.parabolic_trough`
12
+ - :func:`tespy.components.heat_exchangers.solar_collector`
13
+
14
+
15
+ This file is part of project TESPy (github.com/oemof/tespy). It's copyrighted
16
+ by the contributors recorded in the version control history of the file,
17
+ available from its original location tespy/components/heat_exchangers.py
18
+
19
+ SPDX-License-Identifier: MIT
20
+ """
21
+
22
+ import logging
23
+ import warnings
24
+
25
+ import numpy as np
26
+
27
+ from tespy.components.components import component
28
+ from tespy.tools.data_containers import dc_cc
29
+ from tespy.tools.data_containers import dc_cp
30
+ from tespy.tools.data_containers import dc_gcp
31
+ from tespy.tools.data_containers import dc_simple
32
+ from tespy.tools.fluid_properties import T_bp_p
33
+ from tespy.tools.fluid_properties import T_mix_ph
34
+ from tespy.tools.fluid_properties import dh_mix_dpQ
35
+ from tespy.tools.fluid_properties import h_mix_pQ
36
+ from tespy.tools.fluid_properties import h_mix_pT
37
+ from tespy.tools.fluid_properties import s_mix_ph
38
+ from tespy.tools.fluid_properties import v_mix_ph
39
+ from tespy.tools.fluid_properties import visc_mix_ph
40
+ from tespy.tools.global_vars import err
41
+ from tespy.tools.helpers import lamb
42
+
43
+ # %%
44
+
45
+
46
+ class heat_exchanger_simple(component):
47
+ r"""
48
+ A basic heat exchanger representing a heat source or heat sink.
49
+
50
+ The component heat_exchanger_simple is the parent class for the components
51
+ solar_collector and pipe (of module piping).
52
+
53
+ Equations
54
+
55
+ **mandatory equations**
56
+
57
+ - :func:`tespy.components.components.component.fluid_func`
58
+ - :func:`tespy.components.components.component.mass_flow_func`
59
+
60
+ **optional equations**
61
+
62
+ .. math::
63
+
64
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) -
65
+ \dot{Q}
66
+
67
+ 0 = p_{in} \cdot pr - p_{out}
68
+
69
+ - :func:`tespy.components.components.component.zeta_func`
70
+
71
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.darcy_func`
72
+ or :func:`tespy.components.heat_exchangers.heat_exchanger_simple.hw_func`
73
+
74
+ **additional equations**
75
+
76
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.additional_equations`
77
+
78
+ Inlets/Outlets
79
+
80
+ - in1
81
+ - out1
82
+
83
+ Image
84
+
85
+ .. image:: _images/pipe.svg
86
+ :scale: 100 %
87
+ :alt: alternative text
88
+ :align: center
89
+
90
+ Parameters
91
+ ----------
92
+ label : str
93
+ The label of the component.
94
+
95
+ design : list
96
+ List containing design parameters (stated as String).
97
+
98
+ offdesign : list
99
+ List containing offdesign parameters (stated as String).
100
+
101
+ design_path: str
102
+ Path to the components design case.
103
+
104
+ local_offdesign : boolean
105
+ Treat this component in offdesign mode in a design calculation.
106
+
107
+ local_design : boolean
108
+ Treat this component in design mode in an offdesign calculation.
109
+
110
+ char_warnings: boolean
111
+ Ignore warnings on default characteristics usage for this component.
112
+
113
+ printout: boolean
114
+ Include this component in the network's results printout.
115
+
116
+ Q : str/float/tespy.tools.data_containers.dc_cp
117
+ Heat transfer, :math:`Q/\text{W}`.
118
+
119
+ pr : str/float/tespy.tools.data_containers.dc_cp
120
+ Outlet to inlet pressure ratio, :math:`pr/1`.
121
+
122
+ zeta : str/float/tespy.tools.data_containers.dc_cp
123
+ Geometry independent friction coefficient,
124
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
125
+
126
+ D : str/float/tespy.tools.data_containers.dc_cp
127
+ Diameter of the pipes, :math:`D/\text{m}`.
128
+
129
+ L : str/float/tespy.tools.data_containers.dc_cp
130
+ Length of the pipes, :math:`L/\text{m}`.
131
+
132
+ ks : str/float/tespy.tools.data_containers.dc_cp
133
+ Pipe's roughness, :math:`ks/\text{m}` for darcy friction,
134
+ :math:`ks/\text{1}` for hazen-williams equation.
135
+
136
+ hydro_group : str/tespy.tools.data_containers.dc_gcp
137
+ Parametergroup for pressure drop calculation based on pipes dimensions.
138
+ Choose 'HW' for hazen-williams equation, else darcy friction factor is
139
+ used.
140
+
141
+ kA : str/float/tespy.tools.data_containers.dc_cp
142
+ Area independent heat transition coefficient,
143
+ :math:`kA/\frac{\text{W}}{\text{K}}`.
144
+
145
+ kA_char : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
146
+ Characteristic line for heat transfer coefficient.
147
+
148
+ Tamb : float/tespy.tools.data_containers.dc_simple
149
+ Ambient temperature, provide parameter in network's temperature unit.
150
+
151
+ kA_group : tespy.tools.data_containers.dc_gcp
152
+ Parametergroup for heat transfer calculation from ambient temperature
153
+ and area independent heat transfer coefficient kA.
154
+
155
+ Example
156
+ -------
157
+ The heat_exchanger_simple can be used as a sink or source of heat. This
158
+ component does not simulate the secondary side of the heat exchanger. It
159
+ is possible to calculate the pressure ratio with the Darcy-Weisbach
160
+ equation or in case of liquid water use the Hazen-Williams equation.
161
+ Also, given ambient temperature and the heat transfer coeffiecient, it is
162
+ possible to predict heat transfer.
163
+
164
+ >>> from tespy.components import sink, source, heat_exchanger_simple
165
+ >>> from tespy.connections import connection
166
+ >>> from tespy.networks import network
167
+ >>> import shutil
168
+ >>> fluids = ['N2']
169
+ >>> nw = network(fluids=fluids)
170
+ >>> nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False)
171
+ >>> so1 = source('source 1')
172
+ >>> si1 = sink('sink 1')
173
+ >>> heat_sink = heat_exchanger_simple('heat sink')
174
+ >>> heat_sink.component()
175
+ 'heat exchanger simple'
176
+ >>> heat_sink.set_attr(Tamb=10, pr=0.95, design=['pr'],
177
+ ... offdesign=['zeta', 'kA_char'])
178
+ >>> inc = connection(so1, 'out1', heat_sink, 'in1')
179
+ >>> outg = connection(heat_sink, 'out1', si1, 'in1')
180
+ >>> nw.add_conns(inc, outg)
181
+
182
+ It is possible to determine the amount of heat transferred when the fluid
183
+ enters the heat sink at a temperature of 200 °C and is cooled down to
184
+ 150 °C. Given an ambient temperature of 10 °C this also determines the heat
185
+ transfer coefficient to the ambient. Assuming a characteristic function
186
+ for the heat transfer coefficient we can predict the heat transferred at
187
+ variable flow rates.
188
+
189
+ >>> inc.set_attr(fluid={'N2': 1}, m=1, T=200, p=5)
190
+ >>> outg.set_attr(T=150, design=['T'])
191
+ >>> nw.solve('design')
192
+ >>> nw.save('tmp')
193
+ >>> round(heat_sink.Q.val, 0)
194
+ -52581.0
195
+ >>> round(heat_sink.kA.val, 0)
196
+ 321.0
197
+ >>> inc.set_attr(m=1.25)
198
+ >>> nw.solve('offdesign', design_path='tmp')
199
+ >>> round(heat_sink.Q.val, 0)
200
+ -56599.0
201
+ >>> round(outg.T.val, 1)
202
+ 156.9
203
+ >>> inc.set_attr(m=0.75)
204
+ >>> nw.solve('offdesign', design_path='tmp')
205
+ >>> round(heat_sink.Q.val, 1)
206
+ -47275.8
207
+ >>> round(outg.T.val, 1)
208
+ 140.0
209
+ >>> shutil.rmtree('./tmp', ignore_errors=True)
210
+ """
211
+
212
+ @staticmethod
213
+ def component():
214
+ return 'heat exchanger simple'
215
+
216
+ @staticmethod
217
+ def attr():
218
+ return {
219
+ 'Q': dc_cp(),
220
+ 'pr': dc_cp(min_val=1e-4, max_val=1), 'zeta': dc_cp(min_val=0),
221
+ 'D': dc_cp(min_val=1e-2, max_val=2, d=1e-4),
222
+ 'L': dc_cp(min_val=1e-1, d=1e-3),
223
+ 'ks': dc_cp(val=1e-4, min_val=1e-7, max_val=1e-3, d=1e-8),
224
+ 'kA': dc_cp(min_val=0, d=1),
225
+ 'kA_char': dc_cc(param='m'), 'Tamb': dc_simple(),
226
+ 'SQ1': dc_simple(), 'SQ2': dc_simple(), 'Sirr': dc_simple(),
227
+ 'hydro_group': dc_gcp(), 'kA_group': dc_gcp(),
228
+ 'kA_char_group': dc_gcp()
229
+ }
230
+
231
+ @staticmethod
232
+ def inlets():
233
+ return ['in1']
234
+
235
+ @staticmethod
236
+ def outlets():
237
+ return ['out1']
238
+
239
+ def comp_init(self, nw):
240
+
241
+ component.comp_init(self, nw)
242
+
243
+ self.Tamb.val_SI = ((self.Tamb.val + nw.T[nw.T_unit][0]) *
244
+ nw.T[nw.T_unit][1])
245
+
246
+ # parameters for hydro group
247
+ self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])
248
+
249
+ is_set = self.L.is_set and self.ks.is_set and self.D.is_set
250
+
251
+ if is_set:
252
+ self.hydro_group.set_attr(is_set=True)
253
+ if self.hydro_group.method == 'HW':
254
+ method = 'Hazen-Williams equation'
255
+ else:
256
+ method = 'darcy friction factor'
257
+ msg = (
258
+ 'Pressure loss calculation from pipe dimensions method is set '
259
+ 'to ' + method + '.')
260
+ logging.debug(msg)
261
+
262
+ elif self.hydro_group.is_set:
263
+ msg = (
264
+ 'All parameters of the component group have to be specified! '
265
+ 'This component group uses the following parameters: L, ks, D '
266
+ 'at ' + self.label + '. Group will be set to False.')
267
+ logging.warning(msg)
268
+ self.hydro_group.set_attr(is_set=False)
269
+ else:
270
+ self.hydro_group.set_attr(is_set=False)
271
+
272
+ # parameters for kA group
273
+ self.kA_group.set_attr(elements=[self.kA, self.Tamb])
274
+
275
+ is_set = self.kA.is_set and self.Tamb.is_set
276
+
277
+ if is_set:
278
+ self.kA_group.set_attr(is_set=True)
279
+ elif self.kA_group.is_set:
280
+ msg = (
281
+ 'All parameters of the component group have to be specified! '
282
+ 'This component group uses the following parameters: kA, Tamb '
283
+ 'at ' + self.label + '. Group will be set to False.')
284
+ logging.warning(msg)
285
+ self.kA_group.set_attr(is_set=False)
286
+ else:
287
+ self.kA_group.set_attr(is_set=False)
288
+
289
+ # parameters for kA_char group
290
+ self.kA_char_group.set_attr(elements=[self.kA_char, self.Tamb])
291
+
292
+ is_set = self.kA_char.is_set and self.Tamb.is_set
293
+
294
+ if is_set:
295
+ self.kA_char_group.set_attr(is_set=True)
296
+ elif self.kA_char_group.is_set:
297
+ msg = (
298
+ 'All parameters of the component group have to be specified! '
299
+ 'This component group uses the following parameters: kA_char, '
300
+ 'Tamb at ' + self.label + '. Group will be set to False.')
301
+ logging.warning(msg)
302
+ self.kA_char_group.set_attr(is_set=False)
303
+ else:
304
+ self.kA_char_group.set_attr(is_set=False)
305
+
306
+ # number of mandatroy equations for
307
+ # fluid balance: num_fl
308
+ # mass flow: 1
309
+ self.num_eq = self.num_nw_fluids + 1
310
+ for var in [self.Q, self.pr, self.zeta, self.hydro_group,
311
+ self.kA_group, self.kA_char_group]:
312
+ if var.is_set is True:
313
+ self.num_eq += 1
314
+
315
+ if self.kA.is_set:
316
+ msg = (
317
+ 'The usage of the parameter kA has changed for offdesign '
318
+ 'calculation. Specifying kA will keep a constant value for kA '
319
+ 'in the calculation. If you want to use the value adaption of '
320
+ 'kA by the characteristic line, please use kA_char as '
321
+ 'parameter instead (occurred at ' + self.label + '). This '
322
+ 'warning will disappear in TESPy version 0.3.2.')
323
+ warnings.warn(msg, FutureWarning, stacklevel=2)
324
+
325
+ self.jacobian = np.zeros((
326
+ self.num_eq,
327
+ self.num_i + self.num_o + self.num_vars,
328
+ self.num_nw_vars))
329
+
330
+ self.residual = np.zeros(self.num_eq)
331
+ pos = self.num_nw_fluids
332
+ self.jacobian[0:pos] = self.fluid_deriv()
333
+ self.jacobian[pos:pos + 1] = self.mass_flow_deriv()
334
+
335
+ def equations(self):
336
+ r"""Calculate residual vector with results of equations."""
337
+ k = 0
338
+ ######################################################################
339
+ # equations for fluid balance
340
+ self.residual[k:k + self.num_nw_fluids] = self.fluid_func()
341
+ k += self.num_nw_fluids
342
+
343
+ ######################################################################
344
+ # equations for mass flow balance
345
+ self.residual[k] = self.mass_flow_func()
346
+ k += 1
347
+
348
+ ######################################################################
349
+ # equations for specified heta transfer
350
+ if self.Q.is_set:
351
+ self.residual[k] = self.inl[0].m.val_SI * (
352
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI) - self.Q.val
353
+ k += 1
354
+
355
+ ######################################################################
356
+ # equations for specified pressure ratio
357
+ if self.pr.is_set:
358
+ self.residual[k] = (
359
+ self.inl[0].p.val_SI * self.pr.val - self.outl[0].p.val_SI)
360
+ k += 1
361
+
362
+ ######################################################################
363
+ # equations for specified zeta
364
+ if self.zeta.is_set:
365
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
366
+ self.residual[k] = self.zeta_func(zeta='zeta')
367
+ k += 1
368
+
369
+ ######################################################################
370
+ # equation for specified hydro-group paremeters
371
+ if self.hydro_group.is_set:
372
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
373
+ # hazen williams equation
374
+ if self.hydro_group.method == 'HW':
375
+ func = self.hw_func
376
+ # darcy friction factor
377
+ else:
378
+ func = self.darcy_func
379
+ self.residual[k] = func()
380
+ k += 1
381
+
382
+ ######################################################################
383
+ # additional equations
384
+ self.additional_equations(k)
385
+
386
+ def additional_equations(self, k):
387
+ r"""
388
+ Calculate results of additional equations.
389
+
390
+ Equations
391
+
392
+ **optional equations**
393
+
394
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.kA_func`
395
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.kA_char_func`
396
+ """
397
+ ######################################################################
398
+ # equation for specified kA_group paremeters
399
+ if self.kA_group.is_set:
400
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
401
+ self.residual[k] = self.kA_func()
402
+ k += 1
403
+
404
+ ######################################################################
405
+ # equation for specified kA_char_group paremeters
406
+ if self.kA_char_group.is_set:
407
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
408
+ self.residual[k] = self.kA_char_func()
409
+ k += 1
410
+
411
+ def derivatives(self, increment_filter):
412
+ r"""Calculate partial derivatives for given equations."""
413
+ ######################################################################
414
+ # derivatives fluid and mass balance are static
415
+ k = self.num_nw_fluids + 1
416
+
417
+ ######################################################################
418
+ # derivatives for specified heat transfer
419
+ if self.Q.is_set:
420
+ self.jacobian[k, 0, 0] = (
421
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
422
+ self.jacobian[k, 0, 2] = -self.inl[0].m.val_SI
423
+ self.jacobian[k, 1, 2] = self.inl[0].m.val_SI
424
+ # custom variable Q
425
+ if self.Q.is_var:
426
+ self.jacobian[k, 2 + self.Q.var_pos, 0] = -1
427
+ k += 1
428
+
429
+ ######################################################################
430
+ # derivatives for specified pressure ratio
431
+ if self.pr.is_set:
432
+ self.jacobian[k, 0, 1] = self.pr.val
433
+ self.jacobian[k, 1, 1] = -1
434
+ # custom variable pr
435
+ if self.pr.is_var:
436
+ self.jacobian[k, 2 + self.pr.var_pos, 0] = (
437
+ self.inl[0].p.val_SI)
438
+ k += 1
439
+
440
+ ######################################################################
441
+ # derivatives for specified zeta
442
+ if self.zeta.is_set:
443
+ f = self.zeta_func
444
+ if not increment_filter[0, 0]:
445
+ self.jacobian[k, 0, 0] = self.numeric_deriv(
446
+ f, 'm', 0, zeta='zeta')
447
+ if not increment_filter[0, 2]:
448
+ self.jacobian[k, 0, 1] = self.numeric_deriv(
449
+ f, 'p', 0, zeta='zeta')
450
+ if not increment_filter[0, 2]:
451
+ self.jacobian[k, 0, 2] = self.numeric_deriv(
452
+ f, 'h', 0, zeta='zeta')
453
+ if not increment_filter[1, 1]:
454
+ self.jacobian[k, 1, 1] = self.numeric_deriv(
455
+ f, 'p', 1, zeta='zeta')
456
+ if not increment_filter[1, 2]:
457
+ self.jacobian[k, 1, 2] = self.numeric_deriv(
458
+ f, 'h', 1, zeta='zeta')
459
+ # custom variable zeta
460
+ if self.zeta.is_var:
461
+ self.jacobian[k, 2 + self.zeta.var_pos, 0] = (
462
+ self.numeric_deriv(f, 'zeta', 2, zeta='zeta'))
463
+ k += 1
464
+
465
+ ######################################################################
466
+ # derivatives for specified hydro-group parameters
467
+ if self.hydro_group.is_set:
468
+ # hazen williams equation
469
+ if self.hydro_group.method == 'HW':
470
+ func = self.hw_func
471
+ # darcy friction factor
472
+ else:
473
+ func = self.darcy_func
474
+
475
+ if not increment_filter[0, 0]:
476
+ self.jacobian[k, 0, 0] = self.numeric_deriv(func, 'm', 0)
477
+ if not increment_filter[0, 1]:
478
+ self.jacobian[k, 0, 1] = self.numeric_deriv(func, 'p', 0)
479
+ if not increment_filter[0, 2]:
480
+ self.jacobian[k, 0, 2] = self.numeric_deriv(func, 'h', 0)
481
+ if not increment_filter[1, 1]:
482
+ self.jacobian[k, 1, 1] = self.numeric_deriv(func, 'p', 1)
483
+ if not increment_filter[1, 2]:
484
+ self.jacobian[k, 1, 2] = self.numeric_deriv(func, 'h', 1)
485
+ # custom variables of hydro group
486
+ for var in self.hydro_group.elements:
487
+ if var.is_var:
488
+ self.jacobian[k, 2 + var.var_pos, 0] = (
489
+ self.numeric_deriv(func, self.vars[var], 2))
490
+ k += 1
491
+
492
+ ######################################################################
493
+ # derivatives for additional equations
494
+ self.additional_derivatives(increment_filter, k)
495
+
496
+ def additional_derivatives(self, increment_filter, k):
497
+ r"""Calculategit partial derivatives for given additional equations."""
498
+ ######################################################################
499
+ # derivatives for specified kA_group paremeters
500
+ if self.kA_group.is_set:
501
+ f = self.kA_func
502
+ self.jacobian[k, 0, 0] = (
503
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
504
+ if not increment_filter[0, 1]:
505
+ self.jacobian[k, 0, 1] = self.numeric_deriv(f, 'p', 0)
506
+ if not increment_filter[0, 2]:
507
+ self.jacobian[k, 0, 2] = self.numeric_deriv(f, 'h', 0)
508
+ if not increment_filter[1, 1]:
509
+ self.jacobian[k, 1, 1] = self.numeric_deriv(f, 'p', 1)
510
+ if not increment_filter[1, 2]:
511
+ self.jacobian[k, 1, 2] = self.numeric_deriv(f, 'h', 1)
512
+ if self.kA.is_var:
513
+ self.jacobian[k, 2 + self.kA.var_pos, 0] = (
514
+ self.numeric_deriv(f, self.vars[self.kA], 2))
515
+ k += 1
516
+
517
+ ######################################################################
518
+ # derivatives for specified kA_char_group paremeters
519
+
520
+ if self.kA_char_group.is_set:
521
+ f = self.kA_char_func
522
+ if not increment_filter[0, 0]:
523
+ self.jacobian[k, 0, 0] = self.numeric_deriv(f, 'm', 0)
524
+ if not increment_filter[0, 1]:
525
+ self.jacobian[k, 0, 1] = self.numeric_deriv(f, 'p', 0)
526
+ if not increment_filter[0, 2]:
527
+ self.jacobian[k, 0, 2] = self.numeric_deriv(f, 'h', 0)
528
+ if not increment_filter[1, 1]:
529
+ self.jacobian[k, 1, 1] = self.numeric_deriv(f, 'p', 1)
530
+ if not increment_filter[1, 2]:
531
+ self.jacobian[k, 1, 2] = self.numeric_deriv(f, 'h', 1)
532
+ k += 1
533
+
534
+ def darcy_func(self):
535
+ r"""
536
+ Equation for pressure drop calculation from darcy friction factor.
537
+
538
+ Returns
539
+ -------
540
+ res : float
541
+ Residual value of equation.
542
+
543
+ .. math::
544
+
545
+ Re = \frac{4 \cdot |\dot{m}_{in}|}{\pi \cdot D \cdot
546
+ \frac{\eta_{in}+\eta_{out}}{2}}\\
547
+
548
+ 0 = p_{in} - p_{out} - \frac{8 \cdot |\dot{m}_{in}| \cdot
549
+ \dot{m}_{in} \cdot \frac{v_{in}+v_{out}}{2} \cdot L \cdot
550
+ \lambda\left(Re, ks, D\right)}{\pi^2 \cdot D^5}\\
551
+
552
+ \eta: \text{dynamic viscosity}\\
553
+ v: \text{specific volume}\\
554
+ \lambda: \text{darcy friction factor}
555
+ """
556
+ i, o = self.inl[0].to_flow(), self.outl[0].to_flow()
557
+
558
+ if abs(i[0]) < 1e-4:
559
+ return i[1] - o[1]
560
+
561
+ visc_i = visc_mix_ph(i, T0=self.inl[0].T.val_SI)
562
+ visc_o = visc_mix_ph(o, T0=self.outl[0].T.val_SI)
563
+ v_i = v_mix_ph(i, T0=self.inl[0].T.val_SI)
564
+ v_o = v_mix_ph(o, T0=self.outl[0].T.val_SI)
565
+
566
+ re = 4 * abs(i[0]) / (np.pi * self.D.val * (visc_i + visc_o) / 2)
567
+
568
+ return ((i[1] - o[1]) - 8 * abs(i[0]) * i[0] * (v_i + v_o) / 2 *
569
+ self.L.val * lamb(re, self.ks.val, self.D.val) /
570
+ (np.pi ** 2 * self.D.val ** 5))
571
+
572
+ def hw_func(self):
573
+ r"""
574
+ Equation for pressure drop calculation from Hazen-Williams equation.
575
+
576
+ Returns
577
+ -------
578
+ res : float
579
+ Residual value of equation.
580
+
581
+ .. math::
582
+
583
+ res = \left(p_{in} - p_{out} \right) \cdot \left(-1\right)^i -
584
+ \frac{10.67 \cdot |\dot{m}_{in}| ^ {1.852}
585
+ \cdot L}{ks^{1.852} \cdot D^{4.871}} \cdot g \cdot
586
+ \left(\frac{v_{in} + v_{out}}{2}\right)^{0.852}
587
+
588
+ i = \begin{cases}
589
+ 0 & \dot{m}_{in} \geq 0\\
590
+ 1 & \dot{m}_{in} < 0
591
+ \end{cases}
592
+
593
+ Note
594
+ ----
595
+ Gravity g is set to :math:`9.81 \frac{m}{s^2}`
596
+ """
597
+ i, o = self.inl[0].to_flow(), self.outl[0].to_flow()
598
+
599
+ if abs(i[0]) < 1e-4:
600
+ return i[1] - o[1]
601
+
602
+ v_i = v_mix_ph(i, T0=self.inl[0].T.val_SI)
603
+ v_o = v_mix_ph(o, T0=self.outl[0].T.val_SI)
604
+ flow_dir = np.sign(i[0])
605
+
606
+ return ((i[1] - o[1]) * flow_dir -
607
+ (10.67 * abs(i[0]) ** 1.852 * self.L.val /
608
+ (self.ks.val ** 1.852 * self.D.val ** 4.871)) *
609
+ (9.81 * ((v_i + v_o) / 2) ** 0.852))
610
+
611
+ def kA_func(self):
612
+ r"""
613
+ Calculate heat transfer from heat transfer coefficient.
614
+
615
+ Returns
616
+ -------
617
+ res : float
618
+ Residual value of equation.
619
+
620
+ .. math::
621
+
622
+ ttd_u = \begin{cases}
623
+ T_{in} - T_{amb} & \dot{m} \geq 0\\
624
+ T_{out} - T_{amb} & \dot{m} < 0
625
+ \end{cases}
626
+
627
+ ttd_l = \begin{cases}
628
+ T_{in} - T_{amb} & \dot{m} < 0\\
629
+ T_{out} - T_{amb} & \dot{m} \geq 0
630
+ \end{cases}
631
+
632
+ 0 = \dot{m}_{in} \cdot \left( h_{out} - h_{in}\right) +
633
+ kA \cdot \frac{ttd_u - ttd_l}
634
+ {\ln{\frac{ttd_u}{ttd_l}}}
635
+
636
+ T_{amb}: \text{ambient temperature}
637
+ """
638
+ i, o = self.inl[0].to_flow(), self.outl[0].to_flow()
639
+
640
+ ttd_1 = T_mix_ph(i, T0=self.inl[0].T.val_SI) - self.Tamb.val_SI
641
+ ttd_2 = T_mix_ph(o, T0=self.outl[0].T.val_SI) - self.Tamb.val_SI
642
+
643
+ if ttd_1 > ttd_2:
644
+ td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
645
+ elif ttd_1 < ttd_2:
646
+ td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
647
+ else:
648
+ td_log = 0
649
+
650
+ print(ttd_1, ttd_2)
651
+
652
+ return i[0] * (o[2] - i[2]) + self.kA.val * td_log
653
+
654
+ def kA_char_func(self):
655
+ r"""
656
+ Calculate heat transfer from heat transfer coefficient characteristic.
657
+
658
+ Returns
659
+ -------
660
+ res : float
661
+ Residual value of equation.
662
+
663
+ .. math::
664
+
665
+ ttd_u = \begin{cases}
666
+ T_{in} - T_{amb} & \dot{m} \geq 0\\
667
+ T_{out} - T_{amb} & \dot{m} < 0
668
+ \end{cases}
669
+
670
+ ttd_l = \begin{cases}
671
+ T_{in} - T_{amb} & \dot{m} < 0\\
672
+ T_{out} - T_{amb} & \dot{m} \geq 0
673
+ \end{cases}
674
+
675
+ 0 = \dot{m}_{in} \cdot \left( h_{out} - h_{in}\right) +
676
+ kA_{ref} \cdot f_{kA} \cdot \frac{ttd_u - ttd_l}
677
+ {\ln{\frac{ttd_u}{ttd_l}}}
678
+
679
+ f_{kA} = \frac{2}{1 + \frac{1}
680
+ {f\left(\frac{m_1}{m_{1,ref}}\right)}}
681
+
682
+ T_{amb}: \text{ambient temperature}
683
+
684
+ Note
685
+ ----
686
+ For standard function of f\ :subscript:`1` \ see module
687
+ :func:`tespy.data`.
688
+ """
689
+ i, o = self.inl[0].to_flow(), self.outl[0].to_flow()
690
+
691
+ ttd_1 = T_mix_ph(i, T0=self.inl[0].T.val_SI) - self.Tamb.val_SI
692
+ ttd_2 = T_mix_ph(o, T0=self.outl[0].T.val_SI) - self.Tamb.val_SI
693
+
694
+ if ttd_1 > ttd_2:
695
+ td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
696
+ elif ttd_1 < ttd_2:
697
+ td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
698
+ else:
699
+ td_log = 0
700
+
701
+ f = 1
702
+ if not np.isnan(self.inl[0].m.design):
703
+ if self.kA_char.param == 'm':
704
+ f = self.kA_char.func.evaluate(i[0] / self.inl[0].m.design)
705
+
706
+ fkA = 2 / (1 + 1 / f)
707
+
708
+ return i[0] * (o[2] - i[2]) + self.kA.design * fkA * td_log
709
+
710
+ def bus_func(self, bus):
711
+ r"""
712
+ Calculate the value of the bus function.
713
+
714
+ Parameters
715
+ ----------
716
+ bus : tespy.connections.bus
717
+ TESPy bus object.
718
+
719
+ Returns
720
+ -------
721
+ val : float
722
+ Value of energy transfer :math:`\dot{E}`. This value is passed to
723
+ :py:meth:`tespy.components.components.component.calc_bus_value`
724
+ for value manipulation according to the specified characteristic
725
+ line of the bus.
726
+
727
+ .. math::
728
+
729
+ \dot{E} = \dot{m}_{in} \cdot \left( h_{out} - h_{in} \right)
730
+ """
731
+ i = self.inl[0].to_flow()
732
+ o = self.outl[0].to_flow()
733
+ val = i[0] * (o[2] - i[2])
734
+
735
+ return val
736
+
737
+ def bus_deriv(self, bus):
738
+ r"""
739
+ Calculate partial derivatives of the bus function.
740
+
741
+ Parameters
742
+ ----------
743
+ bus : tespy.connections.bus
744
+ TESPy bus object.
745
+
746
+ Returns
747
+ -------
748
+ mat_deriv : ndarray
749
+ Matrix of partial derivatives.
750
+ """
751
+ deriv = np.zeros((1, 2, self.num_nw_vars))
752
+ f = self.calc_bus_value
753
+ deriv[0, 0, 0] = self.numeric_deriv(f, 'm', 0, bus=bus)
754
+ deriv[0, 0, 2] = self.numeric_deriv(f, 'h', 0, bus=bus)
755
+ deriv[0, 1, 2] = self.numeric_deriv(f, 'h', 1, bus=bus)
756
+ return deriv
757
+
758
+ def initialise_source(self, c, key):
759
+ r"""
760
+ Return a starting value for pressure and enthalpy the outlets.
761
+
762
+ Parameters
763
+ ----------
764
+ c : tespy.connections.connection
765
+ Connection to perform initialisation on.
766
+
767
+ key : str
768
+ Fluid property to retrieve.
769
+
770
+ Returns
771
+ -------
772
+ val : float
773
+ Starting value for pressure/enthalpy in SI units.
774
+
775
+ .. math::
776
+
777
+ val = \begin{cases}
778
+ \begin{cases}
779
+ 1 \cdot 10^5 \; \frac{\text{J}}{\text{kg}} & \dot{Q} < 0\\
780
+ 3 \cdot 10^5 \; \frac{\text{J}}{\text{kg}} & \dot{Q} = 0\\
781
+ 5 \cdot 10^5 \; \frac{\text{J}}{\text{kg}} & \dot{Q} > 0
782
+ \end{cases} & \text{key = 'h'}\\
783
+ \; \; \; \; 10^5 \text{Pa} & \text{key = 'p'}
784
+ \end{cases}
785
+
786
+ """
787
+ if key == 'p':
788
+ return 1e5
789
+ elif key == 'h':
790
+ if self.Q.val < 0 and self.Q.is_set:
791
+ return 1e5
792
+ elif self.Q.val > 0 and self.Q.is_set:
793
+ return 5e5
794
+ else:
795
+ return 3e5
796
+
797
+ def initialise_target(self, c, key):
798
+ r"""
799
+ Return a starting value for pressure and enthalpy the inlets.
800
+
801
+ Parameters
802
+ ----------
803
+ c : tespy.connections.connection
804
+ Connection to perform initialisation on.
805
+
806
+ key : str
807
+ Fluid property to retrieve.
808
+
809
+ Returns
810
+ -------
811
+ val : float
812
+ Starting value for pressure/enthalpy in SI units.
813
+
814
+ .. math::
815
+
816
+ val = \begin{cases}
817
+ 1 \cdot 10^5 & \text{key = 'p'}\\
818
+ \begin{cases}
819
+ 5 \cdot 10^5 & \dot{Q} < 0\\
820
+ 3 \cdot 10^5 & \dot{Q} = 0\\
821
+ 1 \cdot 10^5 & \dot{Q} > 0
822
+ \end{cases} & \text{key = 'h'}\\
823
+ \end{cases}
824
+ """
825
+ if key == 'p':
826
+ return 1e5
827
+ elif key == 'h':
828
+ if self.Q.val < 0 and self.Q.is_set:
829
+ return 5e5
830
+ elif self.Q.val > 0 and self.Q.is_set:
831
+ return 1e5
832
+ else:
833
+ return 3e5
834
+
835
+ def calc_parameters(self):
836
+ r"""Postprocessing parameter calculation."""
837
+ i = self.inl[0].to_flow()
838
+ o = self.outl[0].to_flow()
839
+ v_i = v_mix_ph(i, T0=self.inl[0].T.val_SI)
840
+ v_o = v_mix_ph(o, T0=self.outl[0].T.val_SI)
841
+
842
+ self.SQ1.val = i[0] * (s_mix_ph(o) - s_mix_ph(i))
843
+ self.Q.val = i[0] * (o[2] - i[2])
844
+ self.pr.val = o[1] / i[1]
845
+ self.zeta.val = ((i[1] - o[1]) * np.pi ** 2 /
846
+ (8 * i[0] ** 2 * (v_i + v_o) / 2))
847
+
848
+ if self.Tamb.is_set:
849
+ self.SQ2.val = -i[0] * (o[2] - i[2]) / self.Tamb.val_SI
850
+ self.Sirr.val = self.SQ1.val + self.SQ2.val
851
+
852
+ ttd_1 = T_mix_ph(i, T0=self.inl[0].T.val_SI) - self.Tamb.val_SI
853
+ ttd_2 = T_mix_ph(o, T0=self.outl[0].T.val_SI) - self.Tamb.val_SI
854
+
855
+ if ttd_1 > ttd_2:
856
+ td_log = (ttd_1 - ttd_2) / np.log(ttd_1 / ttd_2)
857
+ elif ttd_1 < ttd_2:
858
+ td_log = (ttd_2 - ttd_1) / np.log(ttd_2 / ttd_1)
859
+ else:
860
+ td_log = 0
861
+
862
+ self.kA.val = abs(i[0] * (o[2] - i[2]) / td_log)
863
+
864
+ if self.kA.is_set:
865
+ # get bound errors for kA characteristic line
866
+ if self.kA_char.param == 'm':
867
+ self.kA_char.func.get_bound_errors(i[0] / self.inl[0].m.design,
868
+ self.label)
869
+
870
+ self.check_parameter_bounds()
871
+
872
+ # %%
873
+
874
+
875
+ class parabolic_trough(heat_exchanger_simple):
876
+ r"""
877
+ The parabolic trough calculates heat output from irradiance.
878
+
879
+ Equations
880
+
881
+ **mandatory equations**
882
+
883
+ - :func:`tespy.components.components.component.fluid_func`
884
+ - :func:`tespy.components.components.component.mass_flow_func`
885
+
886
+ **optional equations**
887
+
888
+ .. math::
889
+
890
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) -
891
+ \dot{Q}
892
+
893
+ 0 = p_{in} \cdot pr - p_{out}
894
+
895
+ - :func:`tespy.components.components.component.zeta_func`
896
+
897
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.darcy_func`
898
+ or :func:`tespy.components.heat_exchangers.heat_exchanger_simple.hw_func`
899
+
900
+ **additional equations**
901
+
902
+ - :func:`tespy.components.heat_exchangers.parabolic_trough.additional_equations`
903
+
904
+ Inlets/Outlets
905
+
906
+ - in1
907
+ - out1
908
+
909
+ Image
910
+
911
+ .. image:: _images/parabolic_trough.svg
912
+ :scale: 100 %
913
+ :alt: alternative text
914
+ :align: center
915
+
916
+ Parameters
917
+ ----------
918
+ label : str
919
+ The label of the component.
920
+
921
+ design : list
922
+ List containing design parameters (stated as String).
923
+
924
+ offdesign : list
925
+ List containing offdesign parameters (stated as String).
926
+
927
+ design_path: str
928
+ Path to the components design case.
929
+
930
+ local_offdesign : boolean
931
+ Treat this component in offdesign mode in a design calculation.
932
+
933
+ local_design : boolean
934
+ Treat this component in design mode in an offdesign calculation.
935
+
936
+ char_warnings: boolean
937
+ Ignore warnings on default characteristics usage for this component.
938
+
939
+ printout: boolean
940
+ Include this component in the network's results printout.
941
+
942
+ Q : str/float/tespy.tools.data_containers.dc_cp
943
+ Heat transfer, :math:`Q/\text{W}`.
944
+
945
+ pr : str/float/tespy.tools.data_containers.dc_cp
946
+ Outlet to inlet pressure ratio, :math:`pr/1`.
947
+
948
+ zeta : str/float/tespy.tools.data_containers.dc_cp
949
+ Geometry independent friction coefficient,
950
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
951
+
952
+ D : str/float/tespy.tools.data_containers.dc_cp
953
+ Diameter of the absorber tube, :math:`D/\text{m}`.
954
+
955
+ L : str/float/tespy.tools.data_containers.dc_cp
956
+ Length of the absorber tube, :math:`L/\text{m}`.
957
+
958
+ ks : str/float/tespy.tools.data_containers.dc_cp
959
+ Tube's roughness, :math:`ks/\text{m}` for darcy friction,
960
+ :math:`ks/\text{1}` for hazen-williams equation.
961
+
962
+ hydro_group : str/tespy.tools.data_containers.dc_gcp
963
+ Parametergroup for pressure drop calculation based on pipes dimensions.
964
+ Choose 'HW' for hazen-williams equation, else darcy friction factor is
965
+ used.
966
+
967
+ E : str/float/tespy.tools.data_containers.dc_cp
968
+ Direct irradiance to tilted collector,
969
+ :math:`E/\frac{\text{W}}{\text{m}^2}`.
970
+
971
+ aoi : str/float/tespy.tools.data_containers.dc_cp
972
+ Angle of incidience, :math:`aoi/^\circ`.
973
+
974
+ doc : str/float/tespy.tools.data_containers.dc_cp
975
+ Degree of cleanliness (1: full absorption, 0: no absorption),
976
+ :math:`X`.
977
+
978
+ eta_opt : str/float/tespy.tools.data_containers.dc_cp
979
+ (constant) optical losses due to surface reflection,
980
+ :math:`\eta_{opt}`.
981
+
982
+ c_1 : str/float/tespy.tools.data_containers.dc_cp
983
+ Linear thermal loss key figure,
984
+ :math:`c_1/\frac{\text{W}}{\text{K} \cdot \text{m}^2}`.
985
+
986
+ c_2 : str/float/tespy.tools.data_containers.dc_cp
987
+ Quadratic thermal loss key figure,
988
+ :math:`c_2/\frac{\text{W}}{\text{K}^2 \cdot \text{m}^2}`.
989
+
990
+ iam_1 : str/float/tespy.tools.data_containers.dc_cp
991
+ Linear incidence angle modifier,
992
+ :math:`iam_1/\frac{1}{^\circ}`.
993
+
994
+ iam_2 : str/float/tespy.tools.data_containers.dc_cp
995
+ Quadratic incidence angle modifier,
996
+ :math:`iam_2/\left(\frac{1}{^\circ}\right)^2`.
997
+
998
+ A : str/float/tespy.tools.data_containers.dc_cp
999
+ Collector aperture surface area :math:`A/\text{m}^2`.
1000
+
1001
+ Tamb : float/tespy.tools.data_containers.dc_simple
1002
+ Ambient temperature, provide parameter in network's temperature unit.
1003
+
1004
+ energy_group : tespy.tools.data_containers.dc_gcp
1005
+ Parametergroup for energy balance of solarthermal collector.
1006
+
1007
+ Example
1008
+ -------
1009
+ A parabolic trough is installed using S800 as thermo-fluid.
1010
+ First, the operation conditions from :cite:`Janotte2014` are reproduced.
1011
+ Therefore, the direct normal irradiance :math:`\dot{E}_\mathrm{DNI}` is at
1012
+ 1000 :math:`\frac{\text{W}}{\text{m}^2}` at an angle of incidence
1013
+ :math:`aoi` at 20 °. This means, the direct irradiance to the parabolic
1014
+ trough :math:`E` is at
1015
+ :math:`\dot{E}_{DNI} \cdot cos\left(20^\circ\right)`.
1016
+
1017
+ >>> from tespy.components import sink, source, parabolic_trough
1018
+ >>> from tespy.connections import connection
1019
+ >>> from tespy.networks import network
1020
+ >>> import numpy as np
1021
+ >>> import shutil
1022
+ >>> fluids = ['INCOMP::S800']
1023
+ >>> nw = network(fluids=fluids)
1024
+ >>> nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False)
1025
+ >>> so = source('source')
1026
+ >>> si = sink('sink')
1027
+ >>> pt = parabolic_trough('parabolic trough collector')
1028
+ >>> pt.component()
1029
+ 'parabolic trough'
1030
+ >>> inc = connection(so, 'out1', pt, 'in1')
1031
+ >>> outg = connection(pt, 'out1', si, 'in1')
1032
+ >>> nw.add_conns(inc, outg)
1033
+
1034
+ The pressure ratio is at a constant level of 1. However, it is possible to
1035
+ specify the pressure losses from the absorber tube length, roughness and
1036
+ diameter, too. The aperture surface :math:`A` is specified to 1
1037
+ :math:`\text{m}^2` for simplicity reasons.
1038
+
1039
+ >>> aoi = 20
1040
+ >>> E = 1000 * np.cos(aoi / 180 * np.pi)
1041
+ >>> pt.set_attr(pr=1, aoi=aoi, doc=1,
1042
+ ... Tamb=20, A=1, eta_opt=0.816, c_1=0.0622, c_2=0.00023, E=E,
1043
+ ... iam_1=-1.59e-3, iam_2=9.77e-5)
1044
+ >>> inc.set_attr(fluid={'S800': 1}, T=220, p=2)
1045
+ >>> outg.set_attr(T=260)
1046
+ >>> nw.solve('design')
1047
+ >>> round(pt.Q.val, 0)
1048
+ 736.0
1049
+
1050
+ For example, it is possible to calculate the aperture area of the parabolic
1051
+ trough given the total heat production, outflow temperature and mass flow.
1052
+
1053
+ >>> pt.set_attr(A='var', Q=5e6, Tamb=25)
1054
+ >>> inc.set_attr(T=None)
1055
+ >>> outg.set_attr(T=350, m=20)
1056
+ >>> nw.solve('design')
1057
+ >>> round(inc.T.val)
1058
+ 229.0
1059
+ >>> round(pt.A.val)
1060
+ 6862.0
1061
+
1062
+ Given this design, it is possible to calculate the outlet temperature as
1063
+ well as the heat transfer at different operating points.
1064
+
1065
+ >>> aoi = 30
1066
+ >>> E = 800 * np.cos(aoi / 180 * np.pi)
1067
+ >>> pt.set_attr(A=pt.A.val, aoi=aoi, Q=None, E=E)
1068
+ >>> inc.set_attr(T=150)
1069
+ >>> outg.set_attr(T=None)
1070
+ >>> nw.solve('design')
1071
+ >>> round(outg.T.val)
1072
+ 244.0
1073
+ >>> round(pt.Q.val)
1074
+ 3603027.0
1075
+ """
1076
+
1077
+ @staticmethod
1078
+ def component():
1079
+ return 'parabolic trough'
1080
+
1081
+ @staticmethod
1082
+ def attr():
1083
+ return {
1084
+ 'Q': dc_cp(),
1085
+ 'pr': dc_cp(min_val=1e-4, max_val=1), 'zeta': dc_cp(min_val=0),
1086
+ 'D': dc_cp(min_val=1e-2, max_val=2, d=1e-4),
1087
+ 'L': dc_cp(min_val=1e-1, d=1e-3),
1088
+ 'ks': dc_cp(val=1e-4, min_val=1e-7, max_val=1e-4, d=1e-8),
1089
+ 'E': dc_cp(min_val=0), 'A': dc_cp(min_val=0),
1090
+ 'eta_opt': dc_cp(min_val=0, max_val=1),
1091
+ 'c_1': dc_cp(min_val=0), 'c_2': dc_cp(min_val=0),
1092
+ 'iam_1': dc_cp(), 'iam_2': dc_cp(),
1093
+ 'aoi': dc_cp(min_val=-90, max_val=90),
1094
+ 'doc': dc_cp(min_val=0, max_val=1),
1095
+ 'Tamb': dc_simple(),
1096
+ 'Q_loss': dc_cp(min_val=0), 'SQ': dc_simple(),
1097
+ 'hydro_group': dc_gcp(), 'energy_group': dc_gcp()
1098
+ }
1099
+
1100
+ def comp_init(self, nw):
1101
+
1102
+ component.comp_init(self, nw)
1103
+
1104
+ self.Tamb.val_SI = ((self.Tamb.val + nw.T[nw.T_unit][0]) *
1105
+ nw.T[nw.T_unit][1])
1106
+
1107
+ # parameters for hydro group
1108
+ self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])
1109
+
1110
+ is_set = True
1111
+ for e in self.hydro_group.elements:
1112
+ if e.is_set is False:
1113
+ is_set = False
1114
+
1115
+ if is_set is True:
1116
+ self.hydro_group.set_attr(is_set=True)
1117
+ elif self.hydro_group.is_set is True:
1118
+ msg = (
1119
+ 'All parameters of the component group have to be specified! '
1120
+ 'This component group uses the following parameters: L, ks, D '
1121
+ 'at ' + self.label + '. Group will be set to False.')
1122
+ logging.warning(msg)
1123
+ self.hydro_group.set_attr(is_set=False)
1124
+ else:
1125
+ self.hydro_group.set_attr(is_set=False)
1126
+
1127
+ # parameters for energy group
1128
+ self.energy_group.set_attr(
1129
+ elements=[
1130
+ self.E, self.eta_opt, self.aoi, self.doc, self.c_1, self.c_2,
1131
+ self.iam_1, self.iam_2, self.A, self.Tamb])
1132
+
1133
+ is_set = True
1134
+ for e in self.energy_group.elements:
1135
+ if e.is_set is False:
1136
+ is_set = False
1137
+
1138
+ if is_set is True:
1139
+ self.energy_group.set_attr(is_set=True)
1140
+ elif self.energy_group.is_set is True:
1141
+ msg = (
1142
+ 'All parameters of the component group have to be specified! '
1143
+ 'This component group uses the following parameters: E, '
1144
+ 'eta_opt, aoi, doc, c_1, c_2, iam_1, iam_2, A, Tamb at ' +
1145
+ self.label + '. Group will be set to False.')
1146
+ logging.warning(msg)
1147
+ self.energy_group.set_attr(is_set=False)
1148
+ else:
1149
+ self.energy_group.set_attr(is_set=False)
1150
+
1151
+ # number of mandatroy equations for
1152
+ # fluid balance: num_fl
1153
+ # mass flow: 1
1154
+ self.num_eq = self.num_nw_fluids + 1
1155
+ for var in [self.Q, self.pr, self.zeta, self.hydro_group,
1156
+ self.energy_group]:
1157
+ if var.is_set is True:
1158
+ self.num_eq += 1
1159
+
1160
+ self.jacobian = np.zeros((
1161
+ self.num_eq,
1162
+ self.num_i + self.num_o + self.num_vars,
1163
+ self.num_nw_vars))
1164
+
1165
+ self.residual = np.zeros(self.num_eq)
1166
+ pos = self.num_nw_fluids
1167
+ self.jacobian[0:pos] = self.fluid_deriv()
1168
+ self.jacobian[pos:pos + 1] = self.mass_flow_deriv()
1169
+
1170
+ def additional_equations(self, k):
1171
+ r"""
1172
+ Calculate results of additional equations.
1173
+
1174
+ Equations
1175
+
1176
+ **optional equations**
1177
+
1178
+ - :func:`tespy.components.heat_exchangers.parabolic_trough.energy_func`
1179
+ """
1180
+ ######################################################################
1181
+ # equation for specified energy-group paremeters
1182
+ if self.energy_group.is_set:
1183
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1184
+ self.residual[k] = self.energy_func()
1185
+
1186
+ def additional_derivatives(self, increment_filter, k):
1187
+ r"""Calculate partial derivatives for given additional equations."""
1188
+ ######################################################################
1189
+ # derivatives for specified energy-group paremeters
1190
+ if self.energy_group.is_set:
1191
+ f = self.energy_func
1192
+ self.jacobian[k, 0, 0] = (
1193
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
1194
+ if not increment_filter[0, 1]:
1195
+ self.jacobian[k, 0, 1] = self.numeric_deriv(f, 'p', 0)
1196
+ if not increment_filter[0, 2]:
1197
+ self.jacobian[k, 0, 2] = self.numeric_deriv(f, 'h', 0)
1198
+ if not increment_filter[1, 1]:
1199
+ self.jacobian[k, 1, 1] = self.numeric_deriv(f, 'p', 1)
1200
+ if not increment_filter[1, 2]:
1201
+ self.jacobian[k, 1, 2] = self.numeric_deriv(f, 'h', 1)
1202
+ # custom variables for the energy-group
1203
+ for var in self.energy_group.elements:
1204
+ if var == self.Tamb:
1205
+ continue
1206
+ if var.is_var:
1207
+ self.jacobian[k, 2 + var.var_pos, 0] = (
1208
+ self.numeric_deriv(f, self.vars[var], 2))
1209
+ k += 1
1210
+
1211
+ def energy_func(self):
1212
+ r"""
1213
+ Equation for solar collector energy balance.
1214
+
1215
+ Returns
1216
+ -------
1217
+ res : float
1218
+ Residual value of equation.
1219
+
1220
+ Note
1221
+ ----
1222
+ .. math::
1223
+
1224
+ \begin{split}
1225
+ T_m = & \frac{T_{out} + T_{in}}{2}\\
1226
+ iam = & 1 - iam_1 \cdot |aoi| - iam_2 \cdot aoi^2\\
1227
+ 0 = & \dot{m} \cdot \left( h_{out} - h_{in} \right)\\
1228
+ & - A \cdot \left[E \cdot \eta_{opt} \cdot doc^{1.5} \cdot
1229
+ iam \right. \\
1230
+ & \left. - c_1 \cdot \left(T_m - T_{amb} \right) -
1231
+ c_2 \cdot \left(T_m - T_{amb}\right)^2
1232
+ \vphantom{ \eta_{opt} \cdot doc^{1.5}} \right]
1233
+ \end{split}
1234
+
1235
+ Reference: :cite:`Janotte2014`.
1236
+ """
1237
+ i = self.inl[0].to_flow()
1238
+ o = self.outl[0].to_flow()
1239
+
1240
+ T_m = (T_mix_ph(i, T0=self.inl[0].T.val_SI) +
1241
+ T_mix_ph(o, T0=self.outl[0].T.val_SI)) / 2
1242
+
1243
+ iam = (
1244
+ 1 - self.iam_1.val * abs(self.aoi.val) -
1245
+ self.iam_2.val * self.aoi.val ** 2)
1246
+
1247
+ return (i[0] * (o[2] - i[2]) -
1248
+ self.A.val * (
1249
+ self.E.val * self.eta_opt.val * self.doc.val ** 1.5 * iam -
1250
+ (T_m - self.Tamb.val_SI) * self.c_1.val -
1251
+ self.c_2.val * (T_m - self.Tamb.val_SI) ** 2))
1252
+
1253
+ def calc_parameters(self):
1254
+ r"""Postprocessing parameter calculation."""
1255
+ i = self.inl[0].to_flow()
1256
+ o = self.outl[0].to_flow()
1257
+
1258
+ self.SQ.val = i[0] * (s_mix_ph(o) - s_mix_ph(i))
1259
+ self.Q.val = i[0] * (o[2] - i[2])
1260
+ self.pr.val = o[1] / i[1]
1261
+ self.zeta.val = ((i[1] - o[1]) * np.pi ** 2 /
1262
+ (8 * i[0] ** 2 * (v_mix_ph(i) + v_mix_ph(o)) / 2))
1263
+ if self.energy_group.is_set is True:
1264
+ self.Q_loss.val = self.E.val * self.A.val - self.Q.val
1265
+
1266
+ self.check_parameter_bounds()
1267
+
1268
+ # %%
1269
+
1270
+
1271
+ class solar_collector(heat_exchanger_simple):
1272
+ r"""
1273
+ The solar collector calculates heat output from irradiance.
1274
+
1275
+ Equations
1276
+
1277
+ **mandatory equations**
1278
+
1279
+ - :func:`tespy.components.components.component.fluid_func`
1280
+ - :func:`tespy.components.components.component.mass_flow_func`
1281
+
1282
+ **optional equations**
1283
+
1284
+ .. math::
1285
+
1286
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) -
1287
+ \dot{Q}
1288
+
1289
+ 0 = p_{in} \cdot pr - p_{out}
1290
+
1291
+ - :func:`tespy.components.components.component.zeta_func`
1292
+
1293
+ - :func:`tespy.components.heat_exchangers.heat_exchanger_simple.darcy_func`
1294
+ or :func:`tespy.components.heat_exchangers.heat_exchanger_simple.hw_func`
1295
+
1296
+ **additional equations**
1297
+
1298
+ - :func:`tespy.components.heat_exchangers.solar_collector.additional_equations`
1299
+
1300
+ Inlets/Outlets
1301
+
1302
+ - in1
1303
+ - out1
1304
+
1305
+ Image
1306
+
1307
+ .. image:: _images/solar_collector.svg
1308
+ :scale: 100 %
1309
+ :alt: alternative text
1310
+ :align: center
1311
+
1312
+ Parameters
1313
+ ----------
1314
+ label : str
1315
+ The label of the component.
1316
+
1317
+ design : list
1318
+ List containing design parameters (stated as String).
1319
+
1320
+ offdesign : list
1321
+ List containing offdesign parameters (stated as String).
1322
+
1323
+ design_path: str
1324
+ Path to the components design case.
1325
+
1326
+ local_offdesign : boolean
1327
+ Treat this component in offdesign mode in a design calculation.
1328
+
1329
+ local_design : boolean
1330
+ Treat this component in design mode in an offdesign calculation.
1331
+
1332
+ char_warnings: boolean
1333
+ Ignore warnings on default characteristics usage for this component.
1334
+
1335
+ printout: boolean
1336
+ Include this component in the network's results printout.
1337
+
1338
+ Q : str/float/tespy.tools.data_containers.dc_cp
1339
+ Heat transfer, :math:`Q/\text{W}`.
1340
+
1341
+ pr : str/float/tespy.tools.data_containers.dc_cp
1342
+ Outlet to inlet pressure ratio, :math:`pr/1`.
1343
+
1344
+ zeta : str/float/tespy.tools.data_containers.dc_cp
1345
+ Geometry independent friction coefficient,
1346
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
1347
+
1348
+ D : str/float/tespy.tools.data_containers.dc_cp
1349
+ Diameter of the pipes, :math:`D/\text{m}`.
1350
+
1351
+ L : str/float/tespy.tools.data_containers.dc_cp
1352
+ Length of the pipes, :math:`L/\text{m}`.
1353
+
1354
+ ks : str/float/tespy.tools.data_containers.dc_cp
1355
+ Pipe's roughness, :math:`ks/\text{m}` for darcy friction,
1356
+ :math:`ks/\text{1}` for hazen-williams equation.
1357
+
1358
+ hydro_group : str/tespy.tools.data_containers.dc_gcp
1359
+ Parametergroup for pressure drop calculation based on pipes dimensions.
1360
+ Choose 'HW' for hazen-williams equation, else darcy friction factor is
1361
+ used.
1362
+
1363
+ E : str/float/tespy.tools.data_containers.dc_cp
1364
+ irradiance at tilted collector surface area,
1365
+ :math:`E/\frac{\text{W}}{\text{m}^2}`.
1366
+
1367
+ eta_opt : str/float/tespy.tools.data_containers.dc_cp
1368
+ optical loss at surface cover,
1369
+ :math:`\eta_{opt}`.
1370
+
1371
+ lkf_lin : str/float/tespy.tools.data_containers.dc_cp
1372
+ Linear thermal loss key figure,
1373
+ :math:`\alpha_1/\frac{\text{W}}{\text{K} \cdot \text{m}^2}`.
1374
+
1375
+ lkf_quad : str/float/tespy.tools.data_containers.dc_cp
1376
+ Quadratic thermal loss key figure,
1377
+ :math:`\alpha_2/\frac{\text{W}}{\text{K}^2 \cdot \text{m}^2}`.
1378
+
1379
+ A : str/float/tespy.tools.data_containers.dc_cp
1380
+ Collector surface area :math:`A/\text{m}^2`.
1381
+
1382
+ Tamb : float/tespy.tools.data_containers.dc_simple
1383
+ Ambient temperature, provide parameter in network's temperature unit.
1384
+
1385
+ energy_group : tespy.tools.data_containers.dc_gcp
1386
+ Parametergroup for energy balance of solarthermal collector.
1387
+
1388
+ Example
1389
+ -------
1390
+ The solar collector is used to calculate heat transferred to the heating
1391
+ system from irradiance on a tilted plane. For instance, it is possible to
1392
+ calculate the collector surface area required to transfer a specific amount
1393
+ of heat at a given irradiance. The collector parameters are the linear and
1394
+ the quadratic loss keyfigure as well as the optical effifiency.
1395
+
1396
+ >>> from tespy.components import sink, source, solar_collector
1397
+ >>> from tespy.connections import connection
1398
+ >>> from tespy.networks import network
1399
+ >>> import shutil
1400
+ >>> fluids = ['H2O']
1401
+ >>> nw = network(fluids=fluids)
1402
+ >>> nw.set_attr(p_unit='bar', T_unit='C', h_unit='kJ / kg', iterinfo=False)
1403
+ >>> so = source('source')
1404
+ >>> si = sink('sink')
1405
+ >>> sc = solar_collector('solar collector')
1406
+ >>> sc.component()
1407
+ 'solar collector'
1408
+ >>> sc.set_attr(pr=0.95, Q=1e4, design=['pr', 'Q'], offdesign=['zeta'],
1409
+ ... Tamb=25, A='var', eta_opt=0.92, lkf_lin=1, lkf_quad=0.005, E=8e2)
1410
+ >>> inc = connection(so, 'out1', sc, 'in1')
1411
+ >>> outg = connection(sc, 'out1', si, 'in1')
1412
+ >>> nw.add_conns(inc, outg)
1413
+
1414
+ The outlet temperature should be at 90 °C at a constant mass flow, which
1415
+ is determined in the design calculation. In offdesign operation (at a
1416
+ different irradiance) using the calculated surface area and mass flow, it
1417
+ is possible to predict the outlet temperature. It would instead be
1418
+ possible to calulate the change in mass flow required to hold the
1419
+ specified outlet temperature, too.
1420
+
1421
+ >>> inc.set_attr(fluid={'H2O': 1}, T=40, p=3, offdesign=['m'])
1422
+ >>> outg.set_attr(T=90, design=['T'])
1423
+ >>> nw.solve('design')
1424
+ >>> nw.save('tmp')
1425
+ >>> round(sc.A.val, 1)
1426
+ 14.5
1427
+ >>> sc.set_attr(A=sc.A.val, E=5e2, Tamb=20)
1428
+ >>> nw.solve('offdesign', design_path='tmp')
1429
+ >>> round(sc.Q.val, 1)
1430
+ 6083.8
1431
+ >>> round(outg.T.val, 1)
1432
+ 70.5
1433
+ >>> shutil.rmtree('./tmp', ignore_errors=True)
1434
+ """
1435
+
1436
+ @staticmethod
1437
+ def component():
1438
+ return 'solar collector'
1439
+
1440
+ @staticmethod
1441
+ def attr():
1442
+ return {
1443
+ 'Q': dc_cp(),
1444
+ 'pr': dc_cp(min_val=1e-4, max_val=1), 'zeta': dc_cp(min_val=0),
1445
+ 'D': dc_cp(min_val=1e-2, max_val=2, d=1e-4),
1446
+ 'L': dc_cp(min_val=1e-1, d=1e-3),
1447
+ 'ks': dc_cp(val=1e-4, min_val=1e-7, max_val=1e-4, d=1e-8),
1448
+ 'E': dc_cp(min_val=0), 'A': dc_cp(min_val=0),
1449
+ 'eta_opt': dc_cp(min_val=0, max_val=1),
1450
+ 'lkf_lin': dc_cp(min_val=0), 'lkf_quad': dc_cp(min_val=0),
1451
+ 'Tamb': dc_simple(),
1452
+ 'Q_loss': dc_cp(min_val=0), 'SQ': dc_simple(),
1453
+ 'hydro_group': dc_gcp(), 'energy_group': dc_gcp()
1454
+ }
1455
+
1456
+ def comp_init(self, nw):
1457
+
1458
+ component.comp_init(self, nw)
1459
+
1460
+ self.Tamb.val_SI = ((self.Tamb.val + nw.T[nw.T_unit][0]) *
1461
+ nw.T[nw.T_unit][1])
1462
+
1463
+ # parameters for hydro group
1464
+ self.hydro_group.set_attr(elements=[self.L, self.ks, self.D])
1465
+
1466
+ is_set = True
1467
+ for e in self.hydro_group.elements:
1468
+ if e.is_set is False:
1469
+ is_set = False
1470
+
1471
+ if is_set is True:
1472
+ self.hydro_group.set_attr(is_set=True)
1473
+ elif self.hydro_group.is_set is True:
1474
+ msg = ('All parameters of the component group have to be '
1475
+ 'specified! This component group uses the following '
1476
+ 'parameters: L, ks, D at ' + self.label + '. '
1477
+ 'Group will be set to False.')
1478
+ logging.warning(msg)
1479
+ self.hydro_group.set_attr(is_set=False)
1480
+ else:
1481
+ self.hydro_group.set_attr(is_set=False)
1482
+
1483
+ # parameters for energy group
1484
+ self.energy_group.set_attr(
1485
+ elements=[self.E, self.eta_opt, self.lkf_lin,
1486
+ self.lkf_quad, self.A, self.Tamb])
1487
+
1488
+ is_set = True
1489
+ for e in self.energy_group.elements:
1490
+ if e.is_set is False:
1491
+ is_set = False
1492
+
1493
+ if is_set is True:
1494
+ self.energy_group.set_attr(is_set=True)
1495
+ elif self.energy_group.is_set is True:
1496
+ msg = ('All parameters of the component group have to be '
1497
+ 'specified! This component group uses the following '
1498
+ 'parameters: E, eta_opt, lkf_lin, lkf_quad, A, Tamb at ' +
1499
+ self.label + '. Group will be set to False.')
1500
+ logging.warning(msg)
1501
+ self.energy_group.set_attr(is_set=False)
1502
+ else:
1503
+ self.energy_group.set_attr(is_set=False)
1504
+
1505
+ # number of mandatroy equations for
1506
+ # fluid balance: num_fl
1507
+ # mass flow: 1
1508
+ self.num_eq = self.num_nw_fluids + 1
1509
+ for var in [self.Q, self.pr, self.zeta, self.hydro_group,
1510
+ self.energy_group]:
1511
+ if var.is_set is True:
1512
+ self.num_eq += 1
1513
+
1514
+ self.jacobian = np.zeros((
1515
+ self.num_eq,
1516
+ self.num_i + self.num_o + self.num_vars,
1517
+ self.num_nw_vars))
1518
+
1519
+ self.residual = np.zeros(self.num_eq)
1520
+ pos = self.num_nw_fluids
1521
+ self.jacobian[0:pos] = self.fluid_deriv()
1522
+ self.jacobian[pos:pos + 1] = self.mass_flow_deriv()
1523
+
1524
+ def additional_equations(self, k):
1525
+ r"""
1526
+ Calculate results of additional equations.
1527
+
1528
+ Equations
1529
+
1530
+ **optional equations**
1531
+
1532
+ - :func:`tespy.components.heat_exchangers.solar_collector.energy_func`
1533
+ """
1534
+ ######################################################################
1535
+ # equation for specified energy-group paremeters
1536
+ if self.energy_group.is_set:
1537
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1538
+ self.residual[k] = self.energy_func()
1539
+
1540
+ def additional_derivatives(self, increment_filter, k):
1541
+ r"""Calculate partial derivatives for given additional equations."""
1542
+ ######################################################################
1543
+ # derivatives for specified energy-group paremeters
1544
+ if self.energy_group.is_set:
1545
+ f = self.energy_func
1546
+ self.jacobian[k, 0, 0] = (
1547
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
1548
+ if not increment_filter[0, 1]:
1549
+ self.jacobian[k, 0, 1] = self.numeric_deriv(f, 'p', 0)
1550
+ if not increment_filter[0, 2]:
1551
+ self.jacobian[k, 0, 2] = self.numeric_deriv(f, 'h', 0)
1552
+ if not increment_filter[1, 1]:
1553
+ self.jacobian[k, 1, 1] = self.numeric_deriv(f, 'p', 1)
1554
+ if not increment_filter[1, 2]:
1555
+ self.jacobian[k, 1, 2] = self.numeric_deriv(f, 'h', 1)
1556
+ # custom variables for the energy-group
1557
+ for var in self.energy_group.elements:
1558
+ if var == self.Tamb:
1559
+ continue
1560
+ if var.is_var:
1561
+ self.jacobian[k, 2 + var.var_pos, 0] = (
1562
+ self.numeric_deriv(f, self.vars[var], 2))
1563
+ k += 1
1564
+
1565
+ def energy_func(self):
1566
+ r"""
1567
+ Equation for parabolic trough energy balance.
1568
+
1569
+ Returns
1570
+ -------
1571
+ res : float
1572
+ Residual value of equation.
1573
+
1574
+ Note
1575
+ ----
1576
+ .. math::
1577
+
1578
+ \begin{split}
1579
+ T_m = & \frac{T_{out} + T_{in}}{2}\\
1580
+ 0 = & \dot{m} \cdot \left( h_{out} - h_{in} \right)\\
1581
+ & - A \cdot \left[E \cdot \eta_{opt} - \alpha_1 \cdot
1582
+ \left(T_m - T_{amb} \right) - \alpha_2 \cdot
1583
+ \left(T_m - T_{amb}\right)^2 \right]
1584
+ \end{split}
1585
+
1586
+ Reference: :cite:`Quaschning2013`.
1587
+ """
1588
+ i = self.inl[0].to_flow()
1589
+ o = self.outl[0].to_flow()
1590
+
1591
+ T_m = (T_mix_ph(i, T0=self.inl[0].T.val_SI) +
1592
+ T_mix_ph(o, T0=self.outl[0].T.val_SI)) / 2
1593
+
1594
+ return (i[0] * (o[2] - i[2]) -
1595
+ self.A.val * (
1596
+ self.E.val * self.eta_opt.val -
1597
+ (T_m - self.Tamb.val_SI) * self.lkf_lin.val -
1598
+ self.lkf_quad.val * (T_m - self.Tamb.val_SI) ** 2))
1599
+
1600
+ def calc_parameters(self):
1601
+ r"""Postprocessing parameter calculation."""
1602
+ i = self.inl[0].to_flow()
1603
+ o = self.outl[0].to_flow()
1604
+
1605
+ self.SQ.val = i[0] * (s_mix_ph(o) - s_mix_ph(i))
1606
+ self.Q.val = i[0] * (o[2] - i[2])
1607
+ self.pr.val = o[1] / i[1]
1608
+ self.zeta.val = ((i[1] - o[1]) * np.pi ** 2 /
1609
+ (8 * i[0] ** 2 * (v_mix_ph(i) + v_mix_ph(o)) / 2))
1610
+ if self.energy_group.is_set is True:
1611
+ self.Q_loss.val = self.E.val * self.A.val - self.Q.val
1612
+
1613
+ self.check_parameter_bounds()
1614
+
1615
+ # %%
1616
+
1617
+
1618
+ class heat_exchanger(component):
1619
+ r"""
1620
+ Class heat_exchanger is the parent class for condenser and desuperheater.
1621
+
1622
+ The heat exchanger represents counter current heat exchangers. Both, hot
1623
+ and cold side of the heat exchanger, are simulated.
1624
+
1625
+ Equations
1626
+
1627
+ **mandatory equations**
1628
+
1629
+ - :func:`tespy.components.components.component.fluid_func`
1630
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.mass_flow_func`
1631
+
1632
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.energy_func`
1633
+
1634
+ **optional equations**
1635
+
1636
+ .. math::
1637
+
1638
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) - \dot{Q}
1639
+
1640
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.kA_func`
1641
+ - :func:`tespy.components.heat_exchangers.condenser.kA_char_func`
1642
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.ttd_u_func`
1643
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.ttd_l_func`
1644
+
1645
+ .. math::
1646
+
1647
+ 0 = p_{1,in} \cdot pr1 - p_{1,out}\\
1648
+ 0 = p_{2,in} \cdot pr2 - p_{2,out}
1649
+
1650
+ - hot side :func:`tespy.components.components.component.zeta_func`
1651
+ - cold side :func:`tespy.components.components.component.zeta_func`
1652
+
1653
+ **additional equations**
1654
+
1655
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.additional_equations`
1656
+
1657
+ Inlets/Outlets
1658
+
1659
+ - in1, in2 (index 1: hot side, index 2: cold side)
1660
+ - out1, out2 (index 1: hot side, index 2: cold side)
1661
+
1662
+ Image
1663
+
1664
+ .. image:: _images/heat_exchanger.svg
1665
+ :scale: 100 %
1666
+ :alt: alternative text
1667
+ :align: center
1668
+
1669
+ Parameters
1670
+ ----------
1671
+ label : str
1672
+ The label of the component.
1673
+
1674
+ design : list
1675
+ List containing design parameters (stated as String).
1676
+
1677
+ offdesign : list
1678
+ List containing offdesign parameters (stated as String).
1679
+
1680
+ design_path: str
1681
+ Path to the components design case.
1682
+
1683
+ local_offdesign : boolean
1684
+ Treat this component in offdesign mode in a design calculation.
1685
+
1686
+ local_design : boolean
1687
+ Treat this component in design mode in an offdesign calculation.
1688
+
1689
+ char_warnings: boolean
1690
+ Ignore warnings on default characteristics usage for this component.
1691
+
1692
+ printout: boolean
1693
+ Include this component in the network's results printout.
1694
+
1695
+ Q : str/float/tespy.tools.data_containers.dc_cp
1696
+ Heat transfer, :math:`Q/\text{W}`.
1697
+
1698
+ pr1 : str/float/tespy.tools.data_containers.dc_cp
1699
+ Outlet to inlet pressure ratio at hot side, :math:`pr/1`.
1700
+
1701
+ pr2 : str/float/tespy.tools.data_containers.dc_cp
1702
+ Outlet to inlet pressure ratio at cold side, :math:`pr/1`.
1703
+
1704
+ zeta1 : str/float/tespy.tools.data_containers.dc_cp
1705
+ Geometry independent friction coefficient at hot side,
1706
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
1707
+
1708
+ zeta2 : str/float/tespy.tools.data_containers.dc_cp
1709
+ Geometry independent friction coefficient at cold side,
1710
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
1711
+
1712
+ kA : float/tespy.tools.data_containers.dc_cp
1713
+ Area independent heat transition coefficient,
1714
+ :math:`kA/\frac{\text{W}}{\text{K}}`.
1715
+
1716
+ kA_char : tespy.tools.data_containers.dc_simple
1717
+ Area independent heat transition coefficient characteristic.
1718
+
1719
+ kA_char1 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
1720
+ Characteristic line for hot side heat transfer coefficient.
1721
+
1722
+ kA_char2 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
1723
+ Characteristic line for cold side heat transfer coefficient.
1724
+
1725
+ Note
1726
+ ----
1727
+ The heat exchanger and subclasses (desuperheater, condenser) are
1728
+ countercurrent heat exchangers. Equations (kA, ttd_u, ttd_l) do not work
1729
+ for directcurrent and crosscurrent or combinations of different types.
1730
+
1731
+ Example
1732
+ -------
1733
+ A water cooling is installed to transfer heat from hot exhaust air. The
1734
+ heat exchanger is designed for a terminal temperature difference of 5 K.
1735
+ From this, it is possible to calculate the heat transfer coefficient and
1736
+ predict water and air outlet temperature in offdesign operation.
1737
+
1738
+ >>> from tespy.components import sink, source, heat_exchanger
1739
+ >>> from tespy.connections import connection
1740
+ >>> from tespy.networks import network
1741
+ >>> import shutil
1742
+ >>> nw = network(fluids=['water', 'air'], T_unit='C', p_unit='bar',
1743
+ ... h_unit='kJ / kg', iterinfo=False)
1744
+ >>> exhaust_hot = source('Exhaust air outlet')
1745
+ >>> exhaust_cold = sink('Exhaust air inlet')
1746
+ >>> cw_cold = source('cooling water inlet')
1747
+ >>> cw_hot = sink('cooling water outlet')
1748
+ >>> he = heat_exchanger('waste heat exchanger')
1749
+ >>> he.component()
1750
+ 'heat exchanger'
1751
+ >>> ex_he = connection(exhaust_hot, 'out1', he, 'in1')
1752
+ >>> he_ex = connection(he, 'out1', exhaust_cold, 'in1')
1753
+ >>> cw_he = connection(cw_cold, 'out1', he, 'in2')
1754
+ >>> he_cw = connection(he, 'out2', cw_hot, 'in1')
1755
+ >>> nw.add_conns(ex_he, he_ex, cw_he, he_cw)
1756
+
1757
+ The volumetric flow of the air is at 100 l/s. After designing the component
1758
+ it is possible to predict the temperature at different flow rates or
1759
+ different inlet temperatures of the exhaust air.
1760
+
1761
+ >>> he.set_attr(pr1=0.98, pr2=0.98, ttd_u=5,
1762
+ ... design=['pr1', 'pr2', 'ttd_u'], offdesign=['zeta1', 'zeta2', 'kA_char'])
1763
+ >>> cw_he.set_attr(fluid={'air': 0, 'water': 1}, T=10, p=3,
1764
+ ... offdesign=['m'])
1765
+ >>> ex_he.set_attr(fluid={'air': 1, 'water': 0}, v=0.1, T=35)
1766
+ >>> he_ex.set_attr(T=17.5, p=1, design=['T'])
1767
+ >>> nw.solve('design')
1768
+ >>> nw.save('tmp')
1769
+ >>> round(ex_he.T.val - he_cw.T.val, 0)
1770
+ 5.0
1771
+ >>> ex_he.set_attr(v=0.075)
1772
+ >>> nw.solve('offdesign', design_path='tmp')
1773
+ >>> round(he_cw.T.val, 1)
1774
+ 27.5
1775
+ >>> round(he_ex.T.val, 1)
1776
+ 14.4
1777
+ >>> ex_he.set_attr(v=0.1, T=40)
1778
+ >>> nw.solve('offdesign', design_path='tmp')
1779
+ >>> round(he_cw.T.val, 1)
1780
+ 33.9
1781
+ >>> round(he_ex.T.val, 1)
1782
+ 18.8
1783
+ >>> shutil.rmtree('./tmp', ignore_errors=True)
1784
+ """
1785
+
1786
+ @staticmethod
1787
+ def component():
1788
+ return 'heat exchanger'
1789
+
1790
+ @staticmethod
1791
+ def attr():
1792
+ return {
1793
+ 'Q': dc_cp(max_val=0),
1794
+ 'kA': dc_cp(min_val=0),
1795
+ 'td_log': dc_cp(min_val=0),
1796
+ 'ttd_u': dc_cp(min_val=0), 'ttd_l': dc_cp(min_val=0),
1797
+ 'pr1': dc_cp(max_val=1), 'pr2': dc_cp(max_val=1),
1798
+ 'zeta1': dc_cp(min_val=0), 'zeta2': dc_cp(min_val=0),
1799
+ 'kA_char': dc_simple(),
1800
+ 'kA_char1': dc_cc(param='m'), 'kA_char2': dc_cc(param='m'),
1801
+ 'SQ1': dc_simple(), 'SQ2': dc_simple(), 'Sirr': dc_simple()
1802
+ }
1803
+
1804
+ @staticmethod
1805
+ def inlets():
1806
+ return ['in1', 'in2']
1807
+
1808
+ @staticmethod
1809
+ def outlets():
1810
+ return ['out1', 'out2']
1811
+
1812
+ def comp_init(self, nw):
1813
+
1814
+ component.comp_init(self, nw)
1815
+
1816
+ # number of mandatroy equations for
1817
+ # fluid balance: num_fl * 2
1818
+ # mass flow: 2
1819
+ # energy balance: 1
1820
+ self.num_eq = self.num_nw_fluids * 2 + 3
1821
+ for var in [self.Q, self.kA, self.kA_char, self.ttd_u, self.ttd_l,
1822
+ self.pr1, self.pr2, self.zeta1, self.zeta2]:
1823
+ if var.is_set is True:
1824
+ self.num_eq += 1
1825
+
1826
+ if self.kA.is_set:
1827
+ msg = (
1828
+ 'The usage of the parameter kA has changed for offdesign '
1829
+ 'calculation. Specifying kA will keep a constant value for kA '
1830
+ 'in the calculation. If you want to use the value adaption of '
1831
+ 'kA by the characteristic line, please use kA_char as '
1832
+ 'parameter instead (occurred at ' + self.label + '). This '
1833
+ 'warning will disappear in TESPy version 0.3.2.')
1834
+ warnings.warn(msg, FutureWarning, stacklevel=2)
1835
+
1836
+ self.jacobian = np.zeros((
1837
+ self.num_eq,
1838
+ self.num_i + self.num_o + self.num_vars,
1839
+ self.num_nw_vars))
1840
+
1841
+ self.residual = np.zeros(self.num_eq)
1842
+ pos = self.num_nw_fluids * 2
1843
+ self.jacobian[0:pos] = self.fluid_deriv()
1844
+ self.jacobian[pos:pos + 2] = self.mass_flow_deriv()
1845
+
1846
+ def equations(self):
1847
+ r"""Calculate residual vector with results of equations."""
1848
+ k = 0
1849
+ ######################################################################
1850
+ # equations for fluid balance
1851
+ self.residual[k:k + self.num_nw_fluids * 2] = self.fluid_func()
1852
+ k += self.num_nw_fluids * 2
1853
+
1854
+ ######################################################################
1855
+ # equations for mass flow balance
1856
+ self.residual[k:k + 2] = self.mass_flow_func()
1857
+ k += 2
1858
+
1859
+ ######################################################################
1860
+ # equations for energy balance
1861
+ self.residual[k] = self.energy_func()
1862
+ k += 1
1863
+
1864
+ ######################################################################
1865
+ # equations for specified heat transfer
1866
+ if self.Q.is_set:
1867
+ self.residual[k] = (
1868
+ self.inl[0].m.val_SI * (
1869
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI) - self.Q.val)
1870
+ k += 1
1871
+
1872
+ ######################################################################
1873
+ # equations for specified heat transfer coefficient
1874
+ if self.kA.is_set:
1875
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1876
+ self.residual[k] = self.kA_func()
1877
+ k += 1
1878
+
1879
+ ######################################################################
1880
+ # equations for specified heat transfer coefficient characteristic
1881
+ if self.kA_char.is_set:
1882
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1883
+ self.residual[k] = self.kA_char_func()
1884
+ k += 1
1885
+
1886
+ ######################################################################
1887
+ # equations for specified upper terminal temperature difference
1888
+ if self.ttd_u.is_set:
1889
+ self.residual[k] = self.ttd_u_func()
1890
+ k += 1
1891
+
1892
+ ######################################################################
1893
+ # equations for specified lower terminal temperature difference
1894
+ if self.ttd_l.is_set:
1895
+ self.residual[k] = self.ttd_l_func()
1896
+ k += 1
1897
+
1898
+ ######################################################################
1899
+ # equations for specified pressure ratio at hot side
1900
+ if self.pr1.is_set:
1901
+ self.residual[k] = (
1902
+ self.pr1.val * self.inl[0].p.val_SI - self.outl[0].p.val_SI)
1903
+ k += 1
1904
+
1905
+ ######################################################################
1906
+ # equations for specified pressure ratio at cold side
1907
+ if self.pr2.is_set:
1908
+ self.residual[k] = (
1909
+ self.pr2.val * self.inl[1].p.val_SI - self.outl[1].p.val_SI)
1910
+ k += 1
1911
+
1912
+ ######################################################################
1913
+ # equations for specified zeta at hot side
1914
+ if self.zeta1.is_set:
1915
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1916
+ self.residual[k] = self.zeta_func(
1917
+ zeta='zeta1', inconn=0, outconn=0)
1918
+ k += 1
1919
+
1920
+ ######################################################################
1921
+ # equations for specified zeta at cold side
1922
+ if self.zeta2.is_set:
1923
+ if np.absolute(self.residual[k]) > err ** 2 or self.it % 4 == 0:
1924
+ self.residual[k] = self.zeta_func(
1925
+ zeta='zeta2', inconn=1, outconn=1)
1926
+ k += 1
1927
+
1928
+ ######################################################################
1929
+ # additional equations
1930
+ self.additional_equations(k)
1931
+
1932
+ def additional_equations(self, k):
1933
+ r"""Calculate results of additional equations."""
1934
+ return
1935
+
1936
+ def derivatives(self, increment_filter):
1937
+ r"""
1938
+ Calculate partial derivatives for given equations.
1939
+
1940
+ Returns
1941
+ -------
1942
+ mat_deriv : ndarray
1943
+ Matrix of partial derivatives.
1944
+ """
1945
+ ######################################################################
1946
+ # derivatives fluid and mass balance are static
1947
+ k = self.num_nw_fluids * 2 + 2
1948
+
1949
+ ######################################################################
1950
+ # derivatives for energy balance equation
1951
+ for i in range(2):
1952
+ self.jacobian[k, i, 0] = (
1953
+ self.outl[i].h.val_SI - self.inl[i].h.val_SI)
1954
+ self.jacobian[k, i, 2] = -self.inl[i].m.val_SI
1955
+
1956
+ self.jacobian[k, 2, 2] = self.inl[0].m.val_SI
1957
+ self.jacobian[k, 3, 2] = self.inl[1].m.val_SI
1958
+ k += 1
1959
+
1960
+ ######################################################################
1961
+ # derivatives for specified heat transfer
1962
+ if self.Q.is_set:
1963
+ self.jacobian[k, 0, 0] = (
1964
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
1965
+ self.jacobian[k, 0, 2] = -self.inl[0].m.val_SI
1966
+ self.jacobian[k, 2, 2] = self.inl[0].m.val_SI
1967
+ k += 1
1968
+
1969
+ ######################################################################
1970
+ # derivatives for specified heat transfer coefficient
1971
+ if self.kA.is_set:
1972
+ f = self.kA_func
1973
+ self.jacobian[k, 0, 0] = (
1974
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI)
1975
+ for i in range(4):
1976
+ if not increment_filter[i, 1]:
1977
+ self.jacobian[k, i, 1] = self.numeric_deriv(f, 'p', i)
1978
+ if not increment_filter[i, 2]:
1979
+ self.jacobian[k, i, 2] = self.numeric_deriv(f, 'h', i)
1980
+ k += 1
1981
+
1982
+ ######################################################################
1983
+ # derivatives for specified heat transfer coefficient
1984
+ if self.kA_char.is_set:
1985
+ f = self.kA_char_func
1986
+ if not increment_filter[0, 0]:
1987
+ self.jacobian[k, 0, 0] = self.numeric_deriv(f, 'm', 0)
1988
+ if not increment_filter[1, 0]:
1989
+ self.jacobian[k, 1, 0] = self.numeric_deriv(f, 'm', 1)
1990
+ for i in range(4):
1991
+ if not increment_filter[i, 1]:
1992
+ self.jacobian[k, i, 1] = self.numeric_deriv(f, 'p', i)
1993
+ if not increment_filter[i, 2]:
1994
+ self.jacobian[k, i, 2] = self.numeric_deriv(f, 'h', i)
1995
+ k += 1
1996
+
1997
+ ######################################################################
1998
+ # derivatives for specified upper terminal temperature difference
1999
+ if self.ttd_u.is_set:
2000
+ f = self.ttd_u_func
2001
+ for i in [0, 3]:
2002
+ if not increment_filter[i, 1]:
2003
+ self.jacobian[k, i, 1] = self.numeric_deriv(f, 'p', i)
2004
+ if not increment_filter[i, 2]:
2005
+ self.jacobian[k, i, 2] = self.numeric_deriv(f, 'h', i)
2006
+ k += 1
2007
+
2008
+ ######################################################################
2009
+ # derivatives for specified lower terminal temperature difference
2010
+ if self.ttd_l.is_set:
2011
+ f = self.ttd_l_func
2012
+ for i in [1, 2]:
2013
+ if not increment_filter[i, 1]:
2014
+ self.jacobian[k, i, 1] = self.numeric_deriv(f, 'p', i)
2015
+ if not increment_filter[i, 2]:
2016
+ self.jacobian[k, i, 2] = self.numeric_deriv(f, 'h', i)
2017
+ k += 1
2018
+
2019
+ ######################################################################
2020
+ # derivatives for specified pressure ratio at hot side
2021
+ if self.pr1.is_set:
2022
+ self.jacobian[k, 0, 1] = self.pr1.val
2023
+ self.jacobian[k, 2, 1] = -1
2024
+ k += 1
2025
+
2026
+ ######################################################################
2027
+ # derivatives for specified pressure ratio at cold side
2028
+ if self.pr2.is_set:
2029
+ self.jacobian[k, 1, 1] = self.pr2.val
2030
+ self.jacobian[k, 3, 1] = -1
2031
+ k += 1
2032
+
2033
+ ######################################################################
2034
+ # derivatives for specified zeta at hot side
2035
+ if self.zeta1.is_set:
2036
+ f = self.zeta_func
2037
+ if not increment_filter[0, 0]:
2038
+ self.jacobian[k, 0, 0] = self.numeric_deriv(
2039
+ f, 'm', 0, zeta='zeta1', inconn=0, outconn=0)
2040
+ if not increment_filter[0, 1]:
2041
+ self.jacobian[k, 0, 1] = self.numeric_deriv(
2042
+ f, 'p', 0, zeta='zeta1', inconn=0, outconn=0)
2043
+ if not increment_filter[0, 2]:
2044
+ self.jacobian[k, 0, 2] = self.numeric_deriv(
2045
+ f, 'h', 0, zeta='zeta1', inconn=0, outconn=0)
2046
+ if not increment_filter[2, 1]:
2047
+ self.jacobian[k, 2, 1] = self.numeric_deriv(
2048
+ f, 'p', 2, zeta='zeta1', inconn=0, outconn=0)
2049
+ if not increment_filter[2, 2]:
2050
+ self.jacobian[k, 2, 2] = self.numeric_deriv(
2051
+ f, 'h', 2, zeta='zeta1', inconn=0, outconn=0)
2052
+ k += 1
2053
+
2054
+ ######################################################################
2055
+ # derivatives for specified zeta at cold side
2056
+ if self.zeta2.is_set:
2057
+ f = self.zeta_func
2058
+ if not increment_filter[1, 0]:
2059
+ self.jacobian[k, 1, 0] = self.numeric_deriv(
2060
+ f, 'm', 1, zeta='zeta2', inconn=1, outconn=1)
2061
+ if not increment_filter[1, 1]:
2062
+ self.jacobian[k, 1, 1] = self.numeric_deriv(
2063
+ f, 'p', 1, zeta='zeta2', inconn=1, outconn=1)
2064
+ if not increment_filter[1, 2]:
2065
+ self.jacobian[k, 1, 2] = self.numeric_deriv(
2066
+ f, 'h', 1, zeta='zeta2', inconn=1, outconn=1)
2067
+ if not increment_filter[3, 1]:
2068
+ self.jacobian[k, 3, 1] = self.numeric_deriv(
2069
+ f, 'p', 3, zeta='zeta2', inconn=1, outconn=1)
2070
+ if not increment_filter[3, 2]:
2071
+ self.jacobian[k, 3, 2] = self.numeric_deriv(
2072
+ f, 'h', 3, zeta='zeta2', inconn=1, outconn=1)
2073
+ k += 1
2074
+
2075
+ ######################################################################
2076
+ # derivatives for additional equations
2077
+ self.additional_derivatives(increment_filter, k)
2078
+
2079
+ def additional_derivatives(self, increment_filter, k):
2080
+ r"""Calculate partial derivatives for given additional equations."""
2081
+ return
2082
+
2083
+ def mass_flow_func(self):
2084
+ r"""
2085
+ Calculate the residual value for mass flow balance equation.
2086
+
2087
+ Returns
2088
+ -------
2089
+ residual : list
2090
+ Vector with residual value for component's mass flow balance.
2091
+
2092
+ .. math::
2093
+
2094
+ 0 = \dot{m}_{in,i} - \dot{m}_{out,i} \;
2095
+ \forall i \in inlets/outlets
2096
+ """
2097
+ residual = []
2098
+ for i in range(self.num_i):
2099
+ residual += [self.inl[i].m.val_SI - self.outl[i].m.val_SI]
2100
+ return residual
2101
+
2102
+ def mass_flow_deriv(self):
2103
+ r"""
2104
+ Calculate partial derivatives for all mass flow balance equations.
2105
+
2106
+ Returns
2107
+ -------
2108
+ deriv : list
2109
+ Matrix with partial derivatives for the mass flow balance
2110
+ equations.
2111
+ """
2112
+ deriv = np.zeros((2, 4 + self.num_vars, self.num_nw_vars))
2113
+ for i in range(self.num_i):
2114
+ deriv[i, i, 0] = 1
2115
+ for j in range(self.num_o):
2116
+ deriv[j, j + i + 1, 0] = -1
2117
+ return deriv
2118
+
2119
+ def energy_func(self):
2120
+ r"""
2121
+ Equation for heat exchanger energy balance.
2122
+
2123
+ Returns
2124
+ -------
2125
+ res : float
2126
+ Residual value of equation.
2127
+
2128
+ .. math::
2129
+
2130
+ 0 = \dot{m}_{1,in} \cdot \left(h_{1,out} - h_{1,in} \right) +
2131
+ \dot{m}_{2,in} \cdot \left(h_{2,out} - h_{2,in} \right)
2132
+ """
2133
+ return (
2134
+ self.inl[0].m.val_SI * (
2135
+ self.outl[0].h.val_SI - self.inl[0].h.val_SI) +
2136
+ self.inl[1].m.val_SI * (
2137
+ self.outl[1].h.val_SI - self.inl[1].h.val_SI))
2138
+
2139
+ def kA_func(self):
2140
+ r"""
2141
+ Calculate heat transfer from heat transfer coefficient.
2142
+
2143
+ Returns
2144
+ -------
2145
+ res : float
2146
+ Residual value of equation.
2147
+
2148
+ .. math::
2149
+
2150
+ res = \dot{m}_{1,in} \cdot \left( h_{1,out} - h_{1,in}\right) +
2151
+ kA \cdot \frac{T_{1,out} -
2152
+ T_{2,in} - T_{1,in} + T_{2,out}}
2153
+ {\ln{\frac{T_{1,out} - T_{2,in}}{T_{1,in} - T_{2,out}}}}
2154
+
2155
+ Note
2156
+ ----
2157
+ For standard functions f\ :subscript:`1` \ and f\ :subscript:`2` \ see
2158
+ module :func:`tespy.data`.
2159
+
2160
+ - Calculate temperatures at inlets and outlets.
2161
+ - Perform value manipulation, if temperature levels are not physically
2162
+ feasible.
2163
+ """
2164
+ i1 = self.inl[0].to_flow()
2165
+ i2 = self.inl[1].to_flow()
2166
+ o1 = self.outl[0].to_flow()
2167
+ o2 = self.outl[1].to_flow()
2168
+
2169
+ T_i1 = T_mix_ph(i1, T0=self.inl[0].T.val_SI)
2170
+ T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
2171
+ T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
2172
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2173
+
2174
+ if T_i1 <= T_o2:
2175
+ T_i1 = T_o2 + 0.01
2176
+ if T_i1 <= T_o2:
2177
+ T_o2 = T_i1 - 0.01
2178
+ if T_i1 <= T_o2:
2179
+ T_o1 = T_i2 + 0.02
2180
+ if T_o1 <= T_i2:
2181
+ T_i2 = T_o1 - 0.02
2182
+
2183
+ td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
2184
+ np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
2185
+
2186
+ return i1[0] * (o1[2] - i1[2]) + self.kA.val * td_log
2187
+
2188
+ def kA_char_func(self):
2189
+ r"""
2190
+ Calculate heat transfer from heat transfer coefficient characteristic.
2191
+
2192
+ Returns
2193
+ -------
2194
+ res : float
2195
+ Residual value of equation.
2196
+
2197
+ .. math::
2198
+
2199
+ res = \dot{m}_{1,in} \cdot \left( h_{1,out} - h_{1,in}\right) +
2200
+ kA_{ref} \cdot f_{kA} \cdot \frac{T_{1,out} -
2201
+ T_{2,in} - T_{1,in} + T_{2,out}}
2202
+ {\ln{\frac{T_{1,out} - T_{2,in}}{T_{1,in} - T_{2,out}}}}
2203
+
2204
+ f_{kA} = \frac{2}{
2205
+ \frac{1}{f_1\left(\frac{m_1}{m_{1,ref}}\right)} +
2206
+ \frac{1}{f_2\left(\frac{m_2}{m_{2,ref}}\right)}}
2207
+
2208
+ Note
2209
+ ----
2210
+ For standard functions f\ :subscript:`1` \ and f\ :subscript:`2` \ see
2211
+ module :func:`tespy.data`.
2212
+
2213
+ - Calculate temperatures at inlets and outlets.
2214
+ - Perform value manipulation, if temperature levels are not physically
2215
+ feasible.
2216
+ """
2217
+ i1 = self.inl[0].to_flow()
2218
+ i2 = self.inl[1].to_flow()
2219
+ o1 = self.outl[0].to_flow()
2220
+ o2 = self.outl[1].to_flow()
2221
+
2222
+ i1_d = self.inl[0].to_flow_design()
2223
+ i2_d = self.inl[1].to_flow_design()
2224
+
2225
+ T_i1 = T_mix_ph(i1, T0=self.inl[0].T.val_SI)
2226
+ T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
2227
+ T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
2228
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2229
+
2230
+ if T_i1 <= T_o2:
2231
+ T_i1 = T_o2 + 0.01
2232
+ if T_i1 <= T_o2:
2233
+ T_o2 = T_i1 - 0.01
2234
+ if T_i1 <= T_o2:
2235
+ T_o1 = T_i2 + 0.02
2236
+ if T_o1 <= T_i2:
2237
+ T_i2 = T_o1 - 0.02
2238
+
2239
+ fkA1 = 1
2240
+ if self.kA_char1.param == 'm':
2241
+ fkA1 = self.kA_char1.func.evaluate(i1[0] / i1_d[0])
2242
+
2243
+ fkA2 = 1
2244
+ if self.kA_char2.param == 'm':
2245
+ fkA2 = self.kA_char2.func.evaluate(i2[0] / i2_d[0])
2246
+
2247
+ fkA = 2 / (1 / fkA1 + 1 / fkA2)
2248
+
2249
+ td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
2250
+ np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
2251
+ return i1[0] * (o1[2] - i1[2]) + self.kA.design * fkA * td_log
2252
+
2253
+ def ttd_u_func(self):
2254
+ r"""
2255
+ Equation for upper terminal temperature difference.
2256
+
2257
+ Returns
2258
+ -------
2259
+ res : float
2260
+ Residual value of equation.
2261
+
2262
+ .. math::
2263
+
2264
+ res = ttd_{u} - T_{1,in} + T_{2,out}
2265
+ """
2266
+ T_i1 = T_mix_ph(self.inl[0].to_flow(), T0=self.inl[0].T.val_SI)
2267
+ T_o2 = T_mix_ph(self.outl[1].to_flow(), T0=self.outl[1].T.val_SI)
2268
+ return self.ttd_u.val - T_i1 + T_o2
2269
+
2270
+ def ttd_l_func(self):
2271
+ r"""
2272
+ Equation for upper terminal temperature difference.
2273
+
2274
+ Returns
2275
+ -------
2276
+ res : float
2277
+ Residual value of equation.
2278
+
2279
+ .. math::
2280
+
2281
+ res = ttd_{l} - T_{1,out} + T_{2,in}
2282
+ """
2283
+ i2 = self.inl[1].to_flow()
2284
+ o1 = self.outl[0].to_flow()
2285
+ return (self.ttd_l.val - T_mix_ph(o1, T0=self.outl[0].T.val_SI) +
2286
+ T_mix_ph(i2, T0=self.inl[1].T.val_SI))
2287
+
2288
+ def bus_func(self, bus):
2289
+ r"""
2290
+ Calculate the value of the bus function.
2291
+
2292
+ Parameters
2293
+ ----------
2294
+ bus : tespy.connections.bus
2295
+ TESPy bus object.
2296
+
2297
+ Returns
2298
+ -------
2299
+ val : float
2300
+ Value of energy transfer :math:`\dot{E}`. This value is passed to
2301
+ :py:meth:`tespy.components.components.component.calc_bus_value`
2302
+ for value manipulation according to the specified characteristic
2303
+ line of the bus.
2304
+
2305
+ .. math::
2306
+
2307
+ \dot{E} = \dot{m}_{1,in} \cdot \left(
2308
+ h_{1,out} - h_{1,in} \right)
2309
+ """
2310
+ i = self.inl[0].to_flow()
2311
+ o = self.outl[0].to_flow()
2312
+ val = i[0] * (o[2] - i[2])
2313
+
2314
+ return val
2315
+
2316
+ def bus_deriv(self, bus):
2317
+ r"""
2318
+ Calculate partial derivatives of the bus function.
2319
+
2320
+ Parameters
2321
+ ----------
2322
+ bus : tespy.connections.bus
2323
+ TESPy bus object.
2324
+
2325
+ Returns
2326
+ -------
2327
+ mat_deriv : ndarray
2328
+ Matrix of partial derivatives.
2329
+ """
2330
+ deriv = np.zeros((1, 4, self.num_nw_vars))
2331
+ f = self.calc_bus_value
2332
+ deriv[0, 0, 0] = self.numeric_deriv(f, 'm', 0, bus=bus)
2333
+ deriv[0, 0, 2] = self.numeric_deriv(f, 'h', 0, bus=bus)
2334
+ deriv[0, 2, 2] = self.numeric_deriv(f, 'h', 2, bus=bus)
2335
+ return deriv
2336
+
2337
+ def initialise_source(self, c, key):
2338
+ r"""
2339
+ Return a starting value for pressure and enthalpy at outlet.
2340
+
2341
+ Parameters
2342
+ ----------
2343
+ c : tespy.connections.connection
2344
+ Connection to perform initialisation on.
2345
+
2346
+ key : str
2347
+ Fluid property to retrieve.
2348
+
2349
+ Returns
2350
+ -------
2351
+ val : float
2352
+ Starting value for pressure/enthalpy in SI units.
2353
+
2354
+ .. math::
2355
+
2356
+ val = \begin{cases}
2357
+ 4 \cdot 10^5 & \text{key = 'p'}\\
2358
+ h\left(p, 200 \text{K} \right) & \text{key = 'h' at outlet 1}\\
2359
+ h\left(p, 250 \text{K} \right) & \text{key = 'h' at outlet 2}
2360
+ \end{cases}
2361
+ """
2362
+ if key == 'p':
2363
+ return 50e5
2364
+ elif key == 'h':
2365
+ flow = c.to_flow()
2366
+ if c.source_id == 'out1':
2367
+ T = 200 + 273.15
2368
+ return h_mix_pT(flow, T)
2369
+ else:
2370
+ T = 250 + 273.15
2371
+ return h_mix_pT(flow, T)
2372
+
2373
+ def initialise_target(self, c, key):
2374
+ r"""
2375
+ Return a starting value for pressure and enthalpy at inlet.
2376
+
2377
+ Parameters
2378
+ ----------
2379
+ c : tespy.connections.connection
2380
+ Connection to perform initialisation on.
2381
+
2382
+ key : str
2383
+ Fluid property to retrieve.
2384
+
2385
+ Returns
2386
+ -------
2387
+ val : float
2388
+ Starting value for pressure/enthalpy in SI units.
2389
+
2390
+ .. math::
2391
+
2392
+ val = \begin{cases}
2393
+ 4 \cdot 10^5 & \text{key = 'p'}\\
2394
+ h\left(p, 300 \text{K} \right) & \text{key = 'h' at inlet 1}\\
2395
+ h\left(p, 220 \text{K} \right) & \text{key = 'h' at outlet 2}
2396
+ \end{cases}
2397
+ """
2398
+ if key == 'p':
2399
+ return 50e5
2400
+ elif key == 'h':
2401
+ flow = c.to_flow()
2402
+ if c.target_id == 'in1':
2403
+ T = 300 + 273.15
2404
+ return h_mix_pT(flow, T)
2405
+ else:
2406
+ T = 220 + 273.15
2407
+ return h_mix_pT(flow, T)
2408
+
2409
+ def calc_parameters(self):
2410
+ r"""Postprocessing parameter calculation."""
2411
+ # connection information
2412
+ i1 = self.inl[0].to_flow()
2413
+ i2 = self.inl[1].to_flow()
2414
+ o1 = self.outl[0].to_flow()
2415
+ o2 = self.outl[1].to_flow()
2416
+
2417
+ # temperatures
2418
+ if isinstance(self, condenser):
2419
+ T_i1 = T_bp_p(i1)
2420
+ else:
2421
+ T_i1 = T_mix_ph(i1, T0=self.inl[0].T.val_SI)
2422
+ T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
2423
+ T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
2424
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2425
+
2426
+ # specific volume
2427
+ v_i1 = v_mix_ph(i1, T0=T_i1)
2428
+ v_i2 = v_mix_ph(i2, T0=T_i2)
2429
+ v_o1 = v_mix_ph(o1, T0=T_o1)
2430
+ v_o2 = v_mix_ph(o2, T0=T_o2)
2431
+
2432
+ # specific entropy
2433
+ s_i1 = s_mix_ph(i1, T0=T_i1)
2434
+ s_i2 = s_mix_ph(i2, T0=T_i2)
2435
+ s_o1 = s_mix_ph(o1, T0=T_o1)
2436
+ s_o2 = s_mix_ph(o2, T0=T_o2)
2437
+
2438
+ # component parameters
2439
+ self.ttd_u.val = T_i1 - T_o2
2440
+ self.ttd_l.val = T_o1 - T_i2
2441
+ self.Q.val = i1[0] * (o1[2] - i1[2])
2442
+
2443
+ self.pr1.val = o1[1] / i1[1]
2444
+ self.pr2.val = o2[1] / i2[1]
2445
+ self.zeta1.val = ((i1[1] - o1[1]) * np.pi ** 2 /
2446
+ (8 * i1[0] ** 2 * (v_i1 + v_o1) / 2))
2447
+ self.zeta2.val = ((i2[1] - o2[1]) * np.pi ** 2 /
2448
+ (8 * i2[0] ** 2 * (v_i2 + v_o2) / 2))
2449
+
2450
+ self.SQ1.val = self.inl[0].m.val_SI * (s_o1 - s_i1)
2451
+ self.SQ2.val = self.inl[1].m.val_SI * (s_o2 - s_i2)
2452
+ self.Sirr.val = self.SQ1.val + self.SQ2.val
2453
+
2454
+ # kA and logarithmic temperature difference
2455
+ if T_i1 <= T_o2 or T_o1 <= T_i2:
2456
+ self.td_log.val = np.nan
2457
+ self.kA.val = np.nan
2458
+ else:
2459
+ self.td_log.val = ((T_o1 - T_i2 - T_i1 + T_o2) /
2460
+ np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
2461
+ self.kA.val = -(i1[0] * (o1[2] - i1[2]) / self.td_log.val)
2462
+
2463
+ if self.kA_char.is_set:
2464
+ # get bound errors for kA hot side characteristics
2465
+ if self.kA_char1.param == 'm':
2466
+ i1_d = self.inl[0].to_flow_design()
2467
+ if not np.isnan(i1_d[0]):
2468
+ if not i1[0] == 0:
2469
+ self.kA_char1.func.get_bound_errors(i1[0] / i1_d[0],
2470
+ self.label)
2471
+
2472
+ # get bound errors for kA copld side characteristics
2473
+ if self.kA_char2.param == 'm':
2474
+ i2_d = self.inl[1].to_flow_design()
2475
+ if not np.isnan(i2_d[0]):
2476
+ if not i1[0] == 0:
2477
+ self.kA_char2.func.get_bound_errors(i2[0] / i2_d[0],
2478
+ self.label)
2479
+
2480
+ self.check_parameter_bounds()
2481
+
2482
+ # %%
2483
+
2484
+
2485
+ class condenser(heat_exchanger):
2486
+ r"""
2487
+ A condenser cools a fluid until it is in liquid state.
2488
+
2489
+ The condensing fluid is cooled by the cold side fluid. The fluid on the hot
2490
+ side of the condenser must be pure. Subcooling is available.
2491
+
2492
+ Equations
2493
+
2494
+ **mandatory equations**
2495
+
2496
+ - :func:`tespy.components.components.component.fluid_func`
2497
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.mass_flow_func`
2498
+ - :func:`tespy.components.heat_exchangers.condenser.energy_func`
2499
+
2500
+ **optional equations**
2501
+
2502
+ .. math::
2503
+
2504
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) - \dot{Q}
2505
+
2506
+ - :func:`tespy.components.heat_exchangers.condenser.kA_func`
2507
+ - :func:`tespy.components.heat_exchangers.condenser.kA_char_func`
2508
+ - :func:`tespy.components.heat_exchangers.condenser.ttd_u_func`
2509
+
2510
+ .. math::
2511
+
2512
+ 0 = p_{1,in} \cdot pr1 - p_{1,out}\\
2513
+ 0 = p_{2,in} \cdot pr2 - p_{2,out}
2514
+
2515
+ - hot side :func:`tespy.components.components.component.zeta_func`
2516
+ - cold side :func:`tespy.components.components.component.zeta_func`
2517
+
2518
+ **additional equations**
2519
+
2520
+ - :func:`tespy.components.heat_exchangers.condenser.additional_equations`
2521
+
2522
+ Inlets/Outlets
2523
+
2524
+ - in1, in2 (index 1: hot side, index 2: cold side)
2525
+ - out1, out2 (index 1: hot side, index 2: cold side)
2526
+
2527
+ Image
2528
+
2529
+ .. image:: _images/condenser.svg
2530
+ :scale: 100 %
2531
+ :alt: alternative text
2532
+ :align: center
2533
+
2534
+ Parameters
2535
+ ----------
2536
+ label : str
2537
+ The label of the component.
2538
+
2539
+ design : list
2540
+ List containing design parameters (stated as String).
2541
+
2542
+ offdesign : list
2543
+ List containing offdesign parameters (stated as String).
2544
+
2545
+ design_path: str
2546
+ Path to the components design case.
2547
+
2548
+ local_offdesign : boolean
2549
+ Treat this component in offdesign mode in a design calculation.
2550
+
2551
+ local_design : boolean
2552
+ Treat this component in design mode in an offdesign calculation.
2553
+
2554
+ char_warnings: boolean
2555
+ Ignore warnings on default characteristics usage for this component.
2556
+
2557
+ printout: boolean
2558
+ Include this component in the network's results printout.
2559
+
2560
+ Q : str/float/tespy.tools.data_containers.dc_cp
2561
+ Heat transfer, :math:`Q/\text{W}`.
2562
+
2563
+ pr1 : str/float/tespy.tools.data_containers.dc_cp
2564
+ Outlet to inlet pressure ratio at hot side, :math:`pr/1`.
2565
+
2566
+ pr2 : str/float/tespy.tools.data_containers.dc_cp
2567
+ Outlet to inlet pressure ratio at cold side, :math:`pr/1`.
2568
+
2569
+ zeta1 : str/float/tespy.tools.data_containers.dc_cp
2570
+ Geometry independent friction coefficient at hot side,
2571
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
2572
+
2573
+ zeta2 : str/float/tespy.tools.data_containers.dc_cp
2574
+ Geometry independent friction coefficient at cold side,
2575
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
2576
+
2577
+ kA : float/tespy.tools.data_containers.dc_cp
2578
+ Area independent heat transition coefficient,
2579
+ :math:`kA/\frac{\text{W}}{\text{K}}`.
2580
+
2581
+ kA_char : tespy.tools.data_containers.dc_simple
2582
+ Area independent heat transition coefficient characteristic.
2583
+
2584
+ kA_char1 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
2585
+ Characteristic line for hot side heat transfer coefficient.
2586
+
2587
+ kA_char2 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
2588
+ Characteristic line for cold side heat transfer coefficient.
2589
+
2590
+ subcooling : bool
2591
+ Enable/disable subcooling, default value: disabled.
2592
+
2593
+ Note
2594
+ ----
2595
+ The condenser has an additional equation for enthalpy at hot side outlet:
2596
+ The fluid leaves the component in saturated liquid state. If subcooling
2597
+ is activated, it possible to specify the enthalpy at the outgoing
2598
+ connection manually.
2599
+
2600
+ It has different calculation method for given heat transfer coefficient and
2601
+ upper terminal temperature dierence: These parameters refer to the
2602
+ **condensing** temperature, even if the fluid on the hot side enters the
2603
+ component in superheated state.
2604
+
2605
+ Example
2606
+ -------
2607
+ Air is used to condensate water in a condenser. 1 kg/s waste steam is
2608
+ chilled with a terminal temperature difference of 15 K.
2609
+
2610
+ >>> from tespy.components import sink, source, condenser
2611
+ >>> from tespy.connections import connection
2612
+ >>> from tespy.networks import network
2613
+ >>> from tespy.tools.fluid_properties import T_bp_p
2614
+ >>> import shutil
2615
+ >>> nw = network(fluids=['water', 'air'], T_unit='C', p_unit='bar',
2616
+ ... h_unit='kJ / kg', m_range=[0.01, 1000], iterinfo=False)
2617
+ >>> amb_in = sink('ambient air inlet')
2618
+ >>> amb_out = source('air outlet')
2619
+ >>> waste_steam = source('waste steam')
2620
+ >>> c = sink('condensate sink')
2621
+ >>> cond = condenser('condenser')
2622
+ >>> cond.component()
2623
+ 'condenser'
2624
+ >>> amb_he = connection(amb_out, 'out1', cond, 'in2')
2625
+ >>> he_amb = connection(cond, 'out2', amb_in, 'in1')
2626
+ >>> ws_he = connection(waste_steam, 'out1', cond, 'in1')
2627
+ >>> he_c = connection(cond, 'out1', c, 'in1')
2628
+ >>> nw.add_conns(amb_he, he_amb, ws_he, he_c)
2629
+
2630
+ The air flow can not be controlled, thus is constant in offdesign
2631
+ operation. If the waste steam mass flow or the ambient air temperature
2632
+ change, the outlet temperature of the air will change, too.
2633
+
2634
+ >>> cond.set_attr(pr1=0.98, pr2=0.999, ttd_u=15, design=['pr2', 'ttd_u'],
2635
+ ... offdesign=['zeta2', 'kA_char'])
2636
+ >>> ws_he.set_attr(fluid={'water': 1, 'air': 0}, h=2700, m=1)
2637
+ >>> amb_he.set_attr(fluid={'water': 0, 'air': 1}, T=20, offdesign=['v'])
2638
+ >>> he_amb.set_attr(p=1, T=40, design=['T'])
2639
+ >>> nw.solve('design')
2640
+ >>> nw.save('tmp')
2641
+ >>> round(amb_he.v.val, 2)
2642
+ 103.17
2643
+ >>> round(ws_he.T.val - he_amb.T.val, 1)
2644
+ 66.9
2645
+ >>> round(T_bp_p(ws_he.to_flow()) - 273.15 - he_amb.T.val, 1)
2646
+ 15.0
2647
+ >>> ws_he.set_attr(m=0.7)
2648
+ >>> amb_he.set_attr(T=30)
2649
+ >>> nw.solve('offdesign', design_path='tmp')
2650
+ >>> round(ws_he.T.val - he_amb.T.val, 1)
2651
+ 62.5
2652
+ >>> round(T_bp_p(ws_he.to_flow()) - 273.15 - he_amb.T.val, 1)
2653
+ 11.3
2654
+
2655
+ It is possible to activate subcooling. The difference to boiling point
2656
+ temperature is specified to 5 K.
2657
+
2658
+ >>> cond.set_attr(subcooling=True)
2659
+ >>> he_c.set_attr(Td_bp=-5)
2660
+ >>> nw.solve('offdesign', design_path='tmp')
2661
+ >>> round(ws_he.T.val - he_amb.T.val, 1)
2662
+ 62.5
2663
+ >>> round(T_bp_p(ws_he.to_flow()) - 273.15 - he_amb.T.val, 1)
2664
+ 13.4
2665
+ >>> shutil.rmtree('./tmp', ignore_errors=True)
2666
+ """
2667
+
2668
+ @staticmethod
2669
+ def component():
2670
+ return 'condenser'
2671
+
2672
+ @staticmethod
2673
+ def attr():
2674
+ return {
2675
+ 'Q': dc_cp(max_val=0), 'kA': dc_cp(min_val=0),
2676
+ 'td_log': dc_cp(min_val=0),
2677
+ 'ttd_u': dc_cp(min_val=0), 'ttd_l': dc_cp(min_val=0),
2678
+ 'pr1': dc_cp(max_val=1), 'pr2': dc_cp(max_val=1),
2679
+ 'zeta1': dc_cp(min_val=0), 'zeta2': dc_cp(min_val=0),
2680
+ 'subcooling': dc_simple(val=False),
2681
+ 'kA_char': dc_simple(),
2682
+ 'kA_char1': dc_cc(param='m'), 'kA_char2': dc_cc(param='m'),
2683
+ 'SQ1': dc_simple(), 'SQ2': dc_simple(), 'Sirr': dc_simple(),
2684
+ }
2685
+
2686
+ def comp_init(self, nw):
2687
+
2688
+ component.comp_init(self, nw)
2689
+
2690
+ # number of mandatroy equations for
2691
+ # fluid balance: num_fl * 2
2692
+ # mass flow: 2
2693
+ # energy balance: 1
2694
+ self.num_eq = self.num_nw_fluids * 2 + 3
2695
+ # enthalpy hot side outlet (if not subcooling): 1
2696
+ if self.subcooling.val is False:
2697
+ self.num_eq += 1
2698
+ for var in [self.Q, self.kA, self.kA_char, self.ttd_u, self.ttd_l,
2699
+ self.pr1, self.pr2, self.zeta1, self.zeta2]:
2700
+ if var.is_set is True:
2701
+ self.num_eq += 1
2702
+
2703
+ if self.kA.is_set:
2704
+ msg = (
2705
+ 'The usage of the parameter kA has changed for offdesign '
2706
+ 'calculation. Specifying kA will keep a constant value for kA '
2707
+ 'in the calculation. If you want to use the value adaption of '
2708
+ 'kA by the characteristic line, please use kA_char as '
2709
+ 'parameter instead (occurred at ' + self.label + '). This '
2710
+ 'warning will disappear in TESPy version 0.3.2.')
2711
+ warnings.warn(msg, FutureWarning, stacklevel=2)
2712
+
2713
+ self.jacobian = np.zeros((
2714
+ self.num_eq,
2715
+ self.num_i + self.num_o + self.num_vars,
2716
+ self.num_nw_vars))
2717
+
2718
+ self.residual = np.zeros(self.num_eq)
2719
+ pos = self.num_nw_fluids * 2
2720
+ self.jacobian[0:pos] = self.fluid_deriv()
2721
+ self.jacobian[pos:pos + 2] = self.mass_flow_deriv()
2722
+
2723
+ def additional_equations(self, k):
2724
+ r"""
2725
+ Calculate results of additional equations.
2726
+
2727
+ Equations
2728
+
2729
+ **mandatory equations**
2730
+
2731
+ .. math::
2732
+
2733
+ 0 = h_{1,out} - h\left(p, x=0 \right)\\
2734
+ x: \text{vapour mass fraction}
2735
+ """
2736
+ ######################################################################
2737
+ # equation for saturated liquid at hot side outlet
2738
+ if self.subcooling.val is False:
2739
+ o1 = self.outl[0].to_flow()
2740
+ self.residual[k] = o1[2] - h_mix_pQ(o1, 0)
2741
+ k += 1
2742
+
2743
+ def additional_derivatives(self, increment_filter, k):
2744
+ r"""Calculate partial derivatives for given additional equations."""
2745
+ ######################################################################
2746
+ # derivatives for saturated liquid at hot side outlet equation
2747
+ if self.subcooling.val is False:
2748
+ o1 = self.outl[0].to_flow()
2749
+ self.jacobian[k, 2, 1] = -dh_mix_dpQ(o1, 0)
2750
+ self.jacobian[k, 2, 2] = 1
2751
+ k += 1
2752
+
2753
+ def kA_func(self):
2754
+ r"""
2755
+ Calculate heat transfer from heat transfer coefficient.
2756
+
2757
+ Returns
2758
+ -------
2759
+ res : float
2760
+ Residual value of equation.
2761
+
2762
+ .. math::
2763
+
2764
+ res = \dot{m}_{1,in} \cdot \left( h_{1,out} - h_{1,in}\right) +
2765
+ kA \cdot \frac{T_{1,out} -
2766
+ T_{2,in} - T_s \left(p_{1,in}\right) +
2767
+ T_{2,out}}
2768
+ {\ln{\frac{T_{1,out} - T_{2,in}}
2769
+ {T_s \left(p_{1,in}\right) - T_{2,out}}}}
2770
+ """
2771
+
2772
+ i1 = self.inl[0].to_flow()
2773
+ i2 = self.inl[1].to_flow()
2774
+ o1 = self.outl[0].to_flow()
2775
+ o2 = self.outl[1].to_flow()
2776
+
2777
+ T_i1 = T_bp_p(i1)
2778
+ T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
2779
+ T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
2780
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2781
+
2782
+ if T_i1 <= T_o2 and not self.inl[0].T.val_set:
2783
+ T_i1 = T_o2 + 0.5
2784
+ if T_i1 <= T_o2 and not self.outl[1].T.val_set:
2785
+ T_o2 = T_i1 - 0.5
2786
+
2787
+ if T_o1 <= T_i2 and not self.outl[0].T.val_set:
2788
+ T_o1 = T_i2 + 1
2789
+ if T_o1 <= T_i2 and not self.inl[1].T.val_set:
2790
+ T_i2 = T_o1 - 1
2791
+
2792
+ td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
2793
+ np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
2794
+
2795
+ return i1[0] * (o1[2] - i1[2]) + self.kA.val * td_log
2796
+
2797
+ def kA_char_func(self):
2798
+ r"""
2799
+ Calculate heat transfer from heat transfer coefficient characteristic.
2800
+
2801
+ Returns
2802
+ -------
2803
+ res : float
2804
+ Residual value of equation.
2805
+
2806
+ .. math::
2807
+
2808
+ res = \dot{m}_{1,in} \cdot \left( h_{1,out} - h_{1,in}\right) +
2809
+ kA_{ref} \cdot f_{kA} \cdot \frac{T_{1,out} -
2810
+ T_{2,in} - T_s \left(p_{1,in}\right) +
2811
+ T_{2,out}}
2812
+ {\ln{\frac{T_{1,out} - T_{2,in}}
2813
+ {T_s \left(p_{1,in}\right) - T_{2,out}}}}
2814
+
2815
+ f_{kA} = \frac{2}{
2816
+ \frac{1}{f_1\left(\frac{m_1}{m_{1,ref}}\right)} +
2817
+ \frac{1}{f_2\left(\frac{m_2}{m_{2,ref}}\right)}}
2818
+
2819
+ Note
2820
+ ----
2821
+ For standard functions f\ :subscript:`1` \ and f\ :subscript:`2` \ see
2822
+ module :func:`tespy.data`.
2823
+
2824
+ - Calculate temperatures at inlets and outlets.
2825
+ - Perform value manipulation, if temperature levels are physically
2826
+ infeasible.
2827
+ """
2828
+
2829
+ i1 = self.inl[0].to_flow()
2830
+ i2 = self.inl[1].to_flow()
2831
+ o1 = self.outl[0].to_flow()
2832
+ o2 = self.outl[1].to_flow()
2833
+
2834
+ i1_d = self.inl[0].to_flow_design()
2835
+ i2_d = self.inl[1].to_flow_design()
2836
+
2837
+ T_i1 = T_bp_p(i1)
2838
+ T_i2 = T_mix_ph(i2, T0=self.inl[1].T.val_SI)
2839
+ T_o1 = T_mix_ph(o1, T0=self.outl[0].T.val_SI)
2840
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2841
+
2842
+ if T_i1 <= T_o2 and not self.inl[0].T.val_set:
2843
+ T_i1 = T_o2 + 0.5
2844
+ if T_i1 <= T_o2 and not self.outl[1].T.val_set:
2845
+ T_o2 = T_i1 - 0.5
2846
+
2847
+ if T_o1 <= T_i2 and not self.outl[0].T.val_set:
2848
+ T_o1 = T_i2 + 1
2849
+ if T_o1 <= T_i2 and not self.inl[1].T.val_set:
2850
+ T_i2 = T_o1 - 1
2851
+
2852
+ fkA1 = 1
2853
+ if self.kA_char1.param == 'm':
2854
+ fkA1 = self.kA_char1.func.evaluate(i1[0] / i1_d[0])
2855
+
2856
+ fkA2 = 1
2857
+ if self.kA_char2.param == 'm':
2858
+ fkA2 = self.kA_char2.func.evaluate(i2[0] / i2_d[0])
2859
+
2860
+ fkA = 2 / (1 / fkA1 + 1 / fkA2)
2861
+
2862
+ td_log = ((T_o1 - T_i2 - T_i1 + T_o2) /
2863
+ np.log((T_o1 - T_i2) / (T_i1 - T_o2)))
2864
+
2865
+ return i1[0] * (o1[2] - i1[2]) + self.kA.design * fkA * td_log
2866
+
2867
+ def ttd_u_func(self):
2868
+ r"""
2869
+ Equation for upper terminal temperature difference.
2870
+
2871
+ Returns
2872
+ -------
2873
+ res : float
2874
+ Residual value of equation.
2875
+
2876
+ .. math::
2877
+
2878
+ res = ttd_{u} - T_s \left(p_{1,in}\right) + T_{2,out}
2879
+
2880
+ Note
2881
+ ----
2882
+ The upper terminal temperature difference ttd_u refers to boiling
2883
+ temperature at hot side inlet.
2884
+ """
2885
+ i1 = self.inl[0].to_flow()
2886
+ o2 = self.outl[1].to_flow()
2887
+ T_o2 = T_mix_ph(o2, T0=self.outl[1].T.val_SI)
2888
+ return self.ttd_u.val - T_bp_p(i1) + T_o2
2889
+
2890
+ # %%
2891
+
2892
+
2893
+ class desuperheater(heat_exchanger):
2894
+ r"""
2895
+ The desuperheater cools a fluid to the saturated gas state.
2896
+
2897
+ Equations
2898
+
2899
+ **mandatory equations**
2900
+
2901
+ - :func:`tespy.components.components.component.fluid_func`
2902
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.mass_flow_func`
2903
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.energy_func`
2904
+
2905
+ **optional equations**
2906
+
2907
+ .. math::
2908
+
2909
+ 0 = \dot{m}_{in} \cdot \left(h_{out} - h_{in} \right) - \dot{Q}
2910
+
2911
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.kA_func`
2912
+ - :func:`tespy.components.heat_exchangers.heat_exchanger.ttd_u_func`
2913
+
2914
+ .. math::
2915
+
2916
+ 0 = p_{1,in} \cdot pr1 - p_{1,out}\\
2917
+ 0 = p_{2,in} \cdot pr2 - p_{2,out}
2918
+
2919
+ - hot side :func:`tespy.components.components.component.zeta_func`
2920
+ - cold side :func:`tespy.components.components.component.zeta_func`
2921
+
2922
+ **additional equations**
2923
+
2924
+ - :func:`tespy.components.heat_exchangers.desuperheater.additional_equations`
2925
+
2926
+ Inlets/Outlets
2927
+
2928
+ - in1, in2 (index 1: hot side, index 2: cold side)
2929
+ - out1, out2 (index 1: hot side, index 2: cold side)
2930
+
2931
+ Image
2932
+
2933
+ .. image:: _images/heat_exchanger.svg
2934
+ :scale: 100 %
2935
+ :alt: alternative text
2936
+ :align: center
2937
+
2938
+ Parameters
2939
+ ----------
2940
+ label : str
2941
+ The label of the component.
2942
+
2943
+ design : list
2944
+ List containing design parameters (stated as String).
2945
+
2946
+ offdesign : list
2947
+ List containing offdesign parameters (stated as String).
2948
+
2949
+ design_path: str
2950
+ Path to the components design case.
2951
+
2952
+ local_offdesign : boolean
2953
+ Treat this component in offdesign mode in a design calculation.
2954
+
2955
+ local_design : boolean
2956
+ Treat this component in design mode in an offdesign calculation.
2957
+
2958
+ char_warnings: boolean
2959
+ Ignore warnings on default characteristics usage for this component.
2960
+
2961
+ printout: boolean
2962
+ Include this component in the network's results printout.
2963
+
2964
+ Q : str/float/tespy.tools.data_containers.dc_cp
2965
+ Heat transfer, :math:`Q/\text{W}`.
2966
+
2967
+ pr1 : str/float/tespy.tools.data_containers.dc_cp
2968
+ Outlet to inlet pressure ratio at hot side, :math:`pr/1`.
2969
+
2970
+ pr2 : str/float/tespy.tools.data_containers.dc_cp
2971
+ Outlet to inlet pressure ratio at cold side, :math:`pr/1`.
2972
+
2973
+ zeta1 : str/float/tespy.tools.data_containers.dc_cp
2974
+ Geometry independent friction coefficient at hot side,
2975
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
2976
+
2977
+ zeta2 : str/float/tespy.tools.data_containers.dc_cp
2978
+ Geometry independent friction coefficient at cold side,
2979
+ :math:`\frac{\zeta}{D^4}/\frac{1}{\text{m}^4}`.
2980
+
2981
+ kA : str/float/tespy.tools.data_containers.dc_cp
2982
+ Area independent heat transition coefficient,
2983
+ :math:`kA/\frac{\text{W}}{\text{K}}`.
2984
+
2985
+ kA_char1 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
2986
+ Characteristic line for hot side heat transfer coefficient.
2987
+
2988
+ kA_char2 : tespy.tools.charactersitics.char_line/tespy.tools.data_containers.dc_cc
2989
+ Characteristic line for cold side heat transfer coefficient.
2990
+
2991
+ Note
2992
+ ----
2993
+ The desuperheater has an additional equation for enthalpy at hot side
2994
+ outlet: The fluid leaves the component in saturated gas state.
2995
+
2996
+ Example
2997
+ -------
2998
+ Overheated enthanol is cooled with water in a heat exchanger until it
2999
+ reaches the state of saturated gas.
3000
+
3001
+ >>> from tespy.components import sink, source, desuperheater
3002
+ >>> from tespy.connections import connection
3003
+ >>> from tespy.networks import network
3004
+ >>> from tespy.tools.fluid_properties import T_bp_p
3005
+ >>> import shutil
3006
+ >>> nw = network(fluids=['water', 'ethanol'], T_unit='C', p_unit='bar',
3007
+ ... h_unit='kJ / kg', v_unit='l / s', m_range=[0.001, 10], iterinfo=False)
3008
+ >>> et_in = source('ethanol inlet')
3009
+ >>> et_out = sink('ethanol outlet')
3010
+ >>> cw_in = source('cooling water inlet')
3011
+ >>> cw_out = sink('cooling water outlet')
3012
+ >>> desu = desuperheater('desuperheater')
3013
+ >>> desu.component()
3014
+ 'desuperheater'
3015
+ >>> et_de = connection(et_in, 'out1', desu, 'in1')
3016
+ >>> de_et = connection(desu, 'out1', et_out, 'in1')
3017
+ >>> cw_de = connection(cw_in, 'out1', desu, 'in2')
3018
+ >>> de_cw = connection(desu, 'out2', cw_out, 'in1')
3019
+ >>> nw.add_conns(et_de, de_et, cw_de, de_cw)
3020
+
3021
+ The cooling water enters the component at 15 °C. 10 l/s of ethanol is
3022
+ cooled from 100 K above boiling point. The water flow rate is at 1 l/s.
3023
+ Knowing the component's design parameters it is possible to predict
3024
+ behavior at different inlet temperatures or different volumetric flow of
3025
+ ethanol. Controlling the ethanol's state at the outlet is only possible,
3026
+ if the cooling water flow rate is adjusted accordingly.
3027
+
3028
+ >>> desu.set_attr(pr1=0.99, pr2=0.98, design=['pr1', 'pr2'],
3029
+ ... offdesign=['zeta1', 'zeta2', 'kA_char'])
3030
+ >>> cw_de.set_attr(fluid={'water': 1, 'ethanol': 0}, T=15, v=1,
3031
+ ... design=['v'])
3032
+ >>> de_cw.set_attr(p=1)
3033
+ >>> et_de.set_attr(fluid={'water': 0, 'ethanol': 1}, Td_bp=100, v=10)
3034
+ >>> de_et.set_attr(p=1)
3035
+ >>> nw.solve('design')
3036
+ >>> nw.save('tmp')
3037
+ >>> round(de_cw.T.val, 1)
3038
+ 15.5
3039
+ >>> round(de_et.x.val, 1)
3040
+ 1.0
3041
+ >>> et_de.set_attr(v=12)
3042
+ >>> nw.solve('offdesign', design_path='tmp')
3043
+ >>> round(cw_de.v.val, 2)
3044
+ 1.94
3045
+ >>> et_de.set_attr(v=7)
3046
+ >>> nw.solve('offdesign', design_path='tmp', init_path='tmp')
3047
+ >>> round(cw_de.v.val, 2)
3048
+ 0.41
3049
+ >>> shutil.rmtree('./tmp', ignore_errors=True)
3050
+ """
3051
+
3052
+ @staticmethod
3053
+ def component():
3054
+ return 'desuperheater'
3055
+
3056
+ def comp_init(self, nw):
3057
+
3058
+ component.comp_init(self, nw)
3059
+
3060
+ # number of mandatroy equations for
3061
+ # fluid balance: num_fl * 2
3062
+ # mass flow: 2
3063
+ # energy balance: 1
3064
+ # enthalpy hot side outlet: 1
3065
+ self.num_eq = self.num_nw_fluids * 2 + 4
3066
+ for var in [self.Q, self.kA, self.kA_char, self.ttd_u, self.ttd_l,
3067
+ self.pr1, self.pr2, self.zeta1, self.zeta2]:
3068
+ if var.is_set is True:
3069
+ self.num_eq += 1
3070
+
3071
+ if self.kA.is_set:
3072
+ msg = (
3073
+ 'The usage of the parameter kA has changed for offdesign '
3074
+ 'calculation. Specifying kA will keep a constant value for kA '
3075
+ 'in the calculation. If you want to use the value adaption of '
3076
+ 'kA by the characteristic line, please use kA_char as '
3077
+ 'parameter instead (occurred at ' + self.label + '). This '
3078
+ 'warning will disappear in TESPy version 0.3.2.')
3079
+ warnings.warn(msg, FutureWarning, stacklevel=2)
3080
+
3081
+ self.jacobian = np.zeros((
3082
+ self.num_eq,
3083
+ self.num_i + self.num_o + self.num_vars,
3084
+ self.num_nw_vars))
3085
+
3086
+ self.residual = np.zeros(self.num_eq)
3087
+ pos = self.num_nw_fluids * 2
3088
+ self.jacobian[0:pos] = self.fluid_deriv()
3089
+ self.jacobian[pos:pos + 2] = self.mass_flow_deriv()
3090
+
3091
+ def additional_equations(self, k):
3092
+ r"""
3093
+ Calculate results of additional equations.
3094
+
3095
+ Equations
3096
+
3097
+ **mandatory equations**
3098
+
3099
+ .. math::
3100
+
3101
+ 0 = h_{1,out} - h\left(p, x=1 \right)\\
3102
+ x: \text{vapour mass fraction}
3103
+ """
3104
+ ######################################################################
3105
+ # equation for saturated gas at hot side outlet
3106
+ o1 = self.outl[0].to_flow()
3107
+ self.residual[k] = o1[2] - h_mix_pQ(o1, 1)
3108
+
3109
+ def additional_derivatives(self, increment_filter, k):
3110
+ r"""Calculate partial derivatives for given additional equations."""
3111
+ ######################################################################
3112
+ # derivatives for saturated gas at hot side outlet equation
3113
+ o1 = self.outl[0].to_flow()
3114
+ self.jacobian[k, 2, 1] = -dh_mix_dpQ(o1, 1)
3115
+ self.jacobian[k, 2, 2] = 1
3116
+ k += 1