File indexing completed on 2025-02-22 10:31:32
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <type_traits>
0011
0012 #include "corecel/Types.hh"
0013 #include "corecel/math/Atomics.hh"
0014
0015 #include "../SimpleCaloData.hh"
0016 #include "../StepData.hh"
0017
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022
0023
0024
0025
0026
0027
0028
0029
0030 struct SimpleCaloExecutor
0031 {
0032 NativeRef<StepStateData> const step;
0033 NativeRef<SimpleCaloStateData> calo;
0034
0035 inline CELER_FUNCTION void operator()(TrackSlotId tid);
0036 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid)
0037 {
0038 return (*this)(TrackSlotId{tid.unchecked_get()});
0039 }
0040 };
0041
0042
0043
0044
0045
0046
0047
0048 CELER_FUNCTION void SimpleCaloExecutor::operator()(TrackSlotId tid)
0049 {
0050 CELER_EXPECT(tid < step.data.detector.size());
0051 CELER_EXPECT(!step.data.energy_deposition.empty());
0052
0053 DetectorId det = step.data.detector[tid];
0054 if (!det)
0055 {
0056
0057 return;
0058 }
0059
0060 static_assert(
0061 std::is_same_v<NativeRef<StepStateDataImpl>::Energy::unit_type,
0062 NativeRef<SimpleCaloStateData>::EnergyUnits>);
0063 real_type edep = step.data.energy_deposition[tid].value();
0064 CELER_ASSERT(edep > 0);
0065 CELER_ASSERT(det < calo.energy_deposition.size());
0066 atomic_add(&calo.energy_deposition[det], edep);
0067 }
0068
0069
0070 }
0071 }