Skip to content

Commit

Permalink
Fortran BoxArray: Add nboxes function returning the number of boxes. (#…
Browse files Browse the repository at this point in the history
…4096)

Note that the function returns the total number of boxes including ones
not owned by the MPI process calling the function.
  • Loading branch information
WeiqunZhang authored Aug 19, 2024
1 parent 09977dd commit c49d35e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Src/F_Interfaces/Base/AMReX_boxarray_fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ extern "C" {
ba->maxSize(iv);
}

Long amrex_fi_boxarray_nboxes (const BoxArray* ba)
{
return ba->size();
}

void amrex_fi_boxarray_get_box (const BoxArray* ba, int i, int lo[3], int hi[3])
{
const Box& bx = (*ba)[i];
Expand Down
24 changes: 23 additions & 1 deletion Src/F_Interfaces/Base/AMReX_boxarray_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module amrex_boxarray_module
procedure :: move => amrex_boxarray_move ! transfer ownership
generic :: maxSize => amrex_boxarray_maxsize_int, & ! make the boxes smaller
& amrex_boxarray_maxsize_int3, amrex_boxarray_maxsize_iv
procedure :: nboxes => amrex_boxarray_nboxes
procedure :: get_box => amrex_boxarray_get_box
procedure :: nodal_type => amrex_boxarray_nodal_type ! get index type
procedure :: num_pts => amrex_boxarray_num_pts
Expand Down Expand Up @@ -82,6 +83,13 @@ subroutine amrex_fi_boxarray_maxsize (ba,s) bind(c)
integer(c_int), intent(in) :: s(3)
end subroutine amrex_fi_boxarray_maxsize

pure function amrex_fi_boxarray_nboxes (ba) bind(c)
import
implicit none
type(c_ptr), value, intent(in) :: ba
integer(amrex_long) :: amrex_fi_boxarray_nboxes
end function amrex_fi_boxarray_nboxes

subroutine amrex_fi_boxarray_get_box (ba,i,lo,hi) bind(c)
import
implicit none
Expand Down Expand Up @@ -194,6 +202,16 @@ subroutine amrex_boxarray_maxsize_iv (this, s)
call amrex_fi_boxarray_maxsize(this%p, s)
end subroutine amrex_boxarray_maxsize_iv

pure function amrex_boxarray_nboxes (this) result(n)
class(amrex_boxarray), intent(in) :: this
integer(amrex_long) :: n
if (c_associated(this%p)) then
n = amrex_fi_boxarray_nboxes(this%p)
else
n = 0
end if
end function amrex_boxarray_nboxes

function amrex_boxarray_get_box (this, i) result(bx)
class(amrex_boxarray) :: this
integer, intent(in) :: i
Expand All @@ -220,7 +238,11 @@ end function amrex_boxarray_nodal_type
pure function amrex_boxarray_num_pts (this) result(n)
class(amrex_boxarray), intent(in) :: this
integer(amrex_long) :: n
n = amrex_fi_boxarray_numpts(this%p)
if (c_associated(this%p)) then
n = amrex_fi_boxarray_numpts(this%p)
else
n = 0
end if
end function amrex_boxarray_num_pts

pure function amrex_boxarray_intersects_box (this, bx) result(r)
Expand Down

0 comments on commit c49d35e

Please sign in to comment.