Skip to content

Commit

Permalink
Add .is_valid()
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Jan 31, 2024
1 parent b1b0ffb commit 2d9510f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Src/Particle/AMReX_Particle.H
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,19 @@ struct ParticleIDWrapper
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void flip_valid () noexcept
{
// the leftmost bit is our id sign - we will XOR it with 1 to flip it
// The uppermost bit is our id inverse sign.
// We will XOR it with 1 to flip it.
m_idata ^= static_cast<uint64_t>(1) << 63;
}

/** Check the sign of the id.
/** Check the particle is valid, via the sign of the id.
*
* Returns false if the id is positive, otherwise true (invalid particle).
* Returns true if the particle is valid (the id is positive), otherwise false (invalid particle).
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool negative () const noexcept
bool is_valid () const noexcept
{
// the leftmost bit is our id sign
// the leftmost bit is our id's inverse sign
return m_idata >> 63;
}
};
Expand Down Expand Up @@ -199,13 +200,13 @@ struct ConstParticleIDWrapper

/** Check the sign of the id.
*
* Returns false if the id is positive, otherwise true (invalid particle).
* Returns true if the id is positive, otherwise false (invalid particle).
*/
[[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool negative () const noexcept
bool is_valid () const noexcept
{
// the leftmost bit is our id's inverse sign
return !(m_idata >> 63);
return m_idata >> 63;
}
};

Expand Down

0 comments on commit 2d9510f

Please sign in to comment.