Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran BoxArray: Add nboxes function returning the number of boxes. #4096

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading