-
Notifications
You must be signed in to change notification settings - Fork 9
/
bound.f90
575 lines (575 loc) · 22.5 KB
/
bound.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
module mod_bound
use mpi_f08
use mod_types
implicit none
private
public boundp,bounduvw,updt_rhs,inflow
contains
subroutine bounduvw(cbc,lo,hi,bc,is_correc,halos,is_bound,nb, &
dxc,dxf,dyc,dyf,dzc,dzf,u,v,w)
!
! imposes velocity boundary conditions
!
implicit none
character(len=1), intent(in), dimension(0:1,3,3) :: cbc
integer , intent(in ), dimension(3) :: lo,hi
real(rp), intent(in ), dimension(0:1,3,3) :: bc
logical , intent(in ) :: is_correc
type(MPI_DATATYPE), intent(in ), dimension(3 ) :: halos
logical , intent(in ), dimension(0:1,3) :: is_bound
integer , intent(in ), dimension(0:1,3) :: nb
real(rp), intent(in ), dimension(lo(1)-1:) :: dxc,dxf
real(rp), intent(in ), dimension(lo(2)-1:) :: dyc,dyf
real(rp), intent(in ), dimension(lo(3)-1:) :: dzc,dzf
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: u,v,w
!
call updthalo(lo,hi,1,halos(1),nb(:,1),1,u)
call updthalo(lo,hi,1,halos(2),nb(:,2),2,u)
call updthalo(lo,hi,1,halos(3),nb(:,3),3,u)
call updthalo(lo,hi,1,halos(1),nb(:,1),1,v)
call updthalo(lo,hi,1,halos(2),nb(:,2),2,v)
call updthalo(lo,hi,1,halos(3),nb(:,3),3,v)
call updthalo(lo,hi,1,halos(1),nb(:,1),1,w)
call updthalo(lo,hi,1,halos(2),nb(:,2),2,w)
call updthalo(lo,hi,1,halos(3),nb(:,3),3,w)
!
if(is_bound(0,1)) then
if(.not.is_correc) call set_bc(cbc(0,1,1),0,lo,hi,1,.false.,bc(0,1,1),dxf(lo(1)-1),u)
call set_bc(cbc(0,1,2),0,lo,hi,1,.true. ,bc(0,1,2),dxc(lo(1)-1),v)
call set_bc(cbc(0,1,3),0,lo,hi,1,.true. ,bc(0,1,3),dxc(lo(1)-1),w)
end if
if(is_bound(1,1)) then
if(.not.is_correc) call set_bc(cbc(1,1,1),1,lo,hi,1,.false.,bc(1,1,1),dxf(hi(1) ),u)
call set_bc(cbc(1,1,2),1,lo,hi,1,.true. ,bc(1,1,2),dxc(hi(1) ),v)
call set_bc(cbc(1,1,3),1,lo,hi,1,.true. ,bc(1,1,3),dxc(hi(1) ),w)
end if
if(is_bound(0,2)) then
call set_bc(cbc(0,2,1),0,lo,hi,2,.true. ,bc(0,2,1),dyc(lo(2)-1),u)
if(.not.is_correc) call set_bc(cbc(0,2,2),0,lo,hi,2,.false.,bc(0,2,2),dyf(lo(2)-1),v)
call set_bc(cbc(0,2,3),0,lo,hi,2,.true. ,bc(0,2,3),dyc(lo(2)-1),w)
end if
if(is_bound(1,2)) then
call set_bc(cbc(1,2,1),1,lo,hi,2,.true. ,bc(1,2,1),dyc(hi(2) ),u)
if(.not.is_correc) call set_bc(cbc(1,2,2),1,lo,hi,2,.false.,bc(1,2,2),dyf(hi(2) ),v)
call set_bc(cbc(1,2,3),1,lo,hi,2,.true. ,bc(1,2,3),dyc(hi(2) ),w)
end if
if(is_bound(0,3)) then
call set_bc(cbc(0,3,1),0,lo,hi,3,.true. ,bc(0,3,1),dzc(lo(3)-1),u)
call set_bc(cbc(0,3,2),0,lo,hi,3,.true. ,bc(0,3,2),dzc(lo(3)-1),v)
if(.not.is_correc) call set_bc(cbc(0,3,3),0,lo,hi,3,.false.,bc(0,3,3),dzf(lo(3)-1),w)
end if
if(is_bound(1,3)) then
call set_bc(cbc(1,3,1),1,lo,hi,3,.true. ,bc(1,3,1),dzc(hi(3) ),u)
call set_bc(cbc(1,3,2),1,lo,hi,3,.true. ,bc(1,3,2),dzc(hi(3) ),v)
if(.not.is_correc) call set_bc(cbc(1,3,3),1,lo,hi,3,.false.,bc(1,3,3),dzf(hi(3) ),w)
end if
end subroutine bounduvw
!
subroutine boundp(cbc,lo,hi,bc,halos,is_bound,nb,dxc,dyc,dzc,p)
!
! imposes pressure boundary conditions
!
implicit none
character(len=1), intent(in), dimension(0:1,3) :: cbc
integer , intent(in ), dimension(3 ) :: lo,hi
real(rp), intent(in ), dimension(0:1,3) :: bc
type(MPI_DATATYPE), intent(in ), dimension(3 ) :: halos
logical , intent(in ), dimension(0:1,3) :: is_bound
integer , intent(in ), dimension(0:1,3) :: nb
real(rp), intent(in ), dimension(lo(1)-1:) :: dxc
real(rp), intent(in ), dimension(lo(2)-1:) :: dyc
real(rp), intent(in ), dimension(lo(3)-1:) :: dzc
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p
!
call updthalo(lo,hi,1,halos(1),nb(:,1),1,p)
call updthalo(lo,hi,1,halos(2),nb(:,2),2,p)
call updthalo(lo,hi,1,halos(3),nb(:,3),3,p)
!
if(is_bound(0,1)) then
call set_bc(cbc(0,1),0,lo,hi,1,.true.,bc(0,1),dxc(lo(1)-1),p)
end if
if(is_bound(1,1)) then
call set_bc(cbc(1,1),1,lo,hi,1,.true.,bc(1,1),dxc(hi(1) ),p)
end if
if(is_bound(0,2)) then
call set_bc(cbc(0,2),0,lo,hi,2,.true.,bc(0,2),dyc(lo(2)-1),p)
end if
if(is_bound(1,2)) then
call set_bc(cbc(1,2),1,lo,hi,2,.true.,bc(1,2),dyc(hi(2) ),p)
end if
if(is_bound(0,3)) then
call set_bc(cbc(0,3),0,lo,hi,3,.true.,bc(0,3),dzc(lo(3)-1),p)
end if
if(is_bound(1,3)) then
call set_bc(cbc(1,3),1,lo,hi,3,.true.,bc(1,3),dzc(hi(3) ),p)
end if
end subroutine boundp
!
subroutine set_bc(ctype,ibound,lo,hi,idir,centered,rvalue,dr,p)
implicit none
character(len=1), intent(in) :: ctype
integer , intent(in ) :: ibound
integer , intent(in ), dimension(3) :: lo,hi
integer , intent(in ) :: idir
logical , intent(in ) :: centered
real(rp), intent(in ) :: rvalue,dr
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p
real(rp) :: factor,sgn
!
factor = rvalue
if(ctype == 'D'.and.centered) then
factor = 2._rp*factor
sgn = -1._rp
end if
if(ctype == 'N') then
if( ibound == 0) then
factor = -dr*factor
else if(ibound == 1) then
factor = dr*factor
end if
sgn = 1._rp
end if
!
select case(ctype)
case('P')
select case(idir)
case(1)
!$OMP WORKSHARE
p(lo(idir)-1,:,:) = p(hi(idir),:,:)
p(hi(idir)+1,:,:) = p(lo(idir),:,:)
!$OMP END WORKSHARE
case(2)
!$OMP WORKSHARE
p(:,lo(idir)-1,:) = p(:,hi(idir),:)
p(:,hi(idir)+1,:) = p(:,lo(idir),:)
!$OMP END WORKSHARE
case(3)
!$OMP WORKSHARE
p(:,:,lo(idir)-1) = p(:,:,hi(idir))
p(:,:,hi(idir)+1) = p(:,:,lo(idir))
!$OMP END WORKSHARE
end select
case('D','N')
if(centered) then
select case(idir)
case(1)
if (ibound == 0) then
!$OMP WORKSHARE
p(lo(idir)-1,:,:) = factor+sgn*p(lo(idir),:,:)
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(hi(idir)+1,:,:) = factor+sgn*p(hi(idir),:,:)
!$OMP END WORKSHARE
end if
case(2)
if (ibound == 0) then
!$OMP WORKSHARE
p(:,lo(idir)-1,:) = factor+sgn*p(:,lo(idir),:)
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(:,hi(idir)+1,:) = factor+sgn*p(:,hi(idir),:)
!$OMP END WORKSHARE
end if
case(3)
if (ibound == 0) then
!$OMP WORKSHARE
p(:,:,lo(idir)-1) = factor+sgn*p(:,:,lo(idir))
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(:,:,hi(idir)+1) = factor+sgn*p(:,:,hi(idir))
!$OMP END WORKSHARE
end if
end select
else if(.not.centered.and.ctype == 'D') then
select case(idir)
case(1)
if (ibound == 0) then
!$OMP WORKSHARE
p(lo(idir)-1,:,:) = factor
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(hi(idir) ,:,:) = factor
p(hi(idir)+1,:,:) = p(hi(idir)-1,:,:)
!$OMP END WORKSHARE
end if
case(2)
if (ibound == 0) then
!$OMP WORKSHARE
p(:,lo(idir)-1,:) = factor
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(:,hi(idir) ,:) = factor
p(:,hi(idir)+1,:) = p(:,hi(idir)-1,:)
!$OMP END WORKSHARE
end if
case(3)
if (ibound == 0) then
!$OMP WORKSHARE
p(:,:,lo(idir)-1) = factor
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
p(:,:,hi(idir) ) = factor
p(:,:,hi(idir)+1) = p(:,:,hi(idir)-1)
!$OMP END WORKSHARE
end if
end select
else if(.not.centered.and.ctype == 'N') then
select case(idir)
case(1)
if (ibound == 0) then
!$OMP WORKSHARE
!p(0,:,:) = 1./3.*(-2.*factor+4.*p(1 ,:,:)-p(2 ,:,:))
p(lo(idir)-1,:,:) = factor + p(lo(idir) ,:,:)
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
!p(n,:,:) = 1./3.*(-2.*factor+4.*p(n-1,:,:)-p(n-2,:,:))
p(hi(idir) ,:,:) = factor + p(hi(idir)-1,:,:)
p(hi(idir)+1,:,:) = p(hi(idir) ,:,:) ! not needed
!$OMP END WORKSHARE
end if
case(2)
if (ibound == 0) then
!$OMP WORKSHARE
!p(:,0 ,:) = 1./3.*(-2.*factor+4.*p(:,1,:)-p(:,2 ,:))
p(:,lo(idir)-1,:) = factor + p(:,lo(idir) ,:)
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
!p(:,n,:) = 1./3.*(-2.*factor+4.*p(:,n-1,:)-p(:,n-2,:))
p(:,hi(idir) ,:) = factor + p(:,hi(idir)-1,:)
p(:,hi(idir)+1,:) = p(:,hi(idir) ,:) ! not needed
!$OMP END WORKSHARE
end if
case(3)
if (ibound == 0) then
!$OMP WORKSHARE
!p(:,:,0) = 1./3.*(-2.*factor+4.*p(:,:,1 )-p(:,:,2 ))
p(:,:,lo(idir)-1) = factor + p(:,:,lo(idir) )
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
!p(:,:,n) = 1./3.*(-2.*factor+4.*p(:,:,n-1)-p(:,:,n-2))
p(:,:,hi(idir) ) = factor + p(:,:,hi(idir)-1)
p(:,:,hi(idir)+1) = p(:,:,hi(idir) ) ! not needed
!$OMP END WORKSHARE
end if
end select
end if
end select
end subroutine set_bc
!
subroutine set_open_bc(ibound,lo,hi,idir,visc,dr,p,u,v,w,tr)
!
! a zero or estimated-traction open BC (Bozonnet et al, JCP 2021)
! the latter serves well as a robust outflow BC;
! the estimated traction is computed in subroutine
! `cmpt_estimated_traction`
!
implicit none
integer , intent(in ) :: ibound
integer , intent(in ), dimension(3) :: lo,hi
integer , intent(in ) :: idir
real(rp), intent(in ) :: visc,dr
real(rp), intent(in ), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: u,v,w
real(rp), intent(in ), dimension(0:,:,:), optional :: tr
real(rp) :: factor,sgn
integer :: q
logical :: is_estimated_traction
!
if( ibound == 0) then
sgn = -1._rp
q = lo(idir) - 1
else if(ibound == 1) then
sgn = 1._rp
q = hi(idir)
end if
factor = sgn*dr*2*visc
is_estimated_traction = .false.; if(present(tr)) is_estimated_traction = .true.
select case(idir)
case(1)
if (ibound == 0) then
!$OMP WORKSHARE
u(q,:,:) = u(q+1,:,:) + factor*(.5_rp*max(0._rp,sgn*u(q+1,:,:)**2) + p(q+1,:,:))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
u(q,:,:) = u(q,:,:) + factor*tr(0,:,:)
!$OMP END WORKSHARE
end if
else if(ibound == 1) then
!$OMP WORKSHARE
u(q,:,:) = u(q-1,:,:) + factor*(.5_rp*max(0._rp,sgn*u(q-1,:,:)**2) + p(q,:,:))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
u(q,:,:) = u(q,:,:) + factor*tr(1,:,:)
!$OMP END WORKSHARE
end if
!$OMP WORKSHARE
u(hi(idir)+1,:,:) = u(hi(idir) ,:,:) ! not needed
!$OMP END WORKSHARE
end if
case(2)
if (ibound == 0) then
!$OMP WORKSHARE
v(:,q,:) = v(:,q+1,:) + factor*(.5_rp*max(0._rp,sgn*v(:,q+1,:)**2) + p(:,q+1,:))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
v(:,q,:) = v(:,q,:) + factor*tr(0,:,:)
!$OMP END WORKSHARE
end if
else if(ibound == 1) then
!$OMP WORKSHARE
v(:,q,:) = v(:,q-1,:) + factor*(.5_rp*max(0._rp,sgn*v(:,q-1,:)**2) + p(:,q,:))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
v(:,q,:) = v(:,q,:) + factor*tr(1,:,:)
!$OMP END WORKSHARE
end if
!$OMP WORKSHARE
v(:,hi(idir)+1,:) = v(:,hi(idir) ,:) ! not needed
!$OMP END WORKSHARE
end if
case(3)
if (ibound == 0) then
!$OMP WORKSHARE
w(:,:,q) = w(:,:,q+1) + factor*(.5_rp*max(0._rp,sgn*w(:,:,q+1)**2) + p(:,:,q+1))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
w(:,:,q) = w(:,:,q) + factor*tr(0,:,:)
!$OMP END WORKSHARE
end if
else if(ibound == 1) then
!$OMP WORKSHARE
w(:,:,q) = w(:,:,q-1) + factor*(.5_rp*max(0._rp,sgn*w(:,:,q-1)**2) + p(:,:,q))
!$OMP END WORKSHARE
if(is_estimated_traction) then
!$OMP WORKSHARE
w(:,:,q) = w(:,:,q) + factor*tr(1,:,:)
!$OMP END WORKSHARE
end if
!$OMP WORKSHARE
w(:,:,hi(idir)+1) = w(:,:,hi(idir) ) ! not needed
!$OMP END WORKSHARE
end if
end select
end subroutine set_open_bc
!
subroutine cmpt_estimated_traction(ibound,lo,hi,idir,visc,dr,p,u,v,w,tr)
!
! computes the estimated traction from an interior grid cell
! adjacent to the boundary grid cell, to be used for computing the
! estimated-traction open BC (Bozonnet et al, JCP 2021)
!
implicit none
integer , intent(in ) :: ibound
integer , intent(in ), dimension(3) :: lo,hi
integer , intent(in ) :: idir
real(rp), intent(in ) :: visc,dr ! dr -- grid spacing of the interior grid cell
real(rp), intent(in ), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p
real(rp), intent(in ), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: u,v,w
real(rp), intent(out), dimension(0:,:,:) :: tr
real(rp) :: factor
integer :: q
!
if( ibound == 0) then
q = lo(idir) - 1
else if(ibound == 1) then
q = hi(idir)
end if
factor = 2.*visc/dr
select case(idir)
case(1)
if (ibound == 0) then
!$OMP WORKSHARE
tr(0,:,:) = -p(q+1,:,:) + factor*(u(q+2,:,:)-u(q+1,:,:))
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
tr(1,:,:) = -p(q-1,:,:) + factor*(u(q-1,:,:)-u(q-2,:,:))
!$OMP END WORKSHARE
end if
case(2)
if (ibound == 0) then
!$OMP WORKSHARE
tr(0,:,:) = -p(:,q+1,:) + factor*(v(:,q+2,:)-v(:,q+1,:))
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
tr(1,:,:) = -p(:,q-1,:) + factor*(v(:,q-1,:)-v(:,q-2,:))
!$OMP END WORKSHARE
end if
case(3)
if (ibound == 0) then
!$OMP WORKSHARE
tr(1,:,:) = -p(:,:,q+1) + factor*(w(:,:,q+2)-w(:,:,q+1))
!$OMP END WORKSHARE
else if(ibound == 1) then
!$OMP WORKSHARE
tr(0,:,:) = -p(:,:,q-1) + factor*(w(:,:,q-1)-w(:,:,q-2))
!$OMP END WORKSHARE
end if
end select
end subroutine cmpt_estimated_traction
!
subroutine inflow(is_inflow_bound,is_correc,lo,hi,uin_x,vin_x,win_x, &
uin_y,vin_y,win_y, &
uin_z,vin_z,win_z,u,v,w)
!
implicit none
logical , intent(in ), dimension(0:1,1:3) :: is_inflow_bound
logical , intent(in ) :: is_correc
integer , intent(in ), dimension(3 ) :: lo,hi
real(rp), intent(in ), dimension(lo(2)-1:,lo(3)-1:,0:) :: uin_x,vin_x,win_x
real(rp), intent(in ), dimension(lo(1)-1:,lo(3)-1:,0:) :: uin_y,vin_y,win_y
real(rp), intent(in ), dimension(lo(1)-1:,lo(2)-1:,0:) :: uin_z,vin_z,win_z
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: u,v,w
integer :: ibound,idir,qn,qt,dq
do idir=1,3
do ibound=0,1
if(is_inflow_bound(ibound,idir)) then
qn = (1-ibound)*(lo(idir)-1)+ibound*(hi(idir) )
qt = (1-ibound)*(lo(idir)-1)+ibound*(hi(idir)+1)
if(ibound == 0) dq = 1; if(ibound == 1) dq = -1
select case(idir)
case(1)
if(.not.is_correc) &
u(qn,:,:) = uin_x(:,:,ibound)
v(qt,:,:) = -v(qt+dq,:,:) + 2._rp*vin_x(:,:,ibound)
w(qt,:,:) = -w(qt+dq,:,:) + 2._rp*win_x(:,:,ibound)
case(2)
u(:,qt,:) = -u(:,qt+dq,:) + 2._rp*uin_y(:,:,ibound)
if(.not.is_correc) &
v(:,qn,:) = vin_y(:,:,ibound)
w(:,qt,:) = -w(:,qt+dq,:) + 2._rp*win_y(:,:,ibound)
case(3)
u(:,:,qt) = -u(:,:,qt+dq) + 2._rp*uin_z(:,:,ibound)
v(:,:,qt) = -v(:,:,qt+dq) + 2._rp*vin_z(:,:,ibound)
if(.not.is_correc) &
w(:,:,qn) = win_z(:,:,ibound)
end select
end if
end do
end do
end subroutine inflow
!
subroutine updt_rhs(lo,hi,is_bound,rhsbx,rhsby,rhsbz,p)
!
! updates the right-hand-side of the Helmholtz/Poisson equation
! with the appropriate boundary conditions
!
implicit none
integer , intent(in ), dimension(3) :: lo,hi
logical , intent(in ), dimension(0:1,3) :: is_bound
real(rp), intent(in ), dimension(lo(2):,lo(3):,0:) :: rhsbx
real(rp), intent(in ), dimension(lo(1):,lo(3):,0:) :: rhsby
real(rp), intent(in ), dimension(lo(1):,lo(2):,0:) :: rhsbz
real(rp), intent(inout), dimension(lo(1)-1:,lo(2)-1:,lo(3)-1:) :: p
if(is_bound(0,1)) then
!$OMP WORKSHARE
p(lo(1),lo(2):hi(2),lo(3):hi(3)) = p(lo(1),lo(2):hi(2),lo(3):hi(3)) + rhsbx(lo(2):hi(2),lo(3):hi(3),0)
!$OMP END WORKSHARE
end if
if(is_bound(1,1)) then
!$OMP WORKSHARE
p(hi(1),lo(2):hi(2),lo(3):hi(3)) = p(hi(1),lo(2):hi(2),lo(3):hi(3)) + rhsbx(lo(2):hi(2),lo(3):hi(3),1)
!$OMP END WORKSHARE
end if
if(is_bound(0,2)) then
!$OMP WORKSHARE
p(lo(1):hi(1),lo(2),lo(3):hi(3)) = p(lo(1):hi(1),lo(2),lo(3):hi(3)) + rhsby(lo(1):hi(1),lo(3):hi(3),0)
!$OMP END WORKSHARE
end if
if(is_bound(1,2)) then
!$OMP WORKSHARE
p(lo(1):hi(1),hi(2),lo(3):hi(3)) = p(lo(1):hi(1),hi(2),lo(3):hi(3)) + rhsby(lo(1):hi(1),lo(3):hi(3),1)
!$OMP END WORKSHARE
end if
if(is_bound(0,3)) then
!$OMP WORKSHARE
p(lo(1):hi(1),lo(2):hi(2),lo(3)) = p(lo(1):hi(1),lo(2):hi(2),lo(3)) + rhsbz(lo(1):hi(1),lo(2):hi(2),0)
!$OMP END WORKSHARE
end if
if(is_bound(1,3)) then
!$OMP WORKSHARE
p(lo(1):hi(1),lo(2):hi(2),hi(3)) = p(lo(1):hi(1),lo(2):hi(2),hi(3)) + rhsbz(lo(1):hi(1),lo(2):hi(2),1)
!$OMP END WORKSHARE
end if
end subroutine updt_rhs
!
subroutine updthalo(lo,hi,nh,halo,nb,idir,p)
implicit none
integer , dimension(3), intent(in) :: lo,hi
integer , intent(in) :: nh ! number of ghost points
type(MPI_DATATYPE), intent(in) :: halo
integer , intent(in), dimension(0:1) :: nb
integer , intent(in) :: idir
real(rp), dimension(lo(1)-nh:,lo(2)-nh:,lo(3)-nh:), intent(inout) :: p
!type(MPI_REQUEST) :: requests(4)
!
! this subroutine updates the halo that store info
! from the neighboring computational sub-domain
!
select case(idir)
case(1) ! x direction
call MPI_SENDRECV(p(lo(1) ,lo(2)-nh,lo(3)-nh),1,halo,nb(0),0, &
p(hi(1)+1 ,lo(2)-nh,lo(3)-nh),1,halo,nb(1),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
call MPI_SENDRECV(p(hi(1)-nh+1,lo(2)-nh,lo(3)-nh),1,halo,nb(1),0, &
p(lo(1)-nh ,lo(2)-nh,lo(3)-nh),1,halo,nb(0),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
!call MPI_IRECV( p(hi(1)+1 ,lo(2)-nh,lo(3)-nh),1,halo,nb(1),0, &
! MPI_COMM_WORLD,requests(1))
!call MPI_IRECV( p(lo(1)-nh ,lo(2)-nh,lo(3)-nh),1,halo,nb(0),1, &
! MPI_COMM_WORLD,requests(2))
!call MPI_ISSEND(p(lo(1) ,lo(2)-nh,lo(3)-nh),1,halo,nb(0),0, &
! MPI_COMM_WORLD,requests(3))
!call MPI_ISSEND(p(hi(1)-nh+1,lo(2)-nh,lo(3)-nh),1,halo,nb(1),1, &
! MPI_COMM_WORLD,requests(4))
!call MPI_WAITALL(4,requests,MPI_STATUSES_IGNORE)
case(2) ! y direction
call MPI_SENDRECV(p(lo(1)-nh,lo(2) ,lo(3)-nh),1,halo,nb(0),0, &
p(lo(1)-nh,hi(2)+1 ,lo(3)-nh),1,halo,nb(1),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
call MPI_SENDRECV(p(lo(1)-nh,hi(2)-nh+1,lo(3)-nh),1,halo,nb(1),0, &
p(lo(1)-nh,lo(2)-nh ,lo(3)-nh),1,halo,nb(0),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
!call MPI_IRECV( p(lo(1)-nh,hi(2)+1 ,lo(3)-nh),1,halo,nb(1),0, &
! MPI_COMM_WORLD,requests(1))
!call MPI_IRECV( p(lo(1)-nh,lo(2)-nh ,lo(3)-nh),1,halo,nb(0),1, &
! MPI_COMM_WORLD,requests(2))
!call MPI_ISSEND(p(lo(1)-nh,lo(2) ,lo(3)-nh),1,halo,nb(0),0, &
! MPI_COMM_WORLD,requests(3))
!call MPI_ISSEND(p(lo(1)-nh,hi(2)-nh+1,lo(3)-nh),1,halo,nb(1),1, &
! MPI_COMM_WORLD,requests(4))
!call MPI_WAITALL(4,requests,MPI_STATUSES_IGNORE)
case(3) ! z direction
call MPI_SENDRECV(p(lo(1)-nh,lo(2)-nh,lo(3) ),1,halo,nb(0),0, &
p(lo(1)-nh,lo(2)-nh,hi(3)+1 ),1,halo,nb(1),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
call MPI_SENDRECV(p(lo(1)-nh,lo(2)-nh,hi(3)-nh+1),1,halo,nb(1),0, &
p(lo(1)-nh,lo(2)-nh,lo(3)-nh ),1,halo,nb(0),0, &
MPI_COMM_WORLD,MPI_STATUS_IGNORE)
!call MPI_IRECV( p(lo(1)-nh,lo(2)-nh,hi(3)+1 ),1,halo,nb(1),0, &
! MPI_COMM_WORLD,requests(1))
!call MPI_IRECV( p(lo(1)-nh,lo(2)-nh,lo(3)-nh ),1,halo,nb(0),1, &
! MPI_COMM_WORLD,requests(2))
!call MPI_ISSEND(p(lo(1)-nh,lo(2)-nh,lo(3) ),1,halo,nb(0),0, &
! MPI_COMM_WORLD,requests(3))
!call MPI_ISSEND(p(lo(1)-nh,lo(2)-nh,hi(3)-nh+1),1,halo,nb(1),1, &
! MPI_COMM_WORLD,requests(4))
!call MPI_WAITALL(4,requests,MPI_STATUSES_IGNORE)
end select
end subroutine updthalo
end module mod_bound