-
Notifications
You must be signed in to change notification settings - Fork 4
/
biglobal.py
128 lines (96 loc) · 3.82 KB
/
biglobal.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
## Compute biGlobal stability analysis
import numpy as _np
from mpi4py import MPI
import misc.PETSc_func as pet
from petsc4py import PETSc
import resolvent_all as resol
import restart_init as ri
import timeit
import sys
import os
if __name__ == '__main__':
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
treeBroadcast = str(sys.argv[1])
out_dir = str(sys.argv[2])
target = float(sys.argv[3])
wave = float(sys.argv[4])
os.system('mkdir -p %s' % out_dir)
wavenumber = _np.array([wave])
# target = -0.1 #0. #-0.1
## Number of eigenvalue to compute
nev = 1
## Maximum iterations of the Krylov-Schur method
maxits = 30
## Tolerance of the Krylov-Schur method
tol = 1.e-5
dic = _np.load(treeBroadcast)
gh = dic['gh']
x = dic['xc'][gh:-gh,gh:-gh]
y = dic['yc'][gh:-gh,gh:-gh]
im = dic['im']
jm = dic['jm']
vol = dic['vol']
w = dic['FlowSolutionEndOfRun']
gam = dic['Gamma']
mach = dic['Mach']
IA = dic['IA']
JA = dic['JA']
Jacvol = dic['Aij']
IAdz = dic['IAdz']
JAdz = dic['JAdz']
Jacdz = dic['Aijdz']
IAdz2 = dic['IAdz2']
JAdz2 = dic['JAdz2']
Jacdz2 = dic['Aijdz2']
Jacsurvol = pet.createMatPetscCSR(IA, JA, Jacvol, im*jm*5, im*jm*5, 5*(2*gh+1)**2)
Dz = pet.createMatPetscCSR(IAdz, JAdz, Jacdz, im*jm*5, im*jm*5, 5*(2*gh+1)**2)
Dzz = pet.createMatPetscCSR(IAdz2, JAdz2, Jacdz2, im*jm*5, im*jm*5, 5*(2*gh+1)**2)
## Restriction in space of the Jacobian
xmin = x[0,0]
xmax = x[-1,0]
ymin = y[0,0]
ymax = y[0,-1]
restrixJac = resol.restrix(im, jm, 5, x, y, xmin, xmax, ymin, ymax, square=False)
Jacredux = restrixJac.transposeMatMult(Jacsurvol.matMult(restrixJac))
Dzredux = restrixJac.transposeMatMult(Dz.matMult(restrixJac))
Dzzredux = restrixJac.transposeMatMult(Dzz.matMult(restrixJac))
filename = out_dir + '/spectrum.dat'
eigarray = _np.zeros(len(wavenumber))
for k in range(len(wavenumber)):
Jac3D = Jacredux - wavenumber[k]**2 * Dzzredux + wavenumber[k] * 1.j * Dzredux
ksp = pet.kspLUPetsc(Jac3D)
t1 = timeit.time.time()
## Shift-invert from Petsc - Only direct modes
# vals,vecR,vecI,eps = pet.eigPetsc(Jac3D,ksp,target,nev, restrixJac, tol=tol, maxits=maxits)
## OR manual shift-invert - It can compute direct & adjoint modes
## For direct mode
A, ksp_A = pet.createShiftInvert(Jac3D, target)
## For adjoint mode
# A, ksp_A = pet.createShiftInvert_Transpose(Jac3D, target)
Id = pet.createMatIDPetsc(Jac3D.getSize()[0], Jac3D.getSize()[1])
eigshift, eigenvector, eps = pet.eigPetsc3(comm ,A , Id, Id ,nev=nev,tol=tol,maxits=maxits)
vals = target + 1./_np.array(eigshift)
vecRt = pet.computeEigenvector(comm, eigenvector, restrixJac)
vecR = [vecRt]
t2 = timeit.time.time()
t_eig = t2 - t1
if rank == 0:
print('Time eig:', t_eig)
print('Frequency n', k+1)
print("Complex eigenvalues found:", vals)
# print(_np.real(vals[0]))
eigarray[k] = _np.real(vals[0])
pet.saveSpectrumTecplot(eps,rank,filename)
if rank == 0:
# comm.Barrier()
w_response = _np.reshape( _np.real(vecR[0]), (im,jm,5))
filename1 = out_dir + '/mode_atcenter_eig_n%i_real.dat' % k
resol.__writestate_center_gh(filename1, im, jm, w_response, x, y)
# comm.Barrier()
w_responsei = _np.reshape( _np.imag(vecR[0]), (im,jm,5))
filename2 = out_dir + '/mode_atcenter_eig_n%i_imag.dat' % k
resol.__writestate_center_gh(filename2, im, jm, w_responsei, x, y)
comm.Barrier()
if rank == 0:
print(eigarray)