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

Fix Lost Particle w/ Runtime Attr #795

Merged
merged 2 commits into from
Jan 14, 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
7 changes: 0 additions & 7 deletions src/ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ namespace impactx {
amr_data->InitFromScratch(0.0);

// alloc particle containers
// the lost particles have an extra runtime attribute: s when it was lost
if (!amr_data->m_particles_lost->HasRealComp("s_lost"))
{
bool comm = true;
amr_data->m_particles_lost->AddRealComp("s_lost", comm);
}

// have to resize here, not in the constructor because grids have not
// been built when constructor was called.
amr_data->m_particle_container->reserveData();
Expand Down
32 changes: 31 additions & 1 deletion src/particles/CollectLost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,38 @@ namespace impactx
BL_PROFILE("impactX::collect_lost_particles");

using SrcData = ImpactXParticleContainer::ParticleTileType::ConstParticleTileDataType;

ImpactXParticleContainer& dest = *source.GetLostParticleContainer();

// Check destination has the same attributes as source + "s_lost"
for (auto & name : source.RealSoA_names())
{
amrex::Print() << "name: " << name << std::endl;
if (!dest.HasRealComp(name)) {
amrex::Print() << "adding " << name << std::endl;
dest.AddRealComp(name);
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetRealCompIndex(name) == dest.GetRealCompIndex(name),
"Source and destination Real attributes misaligned!");
}
for (auto & name : source.intSoA_names())
{
if (!dest.HasIntComp(name)) {
dest.AddIntComp(name);
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetIntCompIndex(name) == dest.GetIntCompIndex(name),
"Source and destination Int attributes misaligned!");
}
// the lost particles have an extra runtime attribute: s when it was lost
if (!dest.HasRealComp("s_lost"))
{
bool comm = true;
dest.AddRealComp("s_lost", comm);
}
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.RealSoA_names().size() + 1 == dest.RealSoA_names().size(),
"Source and destination have different Real attributes!");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.intSoA_names().size() == dest.intSoA_names().size(),
"Source and destination have different Int attributes!");

const int s_runtime_index = dest.GetRealCompIndex("s_lost") - dest.NArrayReal;

RefPart const ref_part = source.GetRefParticle();
Expand Down
Loading