Skip to content

Commit

Permalink
Box::numPts() returns 0 for empty boxes (#3747)
Browse files Browse the repository at this point in the history
This is now necessary because the returned long int is converted to
std::uint64_t in ParallelFor.

This is a follow-up on #3742.
  • Loading branch information
WeiqunZhang authored Feb 7, 2024
1 parent a8bc0bf commit 928a485
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Src/Base/AMReX_Box.H
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,10 @@ public:
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE
Long numPts () const noexcept {
return AMREX_D_TERM( static_cast<Long>(length(0)),
*static_cast<Long>(length(1)),
*static_cast<Long>(length(2)));
return ok() ? AMREX_D_TERM( static_cast<Long>(length(0)),
*static_cast<Long>(length(1)),
*static_cast<Long>(length(2)))
: Long(0);
}

/**
Expand All @@ -350,8 +351,10 @@ public:
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE
double d_numPts () const noexcept {
BL_ASSERT(ok());
return AMREX_D_TERM(double(length(0)), *double(length(1)), *double(length(2)));
return ok() ? AMREX_D_TERM( double(length(0)),
*double(length(1)),
*double(length(2)))
: 0.0;
}

/**
Expand All @@ -361,9 +364,10 @@ public:
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE
Long volume () const noexcept {
return AMREX_D_TERM( static_cast<Long>(length(0)-btype[0]),
*static_cast<Long>(length(1)-btype[1]),
*static_cast<Long>(length(2)-btype[2]));
return ok() ? AMREX_D_TERM( static_cast<Long>(length(0)-btype[0]),
*static_cast<Long>(length(1)-btype[1]),
*static_cast<Long>(length(2)-btype[2]))
: Long(0);
}

/**
Expand Down

0 comments on commit 928a485

Please sign in to comment.