-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdv_Script.py
More file actions
59 lines (47 loc) · 1.75 KB
/
Copy pathAdv_Script.py
File metadata and controls
59 lines (47 loc) · 1.75 KB
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
import numpy as np
import sys
import matplotlib.pylab as plt
from matplotlib.animation import FuncAnimation
from Adv_Class import PDE
#Define space and time increments that adhere to Von-Neumann stability.
dx = 1
dt = 0.1
#Create instance of PDE class and apply random noise to concentration array
A = PDE(dt,dx,int(sys.argv[1]),float(sys.argv[2]),float(sys.argv[3]),float(sys.argv[4]),float(sys.argv[5]))
A.Noise()
#If user selects the task to be visual simulation of the system
if str(sys.argv[6]) == 'viz':
#Animation function
def UpdatePlot(*args):
image = ax.imshow(A.order_array)
A.Sweep()
return image,
#Create animation
fig,ax = plt.subplots()
image = ax.imshow(A.order_array)
ani = FuncAnimation(fig,UpdatePlot,blit=True)
plt.title("2D Diffusion Reaction Equation Numerical Solution")
plt.xlabel("x coordinate")
plt.ylabel("y coordinate")
plt.show()
#If user selects the task to be obtaining data relating to the convergence of the solution
elif str(sys.argv[6]) == 'data':
#Loops to calculate the number of iterations to convergence
n = 0
steady_state = False
while steady_state == False:
n +=1
if n%500 == 0:
print(n)
steady_state = A.Sweep()
print("Iterations to convergence: " +str(n))
#Write data to text file and plot the converged array
r_list,conc_list = A.WriteData('SS_Concentration')
A.PlotArray()
#Plot the concentration of the converged array as a function of the distance from the centre
sorted_r,sorted_conc = zip(*sorted(zip(r_list,conc_list)))
plt.plot(r_list,conc_list)
plt.title("Steady State plot of Concentration vs Dist from Centre")
plt.xlabel("|r|")
plt.ylabel("Phi")
plt.show()