Skip to content

Commit

Permalink
Fix Lost Particle w/ Runtime Attr (#795)
Browse files Browse the repository at this point in the history
* Fix Lost Particle w/ Runtime Attr

For some processes and/or diagnostics, we add extra runtime
attributes to our beam (particle container). The logic that
collected "lost" particles in the beamline, i.e., as marked as
lost in apertures, did not account for extra runtime attributes
and thus got lost in bookkeeping.

This fixes the collection logic to be more robust and also copy
any extra runtime attributes over to the "lost" particle recording.

This was first seen with an input that used the nonlinear lens (NLL),
NLL-invariant diagnostics and an aperture at the same time.

* More Robust Implementation
  • Loading branch information
ax3l authored Jan 14, 2025
1 parent 71df0dd commit 4287df8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
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

0 comments on commit 4287df8

Please sign in to comment.