Skip to content

Commit

Permalink
Refactor the use of ix, iy, and iz
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre committed Oct 28, 2024
1 parent 29431e2 commit daae422
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 489 deletions.
62 changes: 17 additions & 45 deletions src/common/m_variables_conversion.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ module m_variables_conversion

end interface ! ============================================================

integer, public :: ixb, ixe, iyb, iye, izb, ize
!$acc declare create(ixb, ixe, iyb, iye, izb, ize)

!! In simulation, gammas, pi_infs, and qvs are already declared in m_global_variables
#ifndef MFC_SIMULATION
real(kind(0d0)), allocatable, public, dimension(:) :: gammas, gs_min, pi_infs, ps_inf, cvs, qvs, qvps
Expand Down Expand Up @@ -628,26 +625,7 @@ contains

integer :: i, j

#ifdef MFC_PRE_PROCESS
ixb = 0; iyb = 0; izb = 0;
ixe = m; iye = n; ize = p;
#else
ixb = -buff_size
ixe = m - ixb

iyb = 0; iye = 0; izb = 0; ize = 0;
if (n > 0) then
iyb = -buff_size; iye = n - iyb

if (p > 0) then
izb = -buff_size; ize = p - izb
end if
end if
#endif

!$acc enter data copyin(ixb, ixe, iyb, iye, izb, ize)
!$acc enter data copyin(is1b, is1e, is2b, is2e, is3b, is3e)
!$acc update device(ixb, ixe, iyb, iye, izb, ize)

#ifdef MFC_SIMULATION
@:ALLOCATE_GLOBAL(gammas (1:num_fluids))
Expand Down Expand Up @@ -784,15 +762,16 @@ contains

!Initialize mv at the quadrature nodes based on the initialized moments and sigma
subroutine s_initialize_mv(qK_cons_vf, mv)

type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
real(kind(0d0)), dimension(ixb:, iyb:, izb:, 1:, 1:), intent(inout) :: mv
real(kind(0d0)), dimension(idwbuff(1)%beg:, idwbuff(2)%beg:, idwbuff(3)%beg:, 1:, 1:), intent(inout) :: mv

integer :: i, j, k, l
real(kind(0d0)) :: mu, sig, nbub_sc

do l = izb, ize
do k = iyb, iye
do j = ixb, ixe
do l = idwbuff(3)%beg, idwbuff(3)%end
do k = idwbuff(2)%beg, idwbuff(2)%end
do j = idwbuff(1)%beg, idwbuff(1)%end

nbub_sc = qK_cons_vf(bubxb)%sf(j, k, l)

Expand All @@ -816,15 +795,15 @@ contains
!Initialize pb at the quadrature nodes using isothermal relations (Preston model)
subroutine s_initialize_pb(qK_cons_vf, mv, pb)
type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
real(kind(0d0)), dimension(ixb:, iyb:, izb:, 1:, 1:), intent(in) :: mv
real(kind(0d0)), dimension(ixb:, iyb:, izb:, 1:, 1:), intent(inout) :: pb
real(kind(0d0)), dimension(idwbuff(1)%beg:, idwbuff(2)%beg:, idwbuff(3)%beg:, 1:, 1:), intent(in) :: mv

Check warning on line 798 in src/common/m_variables_conversion.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_variables_conversion.fpp#L798

Added line #L798 was not covered by tests
real(kind(0d0)), dimension(idwbuff(1)%beg:, idwbuff(2)%beg:, idwbuff(3)%beg:, 1:, 1:), intent(inout) :: pb

integer :: i, j, k, l
real(kind(0d0)) :: mu, sig, nbub_sc

do l = izb, ize
do k = iyb, iye
do j = ixb, ixe
do l = idwbuff(3)%beg, idwbuff(3)%end
do k = idwbuff(2)%beg, idwbuff(2)%end

Check warning on line 805 in src/common/m_variables_conversion.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_variables_conversion.fpp#L804-L805

Added lines #L804 - L805 were not covered by tests
do j = idwbuff(1)%beg, idwbuff(1)%end

nbub_sc = qK_cons_vf(bubxb)%sf(j, k, l)

Expand Down Expand Up @@ -855,19 +834,16 @@ contains
!! @param iz Index bounds in third coordinate direction
subroutine s_convert_conservative_to_primitive_variables(qK_cons_vf, &
qK_prim_vf, &
gm_alphaK_vf, &
ix, iy, iz)
ibounds, &

