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: Ensure Uniqueness of SoA Names #4299

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
11 changes: 11 additions & 0 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <memory>
#include <numeric>
#include <random>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
Expand Down Expand Up @@ -1269,6 +1270,11 @@ public:

void AddRealComp (std::string const & name, int communicate=1)
{
// names must be unique
auto const 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("AddRealComp: name '" + name + "' is already present in the SoA.");
}
m_soa_rdata_names.push_back(name);

m_runtime_comps_defined = true;
Expand Down Expand Up @@ -1297,6 +1303,11 @@ public:

void AddIntComp (std::string const & name, int communicate=1)
{
// names must be unique
auto const 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("AddIntComp: name '" + name + "' is already present in the SoA.");
}
m_soa_idata_names.push_back(name);

m_runtime_comps_defined = true;
Expand Down
7 changes: 7 additions & 0 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <AMReX_MakeParticle.H>

#include <set>
#include <string>
#include <type_traits>
#include <vector>
Expand Down Expand Up @@ -89,6 +90,12 @@ ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssig
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(rdata_name.size() == NArrayReal, "rdata_name must be equal to NArrayReal");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(idata_name.size() == NArrayInt, "idata_name must be equal to NArrayInt");

// ensure names for components are unique
std::set<std::string> const unique_r_names(rdata_name.begin(), rdata_name.end());
std::set<std::string> const unique_i_names(idata_name.begin(), idata_name.end());
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(rdata_name.size() == unique_r_names.size(), "SetSoACompileTimeNames: Provided names in rdata_name are not unique!");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(idata_name.size() == unique_i_names.size(), "SetSoACompileTimeNames: Provided names in idata_name are not unique!");

for (int i=0; i<NArrayReal; ++i)
{
m_soa_rdata_names.at(i) = rdata_name.at(i);
Expand Down
Loading