-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcOther.py
203 lines (161 loc) · 5.23 KB
/
funcOther.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
"""
Utility functions for project.
"""
import numpy as np
# Functions
# -----------------------------------------------------------------------------
def lump(cp, h, k, Gb, t, V, SA, Ti, Tinf):
"""
Lumped capacitance method
"""
Lc = V/SA # characteristic length for sphere, m
Bi = (h*Lc)/k # Biot number Eq 5.10, (-)
rho = Gb*1000 # density, kg/m^3
alpha = k/(rho*cp) # thermal diffusivity, m^2/s
Fo = (alpha*t)/(Lc**2) # Fourier number Eq 5.12, (-)
phi = np.exp(-Bi*Fo) # dimensionless temperature Eq. 5.13, (-)
T = Tinf + (Ti-Tinf)*phi # temperature, K
return T
def volume(d, h, s):
"""
Return volume of a sphere, cylinder, and cube.
d = diameter of sphere, m
h = height of cylinder, m
s = side of cube, m
"""
sphere = (np.pi*d**3)/6
cylinder = (np.pi*d**2)/4*h
cube = s**3
return sphere, cylinder, cube
def surf(d, h, s):
"""
Return surface area of a sphere, cylinder, and cube.
d = diameter of sphere, m
h = height of cylinder, m
s = side of cube, m
"""
sphere = np.pi*d**2
cylinder = np.pi*d*h + (np.pi*d**2)/2
cube = 6*s**2
return sphere, cylinder, cube
def vol(d, m):
"""
Create a list of volumes that comprise a solid sphere. Volume at center is a
sphere volume while subsequent volumes are a spherical shell volume. Units
are determined by diameter parameter d which is assumed in meters for
documentatation purposes.
Parameters
----------
d = diameter of sphere, m
m = number of nodes from center to surface, -
Returns
-------
v = list of volumes, m^3
"""
r = d/2 # radius of sphere, m
nr = m-1 # number of radius steps, -
dr = r/nr # radius step as delta r, m
rad = np.linspace(0, r, nr) # array of each radius step
vc = (4/3)*np.pi*(dr**3) # volume of sphere center
v = [] # store volumes
v.append(vc) # add sphere center volume
# calculate each shell volume and store in v
for i in rad[:-1]:
ri = i
ro = i+dr
vshell = (4/3)*np.pi*(ro**3) - (4/3)*np.pi*(ri**3)
v.append(vshell)
# return list of volumes based on number of node points
return v
def Tvol(T, v):
"""
Determine volume average temperature for a sphere. First, calculates average
temperature between each node point to represent the temperature of that
particular volume. Uses center sphere volume and shell volumes as weights to
calculate the volume average temperature of entire sphere.
Parameters
----------
T = array of temperatures from 1-D numerical solution, K
v = list of volumes inside sphere based on number of node points, m^3
Returns
-------
Tv = volume average temperature of sphere as weighted mean, K
"""
Tv = [] # store volume average temperatures, K
# calculate volume average temperature for each row then store in Tv
for row in T:
idx = np.arange(0, len(row)) # indices for each temperature in row
row_avg = [] # store average temperatures between each node point
for i in idx[:-1]:
ti = row[i] # inner temperature
to = row[i+1] # outer temperature
tavg = (ti+to)/2 # average temperature
row_avg.append(tavg) # store average temperature
# store weighted mean of row average temperatures into Tv
row_wtmean = np.average(row_avg, weights=v)
Tv.append(row_wtmean)
# return list of volume average temperature at each time step
return Tv
def dsv(sa, v):
"""
Calculate the surface area to volume equivalent spherical diameter as Dsv.
Units are assumed as meters, m, and square meters, m^2.
Parameters
----------
sa = surface area, m^2
v = volume, m^3
Returns
-------
Dsv = surface area to volume diameter, m
"""
ds = (sa/np.pi)**(1/2) # surface area equivalent sphere diameter, m
dv = (6/np.pi*v)**(1/3) # volume equivalent sphere diameter, m
# surface area to volume equivalent sphere diameter (Sauter diameter), m
Dsv = (dv**3)/(ds**2)
return Dsv
def biot(h, r, k):
"""
Calculate the dimensionless Biot number represented by Bi.
Parameters
----------
h = heat transfer coefficient, W/m^2K
r = radius of particle, m
k = thermal conductivity, W/mK
Returns
-------
Bi = Biot number, -
"""
Bi = (h*r) / k
return Bi
def py1(k, kr, rho, cp, r):
"""
Calculate the pyrolysis number.
Parameters
----------
k = thermal conductivity, W/mK
kr = rate constant, 1/s
rho = density, kg/m^3
cp = heat capacity, J/kgK
r = radius, m
Returns
-------
py = pyrolysis number, -
"""
py = k / (kr * rho * cp * (r**2))
return py
def py2(h, kr, rho, cp, r):
"""
Calculate the pyrolysis number.
Parameters
----------
h = heat transfer coefficient, W/m^2K
kr = rate constant, 1/s
rho = density, kg/m^3
cp = heat capacity, J/kgK
r = radius, m
Returns
-------
py = pyrolysis number, -
"""
py = h / (kr * rho * cp * r)
return py