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 1e5d663
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 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.
*
* 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 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 1e5d663

Please sign in to comment.