Check warning on line 837 in src/common/m_variables_conversion.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_variables_conversion.fpp#L837

Added line #L837 was not covered by tests
gm_alphaK_vf)

type(scalar_field), dimension(sys_size), intent(in) :: qK_cons_vf
type(scalar_field), dimension(sys_size), intent(inout) :: qK_prim_vf
type(int_bounds_info), dimension(1:3), intent(in) :: ibounds

Check warning on line 842 in src/common/m_variables_conversion.fpp

View check run for this annotation

Codecov / codecov/patch

src/common/m_variables_conversion.fpp#L842

Added line #L842 was not covered by tests
type(scalar_field), &
allocatable, optional, dimension(:), &
intent(in) :: gm_alphaK_vf

type(int_bounds_info), optional, intent(in) :: ix, iy, iz

type(int_bounds_info) :: aix, aiy, aiz

real(kind(0d0)), dimension(num_fluids) :: alpha_K, alpha_rho_K
real(kind(0d0)), dimension(2) :: Re_K
real(kind(0d0)) :: rho_K, gamma_K, pi_inf_K, qv_K, dyn_pres_K
Expand Down Expand Up @@ -910,14 +886,10 @@ contains
end if
#:endif

if (present(ix)) then; aix = ix; else; aix%beg = ixb; aix%end = ixe; end if
if (present(iy)) then; aiy = iy; else; aiy%beg = iyb; aiy%end = iye; end if
if (present(iz)) then; aiz = iz; else; aiz%beg = izb; aiz%end = ize; end if

!$acc parallel loop collapse(3) gang vector default(present) copyin(aix, aiy, aiz) private(alpha_K, alpha_rho_K, Re_K, nRtmp, rho_K, gamma_K, pi_inf_K, qv_K, dyn_pres_K, R3tmp, rhoyks)
do l = aiz%beg, aiz%end
do k = aiy%beg, aiy%end
do j = aix%beg, aix%end
!$acc parallel loop collapse(3) gang vector default(present) private(alpha_K, alpha_rho_K, Re_K, nRtmp, rho_K, gamma_K, pi_inf_K, qv_K, dyn_pres_K, R3tmp, rhoyks)
do l = ibounds(3)%beg, ibounds(3)%end
do k = ibounds(2)%beg, ibounds(2)%end
do j = ibounds(1)%beg, ibounds(1)%end
dyn_pres_K = 0d0

!$acc loop seq
Expand Down
23 changes: 20 additions & 3 deletions src/post_process/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ module m_global_parameters
type(int_bounds_info) :: temperature_idx !< Indexes of first & last temperature eqns.
!> @}

! Cell Indices for the (local) interior points (O-m, O-n, 0-p).
type(int_bounds_info) :: idwint(1:3)

! Cell Indices for the entire (local) domain. In simulation, this includes
! the buffer region. idwbuff and idwint are the same otherwise.
type(int_bounds_info) :: idwbuff(1:3)

!> @name Boundary conditions in the x-, y- and z-coordinate directions
!> @{
type(int_bounds_info) :: bc_x, bc_y, bc_z
Expand Down Expand Up @@ -259,7 +266,6 @@ module m_global_parameters
real(kind(0d0)) :: poly_sigma
real(kind(0d0)) :: sigR
integer :: nmom

!> @}

!> @name surface tension coefficient
Expand Down Expand Up @@ -642,8 +648,6 @@ contains
tempxb = temperature_idx%beg
tempxe = temperature_idx%end

! ==================================================================

#ifdef MFC_MPI
allocate (MPI_IO_DATA%view(1:sys_size))
allocate (MPI_IO_DATA%var(1:sys_size))
Expand Down Expand Up @@ -691,6 +695,19 @@ contains
buff_size = buff_size + fd_number
end if

! Configuring Coordinate Direction Indexes =========================
idwint(1)%beg = 0; idwint(2)%beg = 0; idwint(3)%beg = 0
idwint(1)%end = m; idwint(2)%end = n; idwint(3)%end = p

idwbuff(1)%beg = -buff_size
if (num_dims > 1) then; idwbuff(2)%beg = -buff_size; else; idwbuff(2)%beg = 0; end if
if (num_dims > 2) then; idwbuff(3)%beg = -buff_size; else; idwbuff(3)%beg = 0; end if

