File indexing completed on 2025-09-17 08:53:48
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/math/Algorithms.hh"
0012 #include "corecel/math/Atomics.hh"
0013 #include "celeritas/global/CoreTrackView.hh"
0014
0015 #include "../ParticleTallyData.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022 struct StepDiagnosticExecutor
0023 {
0024 inline CELER_FUNCTION void
0025 operator()(celeritas::CoreTrackView const& track);
0026
0027 NativeCRef<ParticleTallyParamsData> const params;
0028 NativeRef<ParticleTallyStateData> const state;
0029 };
0030
0031
0032
0033
0034
0035 CELER_FUNCTION void
0036 StepDiagnosticExecutor::operator()(CoreTrackView const& track)
0037 {
0038 CELER_EXPECT(params);
0039 CELER_EXPECT(state);
0040
0041 using BinId = ItemId<size_type>;
0042
0043
0044 auto sim = track.sim();
0045 if (sim.status() == TrackStatus::killed)
0046 {
0047
0048 auto get = [this](size_type i, size_type j) -> size_type& {
0049 size_type index = i * params.num_bins + j;
0050 CELER_ENSURE(index < state.counts.size());
0051 return state.counts[BinId(index)];
0052 };
0053
0054 size_type num_steps
0055 = celeritas::min(sim.num_steps(), params.num_bins - 1);
0056 auto particle = track.particle().particle_id();
0057
0058
0059 auto& bin = get(particle.get(), num_steps);
0060 atomic_add(&bin, size_type{1});
0061 }
0062 }
0063
0064
0065 }
0066 }