-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
203 lines (192 loc) · 7.03 KB
/
main.py
File metadata and controls
203 lines (192 loc) · 7.03 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#=====================================================
# Department of Mechanical Engineering, Purdue University
# ME 506: Two-Phase Flow and Heat Transfer
# Fall 2019
# Final: Two-Phase Flow Induced Vibrations
# Julien Brillon | 031064624
# Python 2.7.15
#=====================================================
# Import libraries
import numpy as np
import scipy
import matplotlib.pyplot as plt
import scipy.sparse as scysparse
import scipy.sparse.linalg
from scipy.optimize import fsolve
#=====================================================
from var import *
from polylib import *
from operations import *
#=====================================================
# Equation of Motion
#=====================================================
# from EoM_SinglePhasePCF import *
from EoM_TwoPhasePCF import *
# from EoM_SinglePhasePIAF import *
#*****************************************************
# Display Problem Setup
#*****************************************************
print('\nSETUP:')
print('--------------------------')
print('End conditions: %s' % EndCond)
print('Number of modes: %i' % Nmodes)
print('--------------------------\n')
print('\nPARAMETERS:')
print('--------------------------')
print('rhoG = %f' % rhoG)
print('rhoL = %f' % rhoL)
print('eps = %f' % eps)
print('alpha = %f' % alpha)
print('Ks = %f' % Ks)
print('betaLO = %f' % betaLO)
print('betaL = %f' % betaL)
print('gamma = %f' % gamma)
print('mu = %f' % mu)
print('--------------------------\n')
#*****************************************************
# Get Roots of Frequency Equation
#*****************************************************
print('BEFORE root finding:')
for i in range(0,Nmodes):
print('i = %i\t lambda = %.12f\t err = %.5e' % (i,lambdas[i],freqEq(lambdas[i])))
if(EndCond != 'pinned-pinned'):
GetEigenValues_FreqEq()
print('AFTER root finding:')
for i in range(0,Nmodes):
print('i = %i\t lambda = %.12f\t err = %.5e' % (i,lambdas[i],freqEq(lambdas[i])))
#*****************************************************
# Build Galerkin matrices
#*****************************************************
for k in range(0,Nmodes):
for l in range(0,Nmodes):
[b_sr[k,l], c_sr[k,l], d_sr[k,l], e_sr[k,l]] = evaluate_stdel_intgrals(k,l)
#*****************************************************
# SOLVER
#*****************************************************
print('-------------- Solver Starting ----------------\n')
# Initialize
u = np.float128(u_min)
for i in range(0,npoints):
# Update velocity
u = u + du
u_store[i] = u
# Update Matrices
for k in range(0,Nmodes):
for l in range(0,Nmodes):
M[k,l] = M_sr(k,l)
C[k,l] = C_sr(k,l,u)
K[k,l] = K_sr(k,l,u)
# Method of Solution: Concatenated Matrices
B = concatenate4matrices(zeroMat, M, M, C)
E = concatenate4matrices(-M, zeroMat, zeroMat, K)
B = np.float64(B)
E = np.float64(E)
Y = np.matmul(-np.linalg.inv(B),E) # preferred to np.dot()
Val, Vec = np.linalg.eig(Y)
# Val = np.linalg.eigvals(Y)
omega = Val*(-1.0j)
# print(Val)
# print(Vec)
Vec = Vec.T
w_scatter_store[i,:] = omega
# eigenvalue sorting
omega_plus = np.zeros(2*Nmodes,dtype='complex64')
eigvec_plus = np.zeros((2*Nmodes,2*Nmodes),dtype='complex64')
for k in range(0,2*Nmodes):
if(np.real(omega[k])>=0.0):
omega_plus[k] = omega[k]
eigvec_plus[k,:] = Vec[k,:]
# print('----------')
# print(omega_plus)
# print(eigvec_plus)
# print('----------')
# print('- - -- - -')
# print(np.nonzero(omega_plus)[0])
# print('- - -- - -')
# print('----------')
# print(eigvec_plus[0,:])
eigvec_plus = eigvec_plus[np.nonzero(omega_plus)[0],:]
eigvec_plus = eigvec_plus[:,np.nonzero(omega_plus)[0]]
# print(eigvec_plus)
# print('----------')
# print('----------')
# Keep only non-zeros
omega_plus = omega_plus[np.nonzero(omega_plus)]
if(i==0):
# print()
# print('- - -- - -')
w_store[i,:] = np.sort(omega_plus)
# print(np.argsort(omega_plus))
# print(omega_plus)
eigvec_plus = eigvec_plus[np.argsort(omega_plus),:]
# print()
# print(eigvec_plus)
# eigvec_plus = eigvec_plus[:,np.argsort(omega_plus)]
# print()
# print(eigvec_plus)
# print(w_store[i,:])
eigvec_store[:,:,i] = eigvec_plus
# print('- - -- - -')
else:
l_min_store = np.zeros(Nmodes,dtype='int64')
dummy_index = 0
for l in range(0,Nmodes):
l_min = np.argmin(np.abs(w_store[i-1,l]-omega_plus))
w_store[i,l] = omega_plus[l_min]
l_min_store[dummy_index] = l_min
dummy_index += 1
# print('* * * * * * * * * * *')
# print(omega_plus)
# print(w_store[i,:])
# print(l_min_store)
# print('* * * * * * * * * * *')
# print()
# print(eigvec_plus)
eigvec_plus = eigvec_plus[l_min_store,:]
# print()
# print(eigvec_plus)
eigvec_plus = eigvec_plus[:,l_min_store]
# print()
# print(eigvec_plus)
# print('* * * * * * * * * * *')
eigvec_store[:,:,i] = eigvec_plus
print('-------------- Solver Converged ---------------\n')
#-----------------------------------------------------
# Critical Velocities
#-----------------------------------------------------
u_crit = -np.ones((Nmodes,100),dtype='float64')
for i in range(0,Nmodes):
u_crit_index=-1
for l in range(0,(npoints-1)):
if(np.imag(w_store[l+1,i])*np.imag(w_store[l,i]) < 0.0):
u_crit_index = u_crit_index+1
u_crit[i,u_crit_index]=u_store[l]
#-----------------------------------------------------
# Store data
#-----------------------------------------------------
# Store velocities
data_fileName = 'u_store'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, u_store)
data_fileName = 'u_crit'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, u_crit)
# Store complex values
real_w_store = np.real(w_store)
imag_w_store = np.imag(w_store)
data_fileName = 'real_w_store'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, real_w_store)
data_fileName = 'imag_w_store'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, imag_w_store)
# Store complex values
real_w_scatter_store = np.real(w_scatter_store)
imag_w_scatter_store = np.imag(w_scatter_store)
data_fileName = 'real_w_scatter_store'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, real_w_store)
data_fileName = 'imag_w_scatter_store'
np.savetxt(subdirectories[0]+data_fileName+'.'+data_fileType, imag_w_store)
# Store eigenvectors
subsubdir = 'eigvec/'
for i in range(0,npoints):
data_fileName = getFigFileName(i)
np.savetxt(subdirectories[0]+subsubdir+'real_'+data_fileName+'.'+data_fileType, np.real(eigvec_store[:,:,i]))
np.savetxt(subdirectories[0]+subsubdir+'imag_'+data_fileName+'.'+data_fileType, np.imag(eigvec_store[:,:,i]))
print('-----------------------------------------------------')