idwbuff(1)%end = idwint(1)%end - idwbuff(1)%beg
idwbuff(2)%end = idwint(2)%end - idwbuff(2)%beg
idwbuff(3)%end = idwint(3)%end - idwbuff(3)%beg
! ==================================================================

! Allocating single precision grid variables if needed
if (precision == 1) then
allocate (x_cb_s(-1 - offset_x%beg:m + offset_x%end))
Expand Down
2 changes: 1 addition & 1 deletion src/post_process/m_start_up.f90
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ subroutine s_perform_time_step(t_step)
end if

! Converting the conservative variables to the primitive ones
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf)
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf, idwbuff)

end subroutine s_perform_time_step

Expand Down
13 changes: 13 additions & 0 deletions src/pre_process/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ module m_global_parameters
type(int_bounds_info) :: species_idx !< Indexes of first & last concentration eqns.
type(int_bounds_info) :: temperature_idx !< Indexes of first & last temperature eqns.

! Cell Indices for the (local) interior points (O-m, O-n, 0-p).
type(int_bounds_info) :: idwint(1:3)

! Cell Indices for the entire (local) domain. In simulation and post_process,
! this includes the buffer region. idwbuff and idwint are the same otherwise.
type(int_bounds_info) :: idwbuff(1:3)

type(int_bounds_info) :: bc_x, bc_y, bc_z !<
!! Boundary conditions in the x-, y- and z-coordinate directions

Expand Down Expand Up @@ -722,6 +729,12 @@ contains
tempxb = temperature_idx%beg
tempxe = temperature_idx%end

! Configuring Coordinate Direction Indexes =========================
idwint(1)%beg = 0; idwint(2)%beg = 0; idwint(3)%beg = 0
idwint(1)%end = m; idwint(2)%end = n; idwint(3)%end = p

! There is no buffer region in pre_process.
idwbuff(1) = idwint(1); idwbuff(2) = idwint(2); idwbuff(3) = idwint(3)
! ==================================================================

#ifdef MFC_MPI
Expand Down
3 changes: 2 additions & 1 deletion src/pre_process/m_initial_condition.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ contains
! preexisting initial condition data files were read in on start-up
if (old_ic) then
call s_convert_conservative_to_primitive_variables(q_cons_vf, &
q_prim_vf)
q_prim_vf, &
idwbuff)

Check warning on line 128 in src/pre_process/m_initial_condition.fpp

View check run for this annotation

Codecov / codecov/patch

src/pre_process/m_initial_condition.fpp#L128

Added line #L128 was not covered by tests
end if

! 3D Patch Geometries =============================================
Expand Down
11 changes: 1 addition & 10 deletions src/simulation/m_bubbles.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ contains
subroutine s_initialize_bubbles_module

integer :: i, j, k, l, q
type(int_bounds_info) :: ix, iy, iz

! Configuring Coordinate Direction Indexes =========================
ix%beg = -buff_size; iy%beg = 0; iz%beg = 0

if (n > 0) iy%beg = -buff_size; if (p > 0) iz%beg = -buff_size

ix%end = m - ix%beg; iy%end = n - iy%beg; iz%end = p - iz%beg
! ==================================================================

@:ALLOCATE_GLOBAL(rs(1:nb))
@:ALLOCATE_GLOBAL(vs(1:nb))
Expand All @@ -89,7 +80,7 @@ contains
!$acc update device(ps, ms)
end if

@:ALLOCATE(divu%sf(ix%beg:ix%end, iy%beg:iy%end, iz%beg:iz%end))
@:ALLOCATE(divu%sf(idwbuff(1)%beg:idwbuff(1)%end, idwbuff(2)%beg:idwbuff(2)%end, idwbuff(3)%beg:idwbuff(3)%end))
@:ACC_SETUP_SFs(divu)

@:ALLOCATE_GLOBAL(bub_adv_src(0:m, 0:n, 0:p))
Expand Down
15 changes: 4 additions & 11 deletions src/simulation/m_chemistry.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module m_chemistry

implicit none

type(int_bounds_info), private :: ix, iy, iz
type(scalar_field), private :: grads(1:3)

!$acc declare create(ix, iy, iz)
!$acc declare create(grads)

contains
Expand All @@ -29,16 +27,11 @@ contains

integer :: i

ix%beg = -buff_size
if (n > 0) then; iy%beg = -buff_size; else; iy%beg = 0; end if
if (p > 0) then; iz%beg = -buff_size; else; iz%beg = 0; end if

