-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdracula.py
More file actions
167 lines (120 loc) · 5.71 KB
/
dracula.py
File metadata and controls
167 lines (120 loc) · 5.71 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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 06:43:56 2024
@author: ygaillard
"""
import numpy as np
from scipy.integrate import solve_bvp
from dracula_coeff import a_lmn,A_lmn,B_lmn,C_lmn,D_lmn,E_lmn,F_lmn,G_lmn,a_n,b_n,c_n
from scipy.special import legendre
import JsonSim as JS
class draculaSolver:
def __init__(self,order,eta,mu,Re,nPoints=100):
self.order=order
self.eta=eta
self.mu=mu
self.Re=Re
self.Nt=2*self.order-1
print('Nt:'+str(self.Nt))
self.r = np.linspace(self.eta, 1.0, nPoints )
def load(self):
jsonSim=JS.JsonSim('dracula_output_order'+str(self.order)+'_eta'+str(self.eta)+'_mu'+str(self.mu)+'_Re'+str(self.Re)+'.json',
'order'+str(self.order)+'_eta'+str(self.eta)+'_mu'+str(self.mu)+'_Re'+str(self.Re),
access='r')
if jsonSim.fileExisted:
self.f=jsonSim.siminformation['f']
self.fp=jsonSim.siminformation['fp']
self.g=jsonSim.siminformation['g']
self.gp=jsonSim.siminformation['gp']
self.gpp=jsonSim.siminformation['gpp']
self.gppp=jsonSim.siminformation['gppp']
del jsonSim
return True
else:
print('No file available')
return False
def save(self):
jsonSim=JS.JsonSim('dracula_output_order'+str(self.order)+'_eta'+str(self.eta)+'_mu'+str(self.mu)+'_Re'+str(self.Re)+'.json',
'order'+str(self.order)+'_eta'+str(self.eta)+'_mu'+str(self.mu)+'_Re'+str(self.Re),
access='rw')
jsonSim.write('f', self.f)
jsonSim.write('fp', self.fp)
jsonSim.write('g', self.g)
jsonSim.write('gp', self.gp)
jsonSim.write('gpp', self.gpp)
jsonSim.write('gppp', self.gppp)
del jsonSim
def solve(self):
y = np.zeros( ( (int((self.Nt-1)/2)+1)*6, len( self.r ) ) )
y[0] = np.linspace( self.eta**2/self.mu, 1, len( self.r ) ) # initial guess to fit boundary conditions
result = solve_bvp( self.ode, self.bc, self.r, y, verbose=2 )
rplot = np.linspace( self.eta, 1.0, 100 )
self.f, self.fp, self.g, self.gp, self.gpp, self.gppp=np.zeros((6,self.Nt+1,np.shape(y)[1]))
for n in range(0,int((self.Nt-1)/2)+1):
self.f[2*n]=result.sol( rplot )[6*n+0]
self.fp[2*n]=result.sol( rplot )[6*n+1]
self.g[2*n+1]=result.sol( rplot )[6*n+2]
self.gp[2*n+1]=result.sol( rplot )[6*n+3]
self.gpp[2*n+1]=result.sol( rplot )[6*n+4]
self.gppp[2*n+1]=result.sol( rplot )[6*n+5]
def getFlowResult(self,theta):
Psi=0
Omega=0
for n in range(0,self.Nt+1):
if (n%2==0):
Omega+=np.outer(np.sin(theta)**2*np.polyval(legendre(n), np.cos(theta)),self.f[n])
else:
Psi+=np.outer(np.sin(theta)**2*np.polyval(legendre(n), np.cos(theta)),self.g[n])
return (Psi,Omega)
def ode(self, r, y ):
# y is [ f0, f0', g1, g1', g1'', g1''' ]
f, fp, g, gp, gpp, gppp=np.zeros((6,self.Nt+1,np.shape(y)[1]))
for n in range(0,int((self.Nt-1)/2)+1):
f[2*n]=y[6*n]
fp[2*n]=y[6*n+1]
g[2*n+1]=y[6*n+2]
gp[2*n+1]=y[6*n+3]
gpp[2*n+1]=y[6*n+4]
gppp[2*n+1]=y[6*n+5]
EquList=[]
for n in range(0,self.Nt+1):
if (n%2==0):
subSum=0
for l in range(0,self.Nt+1):
if l>=n+2:
subSum+=2*(2*n+1)/r**2*f[l]
for m in range(0,self.Nt+1):
if (m+l)>n-2:
subSum+=(2*n+1)/2*self.Re/r**2*(a_lmn(l, m, n)*(g[l]*fp[m]-gp[m]*f[l]))
RHSf = (n+1)*(n+2)/r**2*f[n] + subSum
EquList.extend((fp[n],RHSf))
else:
subSum=0
for l in range(0,self.Nt+1):
if l>=n+2:
subSum+=4*(2*n+1)/r**2*(
gpp[l]-2/r*gp[l]+(2-l*(l+1))/r**2*g[l]
)
for m in range(0,self.Nt+1):
if (m+l)>n-2:
subSum+=(2*n+1)/2*self.Re/r**3*(
A_lmn(l, m, n)*r* fp[l]*f[m]
+B_lmn(l, m, n)* f[l]*f[m]
+C_lmn(l, m, n)*r* gppp[l]*g[m]
+D_lmn(l, m, n)*r* gpp[l]*gp[m]
+E_lmn(l, m, n)* gpp[l]*g[m]
+F_lmn(l, m, n)/r* gp[l]*g[m]
+G_lmn(l, m, n)/r**2*g[l]*g[m]
)
RHSg = -a_n(n)/r**2*gpp[n] -b_n(n)/r**3*gp[n] -c_n(n)/r**4*g[n]+subSum
EquList.extend((gp[n],gpp[n],gppp[n],RHSg))
return np.vstack( EquList )
def bc(self,ya, yb ):
bcList=[]
for n in range(0,int((self.Nt-1)/2)+1):
if n==0:
bcList.extend((ya[0]-self.eta**2/self.mu, ya[2], ya[3], yb[0] - 1 , yb[2], yb[3]))
else:
bcList.extend((ya[6*n+0], ya[6*n+2], ya[6*n+3], yb[6*n+0] , yb[6*n+2], yb[6*n+3]))
return np.array( bcList )