-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhtAnh_PBR.py
executable file
·241 lines (187 loc) · 7.72 KB
/
PhtAnh_PBR.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
"""
CASE STUDY 1: Selective oxidation of o-xylene to phthalic anhydride.
Highlights:
-Convection-diffusion-reaction simulation in single packed-bed tube.
-Two-dimensional pseudo homogeneous mathematical model.
-Five PDEs accounting for species mass equations and reactor temperature.
-One ODE accounting for the cooling jacket model.
-Physical properties assumed to be constant.
-Catalytic rate model for V2O5 assumed of pseudo-first-order.
A + 3.B --> C + 3.D
A: o-Xylene
B: Oxygen
C: Phthalic anhydride
D: Water
"""
# FEniCS Project Packages
from dolfin import XDMFFile, Mesh, FiniteElement, triangle, MixedElement, \
FunctionSpace, Measure, Constant, TestFunctions, \
Function, split, Expression, project, dot, grad, dx, \
solve, as_vector, MeshValueCollection, cpp
from ufl.operators import exp
# Mesh format conversion
import meshio
# General-purpose packages in computer science.
import os
import numpy as np
import math as mt
# Time-stepping
t = 0.0
tf = 5.0 # Final time, sec
num_steps = 100 # Number of time steps
delta_t = tf / num_steps # Time step size, sec
dt = Constant(delta_t)
R_path = 'Results'
Writting_xdmf = True # Data storage for later visualization.
"""Gmsh mesh format conversion by package Meshio."""
Wri_path = "Gmsh_meshes"
msh = meshio.read(os.path.join(Wri_path, 'SinglePBR.msh'))
line_cells = []
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells = cell.data
elif cell.type == "line":
if len(line_cells) == 0:
line_cells = cell.data
else:
line_cells = np.vstack([line_cells, cell.data])
line_data = []
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "line":
if len(line_data) == 0:
line_data = msh.cell_data_dict["gmsh:physical"][key]
else:
line_data = np.vstack([line_data, msh.cell_data_dict["gmsh:physical"][key]])
elif key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
triangle_mesh = meshio.Mesh(points=msh.points,
cells={"triangle": triangle_cells})
line_mesh = meshio.Mesh(points=msh.points,
cells=[("line", line_cells)],
cell_data={"name_to_read":[line_data]})
meshio.write(os.path.join(Wri_path, "md_.xdmf"), triangle_mesh)
meshio.xdmf.write(os.path.join(Wri_path, "mf_.xdmf"), line_mesh)
# Reading mesh data stored in .xdmf files.
mesh = Mesh()
with XDMFFile(os.path.join(Wri_path, "md_.xdmf")) as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 1)
with XDMFFile(os.path.join(Wri_path, "mf_.xdmf")) as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
# Define function spaces for PDEs variational formulation.
P1 = FiniteElement('P', mesh.ufl_cell(), 1) # Lagrange 1-order polynomials family
element = MixedElement([P1, P1, P1, P1])
V = FunctionSpace(mesh, element) # Test functions
function_space = FunctionSpace(mesh, P1)
# Splitting test and trial functions
v_A, v_B, v_C, v_T = TestFunctions(V)
u = Function(V)
u_n = Function(V)
u_A, u_B, u_C, u_T = split(u)
# Retrieve boundaries marks for Robin boundary conditions.
ds_in = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=1)
ds_wall = Measure("ds", domain=mesh, subdomain_data=mf, subdomain_id=2)
"""Initial values (t == 0.0)"""
CAo = Constant(0.0) # Initial composition for A
CBo = Constant(0.0) # Initial composition for A
CCo = Constant(0.0) # Initial composition for A
To = Constant(625.15) # Initial packed-bed Temperature
Tcool_init = 625.15 # Coolant initial Temperature
u_0 = Expression(('CA_init', 'CB_init', 'CC_init', 'T_init'),
degree=0, CA_init=CAo, CB_init=CBo, CC_init=CCo, T_init=To)
u_n = project(u_0, V)
u_An, u_Bn, u_Cn, u_Tn = split(u_n)
# Define expressions used in variational forms
R = Constant(8.314) # Gas constant
# Velocity vector over axial coordinate.
Vz = Constant((4.0*1.6)/(3.14159*np.power(0.0254, 2)*3600.0))
w = as_vector([Vz, 0.0])
"""Inlet values"""
PA_in = Constant(0.011e5) # Inlet pressure of A (Limiting reagent)
PB_in = Constant(0.211e5) # Inlet pressure of B (Excess reagent)
PC_in = Constant(0.0) # Inlet pressure of C (Product)
T_in = Constant(625.15) # Reageants inlet Temperature
CA_in = PA_in/(R*T_in) # Inlet composition of A,
CB_in = PB_in/(R*T_in) # Inlet composition of B,
CC_in = PC_in/(R*T_in) # Inlet composition of B,
Tcool_in = Constant(625.15) # Coolant inlet Temperature
Twall = Constant(Tcool_init) # Wall Temperature
"""Transport properties"""
eps = Constant(0.35) # epsilon
knt = 0.6 # Average Conductivity R-Z
D = 0.01 # Average diffusivity R-Z
"""Kinetic parameters"""
alfa = Constant(19.837)
beta = Constant(13636.0)
Uc1 = Constant(3.60E+10)
deltaH = Constant(-307000.0*4.183)
rob = Constant(1300.0)
"""Stoichiometry coefficients"""
cofA = Constant(-1.0)
cofB = Constant(-3.0)
cofC = Constant(1.0)
"""Coolant properties"""
rof = Constant(1.293)
cpf = Constant(992.0)
hw = Constant(96.0) # Wall heat transfer coefficient,
""" Cooling Jacket model """
Length = Constant(3.0)
radius = Constant(0.0127)
A = 2.0*mt.pi*radius*Length
fw = Constant(0.1)
Cpw = Constant(4200.0)
roW = Constant(1000.0)
Vw = Constant(3.0*(np.power(0.0254, 2))*(4.0-(np.power(mt.pi, 2))/4.0))
denominator = ((roW*Cpw*Vw)/dt + fw*Cpw + hw*A*Length)
def Kinetic_oxy(Temperature):
"""Kinetic constant - mathematical expression"""
k_oxy = exp(alfa) * exp(-beta/Temperature)
return k_oxy
if Writting_xdmf:
# Create XDMF - H5 files for visualization output
Root_path = os.path.join(R_path, 'Visual_postprocessing')
xdmffile_A = XDMFFile(os.path.join(Root_path, 'CA.xdmf'))
xdmffile_B = XDMFFile(os.path.join(Root_path, 'CB.xdmf'))
xdmffile_C = XDMFFile(os.path.join(Root_path, 'CC.xdmf'))
xdmffile_D = XDMFFile(os.path.join(Root_path, 'CD.xdmf'))
xdmffile_T = XDMFFile(os.path.join(Root_path, 'T.xdmf'))
# Variational problem definition
F_A = ((u_A - u_An)/dt)*v_A*dx + dot(w, grad(u_A))*v_A*dx + \
eps*D*dot(grad(u_A), grad(v_A))*dx - \
cofA*rob*Kinetic_oxy(u_Tn)*u_A*u_B*(pow(R*u_T, 2)/Uc1)*v_A*dx + \
Vz*(u_A - CA_in)*v_A*ds_in
F_B = ((u_B - u_Bn)/dt)*v_B*dx + dot(w, grad(u_B))*v_B*dx + \
eps*D*dot(grad(u_B), grad(v_B))*dx - \
cofB*rob*Kinetic_oxy(u_Tn)*u_A*u_B*(pow(R*u_T, 2)/Uc1)*v_B*dx + \
Vz*(u_B - CB_in)*v_B*ds_in
F_C = ((u_C - u_Cn)/dt)*v_C*dx + dot(w, grad(u_C))*v_C*dx + \
eps*D*dot(grad(u_C), grad(v_C))*dx - \
cofC*rob*Kinetic_oxy(u_Tn)*u_A*u_B*(pow(R*u_T, 2)/Uc1)*v_C*dx + \
Vz*(u_C - CC_in)*v_C*ds_in
F_T = (rof*cpf*(u_T - u_Tn)/dt)*v_T*dx + \
rof*cpf*dot(w, grad(u_T))*v_T*dx + \
knt*dot(grad(u_T), grad(v_T))*dx + \
deltaH*rob*Kinetic_oxy(u_Tn)*u_A*u_B*(pow(R*u_T, 2)/Uc1)*v_T*dx + \
(rof*cpf*Vz)*(u_T - T_in)*v_T*ds_in + \
hw*(u_T - Twall)*v_T*ds_wall
F = F_A + F_B + F_C + F_T
for n in range(num_steps):
print('{} out of {}'.format(n, num_steps))
t += delta_t # Update current time
# Solve variational problem for time step
solve(F == 0, u, solver_parameters={"newton_solver": {
"relative_tolerance": 1e-6}, "newton_solver": {
"maximum_iterations": 60}})
print('solver done')
# Save solution to files for visualization and postprocessing(HDF5)
_u_A, _u_B, _u_C, _u_T = u_n.split()
_u_D = _u_C*3
if Writting_xdmf:
xdmffile_A.write(_u_A, t)
xdmffile_B.write(_u_B, t)
xdmffile_C.write(_u_C, t)
xdmffile_D.write(_u_D, t)
xdmffile_T.write(_u_T, t)
u_n.assign(u)
# _______________END_______________ #