Skip to content

Commit ada5855

Browse files
committed
Code cleanup
1 parent 02cfbdb commit ada5855

File tree

4 files changed

+47
-46
lines changed

4 files changed

+47
-46
lines changed

ht/hx.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
from fluids.piping import BWG_SI, BWG_integers
3030

3131
__all__ = ['effectiveness_from_NTU', 'NTU_from_effectiveness', 'calc_Cmin',
32-
'calc_Cmax', 'calc_Cr', 'Pp', 'Pc',
32+
'calc_Cmax', 'calc_Cr', 'P_NTU_Pp', 'P_NTU_Pc',
3333
'NTU_from_UA', 'UA_from_NTU', 'effectiveness_NTU_method', 'F_LMTD_Fakheri',
3434
'temperature_effectiveness_basic', 'temperature_effectiveness_TEMA_J',
3535
'temperature_effectiveness_TEMA_H', 'temperature_effectiveness_TEMA_G',
3636
'temperature_effectiveness_TEMA_E', 'temperature_effectiveness_plate',
3737
'temperature_effectiveness_air_cooler',
3838
'P_NTU_method', 'NTU_from_P_basic',
3939
'NTU_from_P_J', 'NTU_from_P_G', 'NTU_from_P_E', 'NTU_from_P_H',
40-
'NTU_from_P_plate', 'check_tubing_TEMA', 'get_tube_TEMA',
40+
'NTU_from_P_plate',
4141
'DBundle_min', 'shell_clearance', 'baffle_thickness', 'D_baffle_holes',
4242
'L_unsupported_max', 'Ntubes', 'size_bundle_from_tubecount',
4343
'Ntubes_Perrys', 'Ntubes_VDI', 'Ntubes_Phadkeb',
@@ -804,7 +804,7 @@ def UA_from_NTU(NTU, Cmin):
804804
return NTU*Cmin
805805

806806

807-
def Pp(x, y):
807+
def P_NTU_Pp(x, y):
808808
r'''Basic helper calculator which accepts a transformed R1 and NTU1 as
809809
inputs for a common term used in the calculation of the P-NTU method for
810810
plate exchangers.
@@ -835,7 +835,7 @@ def Pp(x, y):
835835
836836
Examples
837837
--------
838-
>>> Pp(5, .4)
838+
>>> P_NTU_Pp(5, .4)
839839
0.713634370024
840840
841841
References
@@ -850,7 +850,7 @@ def Pp(x, y):
850850
return (1. - exp(-x*(1. + y)))/(1. + y)
851851

852852

853-
def Pc(x, y):
853+
def P_NTU_Pc(x, y):
854854
r'''Basic helper calculator which accepts a transformed R1 and NTU1 as
855855
inputs for a common term used in the calculation of the P-NTU method for
856856
plate exchangers.
@@ -881,7 +881,7 @@ def Pc(x, y):
881881
882882
Examples
883883
--------
884-
>>> Pc(5, .7)
884+
>>> P_NTU_Pc(5, .7)
885885
0.920670368605
886886
887887
References
@@ -2434,45 +2434,45 @@ def temperature_effectiveness_plate(R1, NTU1, Np1, Np2, counterflow=True,
24342434
300-313. doi:10.1115/1.3250678.
24352435
'''
24362436
if Np1 == 1 and Np2 == 1 and counterflow:
2437-
return Pc(NTU1, R1)
2437+
return P_NTU_Pc(NTU1, R1)
24382438
elif Np1 == 1 and Np2 == 1 and not counterflow:
2439-
return Pp(NTU1, R1)
2439+
return P_NTU_Pp(NTU1, R1)
24402440
elif Np1 == 1 and Np2 == 2:
24412441
# There are four configurations but all have the same formula
24422442
# They do behave different depending on the number of available plates
24432443
# but this model assues infinity
24442444
# There are four more arrangements that are equivalent as well
2445-
A = Pp(NTU1, 0.5*R1)
2446-
B = Pc(NTU1, 0.5*R1)
2445+
A = P_NTU_Pp(NTU1, 0.5*R1)
2446+
B = P_NTU_Pc(NTU1, 0.5*R1)
24472447
return 0.5*(A + B - 0.5*A*B*R1)
24482448
elif Np1 == 1 and Np2 == 3 and counterflow:
24492449
# There are six configurations, two formulas
24502450
# Each behaves differently though as a function of number of plates
2451-
A = Pp(NTU1, R1/3.)
2452-
B = Pc(NTU1, R1/3.)
2451+
A = P_NTU_Pp(NTU1, R1/3.)
2452+
B = P_NTU_Pc(NTU1, R1/3.)
24532453
return 1/3.*(A + B*(1. - R1*A/3.)*(2. - R1*B/3.))
24542454
elif Np1 == 1 and Np2 == 3 and not counterflow:
2455-
A = Pp(NTU1, R1/3.)
2456-
B = Pc(NTU1, R1/3.)
2455+
A = P_NTU_Pp(NTU1, R1/3.)
2456+
B = P_NTU_Pc(NTU1, R1/3.)
24572457
return 1/3.*(B + A*(1. - R1*B/3.)*(2. - R1*A/3.))
24582458
elif Np1 == 1 and Np2 == 4:
24592459
# four configurations
24602460
# Again a function of number of plates, but because expressions assume
24612461
# infinity it gets ignored and they're the same
2462-
A = Pp(NTU1, 0.25*R1)
2463-
B = Pc(NTU1, 0.25*R1)
2462+
A = P_NTU_Pp(NTU1, 0.25*R1)
2463+
B = P_NTU_Pc(NTU1, 0.25*R1)
24642464
t1 = (1. - 0.25*A*R1)
24652465
t2 = (1. - 0.25*B*R1)
24662466
t3 = t1*t2 # minor optimization
24672467
return (1. - t3*t3)/R1
24682468
elif Np1 == 2 and Np2 == 2:
24692469
if counterflow and passes_counterflow:
2470-
return Pc(NTU1, R1)
2470+
return P_NTU_Pc(NTU1, R1)
24712471
elif counterflow and not passes_counterflow:
2472-
A = Pp(0.5*NTU1, R1)
2472+
A = P_NTU_Pp(0.5*NTU1, R1)
24732473
return (2.*A - A*A*(1. + R1))/(1. - R1*A*A)
24742474
elif not counterflow and passes_counterflow:
2475-
B = Pc(0.5*NTU1, R1)
2475+
B = P_NTU_Pc(0.5*NTU1, R1)
24762476
return B*(2. - B*(1. + R1))
24772477
elif not counterflow and not passes_counterflow:
24782478
return temperature_effectiveness_plate(R1, NTU1, Np1=1, Np2=1,
@@ -2483,8 +2483,8 @@ def temperature_effectiveness_plate(R1, NTU1, Np1, Np2, counterflow=True,
24832483
# One place says there are four configurations; no other discussion is
24842484
# presented
24852485
if counterflow:
2486-
H = Pp(0.5*NTU1, 2./3.*R1)
2487-
G = Pc(0.5*NTU1, 2./3.*R1)
2486+
H = P_NTU_Pp(0.5*NTU1, 2./3.*R1)
2487+
G = P_NTU_Pc(0.5*NTU1, 2./3.*R1)
24882488
E = 1./(2./3.*R1*G)
24892489
F = 1./(2./3.*R1*H)
24902490
E2 = E*E
@@ -2496,22 +2496,22 @@ def temperature_effectiveness_plate(R1, NTU1, Np1, Np2, counterflow=True,
24962496
return (A + 0.5*B + 0.5*C + D)/R1
24972497
elif not counterflow:
24982498
D = 2*R1/3.
2499-
A = Pp(NTU1/2, D)
2500-
B = Pc(NTU1/2, D)
2499+
A = P_NTU_Pp(NTU1/2, D)
2500+
B = P_NTU_Pc(NTU1/2, D)
25012501
return (A + B - (2/9. + D/3.)*(A*A + B*B)
25022502
-(5./9. + 4./3.*D)*A*B
25032503
+ D*(1. + D)*A*B*(A + B)/3.
25042504
- D*D*A*A*B*B/9.)
25052505
elif Np1 == 2 and Np2 == 4:
25062506
# Both cases are correct for passes_counterflow=True or False
25072507
if counterflow:
2508-
A = Pp(0.5*NTU1, 0.5*R1)
2509-
B = Pc(0.5*NTU1, 0.5*R1)
2508+
A = P_NTU_Pp(0.5*NTU1, 0.5*R1)
2509+
B = P_NTU_Pc(0.5*NTU1, 0.5*R1)
25102510
D = 0.5*(A + B - 0.5*A*B*R1)
25112511
return (2.*D - (1. + R1)*D*D)/(1. - D*D*R1)
25122512
elif not counterflow:
2513-
A = Pp(0.5*NTU1, 0.5*R1)
2514-
B = Pc(0.5*NTU1, 0.5*R1)
2513+
A = P_NTU_Pp(0.5*NTU1, 0.5*R1)
2514+
B = P_NTU_Pc(0.5*NTU1, 0.5*R1)
25152515
D = 0.5*(A + B - 0.5*A*B*R1)
25162516
return 2.*D - ((1. + R1)*D*D)
25172517
if not reverse:
@@ -3736,7 +3736,7 @@ def NTU_from_P_plate(P1, R1, Np1, Np2, counterflow=True,
37363736
return log(-1./(P1*(R1 + 1.) - 1.))/(R1 + 1.)
37373737
except:
37383738
# raise ValueError("impossible") # numba: uncomment
3739-
raise ValueError(f'The maximum P1 obtainable at the specified R1 is {Pp(1E10, R1):f} at the limit of NTU1=inf.') # numba: delete
3739+
raise ValueError(f'The maximum P1 obtainable at the specified R1 is {P_NTU_Pp(1E10, R1):f} at the limit of NTU1=inf.') # numba: delete
37403740
elif Np1 == 1 and Np2 == 2:
37413741
NTU_max = 100.
37423742
elif Np1 == 1 and Np2 == 3 and counterflow:
@@ -4552,13 +4552,13 @@ def baffle_thickness(Dshell, L_unsupported, service='C'):
45524552

45534553

45544554

4555-
def D_baffle_holes(do, L_unsupported):
4555+
def D_baffle_holes(Do, L_unsupported):
45564556
r'''Determines the diameter of holes in baffles for tubes according to
45574557
TEMA [1]_. Applies for all geometries.
45584558
45594559
Parameters
45604560
----------
4561-
do : float
4561+
Do : float
45624562
Tube outer diameter, [m]
45634563
L_unsupported : float
45644564
Distance between tube supports, [m]
@@ -4573,23 +4573,23 @@ def D_baffle_holes(do, L_unsupported):
45734573
45744574
Examples
45754575
--------
4576-
>>> D_baffle_holes(do=.0508, L_unsupported=0.75)
4576+
>>> D_baffle_holes(Do=.0508, L_unsupported=0.75)
45774577
0.0516
4578-
>>> D_baffle_holes(do=0.01905, L_unsupported=0.3)
4578+
>>> D_baffle_holes(Do=0.01905, L_unsupported=0.3)
45794579
0.01985
4580-
>>> D_baffle_holes(do=0.01905, L_unsupported=1.5)
4580+
>>> D_baffle_holes(Do=0.01905, L_unsupported=1.5)
45814581
0.019450000000000002
45824582
45834583
References
45844584
----------
45854585
.. [1] Standards of the Tubular Exchanger Manufacturers Association,
45864586
Ninth edition, 2007, TEMA, New York.
45874587
'''
4588-
if do > 0.0318 or L_unsupported <= 0.914: # 1-1/4 inches and 36 inches
4588+
if Do > 0.0318 or L_unsupported <= 0.914: # 1-1/4 inches and 36 inches
45894589
extra = 0.0008
45904590
else:
45914591
extra = 0.0004
4592-
d = do + extra
4592+
d = Do + extra
45934593
return d
45944594

45954595

ht/units.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
'https://github.com/hgrecco/pint')
3737
from fluids.units import wraps_numpydoc
3838

39-
"""
40-
Functions which will need custom wrappers:
41-
ht.get_tube_TEMA, ht.check_tubing_TEMA
42-
"""
4339

4440
__funcs = {}
4541

@@ -48,7 +44,7 @@
4844
if name in ('__getattr__', '__test__'):
4945
continue
5046
obj = getattr(ht, name)
51-
if isinstance(obj, types.FunctionType) and obj not in [ht.get_tube_TEMA, ht.check_tubing_TEMA]:
47+
if isinstance(obj, types.FunctionType):
5248
obj = wraps_numpydoc(u)(obj)
5349
elif isinstance(obj, str):
5450
continue

tests/test_hx.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -963,18 +963,18 @@ def test_P_NTU_method_backwards():
963963

964964

965965
def test_Pp():
966-
from ht.hx import Pc, Pp
966+
from ht.hx import P_NTU_Pc, P_NTU_Pp
967967
# randomly chosen test value
968-
ans = Pp(5, .4)
968+
ans = P_NTU_Pp(5, .4)
969969
assert_close(ans, 0.713634370024604)
970970

971971
# Test the limit works with a small difference
972-
assert_close(Pp(2, -1), Pp(2, -1+1E-9))
972+
assert_close(P_NTU_Pp(2, -1), P_NTU_Pp(2, -1+1E-9))
973973

974974
# randomly chosen test value
975-
assert_close(Pc(5, .7), 0.9206703686051108)
975+
assert_close(P_NTU_Pc(5, .7), 0.9206703686051108)
976976
# Test the limit works with a small difference
977-
assert_close(Pc(5, 1), Pc(5, 1-1E-8))
977+
assert_close(P_NTU_Pc(5, 1), P_NTU_Pc(5, 1-1E-8))
978978

979979

980980
def test_temperature_effectiveness_plate():

tests/test_units.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import ht
2929
from ht.units import P_NTU_method, R_to_k, R_value_to_k, effectiveness_NTU_method, k_to_R_value, u
30+
from fluids.units import check_module_docstring_parameters
3031

3132

3233
def assert_pint_allclose(value, magnitude, units, rtol=1e-7):
@@ -104,5 +105,9 @@ def test_check_signatures():
104105
if name in bad_names:
105106
continue
106107
obj = getattr(ht, name)
107-
if isinstance(obj, types.FunctionType) and obj not in [ht.get_tube_TEMA, ht.check_tubing_TEMA]:
108+
if isinstance(obj, types.FunctionType):
108109
check_args_order(obj)
110+
111+
def test_parse_numpydoc_variables_units():
112+
import ht
113+
check_module_docstring_parameters(ht)

0 commit comments

Comments
 (0)