30 integer :: iigrid, igrid
49 integer :: iigrid, igrid, i^D, my_neighbor_type
50 integer :: iside, idim, ic^D, inc^D, ih^D, icdim
52 logical,
dimension(^ND) :: pole
55 integer :: idir,pi^D, mi^D, ph^D, mh^D, ipe_neighbor
56 integer :: nrecvs,nsends
59 integer :: nbuff_bc_recv_srl, nbuff_bc_send_srl, nbuff_bc_recv_r, nbuff_bc_send_r, nbuff_bc_recv_p, nbuff_bc_send_p
64 nrecv_fc=0; nsend_fc=0
65 nbuff_bc_recv_srl=0; nbuff_bc_send_srl=0
66 nbuff_bc_recv_r=0; nbuff_bc_send_r=0
67 nbuff_bc_recv_p=0; nbuff_bc_send_p=0
70 do iigrid=1,igridstail; igrid=igrids(iigrid);
75 if (i^d==0|.and.)
then
76 neighbor_type(0^d&,igrid)=0
77 neighbor(1,0^d&,igrid)=igrid
78 neighbor(2,0^d&,igrid)=
mype
80 call find_neighbor(my_neighbor,my_neighbor_type,tree,i^d,pole)
83 select case (my_neighbor_type)
85 case (neighbor_boundary)
86 neighbor(1,i^d,igrid)=0
87 neighbor(2,i^d,igrid)=-1
89 case (neighbor_coarse)
90 neighbor(1,i^d,igrid)=my_neighbor%node%igrid
91 neighbor(2,i^d,igrid)=my_neighbor%node%ipe
92 if (my_neighbor%node%ipe/=
mype)
then
93 ic^d=1+modulo(tree%node%ig^d-1,2);
94 if ({(i^d==0.or.i^d==2*ic^d-3)|.and.})
then
104 case (neighbor_sibling)
105 neighbor(1,i^d,igrid)=my_neighbor%node%igrid
106 neighbor(2,i^d,igrid)=my_neighbor%node%ipe
107 if (my_neighbor%node%ipe/=
mype)
then
115 neighbor(1,i^d,igrid)=0
116 neighbor(2,i^d,igrid)=-1
119 {
do ic^db=1+int((1-i^db)/2),2-int((1+i^db)/2)
126 child%node => my_neighbor%node%child(ih^d)%node
127 neighbor_child(1,inc^d,igrid)=child%node%igrid
128 neighbor_child(2,inc^d,igrid)=child%node%ipe
129 if (child%node%ipe/=mype)
then
130 nrecv_bc_r=nrecv_bc_r+1
131 nsend_bc_p=nsend_bc_p+1
132 nbuff_bc_send_p=nbuff_bc_send_p+sizes_p_send_total(inc^d)
133 nbuff_bc_recv_r=nbuff_bc_recv_r+sizes_r_recv_total(inc^d)
139 if ({abs(i^d)+}==1)
then
144 select case (my_neighbor_type)
146 case (neighbor_coarse)
147 if (my_neighbor%node%ipe/=mype)
then
148 if (.not.pole(idim)) nsend_fc(idim)=nsend_fc(idim)+1
158 {
do ic^d=icdim,icdim^d%do ic^dd=1,2\}
159 child%node => my_neighbor%node%child(ic^dd)%node
160 if (child%node%ipe/=mype)
then
161 if (.not.pole(^d)) nrecv_fc(^d)=nrecv_fc(^d)+1
169 neighbor_pole(i^d,igrid)=0
170 if (my_neighbor_type>1)
then
173 neighbor_pole(i^d,igrid)=idim
179 neighbor_type(i^d,igrid)=my_neighbor_type
184 if(stagger_grid)
then
189 if ({abs(i^d)+}==1)
then
190 if (neighbor_pole(i^d,igrid)/=0) cycle
197 if (neighbor_type(i^d,igrid)==2)
then
199 pi^d=i^d+kr(idir,^d);
200 mi^d=i^d-kr(idir,^d);
201 ph^d=pi^d-kr(idim,^d)*(2*iside-3);
202 mh^d=mi^d-kr(idim,^d)*(2*iside-3);
204 if (neighbor_type(pi^d,igrid)==2.and.&
205 neighbor_type(ph^d,igrid)==2.and.&
206 mype/=neighbor(2,pi^d,igrid).and.&
207 neighbor_pole(pi^d,igrid)==0)
then
208 nsend_cc(idim) = nsend_cc(idim) + 1
211 if (neighbor_type(mi^d,igrid)==2.and.&
212 neighbor_type(mh^d,igrid)==2.and.&
213 mype/=neighbor(2,mi^d,igrid).and.&
214 neighbor_pole(mi^d,igrid)==0)
then
215 nsend_cc(idim) = nsend_cc(idim) + 1
220 if (neighbor_type(i^d,igrid)==3)
then
222 pi^d=i^d+kr(idir,^d);
223 mi^d=i^d-kr(idir,^d);
224 ph^d=pi^d-kr(idim,^d)*(2*iside-3);
225 mh^d=mi^d-kr(idim,^d)*(2*iside-3);
227 if (neighbor_type(pi^d,igrid)==4.and.&
228 neighbor_type(ph^d,igrid)==3.and.&
229 neighbor_pole(pi^d,igrid)==0)
then
231 {
do ic^db=1+int((1-pi^db)/2),2-int((1+pi^db)/2)
232 inc^db=2*pi^db+ic^db\}
233 if (mype.ne.neighbor_child(2,inc^d,igrid))
then
234 nrecv_cc(idim) = nrecv_cc(idim) + 1
239 if (neighbor_type(mi^d,igrid)==4.and.&
240 neighbor_type(mh^d,igrid)==3.and.&
241 neighbor_pole(mi^d,igrid)==0)
then
243 {
do ic^db=1+int((1-mi^db)/2),2-int((1+mi^db)/2)
244 inc^db=2*mi^db+ic^db\}
245 if (mype.ne.neighbor_child(2,inc^d,igrid))
then
246 nrecv_cc(idim) = nrecv_cc(idim) + 1
259 nrecvs=nrecv_bc_srl+nrecv_bc_r
260 if (
allocated(recvstatus_c_sr))
then
261 deallocate(recvstatus_c_sr,recvrequest_c_sr)
262 allocate(recvstatus_c_sr(mpi_status_size,nrecvs),recvrequest_c_sr(nrecvs))
264 allocate(recvstatus_c_sr(mpi_status_size,nrecvs),recvrequest_c_sr(nrecvs))
266 recvrequest_c_sr=mpi_request_null
269 nsends=nsend_bc_srl+nsend_bc_r
270 if (
allocated(sendstatus_c_sr))
then
271 deallocate(sendstatus_c_sr,sendrequest_c_sr)
272 allocate(sendstatus_c_sr(mpi_status_size,nsends),sendrequest_c_sr(nsends))
274 allocate(sendstatus_c_sr(mpi_status_size,nsends),sendrequest_c_sr(nsends))
276 sendrequest_c_sr=mpi_request_null
279 if (
allocated(recvstatus_c_p))
then
280 deallocate(recvstatus_c_p,recvrequest_c_p)
281 allocate(recvstatus_c_p(mpi_status_size,nrecv_bc_p),recvrequest_c_p(nrecv_bc_p))
283 allocate(recvstatus_c_p(mpi_status_size,nrecv_bc_p),recvrequest_c_p(nrecv_bc_p))
285 recvrequest_c_p=mpi_request_null
288 if (
allocated(sendstatus_c_p))
then
289 deallocate(sendstatus_c_p,sendrequest_c_p)
290 allocate(sendstatus_c_p(mpi_status_size,nsend_bc_p),sendrequest_c_p(nsend_bc_p))
292 allocate(sendstatus_c_p(mpi_status_size,nsend_bc_p),sendrequest_c_p(nsend_bc_p))
294 sendrequest_c_p=mpi_request_null
296 if(stagger_grid)
then
298 if (
allocated(recvbuffer_srl))
then
299 if (nbuff_bc_recv_srl /=
size(recvbuffer_srl))
then
300 deallocate(recvbuffer_srl)
301 allocate(recvbuffer_srl(nbuff_bc_recv_srl))
304 allocate(recvbuffer_srl(nbuff_bc_recv_srl))
306 if (
allocated(recvstatus_srl))
then
307 deallocate(recvstatus_srl,recvrequest_srl)
308 allocate(recvstatus_srl(mpi_status_size,nrecv_bc_srl),recvrequest_srl(nrecv_bc_srl))
310 allocate(recvstatus_srl(mpi_status_size,nrecv_bc_srl),recvrequest_srl(nrecv_bc_srl))
312 recvrequest_srl=mpi_request_null
315 if (
allocated(sendbuffer_srl))
then
316 if (nbuff_bc_send_srl /=
size(sendbuffer_srl))
then
317 deallocate(sendbuffer_srl)
318 allocate(sendbuffer_srl(nbuff_bc_send_srl))
321 allocate(sendbuffer_srl(nbuff_bc_send_srl))
323 if (
allocated(sendstatus_srl))
then
324 deallocate(sendstatus_srl,sendrequest_srl)
325 allocate(sendstatus_srl(mpi_status_size,nsend_bc_srl),sendrequest_srl(nsend_bc_srl))
327 allocate(sendstatus_srl(mpi_status_size,nsend_bc_srl),sendrequest_srl(nsend_bc_srl))
329 sendrequest_srl=mpi_request_null
332 if (
allocated(recvbuffer_r))
then
333 if (nbuff_bc_recv_r /=
size(recvbuffer_r))
then
334 deallocate(recvbuffer_r)
335 allocate(recvbuffer_r(nbuff_bc_recv_r))
338 allocate(recvbuffer_r(nbuff_bc_recv_r))
340 if (
allocated(recvstatus_r))
then
341 deallocate(recvstatus_r,recvrequest_r)
342 allocate(recvstatus_r(mpi_status_size,nrecv_bc_r),recvrequest_r(nrecv_bc_r))
344 allocate(recvstatus_r(mpi_status_size,nrecv_bc_r),recvrequest_r(nrecv_bc_r))
346 recvrequest_r=mpi_request_null
349 if (
allocated(sendbuffer_r))
then
350 if (nbuff_bc_send_r /=
size(sendbuffer_r))
then
351 deallocate(sendbuffer_r)
352 allocate(sendbuffer_r(nbuff_bc_send_r))
355 allocate(sendbuffer_r(nbuff_bc_send_r))
357 if (
allocated(sendstatus_r))
then
358 deallocate(sendstatus_r,sendrequest_r)
359 allocate(sendstatus_r(mpi_status_size,nsend_bc_r),sendrequest_r(nsend_bc_r))
361 allocate(sendstatus_r(mpi_status_size,nsend_bc_r),sendrequest_r(nsend_bc_r))
363 sendrequest_r=mpi_request_null
366 if (
allocated(recvbuffer_p))
then
367 if (nbuff_bc_recv_p /=
size(recvbuffer_p))
then
368 deallocate(recvbuffer_p)
369 allocate(recvbuffer_p(nbuff_bc_recv_p))
372 allocate(recvbuffer_p(nbuff_bc_recv_p))
374 if (
allocated(recvstatus_p))
then
375 deallocate(recvstatus_p,recvrequest_p)
376 allocate(recvstatus_p(mpi_status_size,nrecv_bc_p),recvrequest_p(nrecv_bc_p))
378 allocate(recvstatus_p(mpi_status_size,nrecv_bc_p),recvrequest_p(nrecv_bc_p))
380 recvrequest_p=mpi_request_null
383 if (
allocated(sendbuffer_p))
then
384 if (nbuff_bc_send_p /=
size(sendbuffer_p))
then
385 deallocate(sendbuffer_p)
386 allocate(sendbuffer_p(nbuff_bc_send_p))
389 allocate(sendbuffer_p(nbuff_bc_send_p))
391 if (
allocated(sendstatus_p))
then
392 deallocate(sendstatus_p,sendrequest_p)
393 allocate(sendstatus_p(mpi_status_size,nsend_bc_p),sendrequest_p(nsend_bc_p))
395 allocate(sendstatus_p(mpi_status_size,nsend_bc_p),sendrequest_p(nsend_bc_p))
397 sendrequest_p=mpi_request_null
subroutine find_neighbor(my_neighbor, my_neighbor_type, tree, iD, pole)
find neighors of all blocks
subroutine build_connectivity
subroutine get_level_range
Module with basic grid data structures.
logical, dimension(:,:), allocatable, save igrid_inuse
type(tree_node_ptr), dimension(:), allocatable, save level_tail
The tail pointer of the linked list per refinement level.
type(tree_node_ptr), dimension(:,:), allocatable, save igrid_to_node
Array to go from an [igrid, ipe] index to a node pointer.
update ghost cells of all blocks including physical boundaries
integer, dimension(-1:1^d &) sizes_r_send_total
integer, dimension(-1:1^d &) sizes_srl_send_total
integer, dimension(0:3^d &) sizes_p_recv_total
integer, dimension(-1:1^d &) sizes_srl_recv_total
This module contains definitions of global parameters and variables and some generic functions/subrou...
logical stagger_grid
True for using stagger grid.
integer mype
The rank of the current MPI task.
integer refine_max_level
Maximal number of AMR levels.
integer max_blocks
The maximum number of grid blocks in a processor.