File indexing completed on 2025-02-22 10:31:31
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/cont/Span.hh"
0013 #include "celeritas/Types.hh"
0014 #include "celeritas/global/CoreTrackData.hh"
0015 #include "celeritas/phys/PhysicsStepView.hh"
0016 #include "celeritas/phys/Secondary.hh"
0017
0018 #include "Utils.hh"
0019 #include "../SimTrackView.hh"
0020
0021 namespace celeritas
0022 {
0023 namespace detail
0024 {
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 struct LocateAliveExecutor
0035 {
0036
0037
0038 using ParamsPtr = CRefPtr<CoreParamsData, MemSpace::native>;
0039 using StatePtr = RefPtr<CoreStateData, MemSpace::native>;
0040
0041
0042
0043 ParamsPtr params;
0044 StatePtr state;
0045
0046
0047
0048
0049 inline CELER_FUNCTION void operator()(TrackSlotId tid) const;
0050
0051 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0052 {
0053
0054
0055 return (*this)(TrackSlotId{tid.unchecked_get()});
0056 }
0057 };
0058
0059
0060 CELER_FUNCTION void LocateAliveExecutor::operator()(TrackSlotId tid) const
0061 {
0062 CELER_EXPECT(tid < state->size());
0063
0064
0065 size_type num_secondaries{0};
0066 SimTrackView sim(params->sim, state->sim, tid);
0067
0068 if (sim.status() != TrackStatus::inactive)
0069 {
0070 PhysicsStepView phys(params->physics, state->physics, tid);
0071 for (auto const& secondary : phys.secondaries())
0072 {
0073 if (secondary)
0074 {
0075 ++num_secondaries;
0076 }
0077 }
0078 }
0079
0080 state->init.vacancies[tid] = [&] {
0081 if (sim.status() == TrackStatus::alive)
0082 {
0083
0084 return occupied();
0085 }
0086 else if (num_secondaries > 0
0087 && params->init.track_order != TrackOrder::init_charge)
0088 {
0089
0090
0091
0092
0093
0094 --num_secondaries;
0095 return occupied();
0096 }
0097 else
0098 {
0099
0100
0101
0102 return tid;
0103 }
0104 }();
0105 state->init.secondary_counts[tid] = num_secondaries;
0106 }
0107
0108
0109 }
0110 }