From a393d7ff7e320cefeeb55e31f1b0e0b5ac2d90ca Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Thu, 4 May 2023 12:25:59 -0700 Subject: [PATCH] Implement StructOfArray::empty() and ParticleTile::empty() for pure SoA (#3296) The implementation of `ParticleTile::empty()` was wrong for pure SoA, which led to problems in ImpactX: https://github.com/ECP-WarpX/impactx/pull/348/ The proposed changes: - [x] fix a bug or incorrect behavior in AMReX - [x] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] include documentation in the code and/or rst files, if appropriate --- Src/Particle/AMReX_ParticleTile.H | 4 ++++ Src/Particle/AMReX_StructOfArrays.H | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/Src/Particle/AMReX_ParticleTile.H b/Src/Particle/AMReX_ParticleTile.H index 0cfedd1c17a..b11bca9a2bc 100644 --- a/Src/Particle/AMReX_ParticleTile.H +++ b/Src/Particle/AMReX_ParticleTile.H @@ -746,8 +746,12 @@ struct ParticleTile SoA& GetStructOfArrays () { return m_soa_tile; } const SoA& GetStructOfArrays () const { return m_soa_tile; } + template ::type = 0> bool empty () const { return m_aos_tile.empty(); } + template ::type = 0> + bool empty () const { return m_soa_tile.empty(); } + /** * \brief Returns the total number of particles (real and neighbor) * diff --git a/Src/Particle/AMReX_StructOfArrays.H b/Src/Particle/AMReX_StructOfArrays.H index 0a62c93fd66..172b1e5d807 100644 --- a/Src/Particle/AMReX_StructOfArrays.H +++ b/Src/Particle/AMReX_StructOfArrays.H @@ -88,6 +88,12 @@ struct StructOfArrays { return 0; } + /** + * \brief Returns whether the SoA is empty (i.e. has size() == 0) + * + */ + [[nodiscard]] bool empty () const { return this->size() == 0; } + /** * \brief Returns the number of real particles (excluding neighbors) *