@@ -342,70 +342,68 @@ contains
342342
343343 !> Populate the buffers of the grid variables, which are constituted of the cell- boundary locations and cell- width
344344 !! distributions, based on the boundary conditions.
345- subroutine s_populate_grid_variables_buffers
346-
347- #ifdef MFC_SIMULATION
348- ! Simulation allocates the cell- boundary arrays with buff_size ghost layers, so the
349- ! ghost extrapolation extends over the full buffer. In post- process the module- level
350- ! offset_x/ y/ z (which the x_cb/ y_cb/ z_cb allocations are sized to ) are used instead.
351- type(int_bounds_info) :: offset_x, offset_y, offset_z
352-
353- offset_x%beg = buff_size; offset_x%end = buff_size
354- offset_y%beg = buff_size; offset_y%end = buff_size
355- offset_z%beg = buff_size; offset_z%end = buff_size
356-
357- ! Global domain bounds
345+ subroutine s_populate_grid_variables_buffers (x_cb_in , x_cc_in , dx_in , x_offset , y_offset , z_offset , y_cb_in , y_cc_in , dy_in , &
346+ & z_cb_in , z_cc_in , dz_in , global_bounds )
347+
348+ type(int_bounds_info), intent (in ) :: x_offset, y_offset, z_offset
349+ real (wp), intent (inout ) :: x_cb_in(- 1 - x_offset%beg:)
350+ real (wp), intent (inout ) :: x_cc_in(- buff_size:), dx_in(- buff_size:)
351+ real (wp), optional, intent (inout ) :: y_cb_in(- 1 - y_offset%beg:), z_cb_in(- 1 - z_offset%beg:)
352+ real (wp), optional, intent (inout ) :: y_cc_in(- buff_size:), dy_in(- buff_size:)
353+ real (wp), optional, intent (inout ) :: z_cc_in(- buff_size:), dz_in(- buff_size:)
354+ type(bounds_info), optional, dimension (3 ), intent (out ) :: global_bounds
355+
356+ if (present (global_bounds)) then
358357#ifdef MFC_MPI
359- call s_mpi_allreduce_min(x_cb(- 1 ), glb_bounds(1 )%beg)
360- call s_mpi_allreduce_max(x_cb(m), glb_bounds(1 )%end)
361- if (n > 0 ) then
362- call s_mpi_allreduce_min(y_cb(- 1 ), glb_bounds(2 )%beg)
363- call s_mpi_allreduce_max(y_cb(n), glb_bounds(2 )%end)
364- if (p > 0 ) then
365- call s_mpi_allreduce_min(z_cb(- 1 ), glb_bounds(3 )%beg)
366- call s_mpi_allreduce_max(z_cb(p), glb_bounds(3 )%end)
358+ call s_mpi_allreduce_min(x_cb_in(- 1 ), global_bounds(1 )%beg)
359+ call s_mpi_allreduce_max(x_cb_in(m), global_bounds(1 )%end)
360+ if (n > 0 ) then
361+ call s_mpi_allreduce_min(y_cb_in(- 1 ), global_bounds(2 )%beg)
362+ call s_mpi_allreduce_max(y_cb_in(n), global_bounds(2 )%end)
363+ if (p > 0 ) then
364+ call s_mpi_allreduce_min(z_cb_in(- 1 ), global_bounds(3 )%beg)
365+ call s_mpi_allreduce_max(z_cb_in(p), global_bounds(3 )%end)
366+ end if
367367 end if
368- end if
369368#else
370- glb_bounds(1 )%beg = x_cb(- 1 ); glb_bounds(1 )%end = x_cb(m)
371- if (n > 0 ) then
372- glb_bounds(2 )%beg = y_cb(- 1 ); glb_bounds(2 )%end = y_cb(n)
373- if (p > 0 ) then
374- glb_bounds(3 )%beg = z_cb(- 1 ); glb_bounds(3 )%end = z_cb(p)
369+ global_bounds(1 )%beg = x_cb_in(- 1 ); global_bounds(1 )%end = x_cb_in(m)
370+ if (n > 0 ) then
371+ global_bounds(2 )%beg = y_cb_in(- 1 ); global_bounds(2 )%end = y_cb_in(n)
372+ if (p > 0 ) then
373+ global_bounds(3 )%beg = z_cb_in(- 1 ); global_bounds(3 )%end = z_cb_in(p)
374+ end if
375375 end if
376- end if
377- #endif
378- $:GPU_UPDATE(device= ' [glb_bounds]' )
379376#endif
377+ end if
380378
381- #ifndef MFC_PRE_PROCESS
382- call s_populate_grid_bc_direction(1 , - 1 , bc_x, offset_x)
383- call s_populate_grid_bc_direction(1 , 1 , bc_x, offset_x)
379+ call s_populate_grid_bc_direction(x_cb_in, x_cc_in, dx_in, m, 1 , - 1 , bc_x, x_offset)
380+ call s_populate_grid_bc_direction(x_cb_in, x_cc_in, dx_in, m, 1 , 1 , bc_x, x_offset)
384381
385382 if (n == 0 ) return
386383
387384 #:if not MFC_CASE_OPTIMIZATION or num_dims > 1
388- call s_populate_grid_bc_direction(2 , - 1 , bc_y, offset_y )
389- call s_populate_grid_bc_direction(2 , 1 , bc_y, offset_y )
385+ call s_populate_grid_bc_direction(y_cb_in, y_cc_in, dy_in, n, 2 , - 1 , bc_y, y_offset )
386+ call s_populate_grid_bc_direction(y_cb_in, y_cc_in, dy_in, n, 2 , 1 , bc_y, y_offset )
390387 #:endif
391388
392389 if (p == 0 ) return
393390
394391 #:if not MFC_CASE_OPTIMIZATION or num_dims > 2
395- call s_populate_grid_bc_direction(3 , - 1 , bc_z, offset_z )
396- call s_populate_grid_bc_direction(3 , 1 , bc_z, offset_z )
392+ call s_populate_grid_bc_direction(z_cb_in, z_cc_in, dz_in, p, 3 , - 1 , bc_z, z_offset )
393+ call s_populate_grid_bc_direction(z_cb_in, z_cc_in, dz_in, p, 3 , 1 , bc_z, z_offset )
397394 #:endif
398- #endif
399395
400396 end subroutine s_populate_grid_variables_buffers
401397
402- # ifndef MFC_PRE_PROCESS
403- !> Populate grid variable buffers (cell widths and centers) for one direction and location.
404- subroutine s_populate_grid_bc_direction ( bc_dir , bc_loc , bc_bounds , offset_dir )
398+ !> Populate cell - boundary, cell - center, and cell - width buffers for one coordinate direction.
399+ subroutine s_populate_grid_bc_direction ( cell_boundaries , cell_centers , cell_widths , num_cells , bc_dir , bc_loc , bc_bounds , &
400+ & offset )
405401
406- integer , intent (in ) :: bc_dir, bc_loc
407- type(int_bounds_info), intent (in ) :: bc_bounds, offset_dir
408- integer :: bc_edge
402+ integer , intent (in ) :: num_cells, bc_dir, bc_loc
403+ type(int_bounds_info), intent (in ) :: bc_bounds, offset
404+ real (wp), intent (inout ) :: cell_boundaries(- 1 - offset%beg:)
405+ real (wp), intent (inout ) :: cell_centers(- buff_size:), cell_widths(- buff_size:)
406+ integer :: bc_edge, i, source_index
409407
410408 if (bc_loc == - 1 ) then
411409 bc_edge = bc_bounds%beg
@@ -414,23 +412,55 @@ contains
414412 end if
415413
416414 if (bc_edge >= 0 ) then
417- call s_mpi_sendrecv_grid_variables_buffers(bc_dir, bc_loc, offset_dir)
415+ call s_mpi_sendrecv_grid_variable_buffer(cell_boundaries, cell_centers, cell_widths, num_cells, bc_bounds, bc_loc, &
416+ & offset)
418417 return
419418 end if
420419
421- select case (bc_edge)
422- case (BC_PERIODIC)
423- call s_grid_periodic_bc(bc_dir, bc_loc, offset_dir)
424- case (BC_REFLECTIVE)
425- call s_grid_reflective_bc(bc_dir, bc_loc, offset_dir)
426- case (BC_AXIS)
427- if (bc_dir == 2 ) call s_grid_axis_bc(bc_loc, offset_dir)
428- case default
429- call s_grid_ghost_cell_extrapolation_bc(bc_dir, bc_loc, offset_dir)
430- end select
420+ if (bc_edge == BC_AXIS .and. (bc_dir /= 2 .or. bc_loc == 1 )) return
421+
422+ do i = 1 , buff_size
423+ if (bc_loc == - 1 ) then
424+ select case (bc_edge)
425+ case (BC_PERIODIC)
426+ source_index = num_cells - i + 1
427+ case (BC_REFLECTIVE, BC_AXIS)
428+ source_index = i - 1
429+ case default
430+ source_index = 0
431+ end select
432+ cell_widths(- i) = cell_widths(source_index)
433+ else
434+ select case (bc_edge)
435+ case (BC_PERIODIC)
436+ source_index = i - 1
437+ case (BC_REFLECTIVE)
438+ source_index = num_cells - i + 1
439+ case default
440+ source_index = num_cells
441+ end select
442+ cell_widths(num_cells + i) = cell_widths(source_index)
443+ end if
444+ end do
445+
446+ if (bc_loc == - 1 ) then
447+ do i = 1 , offset%beg
448+ cell_boundaries(- 1 - i) = cell_boundaries(- i) - cell_widths(- i)
449+ end do
450+ do i = 1 , buff_size
451+ cell_centers(- i) = cell_centers(1 - i) - (cell_widths(1 - i) + cell_widths(- i))/ 2._wp
452+ end do
453+ else
454+ do i = 1 , offset%end
455+ cell_boundaries(num_cells + i) = cell_boundaries(num_cells + i - 1 ) + cell_widths(num_cells + i)
456+ end do
457+ do i = 1 , buff_size
458+ cell_centers(num_cells + i) = cell_centers(num_cells + i - 1 ) + (cell_widths(num_cells + i - 1 ) &
459+ & + cell_widths(num_cells + i))/ 2._wp
460+ end do
461+ end if
431462
432463 end subroutine s_populate_grid_bc_direction
433- #endif
434464
435465 !> Deallocate boundary condition buffer arrays allocated during module initialization.
436466 subroutine s_finalize_boundary_common_module ()
0 commit comments