diff --git a/Src/Particle/AMReX_StructOfArrays.H b/Src/Particle/AMReX_StructOfArrays.H index 00097e445b7..9e1697a9b20 100644 --- a/Src/Particle/AMReX_StructOfArrays.H +++ b/Src/Particle/AMReX_StructOfArrays.H @@ -41,10 +41,11 @@ struct StructOfArrays { * @param index component with 0...NReal-1 compile-time and NReal... runtime arguments */ [[nodiscard]] RealVector& GetRealData (const int index) { - AMREX_ASSERT(index >= 0 && index < NReal + static_cast(m_runtime_rdata.size())); - if (index >= 0 && index < NReal) return m_rdata[index]; - else { - AMREX_ASSERT(m_defined); + if (index >= 0 && index < NReal) { + return m_rdata[index]; + } else { + AMREX_ASSERT((index-NReal) < static_cast(m_runtime_rdata.size()) + && m_defined); return m_runtime_rdata[index - NReal]; } } @@ -54,10 +55,11 @@ struct StructOfArrays { * @param index component with 0...NReal-1 compile-time and NReal... runtime arguments */ [[nodiscard]] const RealVector& GetRealData (const int index) const { - AMREX_ASSERT(index >= 0 && index < NReal + static_cast(m_runtime_rdata.size())); - if (index >= 0 && index < NReal) return m_rdata[index]; - else { - AMREX_ASSERT(m_defined); + if (index >= 0 && index < NReal) { + return m_rdata[index]; + } else { + AMREX_ASSERT((index-NReal) < static_cast(m_runtime_rdata.size()) + && m_defined); return m_runtime_rdata[index - NReal]; } } @@ -67,10 +69,11 @@ struct StructOfArrays { * @param index component with 0...NInt-1 compile-time and NInt... runtime arguments */ [[nodiscard]] IntVector& GetIntData (const int index) { - AMREX_ASSERT(index >= 0 && index < NInt + static_cast(m_runtime_idata.size())); - if (index >= 0 && index < NInt) return m_idata[index]; - else { - AMREX_ASSERT(m_defined); + if (index >= 0 && index < NInt) { + return m_idata[index]; + } else { + AMREX_ASSERT((index-NInt) < static_cast(m_runtime_idata.size()) + && m_defined); return m_runtime_idata[index - NInt]; } } @@ -81,10 +84,11 @@ struct StructOfArrays { * @return */ [[nodiscard]] const IntVector& GetIntData (const int index) const { - AMREX_ASSERT(index >= 0 && index < NInt + static_cast(m_runtime_idata.size())); - if (index >= 0 && index < NInt) return m_idata[index]; - else { - AMREX_ASSERT(m_defined); + if (index >= 0 && index < NInt) { + return m_idata[index]; + } else { + AMREX_ASSERT((index-NInt) < static_cast(m_runtime_idata.size()) + && m_defined); return m_runtime_idata[index - NInt]; } } @@ -148,8 +152,12 @@ struct StructOfArrays { void resize (size_t count) { - for (int i = 0; i < NReal; ++i) m_rdata[i].resize(count); - for (int i = 0; i < NInt; ++i) m_idata[i].resize(count); + if constexpr (NReal > 0) { + for (int i = 0; i < NReal; ++i) m_rdata[i].resize(count); + } + if constexpr (NInt > 0) { + for (int i = 0; i < NInt; ++i) m_idata[i].resize(count); + } for (int i = 0; i < int(m_runtime_rdata.size()); ++i) m_runtime_rdata[i].resize(count); for (int i = 0; i < int(m_runtime_idata.size()); ++i) m_runtime_idata[i].resize(count); }