Fill ghost cells of a cell-centred 2D field (e.g. η, bt_H_ref) with the periodically-matching interior values. Explicit-shape dummies avoid per-launch descriptor-walk memcpys.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(inout) | :: | fld(nx_total,ny_total) |
Cell-centred field, shape (nx_total, ny_total). |
||
| integer, | intent(in) | :: | nx_total | |||
| integer, | intent(in) | :: | ny_total | |||
| integer, | intent(in) | :: | nx_phys | |||
| integer, | intent(in) | :: | ny_phys | |||
| integer, | intent(in) | :: | nghost | |||
| logical, | intent(in) | :: | wrap_x |
Wrap ghost columns (west ↔ east). |
||
| logical, | intent(in) | :: | wrap_y |
Wrap ghost rows (south ↔ north). |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private | :: | i | ||||
| integer, | private | :: | j |
pure subroutine ocean_periodic_wrap_centre_2d(fld, nx_total, ny_total, & nx_phys, ny_phys, nghost, & wrap_x, wrap_y) !! Fill ghost cells of a cell-centred 2D field (e.g. η, bt_H_ref) !! with the periodically-matching interior values. !! Explicit-shape dummies avoid per-launch descriptor-walk memcpys. integer, intent(in) :: nx_total, ny_total, nx_phys, ny_phys, nghost real(wp), intent(inout) :: fld(nx_total, ny_total) !! Cell-centred field, shape (nx_total, ny_total). logical, intent(in) :: wrap_x !! Wrap ghost columns (west ↔ east). logical, intent(in) :: wrap_y !! Wrap ghost rows (south ↔ north). integer :: i, j ! X-wrap first, then Y-wrap in a separate loop. The two passes must ! not share a single do-concurrent because the Y-wrap reads ghost ! columns that the X-wrap writes (data dependency across iterations). if (wrap_x) then do concurrent(j=1:ny_total, i=1:nx_total) ! West ghosts: fld(1..nghost, j) := fld(nx_phys+1..nx_phys+nghost, j) if (i <= nghost) then fld(i, j) = fld(i + nx_phys, j) end if ! East ghosts: fld(nx_phys+nghost+1..nx_total, j) := fld(nghost+1..2*nghost, j) if (i > nx_phys + nghost) then fld(i, j) = fld(i - nx_phys, j) end if end do end if if (wrap_y) then do concurrent(j=1:ny_total, i=1:nx_total) ! South ghosts: fld(i, 1..nghost) := fld(i, ny_phys+1..ny_phys+nghost) if (j <= nghost) then fld(i, j) = fld(i, j + ny_phys) end if ! North ghosts: fld(i, ny_phys+nghost+1..ny_total) := fld(i, nghost+1..2*nghost) if (j > ny_phys + nghost) then fld(i, j) = fld(i, j - ny_phys) end if end do end if end subroutine ocean_periodic_wrap_centre_2d