-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBW1.py
158 lines (158 loc) · 3.76 KB
/
BW1.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
# (Implicit in time and centered in space)
import numpy as np
import matplotlib.pyplot as plt
import math
L = 104
Time = 10
alpha = 2.5
dx = 2
dt = 1
V = 4
D = (alpha * V)
a = (1 + ((2 * D * dt) / (dx**2)))
b = (((V * dt) / (2 * dx)) - ((D * dt) / (dx**2)))
c = (-((V * dt) / (2 * dx)) - ((D * dt) / (dx**2)))
l = np.arange(0, (L+dx), dx)
length = len(l)
count = int(Time / dt)
C = np.zeros(length)
C[0] = 100
T10C = np.zeros(length)
# Implicit Matrix
Im = np.zeros((length**2)).reshape(length, length)
for i in range(length):
for j in range(length):
if (i + 1) == j:
Im[i][j] = b
elif (i - 1) == j:
Im[i][j] = c
elif i == j:
Im[i][j] = a
Im[0][0] = 1
Im[0][1] = 0
Im[(length-1)][(length-1)] = 1
Im[(length-1)][(length-2)] = 0
count = int(Time / dt)
for x in range(count):
t = (np.linalg.solve(Im, C))
C = t
C[0] = 100
T10C = t
print('Central\n', T10C)
plt.plot(l, T10C, marker='*')
#%%
# (Implicit in time and forward in space)
a = -2.5
b = 4
c = -0.5
l = np.arange(0, L, dx)
length = len(l)
count = int(Time / dt)
C = np.zeros(length)
C[0] = 100
# Implicit Matrix
Im = np.zeros((length**2)).reshape(length, length)
for i in range(length):
for j in range(length):
if (i + 1) == j:
Im[i][j] = c
elif (i - 1) == j:
Im[i][j] = a
elif i == j:
Im[i][j] = b
Im[0][0] = 1
Im[0][1] = 0
Im[(length-1)][(length-1)] = 1
Im[(length-1)][(length-2)] = 0
count = int(Time / dt)
for x in range(count):
t = (np.linalg.solve(Im, C))
C = t
C[0] = 100
T10F = t
plt.plot(l, T10F, marker='>')
print('Forward\n', T10F)
# (Implicit in time and backward in space)
a = -4.5
b = 8
c = -2.5
l = np.arange(0, L, dx)
length = len(l)
count = int(Time / dt)
C = np.zeros(length)
C[0] = 100
# Implicit Matrix
Im = np.zeros((length**2)).reshape(length, length)
for i in range(length):
for j in range(length):
if (i + 1) == j:
Im[i][j] = c
elif (i - 1) == j:
Im[i][j] = a
elif i == j:
Im[i][j] = b
Im[0][0] = 1
Im[0][1] = 0
Im[(length-1)][(length-1)] = 1
Im[(length-1)][(length-2)] = 0
count = int(Time / dt)
for x in range(count):
t = (np.linalg.solve(Im, C))
C = t
C[0] = 100
T10B = t
plt.plot(l, T10B, marker='<')
print('Backwards\n', T10B)
#%%
# Analytical Solution
Co = 100
C = []
t = 10
for x in range(0, 104, 2):
A = math.erfc((x - V * t) / (2 * math.sqrt(D * t)))
B = ((math.exp(((x * V) / D))) * (math.erfc((x + (V * t)) / 2 * math.sqrt(D * t))))
n = (0.5 * Co * (A + B))
C.append(n)
plt.plot(l, C, marker='.')
print('Analytical\n', C)
# (Implicit in time and backward in space with numerical disoersion)
a = -1.5
b = 2
c = 0.5
l = np.arange(0, L, dx)
length = len(l)
count = int(Time / dt)
C = np.zeros(length)
C[0] = 100
#%%
# Implicit Matrix
Im = np.zeros((length**2)).reshape(length, length)
for i in range(length):
for j in range(length):
if (i + 1) == j:
Im[i][j] = c
elif (i - 1) == j:
Im[i][j] = a
elif i == j:
Im[i][j] = b
Im[0][0] = 1
Im[0][1] = 0
Im[(length-1)][(length-1)] = 1
Im[(length-1)][(length-2)] = 0
print(Im)
count = int(Time / dt)
for x in range(count):
t = (np.linalg.solve(Im, C))
C = t
C[0] = 100
TND = t
plt.plot(l, TND, marker='<')
print('With ND\n', TND)
#%%
# Plotting
plt.xlabel('Distance (m)') # Labeling of X-Axis
plt.ylabel('Contaminant Concentration') # Labeling of Y-axis
plt.title('Distance vs Contaminant Concentration')
plt.grid()
plt.legend(['centered@10','Forward@10','Backward@10','Analytical@10','Model with numerical dispersion'])
plt.show()