forked from decaluwe/2D-porous-flux-model
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ficks_func.py
135 lines (103 loc) · 4.88 KB
/
Ficks_func.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
"""
Author:
Corey R. Randall (08 June 2018)
Description:
This is an external function that calculates fluxes via a Fick's diffusion
model. It was written to be used in 2D_NRSupport_FluxModel.
"""
def Flux_Calc(SV,Nx,dX,Ny,dY,Nspecies,BC_in,inlet_BC,gas,phi_g,tau_g,d_p):
import numpy as np
Fluxes_X = np.zeros((Nx+1)*Ny*Nspecies) # Fluxes in x-direction w/ 0's BC
Fluxes_X_int = np.zeros((Nx-1)*Ny*Nspecies) # Interior x-direction fluxes
Fluxes_Y = np.zeros(Nx*(Ny+1)*Nspecies) # Fluxes in y-direction
# Initialize counters for flux loops:
cnt_x = 0
cnt_y = Nx*Nspecies
# Extract temperature for defining state at each point:
Temp = gas.T
# Constants to reduce use of division:
phi_tau_sq = phi_g / (tau_g**2)
K_g = 4*d_p**2*phi_g**3 / (72*tau_g**2*(1-phi_g)**2) # permeability [m^2]
dX_inv = 1/dX
dY_inv = 1/dY
# Calculate each x-direction flux:
for j in range(Ny):
ind1 = j*Nx*Nspecies # First -> last index of cell on left
ind2 = ind1 + Nspecies
for i in range(Nx-1):
ind3 = ind2 # First -> last index of cell on right
ind4 = ind3 + Nspecies
D1 = sum(SV[ind1:ind2])
D2 = sum(SV[ind3:ind4])
D_av = np.mean([D1,D2])
Y1 = SV[ind1:ind2] / D1
Y2 = SV[ind3:ind4] / D2
# Terms for diffusive flux:
gas.TDY = Temp, np.mean([D1,D2]), np.mean([Y1,Y2],axis=0)
D_AB = gas.mix_diff_coeffs_mass
mu = gas.viscosity
Delta_Y = Y2 - Y1
# Terms for convective flux:
rho_k = np.mean([SV[ind1:ind2],SV[ind3:ind4]],axis=0)
gas.TDY = Temp, D1, Y1
P1 = gas.P
gas.TDY = Temp, D2, Y2
P2 = gas.P
V_conv = -K_g*(P2 - P1)*dX_inv / mu
Fluxes_X_int[cnt_x:cnt_x+Nspecies] = rho_k*V_conv \
- phi_tau_sq*D_AB*D_av*Delta_Y*dX_inv
ind1 = ind3 # Index of right cell becomes index of left
ind2 = ind1 + Nspecies
cnt_x = cnt_x + Nspecies
x1 = j*(Nx+1)*Nspecies + Nspecies # First non-zero x-flux of each row
x2 = x1 + (Nx-1)*Nspecies # Last non-zero x-flux of each row
Fluxes_X[x1:x2] = Fluxes_X_int[j*(Nx-1)*Nspecies:(j+1)*(Nx-1)*Nspecies]
# Calculate each y-direction flux:
for i in range(BC_in): # First row for BC inlet (constant concentation)
D1 = sum(inlet_BC)
D2 = sum(SV[i*Nspecies:(i+1)*Nspecies])
D_av = np.mean([D1,D2])
Y1 = inlet_BC / D1
Y2 = SV[i*Nspecies:(i+1)*Nspecies] / D2
# Terms for diffusive flux:
gas.TDY = Temp, np.mean([D1,D2]), np.mean([Y1,Y2],axis=0)
D_AB = gas.mix_diff_coeffs_mass
mu = gas.viscosity
Delta_Y = Y2 - Y1
# Terms for convective flux:
rho_k = np.mean([inlet_BC,SV[i*Nspecies:(i+1)*Nspecies]],axis=0)
gas.TDY = Temp, D1, Y1
P1 = gas.P
gas.TDY = Temp, D2, Y2
P2 = gas.P
V_conv = -K_g*(P2 - P1)*dY_inv / mu
Fluxes_Y[i*Nspecies:(i+1)*Nspecies] = rho_k*V_conv \
- phi_tau_sq*D_AB*D_av*Delta_Y*dY_inv
for j in range(Ny-1): # Starting with second row and ending before BC
ind1 = j*Nx*Nspecies # First -> last index of cell on top
ind2 = ind1 + Nspecies
for i in range(Nx):
D1 = sum(SV[ind1:ind2])
D2 = sum(SV[ind1+Nx*Nspecies:ind2+Nx*Nspecies])
D_av = np.mean([D1,D2])
Y1 = SV[ind1:ind2] / D1
Y2 = SV[ind1+Nx*Nspecies:ind2+Nx*Nspecies] / D2
# Terms for diffusive flux:
gas.TDY = Temp, np.mean([D1,D2]), np.mean([Y1,Y2],axis=0)
D_AB = gas.mix_diff_coeffs_mass
mu = gas.viscosity
Delta_Y = Y2 - Y1
# Terms for convective flux:
rho_k = np.mean([SV[ind1:ind2],
SV[ind1+Nx*Nspecies:ind2+Nx*Nspecies]],axis=0)
gas.TDY = Temp, D1, Y1
P1 = gas.P
gas.TDY = Temp, D2, Y2
P2 = gas.P
V_conv = -K_g*(P2 - P1)*dY_inv / mu
Fluxes_Y[cnt_y:cnt_y+Nspecies] = rho_k*V_conv \
- phi_tau_sq*D_AB*D_av*Delta_Y*dY_inv
ind1 = ind2
ind2 = ind1 + Nspecies
cnt_y = cnt_y + Nspecies
return Fluxes_X, Fluxes_Y