Skip to content

Commit

Permalink
grid: Move some code into helper routine get_rsgrid_properties
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Jul 18, 2020
1 parent c24cdb2 commit ff68bbe
Showing 1 changed file with 51 additions and 37 deletions.
88 changes: 51 additions & 37 deletions src/grid/grid_api.F
Original file line number Diff line number Diff line change
Expand Up @@ -184,43 +184,7 @@ END SUBROUTINE grid_collocate_pgf_product_cpu
CPASSERT(LBOUND(pab, 1) == 1)
CPASSERT(LBOUND(pab, 2) == 1)

! See rs_grid_create() in ./src/pw/realspace_grid_types.F.
CPASSERT(LBOUND(rsgrid%r, 1) == rsgrid%lb_local(1))
CPASSERT(UBOUND(rsgrid%r, 1) == rsgrid%ub_local(1))
CPASSERT(LBOUND(rsgrid%r, 2) == rsgrid%lb_local(2))
CPASSERT(UBOUND(rsgrid%r, 2) == rsgrid%ub_local(2))
CPASSERT(LBOUND(rsgrid%r, 3) == rsgrid%lb_local(3))
CPASSERT(UBOUND(rsgrid%r, 3) == rsgrid%ub_local(3))

! While the rsgrid code assumes that the grid starts at rsgrid%lb,
! the collocate code assumes that the grid starts at (1,1,1) in Fortran, or (0,0,0) in C.
! So, a point rp(:) gets the following grid coordinates MODULO(rp(:)/dr(:),npts_global(:))

! Number of global grid points in each direction.
npts_global = rsgrid%desc%ub - rsgrid%desc%lb + 1

! Number of local grid points in each direction.
npts_local = rsgrid%ub_local - rsgrid%lb_local + 1

! Number of points the local grid is shifted wrt global grid.
shift_local = rsgrid%lb_local - rsgrid%desc%lb

! Check that rsgrid%desc%perd means what I think it means.
DO i = 1, 3
IF (rsgrid%desc%perd(i) == 1) THEN
! Periodic meaning the grid in this direction is entriely present on every processor.
CPASSERT(npts_local(i) == npts_global(i))
CPASSERT(shift_local(i) == 0)
ELSE
! Not periodic meaning the grid in this direction is distributed among processors.
CPASSERT(npts_local(i) < npts_global(i))
IF (my_use_subpatch) THEN
! Check bounds of grid section that is owned by this processor.
CPASSERT(rsgrid%lb_real(i) == rsgrid%lb_local(i) + rsgrid%desc%border)
CPASSERT(rsgrid%ub_real(i) == rsgrid%ub_local(i) - rsgrid%desc%border)
ENDIF
ENDIF
ENDDO
CALL get_rsgrid_properties(rsgrid, npts_global=npts_global, npts_local=npts_local, shift_local=shift_local)

IF (validate_collocate) THEN
ALLOCATE (grid(SIZE(rsgrid%r, 1), SIZE(rsgrid%r, 2), SIZE(rsgrid%r, 3)))
Expand Down Expand Up @@ -317,4 +281,54 @@ END SUBROUTINE grid_collocate_pgf_product_cpu

END SUBROUTINE collocate_pgf_product

! **************************************************************************************************
!> \brief Helper routines for getting rsgrid properties and asserting underlying assumptions.
!> \param rsgrid ...
!> \param npts_global ...
!> \param npts_local ...
!> \param shift_local ...
! **************************************************************************************************
SUBROUTINE get_rsgrid_properties(rsgrid, npts_global, npts_local, shift_local)
TYPE(realspace_grid_type), INTENT(IN) :: rsgrid
INTEGER, DIMENSION(:) :: npts_global, npts_local, shift_local

INTEGER :: i

! See rs_grid_create() in ./src/pw/realspace_grid_types.F.
CPASSERT(LBOUND(rsgrid%r, 1) == rsgrid%lb_local(1))
CPASSERT(UBOUND(rsgrid%r, 1) == rsgrid%ub_local(1))
CPASSERT(LBOUND(rsgrid%r, 2) == rsgrid%lb_local(2))
CPASSERT(UBOUND(rsgrid%r, 2) == rsgrid%ub_local(2))
CPASSERT(LBOUND(rsgrid%r, 3) == rsgrid%lb_local(3))
CPASSERT(UBOUND(rsgrid%r, 3) == rsgrid%ub_local(3))

! While the rsgrid code assumes that the grid starts at rsgrid%lb,
! the collocate code assumes that the grid starts at (1,1,1) in Fortran, or (0,0,0) in C.
! So, a point rp(:) gets the following grid coordinates MODULO(rp(:)/dr(:),npts_global(:))

! Number of global grid points in each direction.
npts_global = rsgrid%desc%ub - rsgrid%desc%lb + 1

! Number of local grid points in each direction.
npts_local = rsgrid%ub_local - rsgrid%lb_local + 1

! Number of points the local grid is shifted wrt global grid.
shift_local = rsgrid%lb_local - rsgrid%desc%lb

! Check that rsgrid%desc%perd means what I think it means.
DO i = 1, 3
IF (rsgrid%desc%perd(i) == 1) THEN
! Periodic meaning the grid in this direction is entriely present on every processor.
CPASSERT(npts_local(i) == npts_global(i))
CPASSERT(shift_local(i) == 0)
ELSE
! Not periodic meaning the grid in this direction is distributed among processors.
CPASSERT(npts_local(i) < npts_global(i))
! Check bounds of grid section that is owned by this processor.
CPASSERT(rsgrid%lb_real(i) == rsgrid%lb_local(i) + rsgrid%desc%border)
CPASSERT(rsgrid%ub_real(i) == rsgrid%ub_local(i) - rsgrid%desc%border)
ENDIF
ENDDO
END SUBROUTINE get_rsgrid_properties

END MODULE grid_api

0 comments on commit ff68bbe

Please sign in to comment.