Skip to content

Commit 0a304a2

Browse files
Moved all of the IB marker calculation to the GPU without copy
1 parent 4c52155 commit 0a304a2

2 files changed

Lines changed: 65 additions & 66 deletions

File tree

src/simulation/m_ib_patches.fpp

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ module m_ib_patches
6161

6262
contains
6363

64-
impure subroutine s_apply_ib_patches(ib_markers_sf)
64+
impure subroutine s_apply_ib_patches(ib_markers)
6565

66-
integer, dimension(:, :, :), intent(inout), optional :: ib_markers_sf
66+
type(integer_field), intent(inout) :: ib_markers
6767

6868
integer :: i
6969

@@ -76,16 +76,16 @@ contains
7676
do i = 1, num_ibs
7777

7878
if (patch_ib(i)%geometry == 8) then
79-
call s_ib_sphere(i, ib_markers_sf)
79+
call s_ib_sphere(i, ib_markers)
8080
elseif (patch_ib(i)%geometry == 9) then
81-
call s_ib_cuboid(i, ib_markers_sf)
81+
call s_ib_cuboid(i, ib_markers)
8282
elseif (patch_ib(i)%geometry == 10) then
83-
call s_ib_cylinder(i, ib_markers_sf)
83+
call s_ib_cylinder(i, ib_markers)
8484
elseif (patch_ib(i)%geometry == 11) then
85-
call s_ib_3D_airfoil(i, ib_markers_sf)
85+
call s_ib_3D_airfoil(i, ib_markers)
8686
! STL+IBM patch
8787
elseif (patch_ib(i)%geometry == 12) then
88-
call s_ib_model(i, ib_markers_sf)
88+
call s_ib_model(i, ib_markers)
8989
end if
9090
end do
9191
!> @}
@@ -97,16 +97,16 @@ contains
9797
!> @{
9898
do i = 1, num_ibs
9999
if (patch_ib(i)%geometry == 2) then
100-
call s_ib_circle(i, ib_markers_sf)
100+
call s_ib_circle(i, ib_markers)
101101
elseif (patch_ib(i)%geometry == 3) then
102-
call s_ib_rectangle(i, ib_markers_sf)
102+
call s_ib_rectangle(i, ib_markers)
103103
elseif (patch_ib(i)%geometry == 4) then
104-
call s_ib_airfoil(i, ib_markers_sf)
104+
call s_ib_airfoil(i, ib_markers)
105105
! STL+IBM patch
106106
elseif (patch_ib(i)%geometry == 5) then
107-
call s_ib_model(i, ib_markers_sf)
107+
call s_ib_model(i, ib_markers)
108108
elseif (patch_ib(i)%geometry == 6) then
109-
call s_ib_ellipse(i, ib_markers_sf)
109+
call s_ib_ellipse(i, ib_markers)
110110
end if
111111
end do
112112
!> @}
@@ -248,12 +248,12 @@ contains
248248
!! are provided. Note that the circular patch DOES allow for
249249
!! the smoothing of its boundary.
250250
!! @param patch_id is the patch identifier
251-
!! @param ib_markers_sf Array to track patch ids
251+
!! @param ib_markers Array to track patch ids
252252
!! @param ib True if this patch is an immersed boundary
253-
subroutine s_ib_circle(patch_id, ib_markers_sf)
253+
subroutine s_ib_circle(patch_id, ib_markers)
254254

255255
integer, intent(in) :: patch_id
256-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
256+
type(integer_field), intent(inout) :: ib_markers
257257

