Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PC: SoA Name Helpers #4300

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,38 @@ public:
/** Get the names for the int SoA components **/
std::vector<std::string> 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 <class RTYPE>
Expand Down
79 changes: 76 additions & 3 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include <AMReX_MakeParticle.H>

#include <algorithm>
#include <iterator>
#include <set>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>
Expand Down Expand Up @@ -82,10 +85,15 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
}
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
template<
typename ParticleType,
int NArrayReal,
int NArrayInt,
template<class> class Allocator,
class CellAssignor
>
void
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor> :: SetSoACompileTimeNames (
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::SetSoACompileTimeNames (
std::vector<std::string> const & rdata_name, std::vector<std::string> const & idata_name
)
{
Expand All @@ -108,6 +116,71 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
}
}

template<
typename ParticleType,
int NArrayReal,
int NArrayInt,
template<class> class Allocator,
class CellAssignor
>
bool
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::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 <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
bool
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::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> class Allocator,
class CellAssignor
>
int
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::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> class Allocator,
class CellAssignor
>
int
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::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 <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
template <typename P, typename Assignor>
Expand Down
Loading