Skip to content

Commit dbd08c4

Browse files
committed
refactor: use grid_axis struct members in simulation kernel code
Replace flat grid array references (dx/dy/dz, x_cc/y_cc/z_cc, x_cb/y_cb/z_cb) with struct member access (x%spacing/y%spacing/z%spacing, x%cc/y%cc/z%cc, x%cb/y%cb/z%cb) throughout simulation kernel files. m_igr.fpp retains flat array access: NVHPC OpenMP target offload does not correctly resolve declare-target struct pointer components in that file's inline GPU_PARALLEL_LOOP bodies, causing CUDA_ERROR_LAUNCH_FAILED.
1 parent c44457c commit dbd08c4

21 files changed

Lines changed: 407 additions & 395 deletions

src/simulation/m_acoustic_src.fpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,18 +488,18 @@ contains
488488
! Calculate sig spatial support width
489489

490490
if (n == 0) then
491-
sig = dx(j)
491+
sig = x%spacing(j)
492492
else if (p == 0) then
493-
sig = maxval((/dx(j), dy(k)/))
493+
sig = maxval((/x%spacing(j), y%spacing(k)/))
494494
else
495-
sig = maxval((/dx(j), dy(k), dz(l)/))
495+
sig = maxval((/x%spacing(j), y%spacing(k), z%spacing(l)/))
496496
end if
497497
sig = sig*acoustic_spatial_support_width
498498

499499
! Calculate displacement from acoustic source location
500-
r(1) = x_cc(j) - loc(1)
501-
if (n /= 0) r(2) = y_cc(k) - loc(2)
502-
if (p /= 0) r(3) = z_cc(l) - loc(3)
500+
r(1) = x%cc(j) - loc(1)
501+
if (n /= 0) r(2) = y%cc(k) - loc(2)
502+
if (p /= 0) r(3) = z%cc(l) - loc(3)
503503

504504
if (any(support(ai) == (/1, 2, 3, 4/))) then
505505
call s_source_spatial_planar(ai, sig, r, source)

src/simulation/m_bubbles_EE.fpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ contains
104104
do k = 0, n
105105
do j = 0, m
106106
divu_in%sf(j, k, l) = 0._wp
107-
divu_in%sf(j, k, l) = 5.e-1_wp/dx(j)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j + 1, k, &
107+
divu_in%sf(j, k, l) = 5.e-1_wp/x%spacing(j)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j + 1, k, &
108108
& l) - q_prim_vf(eqn_idx%cont%end + idir)%sf(j - 1, k, l))
109109
end do
110110
end do
@@ -116,8 +116,9 @@ contains
116116
do l = 0, p
117117
do k = 0, n
118118
do j = 0, m
119-
divu_in%sf(j, k, l) = divu_in%sf(j, k, l) + 5.e-1_wp/dy(k)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j, &
120-
& k + 1, l) - q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k - 1, l))
119+
divu_in%sf(j, k, l) = divu_in%sf(j, k, &
120+
& l) + 5.e-1_wp/y%spacing(k)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k + 1, &
121+
& l) - q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k - 1, l))
121122
end do
122123
end do
123124
end do
@@ -127,7 +128,8 @@ contains
127128
do l = 0, p
128129
do k = 0, n
129130
do j = 0, m
130-
divu_in%sf(j, k, l) = divu_in%sf(j, k, l) + 5.e-1_wp/dz(l)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k, &
131+
divu_in%sf(j, k, l) = divu_in%sf(j, k, &
132+
& l) + 5.e-1_wp/z%spacing(l)*(q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k, &
131133
& l + 1) - q_prim_vf(eqn_idx%cont%end + idir)%sf(j, k, l - 1))
132134
end do
133135
end do

