-
Notifications
You must be signed in to change notification settings - Fork 2
/
hx_crossflow_solver.py
1976 lines (1731 loc) · 64.2 KB
/
hx_crossflow_solver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
""" Element-based cross-flow heat exchanger model for complex fluids
Author: Andrew Lock
Date refactored: October 2023
Note: This is mostly old and poorly witten code.
One day it will be re-written with best practices.
Refer to publication for details: 10.1016/j.applthermaleng.2019.114390
"""
import numpy as np
import CoolProp as CPCP
from CoolProp.CoolProp import PropsSI as CP
import scipy as sci
from scipy import optimize
import matplotlib.pyplot as plt
from statistics import mean
from scipy.interpolate import interp1d
global EosPF
# ------------------PROPERTY CLASSES-------------------------------------------
class Model:
# Create model detail classes
def __init__(self):
self.Nu_CorrelationH = [] # set correlation for heat transfer in H channel
self.alpha_CorrelationC = [] # set correlation for heat transfer in C channel
self.row_correction = []
self.f_CorrelationH = [] # set correlation for friction factor in H channel
self.f_CorrelationC = [] # set correlation for friction factor in C channel
self.alpha_o = [] # (W/m2)
self.iteration_no = 0 # Iteration counter
self.solver_figure = [] # Switch for solver figure
self.final_figure = [] # Switch for final figures
self.consider_bends = [] # Switch for considering bends in pressure loss
self.bend_loss_coefficient = [] # Friction factor for pressure loss in bends
# Swtich for solver type:
# (0) for pressure differential input,
# (1) for total mass flow input
self.solver_type = []
# Switch for cooler type
self.cooler_type = []
class Geometry:
def __init__(self):
self.dx_i = [] # number of cells
self.k_wall = [] # thermal conductivity (W / m)
self.l_hx_th = [] # (m)
self.HX_length = []
self.n_rows = []
self.n_passes = []
self.pitch_longitudal = [] # - (m) Streamwise tube pitch
self.pitch_transverse = [] # - (m) Normal to stream tube pitch (X,Y)
self.ID = [] # (m) ID of HX pipe
self.t_wall = [] # (m) Pipe wall thickness
self.pitch_fin = [] # (m) Pitch spacing of fins
self.D_fin = [] # (m) Fin diameter
self.t_fin = [] # (m) Fin thickness
self.k_fin = [] # (W/m) Fin matieral thermal conductivity
# def read_yaml(self, filepath):
def micro_init(self):
self.l_hx_th = self.HX_length
self.n_CPR = int(self.l_hx_th // self.dx_i + 1) # Cells per row
self.n_cells = self.n_CPR * self.n_rows
self.n_CP = int(self.n_rows / self.n_passes) # Number of adjacent co-flow rows
if self.n_rows % self.n_passes != 0:
raise MyError("Incorrect pipework arrangement")
self.dx = self.l_hx_th / self.n_CPR
self.A_amb = self.pitch_transverse * self.dx # Air entry/exit area
self.A_CS = np.pi * (self.ID**2) / 4 # Internal cross sectional area of pipe
self.tube_OD = self.ID + (2 * self.t_wall)
self.A_WCS = np.pi * (1 / 4) * ((self.tube_OD**2) - (self.ID**2))
self.A_tube_o = float(np.pi * self.tube_OD * self.dx)
self.A_tube_i = float(np.pi * self.ID * self.dx)
# Equation 3.3.13 fro Kroger
self.eta_phi = ((self.D_fin / self.tube_OD) - 1) * (
1 + (0.35 * (np.log(self.D_fin / self.tube_OD)))
)
self.bend_path_length = np.pi * self.pitch_transverse / 2
if self.D_fin:
# Area of the fins only
self.A_f = (self.dx / self.pitch_fin) * (
(((self.D_fin**2) - (self.tube_OD**2)) * np.pi / 2)
+ self.D_fin * self.t_fin
)
# Area of the root between fins
self.A_r = self.A_tube_o - (
(self.dx / self.pitch_fin) * self.t_fin * self.tube_OD * np.pi
)
# Total exposed area
self.A_ft = self.A_f + self.A_r
# Total maximum cross-section blokage
self.A_FT_airS = (self.tube_OD * self.dx) + (
(self.dx / self.pitch_fin) * self.t_fin * (self.D_fin - self.tube_OD)
)
# Mininum free flow area
self.A_c = self.A_amb - self.A_FT_airS
# Fin height
self.H_f = 0.5 * (self.D_fin - self.tube_OD)
# Ratio of exposed area to root area
self.A_rat = (self.A_f + self.A_r) / self.A_tube_o
# Construct vectors of X position and row number for post-analysis and
# plotting
self.x_pf = np.tile(np.linspace(0, self.HX_length, self.n_CPR + 1), self.n_rows)
self.x_air = np.tile(
np.linspace(self.dx / 2, self.HX_length - self.dx / 2, self.n_CPR),
self.n_rows + 1,
)
self.x_wall = np.tile(
np.linspace(self.dx / 2, self.HX_length - self.dx / 2, self.n_CPR),
self.n_rows,
)
self.row_pf = np.array(
[np.full(self.n_CPR + 1, i) for i in range(self.n_rows)]
).flatten()
self.row_air = np.array(
[np.full(self.n_CPR, i) for i in range(self.n_rows + 1)]
).flatten()
self.row_wall = np.array(
[np.full(self.n_CPR, i) for i in range(self.n_rows)]
).flatten()
class Fluid:
def __init__(self):
self.PF_fluid = []
self.Amb_fluid = []
self.T_PF_in = [] # (K)
self.mdot_PF = [] # (kg/s)
self.P_PF_in = [] # pressure (Pa)
self.T_air_in = [] # (K)
self.vC_in = [] # (m/s)
self.P_amb_in = [] # pressure (Pa)
self.P_PF_dp = (
[]
) # Process fluid pressure drop for boundary conditin option(Pa)
self.T_PF_out = (
[]
) # Outlet process fluid temperature for boundary condition option
def micro_init(self, G):
self.Vdot_C = G.A_amb * self.vC_in # (m3/s) air volumetric flow rate per cell
self.mdot_C = self.Vdot_C * CP(
"D", "P", self.P_amb_in, "T", self.T_air_in, self.Amb_fluid
)
self.mdot_amb_max = self.mdot_C / G.A_c
crit_object = crit_temp_object()
self.T_pc = crit_object((self.P_PF_in - 101325) / 1e6)
class CT_Geometry:
def __init__(self):
self.R_Hd = [] # Aspect ratio H5/d3
self.R_dD = [] # Diameter ratio d5/d3
self.R_AA = [] # Area coverage of heat exchangers Aft/A3
self.R_hD = [] # Ratio of inlet height to diameter H3/d3
self.R_sd = [] # Ratio of number of tower supports to d3
self.R_LH = [] # Ratio of height support to tower height L/H3
self.D_ts = [] # Diameter of tower supports
self.C_Dts = [] # Drag coefficeint of tower supports
self.K_ct = [] # Loss coefficient of cooling tower separation
self.sigma_c = [] # Sigma_c, per Kroger
self.dA_width = (
[]
) # (m2) Frontal width (including series rows) of section of HX analysed in code
self.solver_type = [] #
self.d3 = [] # Initial guess for cooling tower diameter
self.mdot_PF_total = [] # (kg/s) Total PF mass flow rate througout system
self.T_a1 = [] # (K) Ambient temperature
self.p_a1 = [] # (Pa) Ambient temperature
def dim_update(self, d3):
# All dimensions in meters and labelled per Kroger
self.d3 = d3
self.H5 = self.R_Hd * self.d3
self.d5 = self.R_dD * self.d3
self.A3 = np.pi * 0.25 * (self.d3**2)
self.A5 = np.pi * 0.25 * (self.d5**2)
self.A_fr = self.A3 * self.R_AA
self.H3 = self.R_hD * self.d3
self.n_ts = self.R_sd * self.d3
self.L_ts = self.R_LH * self.d3
def micro_init(self, HX_L, pitch_transverse, T_air_in, PC_in):
self.dA_width = pitch_transverse
self.dA_HX = self.dA_width * HX_L
self.T_a1 = T_air_in
self.p_a1 = PC_in # (Pa) Ambient temperature
# ------------------HEAT TRANSFER & FRICTON CORRELATIONS---------------
def calc_Nu(
G,
F,
Re=0,
Pr=0,
P=0,
Tb=0,
Tw=0,
rho_b=0,
rho_w=0,
Correlation=0,
K_c=0,
mu_b=0,
x1=0,
x2=0,
Dh=0,
):
"""Function to return Nusselt number for internal pipe fluid flow.
More options can be added as necessary
"""
if Correlation == 0:
Nu = 1
if Correlation in [1, "Yoon-1"]:
# Yoon et al correlation for Nu based on bulk temperature only
if Tb > F.T_pc:
Nu = 0.14 * Re**0.69 * Pr**0.66
else:
rho_pc = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, F.T_pc], [CPCP.iDmass])
Nu = 0.013 * Re**1 * Pr**-0.05 * (rho_pc / rho_b) ** 1.6
if Correlation in [2, "Yoon-2"]:
# Yoon et al corelation that incorporates wall temperature
h_b, k_b = GetFluidPropLow(
EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iHmass, CPCP.iconductivity]
)
h_w, Cp_w, mu_w, k_w, Pr_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
e[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iviscosity,
CPCP.iconductivity,
CPCP.iPrandtl,
],
)
Re_w = Re * (mu_b / mu_w)
Cp_bar = (h_w - h_b) / (Tw - Tb)
f = ((0.79 * np.log(Re_w)) - 1.64) ** -2
Nu_w = ((f / 8) * (Re_w) * Pr_w) / (
1.07 + (12.7 * ((f / 8) ** 0.5) * ((Pr_w ** (2 / 3)) - 1))
)
Nu = (
1.38
* Nu_w
* ((Cp_bar / Cp_w) ** 0.86)
* ((rho_w / rho_b) ** 0.57)
* (k_w / k_b)
)
if Correlation in [3, "Gnielinski"]: # Gnielinski
f = ((0.79 * np.log(Re)) - 1.64) ** -2
Nu = ((f / 8) * (Re - 1000) * Pr) / (
1 + (12.7 * ((f / 8) ** 0.5) * ((Pr ** (2 / 3)) - 1))
)
if Correlation in [4, "Pitla"]: # Pitla et al
Cp_w, mu_w, k_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[CPCP.iCpmass, CPCP.iviscosity, CPCP.iconductivity],
)
k_b = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iconductivity])
Pr_w = mu_w * Cp_w / k_w
Re_w = Re * (mu_b / mu_w) * (rho_w / rho_b)
f = ((0.79 * np.log(Re)) - 1.64) ** -2
f_w = ((0.79 * np.log(Re_w)) - 1.64) ** -2
Nu_b = ((f / 8) * (Re - 1000) * Pr) / (
1.0 + (12.7 * ((f / 8) ** 0.5) * ((Pr ** (2 / 3)) - 1))
)
Nu_w = ((f_w / 8) * (Re_w - 1000) * Pr_w) / (
1.0 + (12.7 * ((f_w / 8) ** 0.5) * ((Pr_w ** (2 / 3)) - 1))
)
Nu = ((Nu_w + Nu_b) / 2) * (k_w / k_b)
if Correlation == "Mean-Gnielinski":
Tf = (Tb + Tw) / 2
Cp_f, mu_f, k_f, rho_f = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tf],
[CPCP.iCpmass, CPCP.iviscosity, CPCP.iconductivity, CPCP.iDmass],
)
k_b = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iconductivity])
Pr_f = mu_f * Cp_f / k_f
Re_f = Re * (mu_b / mu_f) * (rho_f / rho_b)
f_f = ((0.79 * np.log(Re_f)) - 1.64) ** -2
Nu_f = ((f_f / 8) * (Re_f - 1000) * Pr_f) / (
1.0 + (12.7 * ((f_f / 8) ** 0.5) * ((Pr_f ** (2 / 3)) - 1))
)
Nu = Nu_f * (k_f / k_b)
if Correlation == "Mix-Gnielinski": # Pitla et al
rho_w, mu_w, k_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[CPCP.iDmass, CPCP.iviscosity, CPCP.iconductivity],
)
k_b = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iconductivity])
Re_w = Re * (rho_w / rho_b) * (mu_b / mu_w)
f_w = ((0.79 * np.log(Re_w)) - 1.64) ** -2
Nu = ((f_w / 8) * (Re_w - 1000) * Pr) / (
1.0 + (12.7 * ((f_w / 8) ** 0.5) * ((Pr ** (2 / 3)) - 1))
)
Nu = Nu * (k_w / k_b)
if Correlation in [5, "Wang"]: # Wang et al (UQ)
Tf = (Tb + Tw) / 2
h_b = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iHmass])
h_w = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tw], [CPCP.iHmass])
if (Tb - Tw) == 0:
print(h_b, h_w, Tb, Tw)
Cp_bar = (h_b - h_w) / (Tb - Tw)
Cp_w = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tw], [CPCP.iCpmass])
mu_f = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tf], [CPCP.iviscosity])
k_f = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tf], [CPCP.iconductivity])
k_b = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iconductivity])
Re_f = Re * (mu_b / mu_f)
f_f = (0.79 * np.log(Re_f) - 1.64) ** -2
Pr_f = mu_f * Cp_bar / k_f
Nu_iso = ((f_f / 8) * Re * Pr_f) / (
1.07 + (12.7 * ((f_f / 8) ** 0.5) * ((Pr_f ** (2 / 3)) - 1))
)
Nu = 1.2838 * Nu_iso * ((rho_w / rho_b) ** -0.1458) * (k_f / k_b)
if Correlation in [6, "Aspen"]: # From ASPEN, for liquid being cooled
mu_w = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tw], [CPCP.iviscosity])
if F.PF_fluid == "CO2":
Fp = 1
else:
Fp = (mu_b / mu_w) ** 0.25
Nu_t = 0.02246 * (Re**0.795) * (Pr ** (0.495 - (0.0225 * np.log(Pr)))) * Fp
if Re > 30000:
Nu = Nu_t
else:
Gz = (np.pi * Dh / (4 * x2)) * Re * Pr
Nu_e1 = (365 + 13.03 * (Gz ** (4 / 3))) ** (1 / 4)
Nu_e2 = (365 + 13.03 * (((x2 / x1) * Gz) ** (4 / 3))) ** (1 / 4)
Nu_e3 = ((x2 * Nu_e1) - (x1 * Nu_e2)) / (x2 - x1)
Nu_l = Nu_e3
Nu_t1 = (
1
/ (
(1 / Nu_t**2)
+ (1 / (Nu_l * ((np.exp((min(10000, Re) - 2200) / 730)) ** 2)))
)
) ** 0.5
Nu = max(Nu_t1, Nu_l)
if Correlation == "Krasn.-1969":
if not hasattr(F, "Kras_interp"):
ps = [7.845, 8, 8.5, 9, 10, 12]
ns = [0.3, 0.38, 0.54, 0.61, 0.68, 0.8]
Bs = [0.68, 0.75, 0.85, 0.91, 0.97, 1]
# Changed from 'k' to avoid confict with conductivity
gs = [0.21, 0.18, 0.104, 0.066, 0.040, 0]
F.Kras_interp = interp1d(ps, [ns, Bs, gs], fill_value="extrapolate")
h_b, k_b = GetFluidPropLow(
EosPF, [CPCP.PT_INPUTS, P, Tb], [CPCP.iHmass, CPCP.iconductivity]
)
h_w, Cp_w, k_w, mu_w, Pr_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iconductivity,
CPCP.iviscosity,
CPCP.iPrandtl,
],
)
Re_w = Re * (mu_b / mu_w)
f_w = (0.79 * np.log(Re_w) - 1.64) ** -2
Nu_o = ((f_w / 8) * Re_w * Pr_w) / (
1.07 + (12.7 * ((f_w / 8) ** 0.5) * ((Pr_w ** (2 / 3)) - 1))
)
Cp_bar = (h_w - h_b) / (Tw - Tb)
n, B, g = F.Kras_interp(P / 1e6)
m = B * ((Cp_bar / Cp_w) ** g)
Nu = Nu_o * ((rho_w / rho_b) ** n) * ((Cp_bar / Cp_w) ** m) * (k_w / k_b)
if Correlation == "Liao":
h_b, k_b, mu_b = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tb],
[CPCP.iHmass, CPCP.iconductivity, CPCP.iviscosity],
)
h_w, cp_w, k_w, mu_w, Pr_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iconductivity,
CPCP.iviscosity,
CPCP.iPrandtl,
],
)
Re_w = Re * (mu_b / mu_w)
cp_bar = (h_w - h_b) / (Tw - Tb)
if not rho_w > rho_b:
rho_w = rho_b + 0.01
Gr = rho_b * (rho_w - rho_b) * 9.81 * G.ID**3 / (mu_b**2)
Nu = (
0.128
* Re_w**0.8
* Pr_w**0.3
* (Gr / (Re**2)) ** 0.205
* (rho_b / rho_w) ** 0.437
* (cp_bar / cp_w) ** 0.411
* (k_w / k_b)
)
if Correlation == "Zhang":
Tf = (Tb + Tw) / 2
h_b, k_b, mu_b = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tb],
[CPCP.iHmass, CPCP.iconductivity, CPCP.iviscosity],
)
h_f, cp_f, k_f, mu_f, Pr_f, rho_f = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tf],
[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iconductivity,
CPCP.iviscosity,
CPCP.iPrandtl,
CPCP.iDmass,
],
)
h_w = GetFluidPropLow(EosPF, [CPCP.PT_INPUTS, P, Tw], [CPCP.iHmass])
Re_f = Re * (mu_b / mu_f)
cp_bar_f = (h_w - h_f) / (Tw - Tf)
if not rho_w > rho_f:
rho_w = rho_f + 0.1
Gr_f = rho_f * (rho_w - rho_f) * 9.81 * G.ID**3 / (mu_f**2)
x = (x1 + x2) / 2
Nu = (
0.138
* Re_f**0.68
* Pr_f**0.07
* (rho_f / rho_w) ** -0.74
* (cp_bar_f / cp_f) ** -0.31
* (Gr_f / (Re**2)) ** 0.08
* (1 + ((G.ID / x) ** (2 / 3)))
* (k_f / k_b)
)
if Correlation == "Dang":
Tf = (Tb + Tw) / 2
cp_f, mu_f, k_f, rho_f = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tf],
[CPCP.iCpmass, CPCP.iviscosity, CPCP.iconductivity, CPCP.iDmass],
)
h_w, Cp_w, k_w, mu_w, Pr_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iconductivity,
CPCP.iviscosity,
CPCP.iPrandtl,
],
)
h_b, k_b, cp_b = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tb],
[CPCP.iHmass, CPCP.iconductivity, CPCP.iCpmass],
)
Re_f = Re * (mu_b / mu_f)
Re_w = Re * (mu_b / mu_w)
f_f = ((0.79 * np.log(Re_f)) - 1.64) ** -2
cp_bar = (h_w - h_b) / (Tw - Tb)
rat1 = mu_b / k_b
rat2 = mu_f / k_f
if cp_b > cp_bar:
Pr = Pr
elif rat1 > rat2:
Pr = cp_bar * mu_b / k_b
else:
Pr = cp_bar * mu_f / k_f
Nu = (
((f_f / 8) * (Re - 1000) * Pr)
/ (1.07 + (12.7 * ((f_f / 8) ** 0.5) * ((Pr ** (2 / 3)) - 1)))
* (k_f / k_b)
)
if Correlation == "Liu":
h_b, k_b, cp_b = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tb],
[CPCP.iHmass, CPCP.iconductivity, CPCP.iCpmass],
)
h_w, cp_w, k_w, mu_w, Pr_w = GetFluidPropLow(
EosPF,
[CPCP.PT_INPUTS, P, Tw],
[
CPCP.iHmass,
CPCP.iCpmass,
CPCP.iconductivity,
CPCP.iviscosity,
CPCP.iPrandtl,
],
)
Re_w = Re * (mu_b / mu_w)
Nu = (
0.01
* Re_w**0.9
* Pr_w**0.5
* (rho_w / rho_b) ** 0.906
* (cp_b / cp_w) ** 0.585
* (k_w / k_b)
)
if Correlation == "New_correlation":
t3 = G.ID**3 * 9.81 * rho_b**2 / mu_b**2
if rho_w > rho_b:
t4 = (rho_w - rho_b) / rho_b
else:
t4 = 1
Nu = 2.6859e-9 * Re**0.6544 * Pr**0.2827 * t3**0.77429 * t4**-0.2839
return Nu
def calc_alpha_amb(
G, F, I, Re=0, Pr=0, Tb=0, rho_b=0, Correlation=0, K_c=0, row_correction=0
):
"""Function to return air-side finned tube heat transfer coefficient"""
mu = I.mu_f(Tb)
if Correlation == 1: # Briggs and Young finned tube correlation
k = I.k_f(Tb)
Re = (F.mdot_C / G.A_c) * G.tube_OD / mu
Nu = (
0.134
* (Pr**0.33)
* (Re**0.681)
* ((2 * (G.pitch_fin - G.t_fin) / (G.D_fin - G.tube_OD)) ** 0.2)
* (((G.pitch_fin - G.t_fin) / G.t_fin) ** 0.1134)
)
alpha = Nu * k / G.tube_OD
if Correlation == 2: # Gaugouli finned tube correlation
k = I.k_f(Tb)
Re = (F.mdot_C / G.A_c) * G.tube_OD / mu
Nu = 0.38 * (Re**0.6) * (Pr ** (1 / 3)) * ((G.A_rat) ** -0.15)
alpha = Nu * k / G.tube_OD
if Correlation == 3: # From ASPEN HTFS3-AC
cp = I.cp_f(Tb)
U = F.mdot_C / (rho_b * G.A_amb)
U_f = K_c * U
Re_f = rho_b * U_f * G.tube_OD / mu
u_max = F.mdot_C / (rho_b * G.A_c)
Re_max = u_max * rho_b * G.tube_OD / mu
j = 1.207 * (Re_f**0.04) * (Re_max**-0.5094) * (G.A_rat**-0.312)
alpha = j * cp * F.mdot_amb_max * (Pr ** (-2 / 3))
if Correlation == 4: # ASPEN HTFS3
cp = I.cp_f(Tb)
U = F.mdot_C / (rho_b * G.A_amb)
U_f = K_c * U
Re_f = rho_b * U_f * G.tube_OD / mu
u_max = F.mdot_C / (rho_b * G.A_c)
Re_max = u_max * rho_b * G.tube_OD / mu
j = 0.205 * (Re_max**-0.368) * (Re_f**0.04) * (G.A_rat**-0.15)
alpha = j * cp * F.mdot_amb_max * (Pr ** (-2 / 3))
if row_correction:
# Correction for turbulence difference from multiple rows. From Kroger.
u_max = F.mdot_C / (rho_b * G.A_c)
alpha = alpha * ((1 + (u_max / (G.n_rows**2))) ** -0.14)
return alpha
def calc_f(
Re, P, Tm, Tp, TW, mdot, A, Dh, fluid, Correlation, rho_b, rho_w, mu_b, epsilon=0
):
"""Function to return friction factor for internal pipe flow"""
if Re < 2500:
Nu = 64 / Re
if Correlation == 0:
f = 0
if Correlation == 1:
f = (0.79 * np.log(Re) - 1.64) ** -2 # Petukov
if Correlation == 2:
# Haaland formula for friction factor.
e = 5e-5
f = 1 / (-1.8 * np.log10((6.9 / Re) + ((e / (3.7 * Dh)) ** 1.11))) ** 2
if Correlation == 3: # Blasius fricion factor
if Re < 2e4:
f = 0.316 * Re ** (-1 / 4)
else:
f = 0.184 * Re ** (-1 / 5)
return f
def calc_air_dp(G, rho, mu):
"""Function to return pressure differential per row for air through
finned tube banks, from ASPEN HTRI
"""
K_tube = (
4.75
* G.n_rows
* G.pitch_longitudal
* ((mu / rho) ** 0.3)
* (((G.pitch_transverse / G.tube_OD) - 1) ** -1.86)
* (G.tube_OD**-1.3)
)
phi = (
np.pi
* ((G.D_fin**2) - (G.tube_OD**2))
* (1 / G.pitch_fin)
* G.n_rows
/ (2 * G.D_fin)
)
B = G.A_FT_airS / G.dx
tau = G.D_fin / (G.D_fin - B)
K_fins = 0.0265 * phi * (tau**1.7)
K_ft = K_tube + K_fins
N_G = G.n_rows - 1
G_D = (
((G.pitch_longitudal**2) + ((0.5 * G.pitch_transverse) ** 2)) ** 0.5
) - G.D_fin
G_T = G.pitch_transverse - G.D_fin
G_A = 0.5 * (G.D_fin - G.tube_OD)
GR_eff = (G_D + G_A) / G_T
theta = np.arctan(0.5 * G.pitch_transverse / G.pitch_longitudal)
K_gap = N_G * theta * GR_eff
K_B = K_ft / (
(
(G.D_fin / G.pitch_transverse)
+ (((K_ft / K_gap) ** (1 / 1.7)) * (1 - (G.D_fin / G.pitch_transverse)))
)
** 1.7
)
return K_B, K_ft
# ------------------UTILITY FUNCTIONS----------------------------------
def crit_temp_object():
"""Returns an interpolation object used to find critical point for a given
pressure.
"""
def Cp(T, P):
# return CP('C','T',T,'P',P,'CO2')
HEOS = CPCP.AbstractState("HEOS", "CO2")
HEOS.update(CPCP.PT_INPUTS, P, T)
C = HEOS.cpmass()
return C
P_array = [7.4, 7.5, 7.6, 7.8, 8, 8.5, 9, 9.5, 10]
T_array = []
for i in range(len(P_array)):
Tcrit = optimize.fmin(
lambda T: -1 * Cp(T, (P_array[i] * 1e6) + 101325),
273.15 + 40,
xtol=1e-8,
disp=False,
)
T_array.append(Tcrit[0])
crit_inter = interp1d(P_array, T_array, fill_value="extrapolate")
return crit_inter
class inter_fs:
"""This function creates an interpolation matrix of fluid properties for
the cold (air) side
"""
def __init__(self, T_l, T_h, P, fluid):
n = 100
T = np.linspace(T_l, T_h, n)
V = CP("V", "P", P, "T", T[0:n], fluid)
D = CP("D", "P", P, "T", T[0:n], fluid)
H = CP("H", "P", P, "T", T[0:n], fluid)
K = CP("CONDUCTIVITY", "P", P, "T", T[0:n], fluid)
C = CP("C", "P", P, "T", T[0:n], fluid)
Pr = CP("PRANDTL", "P", P, "T", T[0:n], fluid)
self.mu_f = interp1d(T, V, bounds_error=False, fill_value="extrapolate")
self.rho_f = interp1d(T, D, bounds_error=False, fill_value="extrapolate")
self.h_f = interp1d(T, H, bounds_error=False, fill_value="extrapolate")
self.k_f = interp1d(T, K, bounds_error=False, fill_value="extrapolate")
self.cp_f = interp1d(T, C, bounds_error=False, fill_value="extrapolate")
self.Pr_f = interp1d(T, Pr, bounds_error=False, fill_value="extrapolate")
def get_X0_iter(G, F, M, I, CT):
# Function to get initial values for iterative solver
if M.cooler_type == 1:
X0 = np.zeros((4 * G.n_cells) + (G.n_rows) + 1 + CT.solver_type)
mdot_init = CT.mdot_PF_total / ((CT.A_fr / CT.dA_HX))
else:
X0 = np.zeros((4 * G.n_cells) + (G.n_rows))
mdot_init = F.mdot_PF
dT = F.T_PF_in - F.T_PF_out
for i in range(G.n_passes):
for j in range(G.n_CP):
row = j + (i * G.n_CP)
X0[row * G.n_CPR : (row + 1) * G.n_CPR] = np.linspace(
F.T_PF_in - ((i / G.n_passes) * dT),
F.T_PF_in - (((i + 1) / G.n_passes) * dT),
G.n_CPR,
)
for i in range(G.n_rows):
X0[G.n_cells + (i * G.n_CPR) : G.n_cells + ((i + 1) * G.n_CPR)] = F.T_air_in + (
(F.T_air_outlet_guess - F.T_air_in) * ((G.n_rows - i) / G.n_rows)
)
X0[2 * G.n_cells : 3 * G.n_cells] = F.T_PF_in - (
(F.T_PF_in - F.T_air_outlet_guess) * (((i + 0.45) / G.n_rows))
)
X0[3 * G.n_cells : 4 * G.n_cells] = F.T_PF_in - (
(F.T_PF_in - F.T_air_outlet_guess) * (((i + 1) / G.n_rows))
)
# Mass flow rate
X0[4 * G.n_cells : (4 * G.n_cells) + G.n_rows] = 1e4 * mdot_init / G.n_CP
# Error variable for natural draft equation (velocity)
if M.cooler_type == 1:
X0[(4 * G.n_cells) + G.n_rows] = F.vC_in * 1000
# Error variable for tower diameter for matching PF mass flow rate
if CT.solver_type == 1:
X0[(4 * G.n_cells) + G.n_rows + 1] = CT.d3 * 10
return X0
def open_X(X, M, F, G, CT):
"""
function to unpack the variable vector X into the 6 vectors
TH, TWH, TWC, T_air, PH, PC
"""
T_PF_in = F.T_PF_in
T_air_in = F.T_air_in
n_cells = G.n_cells
n_rows = G.n_rows
n_CPR = G.n_CPR
n_CP = G.n_CP
n_passes = G.n_passes
P_PF_in = F.P_PF_in
PF_fluid = F.PF_fluid
TH = np.zeros(n_cells + n_rows)
T_air = np.zeros(n_cells + n_CPR)
TW_H = np.zeros(n_cells)
TW_C = np.zeros(n_cells)
mdot_vec = np.zeros(n_rows)
v = []
d3 = []
mdot_vec[0:n_rows] = X[4 * n_cells : (4 * n_cells) + n_rows] / 1e4
for i1 in range(n_CP):
TH[i1 * (n_CPR + 1)] = T_PF_in
T_head = []
dir_vec = []
for i2 in range(n_passes):
T_end = []
for i3 in range(n_CP):
row_no = (i2 * n_CP) + i3
start_n = row_no * (n_CPR + 1)
end_n = row_no * (n_CPR + 1) + n_CPR + 1
if i2 % 2 == 0:
dir_vec.append(1)
TH[start_n + 1 : end_n] = X[row_no * (n_CPR) : ((row_no + 1) * (n_CPR))]
T_end.append(TH[end_n - 1])
if i2 % 2 == 1:
dir_vec.append(-1)
TH[start_n : end_n - 1] = X[row_no * (n_CPR) : ((row_no + 1) * (n_CPR))]
T_end.append(TH[start_n])
T_air[0:n_cells] = X[n_cells : (2 * n_cells)]
T_air[n_cells : n_cells + n_CPR] = T_air_in
TW_H[0:n_cells] = X[2 * n_cells : 3 * n_cells]
TW_C[0:n_cells] = X[3 * n_cells : 4 * n_cells]
if M.cooler_type == 1:
v = X[(4 * n_cells) + n_rows] / 1000
if CT.solver_type == 1:
d3 = X[(4 * n_cells) + n_rows + 1] / 10
else:
v = F.vC_in
d3 = 0
return TH, T_air, TW_H, TW_C, dir_vec, mdot_vec, v, d3
# ------------------SOLVER-------------------------------------------
class Callback:
"""Callback function to print status of nonlinear solver"""
def __init__(self, G, M):
self.G = G
self.M = M
self.i = 0
def update(self, x, r):
self.i += 1
e_max = np.max(np.absolute(r))
e_av = np.average(np.absolute(r))
mdot_vec = x[4 * self.G.n_cells : (4 * self.G.n_cells) + self.G.n_rows] / 10000
print("Iteration no", self.i)
print("Maximum residual: ", e_max, "Average residual: ", e_av)
print("Tube mass flow rates:", mdot_vec)
print("---------------------------------------------")
def solve(hx_inputs, mod=None, X0=None, fig_switch=0, verbosity=0):
M = Model()
F = Fluid()
G = Geometry()
CT = CT_Geometry()
hx_inputs(G, F, M, CT)
if (
mod
): # A function that operates on input classes - for iterative optimisation only
# TODO: Can I find a more elegant way of doing this?
mod(F)
mod(M)
mod(G)
if M.cooler_type == 1:
mod(CT)
# Create fluid property objects
global EosPF
EosPF = CPCP.AbstractState("HEOS", F.PF_fluid)
# Initialise objects that contain geometry and fluid property details.
# TODO: This is really ugly. Can I improve it?
G.micro_init()
F.micro_init(G)
if M.cooler_type == 1:
CT.micro_init(G.HX_length, G.pitch_transverse, F.T_air_in, F.P_amb_in)
CT.dim_update(CT.d3)
# Construct iterpolation object for fluid properties
I = inter_fs(F.T_air_in, F.T_PF_in, F.P_amb_in, F.Amb_fluid)
# Creates initial solution values from inputs or interpolation function
if X0 is None:
X0 = get_X0_iter(G, F, M, I, CT)
if verbosity > 0:
print("Number of cells:", G.n_cells)
# TODO: Can I remove this? It's ugly
# n_cells = G.n_cells
# n_rows = G.n_rows
callback = Callback(G, M)
sol = sci.optimize.newton_krylov(
lambda T: equations(T, G, F, M, I, 0, CT),
X0,
method="lgmres",
f_tol=1e-6,
callback=callback.update,
)
# TODO: Process results much more elegantly
(
error,
TH_final,
T_air_final,
TW_H_final,
TW_C_final,
Q1,
Q2,
Q3,
Q4,
Q5,
Q6,
Q7,
Q8,
Q9,
alpha_i_final,
PH,
dp_amb,
mdot_vec,
P_headers,
v,
alpha_o_final,
dT,
d3,
Bu_c,
Bu_j,
Bu_p,
UA,
) = equations(sol, G, F, M, I, 1, CT)
# Compute total properties at inlet/outlet
P_out = P_headers[-1]
E_out = []
if G.n_passes % 2 == 0:
for i in range(G.n_CP):
T_row_out = TH_final[len(TH_final) - ((i + 1) * (G.n_CPR + 1))]
E_out.append(
GetFluidPropLow(
EosPF, [CPCP.PT_INPUTS, P_out, T_row_out], [CPCP.iHmass]
)
* mdot_vec[-1 - i]
)
else:
for i in range(G.n_CP):
T_row_out = TH_final[-((i) * (G.n_CPR + 1)) - 1]
E_out.append(
GetFluidPropLow(
EosPF, [CPCP.PT_INPUTS, P_out, T_row_out], [CPCP.iHmass]
)
* mdot_vec[-1 - i]
)
h_ave = sum(E_out) / sum(mdot_vec[-G.n_CP : G.n_rows])
E_out_total = sum(E_out)
T_out = CP("T", "H", h_ave, "P", P_out, F.PF_fluid)
E_in_total = sum(mdot_vec[0 : G.n_CP]) * GetFluidPropLow(
EosPF, [CPCP.PT_INPUTS, F.P_PF_in, F.T_PF_in], [CPCP.iHmass]
)
PF_dp = F.P_PF_in - P_out
# Determine the average pressure loss of air over the heat exchanger
dp_amb_total = sum(dp_amb)
P_amb_out = F.P_amb_in - dp_amb_total
# Determine the energy difference of PF between inlete and outlet
mdot_total = np.sum(mdot_vec[0:i])
# Check solution via control volume energy balance
dE_PF = E_in_total - E_out_total
# Determine the total energy gain of air over the heat exchanger by summing each cell
i = 0
q_amb_out = 0
for i in range(G.n_CPR):
qi = CP("H", "T", T_air_final[i], "P", P_amb_out, F.Amb_fluid)
q_amb_out = q_amb_out + qi
Q_amb = (
q_amb_out - (G.n_CPR * CP("H", "T", F.T_air_in, "P", F.P_amb_in, F.Amb_fluid))
) * F.mdot_C
T_air_out_ave = mean(T_air_final[0 : G.n_CPR])
# Determine and print the discrepance of energy balance between PF and air
deltaQ = Q_amb - dE_PF
if verbosity > 0:
print("Process fluid outlet temperature is: ", T_out)
print("Mass flow rate vector is:", mdot_vec)
print(