-
Notifications
You must be signed in to change notification settings - Fork 4
/
pois.f90
240 lines (204 loc) · 7.83 KB
/
pois.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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
!=============================================================
! Solves the Poisson eq. for the pressure correction
! using a cosine transform in x (with wavenumbers of 2nd ord. FD)
! and Fourier in z. Tridiagonal FD in y
!
! Everything works in (zy) planes, except for the cosines
!
! old version from MP Simens, storage changed for BGP by
! JJS, Dec 24/2009
!=============================================================
subroutine pois(ut,vt,wt,pt,res,rest,rt,varstep,mpiid,communicator)
use point
use alloc_dns,only:idx,idy,idxx,idyy,phiy,dy,y,kaz,kaz2,kmod,ayp
use ctesp
use omp_lib
use temporal
implicit none
include 'mpif.h'
integer,intent(in):: communicator
! ---------------------- I/O -------------------------------------!
integer mpiid
real*8 dt,varstep
real*8, dimension(nx,mpv) :: res !<<<<<<<<<<<<
complex*16, dimension(0:nz2,ny+1,ib:ie):: wt,rt,ut
complex*16, dimension(0:nz2,ny,ib:ie) :: pt,vt,rest
! -------------------------- Work Arrays -------------------------!
real*8 aypr(3,ny-1),dpdyH,dpdyH1,a
integer i,j,l,k,kk,k2
! --------------------- MPI workspaces -----------------------------!
integer istat(MPI_STATUS_SIZE),ierr,comm,countu,countv,tipo
! ----------------------------------------------------------------!
countu=(nz2+1)*(ny+1)
countv=(nz2+1)*ny
comm = communicator
tipo=MPI_COMPLEX16
! --- compute the divergence, we are in (zy)
do i=ib0,ie
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
rest(:,j,i) = wt(:,j+1,i)*kaz +(vt(:,j+1,i)-vt(:,j,i))*idy(j)
enddo
enddo
! --- add du/dx -------------
do i=ib+1,ie
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
rest(:,j,i)=rest(:,j,i)+idx*(ut(:,j+1,i)-ut(:,j+1,i-1))
enddo
enddo
if (mpiid2.eq.0) tm1 = MPI_WTIME()
if (mpiid.eq.0) then
call MPI_SEND(ut(0,1,ie),countu,tipo,mpiid+1,0,comm,istat,ierr)
elseif (mpiid.eq.pnodes-1) then
call MPI_RECV(rt(0,1,ib),countu,tipo,mpiid-1,0,comm,istat,ierr)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
rest(:,j,ib)=rest(:,j,ib)+idx*(ut(:,j+1,ib)-rt(:,j+1,ib))
enddo
else
call MPI_SENDRECV(ut(0,1,ie),countu,tipo,mpiid+1,0, &
& rt(0,1,ib),countu,tipo,mpiid-1,0, comm,istat,ierr)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
rest(:,j,ib)=rest(:,j,ib)+idx*(ut(:,j+1,ib)-rt(:,j+1,ib))
enddo
endif
if (mpiid2.eq.0) then
tm2 = MPI_WTIME()
tmp15 = tmp15 + abs(tm2-tm1)
endif
! ---- go to lines, transform, and go back to planes ----
call chp2x(res,rest,rt,mpiid,ny,comm)
if (mpiid2.eq.0) then
tm1 = MPI_WTIME()
endif
!=============================================================
!=============================================================
!$OMP PARALLEL DEFAULT(SHARED)
call cosftx(res(2,mpvb),nx,mpvb,mpve,-1)
!$OMP END PARALLEL
!=============================================================
!=============================================================
if (mpiid2.eq.0) then
tm2 = MPI_WTIME()
tmp10 = tmp10 + abs(tm2-tm1)
endif
call chx2p(res,rest,rt,mpiid,ny,comm)
rest(0,:,ib:ie)=real(rest(0,:,ib:ie),kind=8) !Ensuring the 0th mode is Real
! -------- solve poisson in (zy) planes (using equiv. wavenumbers)
do i = ib0,ie
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(k,aypr) SCHEDULE(STATIC)
do k = 0,nz2
aypr = ayp(:,1:ny-1)
aypr(2,1:ny-1) = ayp(2,1:ny-1)-kaz2(k)-kmod(i-1)
if (i==2 .and. k==0) then
aypr(2,ny-1) = 2d0*ayp(2,ny-1)
rest(0,ny-1,2)=0d0
endif
call soltriy(rest(0,1,i),rest(0,1,i),k,aypr)
enddo
! if (i .eq.2) then
! dpdyH = -rest(0,ny-1,1)/(dy(ny)+dy(ny-1))
! dpdyH1 = -phiy(ny-1)/(dy(ny)+dy(ny-1))
! a = -dpdyH/dpdyH1
! write(*,*) 'masas',a,dpdyH,dpdyH1
! endif
enddo
! ---- go to lines, back-transform, and go back to planes ----
call chp2x(res,rest,rt,mpiid,ny,comm)
if (mpiid2.eq.0) then
tm1 = MPI_WTIME()
endif
!$OMP PARALLEL DEFAULT(SHARED)
call cosftx(res(2,mpvb),nx,mpvb,mpve,1)
!$OMP END PARALLEL
if (mpiid2.eq.0) then
tm2 = MPI_WTIME()
tmp10 = tmp10 + abs(tm2-tm1)
endif
call chx2p(res,rest,rt,mpiid,ny,comm)
do i =ib0,ie
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j = 2,ny
pt(:,j,i) = varstep*rest(:,j-1,i)+pt(:,j,i) ! ------- update pressure
wt(:,j,i) = wt(:,j,i)-kaz*rest(:,j-1,i) ! ------- update velocities
enddo
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j = 2,ny-1
vt(:,j,i) = vt(:,j,i)-idyy(j)*(rest(:,j,i)-rest(:,j-1,i))
enddo
enddo
! ------- update u+dp/dx ---
do i=ib0,ie-1
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
ut(:,j+1,i)=ut(:,j+1,i)-idxx*(rest(:,j,i+1)-rest(:,j,i))
enddo
enddo
if (mpiid2.eq.0) tm1 = MPI_WTIME()
if (mpiid.eq.pnodes-1) then
call MPI_SEND(rest,countv,tipo,mpiid-1,1,comm,istat,ierr)
elseif (mpiid.eq.0) then
call MPI_RECV(rt,countv,tipo,mpiid+1,1,comm,istat,ierr)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
ut(:,j+1,ie)=ut(:,j+1,ie)-idxx*(rt(:,j,ib)-rest(:,j,ie))
enddo
else
call MPI_SENDRECV(rest,countv,tipo,mpiid-1,1, &
& rt,countv,tipo,mpiid+1,1, comm,istat,ierr)
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(j) SCHEDULE(STATIC)
do j=1,ny-1
ut(:,j+1,ie)=ut(:,j+1,ie)-idxx*(rt(:,j,ib)-rest(:,j,ie))
enddo
endif
if (mpiid2.eq.0) then
tm2 = MPI_WTIME()
tmp23 = tmp23 + abs(tm2-tm1)-(tp2-tp1)
endif
end subroutine pois
!/*********************************************************************/
!/* */
!/* Resolvedor de un sistema tridiagonal */
!/* resuelve arrays 2D por columnas ... */
!/* */
!/* entrada: a1 a2 a3 us u */
!/* a1 a2 a3 us = u */
!/* a1 a2 a3 us u */
!/* */
!/* nstr Maxima primera dimension de u y us */
!/* nlen Numero de sistemas a resolver */
!/* neq Dimension del sistema a resolver */
!/* iflag=0 Primera llamada (factorizacion y resolucion) */
!/* =1 Solo resolucion */
!/* */
!/* salida: us Solucion */
!/* iflag=1 */
!/* */
!/* */
!/*********************************************************************/
subroutine soltriy(u,us,ii,a) !ii=column to be solved
use ctesp
implicit none
integer ii,j
complex*16 u(0:nz2,ny1),us(0:nz2,ny1)
real*8 a(3,ny1),d
! lu-decomposition
do j = 2,ny1
d=1d0/a(2,j-1)
a(2,j-1) = d
a(1,j ) = - a(1,j)*d
a(2,j ) = a(2,j) + a(1,j)*a(3,j-1)
enddo
a(2,ny1)=1d0/a(2,ny1)
! backsubstitution
us(ii,1) = u(ii,1)
do j = 2,ny1
us(ii,j) = u(ii,j)+a(1,j)*us(ii,j-1)
enddo
us(ii,ny1) = us(ii,ny1)*a(2,ny1)
do j = ny1-1,1,-1
us(ii,j) = (us(ii,j)-a(3,j)*us(ii,j+1))*a(2,j)
enddo
end subroutine soltriy