diff --git a/Src/Particle/AMReX_ParticleContainer.H b/Src/Particle/AMReX_ParticleContainer.H index 2782e74335..82f05a11bd 100644 --- a/Src/Particle/AMReX_ParticleContainer.H +++ b/Src/Particle/AMReX_ParticleContainer.H @@ -1453,6 +1453,38 @@ public: /** Get the names for the int SoA components **/ std::vector GetIntSoANames () const {return m_soa_idata_names;} + /** Check if a container has a ParticleReal component + * + * @param name component name to check + * @return true if found, else false + */ + bool HasRealComp (std::string const & name); + + /** Check if a container has an Integer component + * + * @param name component name to check + * @return true if found, else false + */ + bool HasIntComp (std::string const & name); + + /** Get the ParticleReal SoA index of a component + * + * This throws a runtime exception if the component does not exist. + * + * @param name component name to query index for + * @return zero-based index + */ + int GetRealCompIndex (std::string const & name); + + /** Get the Integer SoA index of a component + * + * This throws a runtime exception if the component does not exist. + * + * @param name component name to query index for + * @return zero-based index + */ + int GetIntCompIndex (std::string const & name); + protected: template diff --git a/Src/Particle/AMReX_ParticleContainerI.H b/Src/Particle/AMReX_ParticleContainerI.H index e8add053d3..e87cda19d7 100644 --- a/Src/Particle/AMReX_ParticleContainerI.H +++ b/Src/Particle/AMReX_ParticleContainerI.H @@ -1,6 +1,9 @@ #include +#include +#include #include +#include #include #include #include @@ -82,10 +85,15 @@ ParticleContainer_impl class Allocator, class CellAssignor> +template< + typename ParticleType, + int NArrayReal, + int NArrayInt, + template class Allocator, + class CellAssignor +> void -ParticleContainer_impl :: SetSoACompileTimeNames ( +ParticleContainer_impl::SetSoACompileTimeNames ( std::vector const & rdata_name, std::vector const & idata_name ) { @@ -108,6 +116,71 @@ ParticleContainer_impl class Allocator, + class CellAssignor +> +bool +ParticleContainer_impl::HasRealComp (std::string const & name) +{ + return std::find(m_soa_rdata_names.begin(), m_soa_rdata_names.end(), name) != std::end(m_soa_rdata_names); +} + +template class Allocator, class CellAssignor> +bool +ParticleContainer_impl::HasIntComp (std::string const & name) +{ + return std::find(m_soa_idata_names.begin(), m_soa_idata_names.end(), name) != std::end(m_soa_idata_names); +} + +template< + typename ParticleType, + int NArrayReal, + int NArrayInt, + template class Allocator, + class CellAssignor +> +int +ParticleContainer_impl::GetRealCompIndex (std::string const & name) +{ + const auto it = std::find(m_soa_rdata_names.begin(), m_soa_rdata_names.end(), name); + + if (it == m_soa_rdata_names.end()) + { + throw std::runtime_error("GetRealCompIndex: Component " + name + " does not exist!"); + } + else + { + return std::distance(m_soa_rdata_names.begin(), it); + } +} + +template< + typename ParticleType, + int NArrayReal, + int NArrayInt, + template class Allocator, + class CellAssignor +> +int +ParticleContainer_impl::GetIntCompIndex (std::string const & name) +{ + const auto it = std::find(m_soa_idata_names.begin(), m_soa_idata_names.end(), name); + + if (it == m_soa_idata_names.end()) + { + throw std::runtime_error("GetIntCompIndex: Component " + name + " does not exist!"); + } + else + { + return std::distance(m_soa_idata_names.begin(), it); + } +} + template class Allocator, class CellAssignor> template