From 5e58cdb20169770d3b5b01f54d7b6bc77cdc8bb6 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 10 Jan 2025 15:50:15 -0800 Subject: [PATCH] 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. --- src/particles/CollectLost.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/particles/CollectLost.cpp b/src/particles/CollectLost.cpp index d2390c268..b905d126d 100644 --- a/src/particles/CollectLost.cpp +++ b/src/particles/CollectLost.cpp @@ -55,8 +55,26 @@ 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.GetRealSoANames()) + { + if (!dest.HasRealComp(name)) { + dest.AddRealComp(name); + } + } + for (auto & name : source.GetIntSoANames()) + { + if (!dest.HasIntComp(name)) { + dest.AddIntComp(name); + } + } + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetRealSoANames().size() + 1 == dest.GetRealSoANames().size(), + "Source and destination have different Real attributes!"); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(source.GetIntSoANames().size() == dest.GetIntSoANames().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();