-
Notifications
You must be signed in to change notification settings - Fork 0
/
initial.f90
113 lines (94 loc) · 2.93 KB
/
initial.f90
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
#include "port.h"
!=============================================================================!
subroutine initial( Uic, ic )
!=============================================================================!
use global
implicit none
complex :: Uic(neq,neq)
integer :: ic, j
!.... local variables
complex :: Eh(neq,neq), Fh(neq,neq), Ehinv(neq,neq), Id(neq,neq)
complex :: eval(neq), evec(neq,neq)
integer :: ieq
!.... local variables for Lapack routines
integer :: ipiv(neq), jpiv(neq), info
integer :: lwork
complex, allocatable :: work(:)
real, allocatable :: rwork(:)
!=============================================================================!
#define USE_LOCAL_INVERSE
!#define DEBUG_MATRICES
lwork = 2 * neq
allocate( work(lwork), rwork(lwork) )
!.... Initialize data-structures
Eh=zero; Fh=zero; Ehinv=zero; eval=zero; evec=zero; ipiv=zero
jpiv=zero; work=zero; rwork=zero
!.... Compute the matrices in the farfield
call parallel( ymax, Eh, Fh, 0 )
#ifdef DEBUG_MATRICES
write(*,*) "Eh = "
do j=1,neq
write(*,"(*('('sf8.2xspf8.2x'i)':x))") Eh(:,j)
end do
#endif
!.... Multiply Fh by Eh^{-1}
#ifdef USE_LOCAL_INVERSE
call inverse( neq, Eh, Ehinv)
#ifdef DEBUG_MATRICES
Id = matmul(Ehinv, Eh)
write(*,*) "Ehinv * Eh = "
do j=1,neq
write(*,"(*('('sf8.2xspf8.2x'i)':x))") Id(:,j)
end do
!write(*,*) "Fh(1) = ", Fh
!write(*,*) "Ehinv = ", Ehinv
#endif
Fh = matmul( Ehinv, Fh )
#else
#ifdef PARTIAL_PIVOTING
call CGETRF( neq, neq, Eh, neq, ipiv, info)
#else
call ZGETC2( neq, Eh, neq, ipiv, jpiv, info)
#endif
if (info.ne.0) then
write(*,*) 'CGETRF/ZGETC2: ', info
call exit(info)
endif
call CGETRS('N', neq, neq, Eh, neq, ipiv, Fh, neq, info)
if (info.ne.0) then
write(*,*) 'CGETRS: ',info
call exit(info)
endif
#endif
!.... Negate the matrix to get the correct eigenvalues
Fh = -Fh
#ifdef DEBUG_MATRICES
write(*,*) "-Ehinv * Fh = "
do j=1,neq
write(*,"(*('('sf8.2xspf8.2x'i)':x))") Fh(:,j)
end do
#endif
!.... solve the eigenproblem
call CGEEV('N', 'V', neq, Fh, neq, eval, evec, &
neq, evec, neq, work, lwork, rwork, info)
!.... use the solutions that are damped to infinity to form the initial
Uic = zero
ic = 0
do ieq = 1, neq
! write(*,*) ieq, eval(ieq), real(eval(ieq))
if ( real(eval(ieq)) .lt. zero ) then
ic = ic + 1
Uic(:,ic) = evec(:,ieq) * exp( eval(ieq) * ymax )
end if
end do
if (ic.ne.4) then
write(*,*) "initial: there should be 4 damped modes"
write(*,*) " but we have ic = ", ic," dampled modes"
call exit(1)
endif
#ifdef VERBOSE
write(*,"('Completed initial')")
#endif
deallocate( work, rwork )
return
end