Skip to content

Commit 1b005f9

Browse files
authored
IBM Fix on Non-uniform Initial Condition (#404)
1 parent 1df0e5c commit 1b005f9

File tree

2 files changed

+98
-11
lines changed

2 files changed

+98
-11
lines changed

src/simulation/m_ibm.fpp

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ module m_ibm
4343
@:CRAY_DECLARE_GLOBAL(real(kind(0d0)), dimension(:, :, :, :), levelset)
4444
@:CRAY_DECLARE_GLOBAL(real(kind(0d0)), dimension(:, :, :, :, :), levelset_norm)
4545
@:CRAY_DECLARE_GLOBAL(type(ghost_point), dimension(:), ghost_points)
46+
@:CRAY_DECLARE_GLOBAL(type(ghost_point), dimension(:), inner_points)
4647

47-
!$acc declare link(levelset, levelset_norm, ghost_points)
48+
!$acc declare link(levelset, levelset_norm, ghost_points, inner_points)
4849
#else
4950

5051
!! Marker for solid cells. 0 if liquid, the patch id of its IB if solid
@@ -53,14 +54,16 @@ module m_ibm
5354
real(kind(0d0)), dimension(:, :, :, :, :), allocatable :: levelset_norm
5455
!! Matrix of normal vector to IB
5556
type(ghost_point), dimension(:), allocatable :: ghost_points
57+
type(ghost_point), dimension(:), allocatable :: inner_points
5658
!! Matrix of normal vector to IB
5759

58-
!$acc declare create(levelset, levelset_norm, ghost_points)
60+
!$acc declare create(levelset, levelset_norm, ghost_points, inner_points)
5961
#endif
6062

6163
integer :: gp_layers !< Number of ghost point layers
6264
integer :: num_gps !< Number of ghost points
63-
!$acc declare create(gp_layers, num_gps)
65+
integer :: num_inner_gps !< Number of ghost points
66+
!$acc declare create(gp_layers, num_gps, num_inner_gps)
6467

6568
contains
6669

@@ -82,7 +85,7 @@ contains
8285
@:ALLOCATE_GLOBAL(levelset(0:m, 0:n, 0:p, num_ibs))
8386
@:ALLOCATE_GLOBAL(levelset_norm(0:m, 0:n, 0:p, num_ibs, 3))
8487

85-
!$acc enter data copyin(gp_layers, num_gps)
88+
!$acc enter data copyin(gp_layers, num_gps, num_inner_gps)
8689

8790
end subroutine s_initialize_ibm_module
8891

@@ -97,12 +100,14 @@ contains
97100

98101
call s_find_num_ghost_points()
99102

100-
!$acc update device(num_gps)
103+
!$acc update device(num_gps, num_inner_gps)
101104
@:ALLOCATE_GLOBAL(ghost_points(num_gps))
102-
!$acc enter data copyin(ghost_points)
105+
@:ALLOCATE_GLOBAL(inner_points(num_inner_gps))
103106

104-
call s_find_ghost_points(ghost_points)
105-
!$acc update device(ghost_points)
107+
!$acc enter data copyin(ghost_points, inner_points)
108+
109+
call s_find_ghost_points(ghost_points, inner_points)
110+
!$acc update device(ghost_points, inner_points)
106111

107112
call s_compute_levelset(levelset, levelset_norm)
108113
!$acc update device(levelset, levelset_norm)
@@ -153,8 +158,9 @@ contains
153158
real(kind(0d0)) :: nbub
154159
real(kind(0d0)) :: buf
155160
type(ghost_point) :: gp
161+
type(ghost_point) :: innerp
156162

157-
!$acc parallel loop gang vector private(physical_loc, dyn_pres, alpha_rho_IP, alpha_IP, pres_IP, vel_IP, vel_g, vel_norm_IP, r_IP, v_IP, pb_IP, mv_IP, nmom_IP, presb_IP, massv_IP, rho, gamma, pi_inf, Re_K, G_K, Gs, gp, norm, buf, j, k, l, q, coeff)
163+
!$acc parallel loop gang vector private(physical_loc, dyn_pres, alpha_rho_IP, alpha_IP, pres_IP, vel_IP, vel_g, vel_norm_IP, r_IP, v_IP, pb_IP, mv_IP, nmom_IP, presb_IP, massv_IP, rho, gamma, pi_inf, Re_K, G_K, Gs, gp, innerp, norm, buf, j, k, l, q, coeff)
158164
do i = 1, num_gps
159165

160166
gp = ghost_points(i)
@@ -288,6 +294,43 @@ contains
288294
end if
289295
end do
290296

297+
!Correct the state of the inner points in IBs
298+
!$acc parallel loop gang vector private(physical_loc, dyn_pres, alpha_rho_IP, alpha_IP, vel_g, rho, gamma, pi_inf, Re_K, innerp, j, k, l, q)
299+
do i = 1, num_inner_gps
300+
301+
vel_g = 0d0
302+
innerp = inner_points(i)
303+
j = innerp%loc(1)
304+
k = innerp%loc(2)
305+
l = innerp%loc(3)
306+
patch_id = inner_points(i)%ib_patch_id
307+
308+
! Calculate physical location of GP
309+
if (p > 0) then
310+
physical_loc = [x_cc(j), y_cc(k), z_cc(l)]
311+
else
312+
physical_loc = [x_cc(j), y_cc(k), 0d0]
313+
end if
314+
315+
!$acc loop seq
316+
do q = 1, num_fluids
317+
q_prim_vf(q)%sf(j, k, l) = alpha_rho_IP(q)
318+
q_prim_vf(advxb + q - 1)%sf(j, k, l) = alpha_IP(q)
319+
end do
320+
321+
call s_convert_species_to_mixture_variables_acc(rho, gamma, pi_inf, qv_K, alpha_IP, &
322+
alpha_rho_IP, Re_K, j, k, l)
323+
324+
dyn_pres = 0d0
325+
326+
!$acc loop seq
327+
do q = momxb, momxe
328+
q_cons_vf(q)%sf(j, k, l) = rho*vel_g(q - momxb + 1)
329+
dyn_pres = dyn_pres + q_cons_vf(q)%sf(j, k, l)* &
330+
vel_g(q - momxb + 1)/2d0
331+
end do
332+
end do
333+
291334
end subroutine s_ibm_correct_state
292335

293336
!> Function that computes that bubble wall pressure for Gilmore bubbles
@@ -413,6 +456,8 @@ contains
413456
j - gp_layers:j + gp_layers, 0)
414457
if (any(subsection_2D == 0)) then
415458
num_gps = num_gps + 1
459+
else
460+
num_inner_gps = num_inner_gps + 1
416461
end if
417462
end if
418463
else
@@ -424,6 +469,8 @@ contains
424469
k - gp_layers:k + gp_layers)
425470
if (any(subsection_3D == 0)) then
426471
num_gps = num_gps + 1
472+
else
473+
num_inner_gps = num_inner_gps + 1
427474
end if
428475
end if
429476
end do
@@ -433,18 +480,20 @@ contains
433480