258258
real(wp), dimension(1:2) :: center
259259
real(wp) :: radius
@@ -272,14 +272,14 @@ contains
272272
! that cell. If both queries check out, the primitive variables of
273273
! the current patch are assigned to this cell.
274274
275-
$:GPU_PARALLEL_LOOP(private='[i,j]', copy='[ib_markers_sf]',&
275+
$:GPU_PARALLEL_LOOP(private='[i,j]',&
276276
& copyin='[patch_id,center,radius]', collapse=2)
277277
do j = 0, n
278278
do i = 0, m
279279
if ((x_cc(i) - center(1))**2 &
280280
+ (y_cc(j) - center(2))**2 <= radius**2) &
281281
then
282-
ib_markers_sf(i, j, 0) = patch_id
282+
ib_markers%sf(i, j, 0) = patch_id
283283
end if
284284
end do
285285
end do
@@ -288,11 +288,11 @@ contains
288288
end subroutine s_ib_circle
289289
290290
!! @param patch_id is the patch identifier
291-
!! @param ib_markers_sf Array to track patch ids
292-
subroutine s_ib_airfoil(patch_id, ib_markers_sf)
291+
!! @param ib_markers Array to track patch ids
292+
subroutine s_ib_airfoil(patch_id, ib_markers)
293293
294294
integer, intent(in) :: patch_id
295-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
295+
type(integer_field), intent(inout) :: ib_markers
296296
297297
real(wp) :: f, ca_in, pa, ma, ta
298298
real(wp) :: xa, yt, xu, yu, xl, yl, xc, yc, dycdxc, sin_c, cos_c
@@ -376,7 +376,7 @@ contains
376376
377377
end if
378378
379-
$:GPU_PARALLEL_LOOP(private='[i,j,xy_local,k,f]', copy='[ib_markers_sf]',&
379+
$:GPU_PARALLEL_LOOP(private='[i,j,xy_local,k,f]', &
380380
& copyin='[patch_id,center,inverse_rotation,offset,ma,ca_in,airfoil_grid_u,airfoil_grid_l]', collapse=2)
381381
do j = 0, n
382382
do i = 0, m
@@ -401,13 +401,13 @@ contains
401401
if (f_approx_equal(airfoil_grid_u(k)%x, xy_local(1))) then
402402
if (xy_local(2) <= airfoil_grid_u(k)%y) then
403403
!!IB
404-
ib_markers_sf(i, j, 0) = patch_id
404+
ib_markers%sf(i, j, 0) = patch_id
405405
end if
406406
else
407407
f = (airfoil_grid_u(k)%x - xy_local(1))/(airfoil_grid_u(k)%x - airfoil_grid_u(k - 1)%x)
408408
if (xy_local(2) <= ((1._wp - f)*airfoil_grid_u(k)%y + f*airfoil_grid_u(k - 1)%y)) then
409409
!!IB
410-
ib_markers_sf(i, j, 0) = patch_id
410+
ib_markers%sf(i, j, 0) = patch_id
411411
end if
412412
end if
413413
else
@@ -418,14 +418,14 @@ contains
418418
if (f_approx_equal(airfoil_grid_l(k)%x, xy_local(1))) then
419419
if (xy_local(2) >= airfoil_grid_l(k)%y) then
420420
!!IB
421-
ib_markers_sf(i, j, 0) = patch_id
421+
ib_markers%sf(i, j, 0) = patch_id
422422
end if
423423
else
424424
f = (airfoil_grid_l(k)%x - xy_local(1))/(airfoil_grid_l(k)%x - airfoil_grid_l(k - 1)%x)
425425

426426
if (xy_local(2) >= ((1._wp - f)*airfoil_grid_l(k)%y + f*airfoil_grid_l(k - 1)%y)) then
427427
!!IB
428-
ib_markers_sf(i, j, 0) = patch_id
428+
ib_markers%sf(i, j, 0) = patch_id
429429
end if
430430
end if
431431
end if
@@ -437,12 +437,12 @@ contains
437437
end subroutine s_ib_airfoil
438438

439439
!! @param patch_id is the patch identifier
440-
!! @param ib_markers_sf Array to track patch ids
440+
!! @param ib_markers Array to track patch ids
441441
!! @param ib True if this patch is an immersed boundary
442-
subroutine s_ib_3D_airfoil(patch_id, ib_markers_sf)
442+
subroutine s_ib_3D_airfoil(patch_id, ib_markers)
443443

444444
integer, intent(in) :: patch_id
445-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
445+
type(integer_field), intent(inout) :: ib_markers
446446

447447
real(wp) :: lz, z_max, z_min, f, ca_in, pa, ma, ta, xa, yt, xu, yu, xl, yl, xc, yc, dycdxc, sin_c, cos_c
448448
integer :: i, j, k, l
@@ -527,7 +527,7 @@ contains
527527
$:GPU_UPDATE(device='[airfoil_grid_l,airfoil_grid_u]')
528528
end if
529529

530-
$:GPU_PARALLEL_LOOP(private='[i,j,l,xyz_local,k,f]', copy='[ib_markers_sf]',&
530+
$:GPU_PARALLEL_LOOP(private='[i,j,l,xyz_local,k,f]',&
531531
& copyin='[patch_id,center,inverse_rotation,offset,ma,ca_in,airfoil_grid_u,airfoil_grid_l,z_min,z_max]', collapse=3)
532532
do l = 0, p
533533
do j = 0, n
@@ -547,13 +547,13 @@ contains
547547
if (f_approx_equal(airfoil_grid_u(k)%x, xyz_local(1))) then
548548
if (xyz_local(2) <= airfoil_grid_u(k)%y) then
549549
!IB
550-
ib_markers_sf(i, j, l) = patch_id
550+
ib_markers%sf(i, j, l) = patch_id
551551
end if
552552
else
553553
f = (airfoil_grid_u(k)%x - xyz_local(1))/(airfoil_grid_u(k)%x - airfoil_grid_u(k - 1)%x)
554554
if (xyz_local(2) <= ((1._wp - f)*airfoil_grid_u(k)%y + f*airfoil_grid_u(k - 1)%y)) then
555555
!!IB
556-
ib_markers_sf(i, j, l) = patch_id
556+
ib_markers%sf(i, j, l) = patch_id
557557
end if
558558
end if
559559
else
@@ -564,14 +564,14 @@ contains
564564
if (f_approx_equal(airfoil_grid_l(k)%x, xyz_local(1))) then
565565
if (xyz_local(2) >= airfoil_grid_l(k)%y) then
566566
!!IB
567-
ib_markers_sf(i, j, l) = patch_id
567+
ib_markers%sf(i, j, l) = patch_id
568568
end if
569569
else
570570
f = (airfoil_grid_l(k)%x - xyz_local(1))/(airfoil_grid_l(k)%x - airfoil_grid_l(k - 1)%x)
571571
572572
if (xyz_local(2) >= ((1._wp - f)*airfoil_grid_l(k)%y + f*airfoil_grid_l(k - 1)%y)) then
573573
!!IB
574-
ib_markers_sf(i, j, l) = patch_id
574+
ib_markers%sf(i, j, l) = patch_id
575575
end if
576576
end if
577577
end if
@@ -593,12 +593,12 @@ contains
593593
!! rectangular patch DOES NOT allow for the smoothing of its
594594
!! boundaries.
595595
!! @param patch_id is the patch identifier
596-
!! @param ib_markers_sf Array to track patch ids
596+
!! @param ib_markers Array to track patch ids
597597
!! @param ib True if this patch is an immersed boundary
598-
subroutine s_ib_rectangle(patch_id, ib_markers_sf)
598+
subroutine s_ib_rectangle(patch_id, ib_markers)
599599
600600
integer, intent(in) :: patch_id
601-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
601+
type(integer_field), intent(inout) :: ib_markers
602602
603603
integer :: i, j, k !< generic loop iterators
604604
real(wp) :: pi_inf, gamma, lit_gamma !< Equation of state parameters
@@ -621,7 +621,7 @@ contains
621621
! domain and verifying whether the current patch has the permission
622622
! to write to that cell. If both queries check out, the primitive
623623
! variables of the current patch are assigned to this cell.
624-
$:GPU_PARALLEL_LOOP(private='[i,j, xy_local]', copy='[ib_markers_sf]',&
624+
$:GPU_PARALLEL_LOOP(private='[i,j, xy_local]',&
625625
& copyin='[patch_id,center,length,inverse_rotation,x_cc,y_cc]', collapse=2)
626626
do j = 0, n
627627
do i = 0, m
@@ -635,7 +635,7 @@ contains
635635
0.5_wp*length(2) >= xy_local(2)) then
636636

637637
! Updating the patch identities bookkeeping variable
638-
ib_markers_sf(i, j, 0) = patch_id
638+
ib_markers%sf(i, j, 0) = patch_id
639639

640640
end if
641641
end do
@@ -650,12 +650,12 @@ contains
650650
!! provided. Please note that the spherical patch DOES allow
651651
!! for the smoothing of its boundary.
652652
!! @param patch_id is the patch identifier
653-
!! @param ib_markers_sf Array to track patch ids
653+
!! @param ib_markers Array to track patch ids
654654
!! @param ib True if this patch is an immersed boundary
655-
subroutine s_ib_sphere(patch_id, ib_markers_sf)
655+
subroutine s_ib_sphere(patch_id, ib_markers)
656656

657657
integer, intent(in) :: patch_id
658-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
658+
type(integer_field), intent(inout) :: ib_markers
659659

660660
! Generic loop iterators
661661
integer :: i, j, k
@@ -676,7 +676,7 @@ contains
676676
! and verifying whether the current patch has permission to write to
677677
! that cell. If both queries check out, the primitive variables of
678678
! the current patch are assigned to this cell.
679-
$:GPU_PARALLEL_LOOP(private='[i,j,k,cart_y,cart_z]', copy='[ib_markers_sf]',&
679+
$:GPU_PARALLEL_LOOP(private='[i,j,k,cart_y,cart_z]',&
680680
& copyin='[patch_id,center,radius]', collapse=3)
681681
do k = 0, p
682682
do j = 0, n
@@ -691,7 +691,7 @@ contains
691691
if (((x_cc(i) - center(1))**2 &
692692
+ (cart_y - center(2))**2 &
693693
+ (cart_z - center(3))**2 <= radius**2)) then
694-
ib_markers_sf(i, j, k) = patch_id
694+
ib_markers%sf(i, j, k) = patch_id
695695
end if
696696
end do
697697
end do
@@ -709,11 +709,11 @@ contains
709709
!! the cuboidal patch DOES NOT allow for the smearing of its
710710
!! boundaries.
711711
!! @param patch_id is the patch identifier
712-
!! @param ib_markers_sf Array to track patch ids
713-
subroutine s_ib_cuboid(patch_id, ib_markers_sf)
712+
!! @param ib_markers Array to track patch ids
713+
subroutine s_ib_cuboid(patch_id, ib_markers)
714714
715715
integer, intent(in) :: patch_id
716-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
716+
type(integer_field), intent(inout) :: ib_markers
717717
718718
integer :: i, j, k !< Generic loop iterators
719719
real(wp), dimension(1:3) :: xyz_local, center, length !< x and y coordinates in local IB frame
@@ -732,7 +732,7 @@ contains
732732
! and verifying whether the current patch has permission to write to
733733
! to that cell. If both queries check out, the primitive variables
734734
! of the current patch are assigned to this cell.
735-
$:GPU_PARALLEL_LOOP(private='[i,j,k,xyz_local,cart_y,cart_z]', copy='[ib_markers_sf]',&
735+
$:GPU_PARALLEL_LOOP(private='[i,j,k,xyz_local,cart_y,cart_z]',&
736736
& copyin='[patch_id,center,length,inverse_rotation]', collapse=3)
737737
do k = 0, p
738738
do j = 0, n
@@ -756,7 +756,7 @@ contains
756756
0.5*length(3) >= xyz_local(3)) then
757757
758758
! Updating the patch identities bookkeeping variable
759-
ib_markers_sf(i, j, k) = patch_id
759+
ib_markers%sf(i, j, k) = patch_id
760760
end if
761761
end do
762762
end do
@@ -774,12 +774,12 @@ contains
774774
!! that the cylindrical patch DOES allow for the smoothing
775775
!! of its lateral boundary.
776776
!! @param patch_id is the patch identifier
777-
!! @param ib_markers_sf Array to track patch ids
777+
!! @param ib_markers Array to track patch ids
778778
!! @param ib True if this patch is an immersed boundary
779-
subroutine s_ib_cylinder(patch_id, ib_markers_sf)
779+
subroutine s_ib_cylinder(patch_id, ib_markers)
780780

781781
integer, intent(in) :: patch_id
782-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
782+
type(integer_field), intent(inout) :: ib_markers
783783

784784
integer :: i, j, k !< Generic loop iterators
785785
real(wp) :: radius
@@ -802,7 +802,7 @@ contains
802802
! domain and verifying whether the current patch has the permission
803803
! to write to that cell. If both queries check out, the primitive
804804
! variables of the current patch are assigned to this cell.
805-
$:GPU_PARALLEL_LOOP(private='[i,j,k,xyz_local,cart_y,cart_z]', copy='[ib_markers_sf]',&
805+
$:GPU_PARALLEL_LOOP(private='[i,j,k,xyz_local,cart_y,cart_z]',&
806806
& copyin='[patch_id,center,length,radius,inverse_rotation]', collapse=3)
807807
do k = 0, p
808808
do j = 0, n
@@ -836,7 +836,7 @@ contains
836836
0.5_wp*length(3) >= xyz_local(3)))) then
837837

838838
! Updating the patch identities bookkeeping variable
839-
ib_markers_sf(i, j, k) = patch_id
839+
ib_markers%sf(i, j, k) = patch_id
840840
end if
841841
end do
842842
end do
@@ -845,10 +845,10 @@ contains
845845

846846
end subroutine s_ib_cylinder
847847

848-
subroutine s_ib_ellipse(patch_id, ib_markers_sf)
848+
subroutine s_ib_ellipse(patch_id, ib_markers)
849849

850850
integer, intent(in) :: patch_id
851-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
851+
type(integer_field), intent(inout) :: ib_markers
852852

853853
integer :: i, j, k !< generic loop iterators
854854
real(wp), dimension(1:3) :: xy_local !< x and y coordinates in local IB frame
@@ -865,7 +865,7 @@ contains
865865
866866
! Checking whether the ellipse covers a particular cell in the
867867
! domain
868-
$:GPU_PARALLEL_LOOP(private='[i,j, xy_local]', copy='[ib_markers_sf]',&
868+
$:GPU_PARALLEL_LOOP(private='[i,j, xy_local]',&
869869
& copyin='[patch_id,center,ellipse_coeffs,inverse_rotation,x_cc,y_cc]', collapse=2)
870870
do j = 0, n
871871
do i = 0, m
@@ -876,7 +876,7 @@ contains
876876
! Ellipse condition (x/a)^2 + (y/b)^2 <= 1
877877
if ((xy_local(1)/ellipse_coeffs(1))**2 + (xy_local(2)/ellipse_coeffs(2))**2 <= 1._wp) then
878878
! Updating the patch identities bookkeeping variable
879-
ib_markers_sf(i, j, 0) = patch_id
879+
ib_markers%sf(i, j, 0) = patch_id
880880
end if
881881
end do
882882
end do
@@ -886,13 +886,13 @@ contains
886886
887887
!> The STL patch is a 2/3D geometry that is imported from an STL file.
888888
!! @param patch_id is the patch identifier
889-
!! @param ib_markers_sf Array to track patch ids
889+
!! @param ib_markers Array to track patch ids
890890
!! @param STL_levelset STL levelset
891891
!! @param STL_levelset_norm STL levelset normals
892-
subroutine s_ib_model(patch_id, ib_markers_sf)
892+
subroutine s_ib_model(patch_id, ib_markers)
893893
894894
integer, intent(in) :: patch_id
895-
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
895+
type(integer_field), intent(inout) :: ib_markers
896896
897897
integer :: i, j, k !< Generic loop iterators
898898
@@ -934,7 +934,7 @@ contains
934934
935935
! Reading STL boundary vertices and compute the levelset and levelset_norm
936936
if (eta > patch_ib(patch_id)%model_threshold) then
937-
ib_markers_sf(i, j, k) = patch_id
937+
ib_markers%sf(i, j, k) = patch_id
938938
end if
939939
940940
end do

0 commit comments

Comments
 (0)