ix%end = m - ix%beg; iy%end = n - iy%beg; iz%end = p - iz%beg

!$acc update device(ix, iy, iz)

do i = 1, 3
@:ALLOCATE(grads(i)%sf(ix%beg:ix%end, iy%beg:iy%end, iz%beg:iz%end))
@:ALLOCATE(grads(i)%sf(&

Check warning on line 31 in src/simulation/m_chemistry.fpp

View check run for this annotation

Codecov / codecov/patch

src/simulation/m_chemistry.fpp#L31

Added line #L31 was not covered by tests
& idwbuff(1)%beg:idwbuff(1)%end, &
& idwbuff(2)%beg:idwbuff(2)%end, &
& idwbuff(3)%beg:idwbuff(3)%end))
end do

!$acc kernels
Expand Down
2 changes: 1 addition & 1 deletion src/simulation/m_data_output.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ contains
if (.not. file_exist) call s_create_directory(trim(t_step_dir))

if (prim_vars_wrt .or. (n == 0 .and. p == 0)) then
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf)
call s_convert_conservative_to_primitive_variables(q_cons_vf, q_prim_vf, idwbuff)
do i = 1, sys_size
!$acc update host(q_prim_vf(i)%sf(:,:,:))
end do
Expand Down
38 changes: 26 additions & 12 deletions src/simulation/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ module m_global_parameters

!$acc declare create(bub_idx)

! Cell Indices for the (local) interior points (O-m, O-n, 0-p).
type(int_bounds_info) :: idwint(1:3)
!$acc declare create(idwint)

! Cell Indices for the entire (local) domain. In simulation and post_process,
! this includes the buffer region. idwbuff and idwint are the same otherwise.
type(int_bounds_info) :: idwbuff(1:3)
!$acc declare create(idwbuff)

!> @name The number of fluids, along with their identifying indexes, respectively,
!! for which viscous effects, e.g. the shear and/or the volume Reynolds (Re)
!! numbers, will be non-negligible.
Expand Down Expand Up @@ -702,8 +711,6 @@ contains
integer :: i, j, k
integer :: fac

type(int_bounds_info) :: ix, iy, iz

#:if not MFC_CASE_OPTIMIZATION
! Determining the degree of the WENO polynomials
weno_polyn = (weno_order - 1)/2
Expand Down Expand Up @@ -1037,18 +1044,25 @@ contains
end if

! Configuring Coordinate Direction Indexes =========================
if (bubbles) then
ix%beg = -buff_size; iy%beg = 0; iz%beg = 0
if (n > 0) then
iy%beg = -buff_size
if (p > 0) then
iz%beg = -buff_size
end if
end if
idwint(1)%beg = 0; idwint(2)%beg = 0; idwint(3)%beg = 0
idwint(1)%end = m; idwint(2)%end = n; idwint(3)%end = p

idwbuff(1)%beg = -buff_size
if (num_dims > 1) then; idwbuff(2)%beg = -buff_size; else; idwbuff(2)%beg = 0; end if
if (num_dims > 2) then; idwbuff(3)%beg = -buff_size; else; idwbuff(3)%beg = 0; end if

ix%end = m - ix%beg; iy%end = n - iy%beg; iz%end = p - iz%beg
idwbuff(1)%end = idwint(1)%end - idwbuff(1)%beg
idwbuff(2)%end = idwint(2)%end - idwbuff(2)%beg
idwbuff(3)%end = idwint(3)%end - idwbuff(3)%beg
!$acc update device(idwint, idwbuff)
! ==================================================================

@:ALLOCATE_GLOBAL(ptil(ix%beg:ix%end, iy%beg:iy%end, iz%beg:iz%end))
! Configuring Coordinate Direction Indexes =========================
if (bubbles) then
@:ALLOCATE_GLOBAL(ptil(&

Check warning on line 1062 in src/simulation/m_global_parameters.fpp

View check run for this annotation

Codecov / codecov/patch

src/simulation/m_global_parameters.fpp#L1062

Added line #L1062 was not covered by tests
& idwbuff(1)%beg:idwbuff(1)%end, &
& idwbuff(2)%beg:idwbuff(2)%end, &
& idwbuff(3)%beg:idwbuff(3)%end))
end if

if (probe_wrt) then
Expand Down
Loading

0 comments on commit daae422

Please sign in to comment.