434481
end subroutine s_find_num_ghost_points
435482

436-
subroutine s_find_ghost_points(ghost_points)
483+
subroutine s_find_ghost_points(ghost_points, inner_points)
437484

438485
type(ghost_point), dimension(num_gps), intent(INOUT) :: ghost_points
486+
type(ghost_point), dimension(num_inner_gps), intent(INOUT) :: inner_points
439487
integer, dimension(2*gp_layers + 1, 2*gp_layers + 1) &
440488
:: subsection_2D
441489
integer, dimension(2*gp_layers + 1, 2*gp_layers + 1, 2*gp_layers + 1) &
442490
:: subsection_3D
443491
integer :: i, j, k !< Iterator variables
444-
integer :: count
492+
integer :: count, count_i
445493
integer :: patch_id
446494

447495
count = 1
496+
count_i = 1
448497

449498
do i = 0, m
450499
do j = 0, n
@@ -460,6 +509,13 @@ contains
460509
patch_id
461510
ghost_points(count)%slip = patch_ib(patch_id)%slip
462511
count = count + 1
512+
else
513+
inner_points(count_i)%loc = [i, j, 0]
514+
patch_id = ib_markers%sf(i, j, 0)
515+
inner_points(count_i)%ib_patch_id = &
516+
patch_id
517+
inner_points(count_i)%slip = patch_ib(patch_id)%slip
518+
count_i = count_i + 1
463519
end if
464520
end if
465521
else
@@ -476,6 +532,13 @@ contains
476532
ib_markers%sf(i, j, k)
477533
ghost_points(count)%slip = patch_ib(patch_id)%slip
478534
count = count + 1
535+
else
536+
inner_points(count_i)%loc = [i, j, k]
537+
patch_id = ib_markers%sf(i, j, k)
538+
inner_points(count_i)%ib_patch_id = &
539+
ib_markers%sf(i, j, k)
540+
inner_points(count_i)%slip = patch_ib(patch_id)%slip
541+
count_i = count_i + 1
479542
end if
480543
end if
481544
end do

src/simulation/m_time_steppers.fpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ contains
297297

298298
call s_compute_rhs(q_cons_ts(1)%vf, q_prim_vf, rhs_vf, pb_ts(1)%sf, rhs_pb, mv_ts(1)%sf, rhs_mv, t_step)
299299

300+
if (ib .and. t_step == 1) then
301+
if (qbmm .and. .not. polytropic) then
302+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf, pb_ts(1)%sf, mv_ts(1)%sf)
303+
else
304+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf)
305+
end if
306+
end if
307+
300308
#ifdef DEBUG
301309
print *, 'got rhs'
302310
#endif
@@ -410,6 +418,14 @@ contains
410418

411419
call s_compute_rhs(q_cons_ts(1)%vf, q_prim_vf, rhs_vf, pb_ts(1)%sf, rhs_pb, mv_ts(1)%sf, rhs_mv, t_step)
412420

421+
if (ib .and. t_step == 1) then
422+
if (qbmm .and. .not. polytropic) then
423+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf, pb_ts(1)%sf, mv_ts(1)%sf)
424+
else
425+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf)
426+
end if
427+
end if
428+
413429
if (run_time_info) then
414430
call s_write_run_time_information(q_prim_vf, t_step)
415431
end if
@@ -591,6 +607,14 @@ contains
591607

592608
call s_compute_rhs(q_cons_ts(1)%vf, q_prim_vf, rhs_vf, pb_ts(1)%sf, rhs_pb, mv_ts(1)%sf, rhs_mv, t_step)
593609

610+
if (ib .and. t_step == 1) then
611+
if (qbmm .and. .not. polytropic) then
612+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf, pb_ts(1)%sf, mv_ts(1)%sf)
613+
else
614+
call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf)
615+
end if
616+
end if
617+
594618
if (run_time_info) then
595619
call s_write_run_time_information(q_prim_vf, t_step)
596620
end if

0 commit comments

Comments
 (0)