-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFVM_QUICK_convection.py
107 lines (83 loc) · 2.25 KB
/
FVM_QUICK_convection.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
'''
Problem is solution a convection-diffusion 1D equation by finite volume method.
For approximation of convection terms QUICK scheme is used.
'''
#Solve FVM QUICK convection-diffusion 1D equation
import numpy as np
import matplotlib.pyplot as plt
#Domain data
n=15 #number of control volumes
a=np.zeros((n,n)) #initial matriX domain
ro=1 #Density
u0=0.2 #velocity
l=1 #length of Domain
dx=l/n #distance between nodes
sigma = 0.1
#Diffusin and convection term
F=ro*u0
D=sigma / dx
#values of phi at boundaries of the Domain
phiA=1
phiB=0
#first Loop for arranging nodes values
for i in range(n):
for j in range(n):
if i==j:
a[i,j]=3/8*F + 2*D #1.075
if i==j-1:
a[i,j]=3/8*F - D #-0.675
if i==j+2:
a[i,j]=F/8 #0.025
if i==j+1:
a[i,j]=(-7*F/8) - D #-0.675
a[0,0]=7/8*F+4*D
a[0,1] = 3/8*F - 4/3*D
a[1,0] = -F-D
a[n-1,-2] = -6/8*F - 4/3 * D
a[-1,-1]=-3/8*F + 4*D
#answer matrix
b=np.zeros((n,1)).reshape(n,1)
b[0]=2/8*F + phiA*F + 8/3 * D * phiA
b[1]=-2*(F/8) * phiA
b[-1]=-F*phiB + D/3*8*phiB
#print OUt values of created Matrix
print(b)
print(a)
#Gauss-Sidel iteration method
#LU decomposition
U=a.copy()
L=a.copy()
for i in range (0,n):
for j in range (0,n):
if i>=j:
U[i,j]=0
for i in range (0,n):
for j in range (0,n):
if j>i:
L[i,j]=0
Linv=np.linalg.inv(L)
T=np.dot(-Linv,U)
C=np.dot(Linv,b)
x_init=np.zeros(n).reshape(n,1)
epsilon=0.0001
conv_criteria=np.array([epsilon]*n).reshape(n,1)
###Iteration process
iteration_number=10000
x=[None]*n
for i in range(1,iteration_number):
x[0]=np.dot(T,x_init) + C
x[i]=np.dot(T,x[i-1]) + C
x.append(x[i])
check_conv=np.less(x[i]-x[i-1],conv_criteria)
if check_conv.any()==True:
print('CONVERGED!')
break
#calculating Analytical solution
x_exact = np.linspace(0.1,1,n)
phi_exact = 1-(((np.exp(ro*u0*x_exact/sigma))-1)/((np.exp(ro*u0*l/sigma))-1))
print(x[-1])
#postProcessing
plt.plot(x_exact,phi_exact,'k',ls='',marker='+',label = 'exact solution')
plt.plot(x_exact,x[-1],marker='^',label='Quick Scheme')
plt.legend()
plt.show()