@@ -79,8 +79,11 @@ module m_bubbles_EL
7979 $:GPU_DECLARE(create=' [nBubs,Rmax_glb,Rmin_glb,q_beta,q_beta_idx]' )
8080
8181 integer, allocatable, dimension(:) :: keep_bubble, prefix_sum
82+ integer, allocatable, dimension(:) :: wrap_bubble_loc
83+ integer, allocatable, dimension(:,:) :: wrap_bubble_dir
8284 integer :: active_bubs
8385 $:GPU_DECLARE(create=' [keep_bubble, prefix_sum, active_bubs]' )
86+ $:GPU_DECLARE(create=' [wrap_bubble_loc, wrap_bubble_dir]' )
8487
8588contains
8689
@@ -110,6 +113,17 @@ contains
110113 call s_mpi_abort(' Please check the lag_params%solver_approach input' )
111114 end if
112115
116+ pcomm_coords(1)%beg = x_cb(buff_size - fd_number - 1)
117+ pcomm_coords(1)%end = x_cb(m - buff_size + fd_number)
118+ if (n > 0) then
119+ pcomm_coords(2)%beg = y_cb(buff_size - fd_number - 1)
120+ pcomm_coords(2)%end = y_cb(n - buff_size + fd_number)
121+ if (p > 0) then
122+ pcomm_coords(3)%beg = z_cb(buff_size - fd_number - 1)
123+ pcomm_coords(3)%end = z_cb(p - buff_size + fd_number)
124+ end if
125+ end if
126+
113127 $:GPU_UPDATE(device=' [lag_num_ts, q_beta_idx]' )
114128
115129 @:ALLOCATE(q_beta%vf(1:q_beta_idx))
@@ -149,6 +163,7 @@ contains
149163 @:ALLOCATE(mtn_dveldt(1:nBubs_glb, 1:3, 1:lag_num_ts))
150164
151165 @:ALLOCATE(keep_bubble(1:nBubs_glb), prefix_sum(1:nBubs_glb))
166+ @:ALLOCATE(wrap_bubble_loc(1:nBubs_glb), wrap_bubble_dir(1:nBubs_glb, 1:num_dims))
152167
153168 if (adap_dt .and. f_is_default(adap_dt_tol)) adap_dt_tol = dflt_adap_dt_tol
154169
@@ -274,7 +289,8 @@ contains
274289 gas_betaC, bub_dphidt, lag_id, gas_p, gas_mv, &
275290 intfc_rad, intfc_vel, mtn_pos, mtn_posPrev, mtn_vel, &
276291 mtn_s, intfc_draddt, intfc_dveldt, gas_dpdt, &
277- gas_dmvdt, mtn_dposdt, mtn_dveldt, lag_num_ts, nBubs)
292+ gas_dmvdt, mtn_dposdt, mtn_dveldt, lag_num_ts, nBubs, &
293+ dest= 1 )
278294 end if
279295
280296 $:GPU_UPDATE(device= ' [bubbles_lagrange, lag_params]' )
@@ -576,8 +592,6 @@ contains
576592 call MPI_TYPE_FREE(view, ierr)
577593 end if
578594
579- print * , proc_rank, lag_id
580-
581595 if (proc_rank == 0 ) then
582596 write (* , ' (A,I0,A,I0)' ) ' Read ' , file_tot_part, ' particles from restart file at t_step = ' , save_count
583597 write (* , ' (A,E15.7,A,E15.7)' ) ' Restart time = ' , mytime, ' , dt = ' , dt
@@ -1358,12 +1372,16 @@ contains
13581372
13591373 type(scalar_field), dimension (sys_size), intent (in ) :: q_prim_vf
13601374 integer , intent (in ) :: dest
1361- integer :: k, i, patch_id, offset
1375+ integer :: k, i, q
1376+ integer :: patch_id, newBubs, new_idx
1377+ real (wp) :: offset
13621378 integer , dimension (3 ) :: cell
13631379
13641380 $:GPU_PARALLEL_LOOP(private= ' [cell]' )
13651381 do k = 1 , nBubs
13661382 keep_bubble(k) = 1
1383+ wrap_bubble_loc(k) = 0
1384+ wrap_bubble_dir(k,:) = 0
13671385
13681386 ! Relocate bubbles at solid boundaries and delete bubbles that leave
13691387 ! buffer regions
@@ -1373,6 +1391,16 @@ contains
13731391 elseif (any (bc_x%end == (/ BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/ )) &
13741392 .and. mtn_pos(k, 1 , dest) > x_cb(m) - intfc_rad(k, dest)) then
13751393 mtn_pos(k, 1 , dest) = x_cb(m) - intfc_rad(k, dest)
1394+ elseif (bc_x%beg == BC_PERIODIC .and. mtn_pos(k, 1 , dest) < pcomm_coords(1 )%beg .and. &
1395+ mtn_posPrev(k, 1 , dest) > pcomm_coords(1 )%beg) then
1396+ !print * , " 1, -1" , mtn_pos(k, 1 , dest), mtn_posPrev(k, 1 , dest), pcomm_coords(1 )%beg
1397+ wrap_bubble_dir(k,1 ) = 1
1398+ wrap_bubble_loc(k) = - 1
1399+ elseif (bc_x%end == BC_PERIODIC .and. mtn_pos(k, 1 , dest) > pcomm_coords(1 )%end .and. &
1400+ mtn_posPrev(k, 1 , dest) < pcomm_coords(1 )%end) then
1401+ !print * , " 1, 1" , mtn_pos(k, 1 , dest), mtn_posPrev(k, 1 , dest), pcomm_coords(1 )%end
1402+ wrap_bubble_dir(k,1 ) = 1
1403+ wrap_bubble_loc(k) = 1
13761404 elseif (mtn_pos(k, 1 , dest) >= x_cb(m + buff_size - fd_number)) then
13771405 keep_bubble(k) = 0
13781406 elseif (mtn_pos(k, 1 , dest) < x_cb(fd_number - buff_size - 1 )) then
@@ -1385,6 +1413,16 @@ contains
13851413 else if (any (bc_y%end == (/ BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/ )) &
13861414 .and. mtn_pos(k, 2 , dest) > y_cb(n) - intfc_rad(k, dest)) then
13871415 mtn_pos(k, 2 , dest) = y_cb(n) - intfc_rad(k, dest)
1416+ elseif (bc_y%beg == BC_PERIODIC .and. mtn_pos(k, 2 , dest) < pcomm_coords(2 )%beg .and. &
1417+ mtn_posPrev(k, 2 , dest) > pcomm_coords(2 )%beg) then
1418+ !print * , " 2, -1" , mtn_pos(k, 2 , dest), mtn_posPrev(k, 2 , dest), pcomm_coords(2 )%beg
1419+ wrap_bubble_dir(k,2 ) = 1
1420+ wrap_bubble_loc(k) = - 1
1421+ elseif (bc_y%end == BC_PERIODIC .and. mtn_pos(k, 2 , dest) > pcomm_coords(2 )%end .and. &
1422+ mtn_posPrev(k, 2 , dest) < pcomm_coords(2 )%end) then
1423+ !print * , " 2, 1" , mtn_pos(k, 2 , dest), mtn_posPrev(k, 2 , dest), pcomm_coords(2 )%end
1424+ wrap_bubble_dir(k,2 ) = 1
1425+ wrap_bubble_loc(k) = 1
13881426 elseif (mtn_pos(k, 2 , dest) >= y_cb(n + buff_size - fd_number)) then
13891427 keep_bubble(k) = 0
13901428 elseif (mtn_pos(k, 2 , dest) < y_cb(fd_number - buff_size - 1 )) then
@@ -1398,6 +1436,14 @@ contains
13981436 else if (any (bc_z%end == (/ BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/ )) &
13991437 .and. mtn_pos(k, 3 , dest) > z_cb(p) - intfc_rad(k, dest)) then
14001438 mtn_pos(k, 3 , dest) = z_cb(p) - intfc_rad(k, dest)
1439+ elseif (bc_z%beg == BC_PERIODIC .and. mtn_pos(k, 3 , dest) < pcomm_coords(3 )%beg .and. &
1440+ mtn_posPrev(k, 3 , dest) > pcomm_coords(3 )%beg) then
1441+ wrap_bubble_dir(k,3 ) = 1
1442+ wrap_bubble_loc(k) = - 1
1443+ elseif (bc_z%end == BC_PERIODIC .and. mtn_pos(k, 3 , dest) > pcomm_coords(3 )%end .and. &
1444+ mtn_posPrev(k, 3 , dest) < pcomm_coords(3 )%end) then
1445+ wrap_bubble_dir(k,3 ) = 1
1446+ wrap_bubble_loc(k) = 1
14011447 elseif (mtn_pos(k, 3 , dest) >= z_cb(p + buff_size - fd_number)) then
14021448 keep_bubble(k) = 0
14031449 elseif (mtn_pos(k, 3 , dest) < z_cb(fd_number - buff_size - 1 )) then
@@ -1436,6 +1482,7 @@ contains
14361482 end if
14371483 end do
14381484
1485+ call nvtxStartRange(" LAG-BC" )
14391486 call nvtxStartRange(" LAG-BC-DEV2HOST" )
14401487 $:GPU_UPDATE(host= ' [bub_R0, Rmax_stats, Rmin_stats, gas_mg, gas_betaT, &
14411488 & gas_betaC, bub_dphidt, lag_id, gas_p, gas_mv, intfc_rad, intfc_vel, &
@@ -1444,6 +1491,7 @@ contains
14441491 & nBubs]' )
14451492 call nvtxEndRange
14461493
1494+ ! Handle deletion of bubbles leaving local domain
14471495 do k = 1 , nBubs
14481496 if (k == 1 ) then
14491497 prefix_sum(k) = keep_bubble(k)
@@ -1456,33 +1504,41 @@ contains
14561504 do k = 1 , nBubs
14571505 if (keep_bubble(k) == 1 ) then
14581506 if (prefix_sum(k) /= k) then
1459- bub_R0(prefix_sum(k)) = bub_R0(k)
1460- Rmax_stats(prefix_sum(k)) = Rmax_stats(k)
1461- Rmin_stats(prefix_sum(k)) = Rmin_stats(k)
1462- gas_mg(prefix_sum(k)) = gas_mg(k)
1463- gas_betaT(prefix_sum(k)) = gas_betaT(k)
1464- gas_betaC(prefix_sum(k)) = gas_betaC(k)
1465- bub_dphidt(prefix_sum(k)) = bub_dphidt(k)
1466- lag_id(prefix_sum(k), 1 ) = lag_id(k, 1 )
1467- gas_p(prefix_sum(k), 1 :2 ) = gas_p(k, 1 :2 )
1468- gas_mv(prefix_sum(k), 1 :2 ) = gas_mv(k, 1 :2 )
1469- intfc_rad(prefix_sum(k), 1 :2 ) = intfc_rad(k, 1 :2 )
1470- intfc_vel(prefix_sum(k), 1 :2 ) = intfc_vel(k, 1 :2 )
1471- mtn_pos(prefix_sum(k), 1 :3 , 1 :2 ) = mtn_pos(k, 1 :3 , 1 :2 )
1472- mtn_posPrev(prefix_sum(k), 1 :3 , 1 :2 ) = mtn_posPrev(k, 1 :3 , 1 :2 )
1473- mtn_vel(prefix_sum(k), 1 :3 , 1 :2 ) = mtn_vel(k, 1 :3 , 1 :2 )
1474- mtn_s(prefix_sum(k), 1 :3 , 1 :2 ) = mtn_s(k, 1 :3 , 1 :2 )
1475- intfc_draddt(prefix_sum(k), 1 :lag_num_ts) = intfc_draddt(k, 1 :lag_num_ts)
1476- intfc_dveldt(prefix_sum(k), 1 :lag_num_ts) = intfc_dveldt(k, 1 :lag_num_ts)
1477- gas_dpdt(prefix_sum(k), 1 :lag_num_ts) = gas_dpdt(k, 1 :lag_num_ts)
1478- gas_dmvdt(prefix_sum(k), 1 :lag_num_ts) = gas_dmvdt(k, 1 :lag_num_ts)
1479- mtn_dposdt(prefix_sum(k), 1 :3 , 1 :lag_num_ts) = mtn_dposdt(k, 1 :3 , 1 :lag_num_ts)
1480- mtn_dveldt(prefix_sum(k), 1 :3 , 1 :lag_num_ts) = mtn_dveldt(k, 1 :3 , 1 :lag_num_ts)
1507+ call s_copy_lag_bubble(k, prefix_sum(k))
14811508 end if
14821509 end if
14831510 if (k == nBubs) nBubs = active_bubs
14841511 end do
14851512
1513+ ! Handle periodic wrapping of bubbles on same processor
1514+ newBubs = 0
1515+ do k = 1 , nBubs
1516+ if (any (wrap_bubble_dir(k, :) == 1 )) then
1517+ newBubs = newBubs + 1
1518+ new_idx = nBubs + newBubs
1519+ call s_copy_lag_bubble(k, new_idx)
1520+ do i = 1 , num_dims
1521+ if (wrap_bubble_dir(k, i) == 1 ) then
1522+ offset = glb_bounds(i)%end - glb_bounds(i)%beg
1523+ if (wrap_bubble_loc(k) == 1 ) then
1524+ do q = 1 , 2
1525+ mtn_pos(new_idx, i, q) = mtn_pos(new_idx, i, q) - offset
1526+ mtn_posPrev(new_idx, i, q) = mtn_posPrev(new_idx, i, q) - offset
1527+ end do
1528+ else if (wrap_bubble_loc(k) == - 1 ) then
1529+ do q = 1 , 2
1530+ mtn_pos(new_idx, i, q) = mtn_pos(new_idx, i, q) + offset
1531+ mtn_posPrev(new_idx, i, q) = mtn_posPrev(new_idx, i, q) + offset
1532+ end do
1533+ end if
1534+ end if
1535+ end do
1536+ end if
1537+ end do
1538+ print * , nBubs, newBubs
1539+ nBubs = nBubs + newBubs
1540+
1541+ ! Handle MPI transfer of bubbles going to another processor' s local domain
14861542 if (num_procs > 1) then
14871543 call nvtxStartRange("LAG-BC-TRANSFER-LIST")
14881544 call s_add_particles_to_transfer_list(nBubs, mtn_pos(:, :, dest), mtn_posPrev(:, :, dest))
@@ -1493,7 +1549,8 @@ contains
14931549 gas_betaC, bub_dphidt, lag_id, gas_p, gas_mv, &
14941550 intfc_rad, intfc_vel, mtn_pos, mtn_posPrev, mtn_vel, &
14951551 mtn_s, intfc_draddt, intfc_dveldt, gas_dpdt, &
1496- gas_dmvdt, mtn_dposdt, mtn_dveldt, lag_num_ts, nBubs)
1552+ gas_dmvdt, mtn_dposdt, mtn_dveldt, lag_num_ts, nBubs, &
1553+ dest)
14971554 call nvtxEndRange
14981555 end if
14991556
@@ -1503,6 +1560,7 @@ contains
15031560 & mtn_pos, mtn_posPrev, mtn_vel, mtn_s, intfc_draddt, intfc_dveldt, &
15041561 & gas_dpdt, gas_dmvdt, mtn_dposdt, mtn_dveldt, nBubs]' )
15051562 call nvtxEndRange
1563+ call nvtxEndRange
15061564
15071565 end subroutine s_enforce_EL_bubbles_boundary_conditions
15081566
@@ -2034,42 +2092,34 @@ contains
20342092
20352093 !> The purpose of this subroutine is to remove one specific particle if dt is too small.
20362094 !! @param bub_id Particle id
2037- impure subroutine s_remove_lag_bubble(bub_id)
2038-
2039- integer, intent(in) :: bub_id
2040-
2041- integer :: i
2042-
2043- $:GPU_LOOP(parallelism=' [seq]' )
2044- do i = bub_id, nBubs - 1
2045- bub_R0(i) = bub_R0(i + 1)
2046- Rmax_stats(i) = Rmax_stats(i + 1)
2047- Rmin_stats(i) = Rmin_stats(i + 1)
2048- gas_mg(i) = gas_mg(i + 1)
2049- gas_betaT(i) = gas_betaT(i + 1)
2050- gas_betaC(i) = gas_betaC(i + 1)
2051- bub_dphidt(i) = bub_dphidt(i + 1)
2052- lag_id(i, 1) = lag_id(i + 1, 1)
2053- gas_p(i, 1:2) = gas_p(i + 1, 1:2)
2054- gas_mv(i, 1:2) = gas_mv(i + 1, 1:2)
2055- intfc_rad(i, 1:2) = intfc_rad(i + 1, 1:2)
2056- intfc_vel(i, 1:2) = intfc_vel(i + 1, 1:2)
2057- mtn_pos(i, 1:3, 1:2) = mtn_pos(i + 1, 1:3, 1:2)
2058- mtn_posPrev(i, 1:3, 1:2) = mtn_posPrev(i + 1, 1:3, 1:2)
2059- mtn_vel(i, 1:3, 1:2) = mtn_vel(i + 1, 1:3, 1:2)
2060- mtn_s(i, 1:3, 1:2) = mtn_s(i + 1, 1:3, 1:2)
2061- intfc_draddt(i, 1:lag_num_ts) = intfc_draddt(i + 1, 1:lag_num_ts)
2062- intfc_dveldt(i, 1:lag_num_ts) = intfc_dveldt(i + 1, 1:lag_num_ts)
2063- gas_dpdt(i, 1:lag_num_ts) = gas_dpdt(i + 1, 1:lag_num_ts)
2064- gas_dmvdt(i, 1:lag_num_ts) = gas_dmvdt(i + 1, 1:lag_num_ts)
2065- mtn_dposdt(i, 1:3, 1:lag_num_ts) = mtn_dposdt(i + 1, 1:3, 1:lag_num_ts)
2066- mtn_dveldt(i, 1:3, 1:lag_num_ts) = mtn_dveldt(i + 1, 1:3, 1:lag_num_ts)
2067- end do
2068-
2069- nBubs = nBubs - 1
2070- $:GPU_UPDATE(device=' [nBubs]' )
2071-
2072- end subroutine s_remove_lag_bubble
2095+ impure subroutine s_copy_lag_bubble (src , dest )
2096+
2097+ integer , intent (in ) :: src, dest
2098+
2099+ bub_R0(dest) = bub_R0(src)
2100+ Rmax_stats(dest) = Rmax_stats(src)
2101+ Rmin_stats(dest) = Rmin_stats(src)
2102+ gas_mg(dest) = gas_mg(src)
2103+ gas_betaT(dest) = gas_betaT(src)
2104+ gas_betaC(dest) = gas_betaC(src)
2105+ bub_dphidt(dest) = bub_dphidt(src)
2106+ lag_id(dest, 1 ) = lag_id(src, 1 )
2107+ gas_p(dest, 1 :2 ) = gas_p(src, 1 :2 )
2108+ gas_mv(dest, 1 :2 ) = gas_mv(src, 1 :2 )
2109+ intfc_rad(dest, 1 :2 ) = intfc_rad(src, 1 :2 )
2110+ intfc_vel(dest, 1 :2 ) = intfc_vel(src, 1 :2 )
2111+ mtn_vel(dest, 1 :3 , 1 :2 ) = mtn_vel(src, 1 :3 , 1 :2 )
2112+ mtn_s(dest, 1 :3 , 1 :2 ) = mtn_s(src, 1 :3 , 1 :2 )
2113+ intfc_draddt(dest, 1 :lag_num_ts) = intfc_draddt(src, 1 :lag_num_ts)
2114+ intfc_dveldt(dest, 1 :lag_num_ts) = intfc_dveldt(src, 1 :lag_num_ts)
2115+ gas_dpdt(dest, 1 :lag_num_ts) = gas_dpdt(src, 1 :lag_num_ts)
2116+ gas_dmvdt(dest, 1 :lag_num_ts) = gas_dmvdt(src, 1 :lag_num_ts)
2117+ mtn_dposdt(dest, 1 :3 , 1 :lag_num_ts) = mtn_dposdt(src, 1 :3 , 1 :lag_num_ts)
2118+ mtn_dveldt(dest, 1 :3 , 1 :lag_num_ts) = mtn_dveldt(src, 1 :3 , 1 :lag_num_ts)
2119+ mtn_pos(dest, 1 :3 , 1 :2 ) = mtn_pos(src, 1 :3 , 1 :2 )
2120+ mtn_posPrev(dest, 1 :3 , 1 :2 ) = mtn_posPrev(src, 1 :3 , 1 :2 )
2121+
2122+ end subroutine s_copy_lag_bubble
20732123
20742124 !> The purpose of this subroutine is to deallocate variables
20752125 impure subroutine s_finalize_lagrangian_solver ()
0 commit comments