src/simulation/m_bubbles_EL.fpp

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -793,48 +793,48 @@ contains
793793
!> Getting p_cell in terms of only the current cell by interpolation
794794
!> Getting the cell volulme as Omega
795795
if (p > 0) then
796-
vol = dx(cell(1))*dy(cell(2))*dz(cell(3))
796+
vol = x%spacing(cell(1))*y%spacing(cell(2))*z%spacing(cell(3))
797797
else
798798
if (cyl_coord) then
799-
vol = dx(cell(1))*dy(cell(2))*y_cc(cell(2))*2._wp*pi
799+
vol = x%spacing(cell(1))*y%spacing(cell(2))*y%cc(cell(2))*2._wp*pi
800800
else
801-
vol = dx(cell(1))*dy(cell(2))*lag_params%charwidth
801+
vol = x%spacing(cell(1))*y%spacing(cell(2))*lag_params%charwidth
802802
end if
803803
end if
804804
805805
!> Obtain bilinear interpolation coefficients, based on the current location of the bubble.
806-
psi(1) = (scoord(1) - real(cell(1)))*dx(cell(1)) + x_cb(cell(1) - 1)
806+
psi(1) = (scoord(1) - real(cell(1)))*x%spacing(cell(1)) + x%cb(cell(1) - 1)
807807
if (cell(1) == (m + buff_size)) then
808808
cell(1) = cell(1) - 1
809809
psi(1) = 1._wp
810810
else if (cell(1) == (-buff_size)) then
811811
psi(1) = 0._wp
812812
else
813-
if (psi(1) < x_cc(cell(1))) cell(1) = cell(1) - 1
814-
psi(1) = abs((psi(1) - x_cc(cell(1)))/(x_cc(cell(1) + 1) - x_cc(cell(1))))
813+
if (psi(1) < x%cc(cell(1))) cell(1) = cell(1) - 1
814+
psi(1) = abs((psi(1) - x%cc(cell(1)))/(x%cc(cell(1) + 1) - x%cc(cell(1))))
815815
end if
816816
817-
psi(2) = (scoord(2) - real(cell(2)))*dy(cell(2)) + y_cb(cell(2) - 1)
817+
psi(2) = (scoord(2) - real(cell(2)))*y%spacing(cell(2)) + y%cb(cell(2) - 1)
818818
if (cell(2) == (n + buff_size)) then
819819
cell(2) = cell(2) - 1
820820
psi(2) = 1._wp
821821
else if (cell(2) == (-buff_size)) then
822822
psi(2) = 0._wp
823823
else
824-
if (psi(2) < y_cc(cell(2))) cell(2) = cell(2) - 1
825-
psi(2) = abs((psi(2) - y_cc(cell(2)))/(y_cc(cell(2) + 1) - y_cc(cell(2))))
824+
if (psi(2) < y%cc(cell(2))) cell(2) = cell(2) - 1
825+
psi(2) = abs((psi(2) - y%cc(cell(2)))/(y%cc(cell(2) + 1) - y%cc(cell(2))))
826826
end if
827827
828828
if (p > 0) then
829-
psi(3) = (scoord(3) - real(cell(3)))*dz(cell(3)) + z_cb(cell(3) - 1)
829+
psi(3) = (scoord(3) - real(cell(3)))*z%spacing(cell(3)) + z%cb(cell(3) - 1)
830830
if (cell(3) == (p + buff_size)) then
831831
cell(3) = cell(3) - 1
832832
psi(3) = 1._wp
833833
else if (cell(3) == (-buff_size)) then
834834
psi(3) = 0._wp
835835
else
836-
if (psi(3) < z_cc(cell(3))) cell(3) = cell(3) - 1
837-
psi(3) = abs((psi(3) - z_cc(cell(3)))/(z_cc(cell(3) + 1) - z_cc(cell(3))))
836+
if (psi(3) < z%cc(cell(3))) cell(3) = cell(3) - 1
837+
psi(3) = abs((psi(3) - z%cc(cell(3)))/(z%cc(cell(3) + 1) - z%cc(cell(3))))
838838
end if
839839
else
840840
psi(3) = 0._wp
@@ -890,7 +890,7 @@ contains
890890
if ((cellaux(1) < -buff_size) .or. (cellaux(2) < -buff_size)) then
891891
celloutside = .true.
892892
end if
893-
if (cyl_coord .and. y_cc(cellaux(2)) < 0._wp) then
893+
if (cyl_coord .and. y%cc(cellaux(2)) < 0._wp) then
894894
celloutside = .true.
895895
end if
896896
if ((cellaux(2) > n + buff_size) .or. (cellaux(1) > m + buff_size)) then
@@ -907,20 +907,20 @@ contains
907907
end if
908908
end if
909909
if (.not. celloutside) then
910-
if (cyl_coord .and. (p == 0) .and. (y_cc(cellaux(2)) < 0._wp)) then
910+
if (cyl_coord .and. (p == 0) .and. (y%cc(cellaux(2)) < 0._wp)) then
911911
celloutside = .true.
912912
end if
913913
end if
914914
915915
if (.not. celloutside) then
916916
!> Obtaining the cell volulme
917917
if (p > 0) then
918-
vol = dx(cellaux(1))*dy(cellaux(2))*dz(cellaux(3))
918+
vol = x%spacing(cellaux(1))*y%spacing(cellaux(2))*z%spacing(cellaux(3))
919919
else
920920
if (cyl_coord) then
921-
vol = dx(cellaux(1))*dy(cellaux(2))*y_cc(cellaux(2))*2._wp*pi
921+
vol = x%spacing(cellaux(1))*y%spacing(cellaux(2))*y%cc(cellaux(2))*2._wp*pi
922922
else
923-
vol = dx(cellaux(1))*dy(cellaux(2))*lag_params%charwidth
923+
vol = x%spacing(cellaux(1))*y%spacing(cellaux(2))*lag_params%charwidth
924924
end if
925925
end if
926926
!> Update values
@@ -1088,40 +1088,40 @@ contains
10881088
integer, dimension(3), intent(inout) :: cell
10891089
integer :: i
10901090
1091-
do while (pos(1) < x_cb(cell(1) - 1))
1091+
do while (pos(1) < x%cb(cell(1) - 1))
10921092
cell(1) = cell(1) - 1
10931093
end do
10941094
1095-
do while (pos(1) > x_cb(cell(1)))
1095+
do while (pos(1) > x%cb(cell(1)))
10961096
cell(1) = cell(1) + 1
10971097
end do
10981098
1099-
do while (pos(2) < y_cb(cell(2) - 1))
1099+
do while (pos(2) < y%cb(cell(2) - 1))
11001100
cell(2) = cell(2) - 1
11011101
end do
11021102
1103-
do while (pos(2) > y_cb(cell(2)))
1103+
do while (pos(2) > y%cb(cell(2)))
11041104
cell(2) = cell(2) + 1
11051105
end do
11061106
11071107
if (p > 0) then
1108-
do while (pos(3) < z_cb(cell(3) - 1))
1108+
do while (pos(3) < z%cb(cell(3) - 1))
11091109
cell(3) = cell(3) - 1
11101110
end do
1111-
do while (pos(3) > z_cb(cell(3)))
1111+
do while (pos(3) > z%cb(cell(3)))
11121112
cell(3) = cell(3) + 1
11131113
end do
11141114
end if
11151115
11161116
! The numbering of the cell of which left boundary is the domain boundary is 0. if comp.coord of the pos is s, the real
11171117
! coordinate of s is (the coordinate of the left boundary of the Floor(s)-th cell) + (s-(int(s))*(cell-width). In other
1118-
! words, the coordinate of the center of the cell is x_cc(cell).
1118+
! words, the coordinate of the center of the cell is x%cc(cell).
11191119
11201120
! coordinates in computational space
1121-
scoord(1) = cell(1) + (pos(1) - x_cb(cell(1) - 1))/dx(cell(1))
1122-
scoord(2) = cell(2) + (pos(2) - y_cb(cell(2) - 1))/dy(cell(2))
1121+
scoord(1) = cell(1) + (pos(1) - x%cb(cell(1) - 1))/x%spacing(cell(1))
1122+
scoord(2) = cell(2) + (pos(2) - y%cb(cell(2) - 1))/y%spacing(cell(2))
11231123
scoord(3) = 0._wp
1124-
if (p > 0) scoord(3) = cell(3) + (pos(3) - z_cb(cell(3) - 1))/dz(cell(3))
1124+
if (p > 0) scoord(3) = cell(3) + (pos(3) - z%cb(cell(3) - 1))/z%spacing(cell(3))
11251125
cell(:) = int(scoord(:))
11261126
do i = 1, num_dims
11271127
if (scoord(i) < 0._wp) cell(i) = cell(i) - 1
@@ -1159,43 +1159,43 @@ contains
11591159
11601160
if (p == 0 .and. cyl_coord .neqv. .true.) then
11611161
! Defining a virtual z-axis that has the same dimensions as y-axis defined in the input file
1162-
particle_in_domain = ((pos_part(1) < x_cb(m + buff_size)) .and. (pos_part(1) >= x_cb(-buff_size - 1)) &
1163-
& .and. (pos_part(2) < y_cb(n + buff_size)) .and. (pos_part(2) >= y_cb(-buff_size - 1)) &
1162+
particle_in_domain = ((pos_part(1) < x%cb(m + buff_size)) .and. (pos_part(1) >= x%cb(-buff_size - 1)) &
1163+
& .and. (pos_part(2) < y%cb(n + buff_size)) .and. (pos_part(2) >= y%cb(-buff_size - 1)) &
11641164
& .and. (pos_part(3) < lag_params%charwidth/2._wp) .and. (pos_part(3) >= &
11651165
& -lag_params%charwidth/2._wp))
11661166
else
11671167
! cyl_coord
1168-
particle_in_domain = ((pos_part(1) < x_cb(m + buff_size)) .and. (pos_part(1) >= x_cb(-buff_size - 1)) &
1169-
& .and. (abs(pos_part(2)) < y_cb(n + buff_size)) .and. (abs(pos_part(2)) >= max(y_cb(-buff_size &
1168+
particle_in_domain = ((pos_part(1) < x%cb(m + buff_size)) .and. (pos_part(1) >= x%cb(-buff_size - 1)) &
1169+
& .and. (abs(pos_part(2)) < y%cb(n + buff_size)) .and. (abs(pos_part(2)) >= max(y%cb(-buff_size &
11701170
& - 1), 0._wp)))
11711171
end if
11721172
11731173
! 3D
11741174
if (p > 0) then
1175-
particle_in_domain = ((pos_part(1) < x_cb(m + buff_size)) .and. (pos_part(1) >= x_cb(-buff_size - 1)) &
1176-
& .and. (pos_part(2) < y_cb(n + buff_size)) .and. (pos_part(2) >= y_cb(-buff_size - 1)) &
1177-
& .and. (pos_part(3) < z_cb(p + buff_size)) .and. (pos_part(3) >= z_cb(-buff_size - 1)))
1175+
particle_in_domain = ((pos_part(1) < x%cb(m + buff_size)) .and. (pos_part(1) >= x%cb(-buff_size - 1)) &
1176+
& .and. (pos_part(2) < y%cb(n + buff_size)) .and. (pos_part(2) >= y%cb(-buff_size - 1)) &
1177+
& .and. (pos_part(3) < z%cb(p + buff_size)) .and. (pos_part(3) >= z%cb(-buff_size - 1)))
11781178
end if
11791179
11801180
! For symmetric and wall boundary condition
11811181
if (any(bc%x%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/))) then
1182-
particle_in_domain = (particle_in_domain .and. (pos_part(1) >= x_cb(-1)))
1182+
particle_in_domain = (particle_in_domain .and. (pos_part(1) >= x%cb(-1)))
11831183
end if
11841184
if (any(bc%x%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/))) then
1185-
particle_in_domain = (particle_in_domain .and. (pos_part(1) < x_cb(m)))
1185+
particle_in_domain = (particle_in_domain .and. (pos_part(1) < x%cb(m)))
11861186
end if
11871187
if (any(bc%y%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/)) .and. (.not. cyl_coord)) then
1188-
particle_in_domain = (particle_in_domain .and. (pos_part(2) >= y_cb(-1)))
1188+
particle_in_domain = (particle_in_domain .and. (pos_part(2) >= y%cb(-1)))
11891189
end if
11901190
if (any(bc%y%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/)) .and. (.not. cyl_coord)) then
1191-
particle_in_domain = (particle_in_domain .and. (pos_part(2) < y_cb(n)))
1191+
particle_in_domain = (particle_in_domain .and. (pos_part(2) < y%cb(n)))
11921192
end if
11931193
if (p > 0) then
11941194
if (any(bc%z%beg == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/))) then
1195-
particle_in_domain = (particle_in_domain .and. (pos_part(3) >= z_cb(-1)))
1195+
particle_in_domain = (particle_in_domain .and. (pos_part(3) >= z%cb(-1)))
11961196
end if
11971197
if (any(bc%z%end == (/BC_REFLECTIVE, BC_CHAR_SLIP_WALL, BC_SLIP_WALL, BC_NO_SLIP_WALL/))) then
1198-
particle_in_domain = (particle_in_domain .and. (pos_part(3) < z_cb(p)))
1198+
particle_in_domain = (particle_in_domain .and. (pos_part(3) < z%cb(p)))
11991199
end if
12001200
end if
12011201
@@ -1207,12 +1207,12 @@ contains
12071207
logical :: particle_in_domain_physical
12081208
real(wp), dimension(3), intent(in) :: pos_part
12091209
1210-
particle_in_domain_physical = ((pos_part(1) < x_cb(m)) .and. (pos_part(1) >= x_cb(-1)) .and. (pos_part(2) < y_cb(n)) &
1211-
& .and. (pos_part(2) >= y_cb(-1)))
1210+
particle_in_domain_physical = ((pos_part(1) < x%cb(m)) .and. (pos_part(1) >= x%cb(-1)) .and. (pos_part(2) < y%cb(n)) &
1211+
& .and. (pos_part(2) >= y%cb(-1)))
12121212
12131213
if (p > 0) then
1214-
particle_in_domain_physical = (particle_in_domain_physical .and. (pos_part(3) < z_cb(p)) .and. (pos_part(3) &
1215-
& >= z_cb(-1)))
1214+
particle_in_domain_physical = (particle_in_domain_physical .and. (pos_part(3) < z%cb(p)) .and. (pos_part(3) &
1215+
& >= z%cb(-1)))
12161216
end if
12171217
12181218
end function particle_in_domain_physical
@@ -1230,9 +1230,9 @@ contains
12301230
do k = 0, p
12311231
do j = 0, n
12321232
do i = 0, m
1233-
dq(i, j, k) = q(i, j, k)*(dx(i + 1) - dx(i - 1)) + q(i + 1, j, k)*(dx(i) + dx(i - 1)) - q(i - 1, j, &
1234-
& k)*(dx(i) + dx(i + 1))
1235-
dq(i, j, k) = dq(i, j, k)/((dx(i) + dx(i - 1))*(dx(i) + dx(i + 1)))
1233+
dq(i, j, k) = q(i, j, k)*(x%spacing(i + 1) - x%spacing(i - 1)) + q(i + 1, j, &
1234+
& k)*(x%spacing(i) + x%spacing(i - 1)) - q(i - 1, j, k)*(x%spacing(i) + x%spacing(i + 1))
1235+
dq(i, j, k) = dq(i, j, k)/((x%spacing(i) + x%spacing(i - 1))*(x%spacing(i) + x%spacing(i + 1)))
12361236
end do
12371237
end do
12381238
end do
@@ -1243,9 +1243,9 @@ contains
12431243
do k = 0, p
12441244
do j = 0, n
12451245
do i = 0, m
1246-
dq(i, j, k) = q(i, j, k)*(dy(j + 1) - dy(j - 1)) + q(i, j + 1, k)*(dy(j) + dy(j - 1)) - q(i, j - 1, &
1247-
& k)*(dy(j) + dy(j + 1))
1248-
dq(i, j, k) = dq(i, j, k)/((dy(j) + dy(j - 1))*(dy(j) + dy(j + 1)))
1246+
dq(i, j, k) = q(i, j, k)*(y%spacing(j + 1) - y%spacing(j - 1)) + q(i, j + 1, &
1247+
& k)*(y%spacing(j) + y%spacing(j - 1)) - q(i, j - 1, k)*(y%spacing(j) + y%spacing(j + 1))
1248+
dq(i, j, k) = dq(i, j, k)/((y%spacing(j) + y%spacing(j - 1))*(y%spacing(j) + y%spacing(j + 1)))
12491249
end do
12501250
end do
12511251
end do
@@ -1256,9 +1256,9 @@ contains
12561256
do k = 0, p
12571257
do j = 0, n
12581258
do i = 0, m
1259-
dq(i, j, k) = q(i, j, k)*(dz(k + 1) - dz(k - 1)) + q(i, j, k + 1)*(dz(k) + dz(k - 1)) - q(i, j, &
1260-
& k - 1)*(dz(k) + dz(k + 1))
1261-
dq(i, j, k) = dq(i, j, k)/((dz(k) + dz(k - 1))*(dz(k) + dz(k + 1)))
1259+
dq(i, j, k) = q(i, j, k)*(z%spacing(k + 1) - z%spacing(k - 1)) + q(i, j, &
1260+
& k + 1)*(z%spacing(k) + z%spacing(k - 1)) - q(i, j, k - 1)*(z%spacing(k) + z%spacing(k + 1))
1261+
dq(i, j, k) = dq(i, j, k)/((z%spacing(k) + z%spacing(k - 1))*(z%spacing(k) + z%spacing(k + 1)))
12621262
end do
12631263
end do
12641264
end do

0 commit comments

Comments
 (0)