File indexing completed on 2026-11-27 10:26:31
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/math/Algorithms.hh"
0012 #include "celeritas/optical/CoreTrackView.hh"
0013 #include "celeritas/optical/WavelengthShiftData.hh"
0014 #include "celeritas/optical/gen/WavelengthShiftGenerator.hh"
0015 #include "celeritas/track/CoreStateCounters.hh"
0016 #include "celeritas/track/Utils.hh"
0017
0018 #include "GeneratorAlgorithms.hh"
0019
0020 namespace celeritas
0021 {
0022 namespace optical
0023 {
0024 namespace detail
0025 {
0026
0027
0028
0029
0030
0031
0032 struct WlsGeneratorExecutor
0033 {
0034
0035
0036 CRefPtr<CoreParamsData, MemSpace::native> params;
0037 RefPtr<CoreStateData, MemSpace::native> state;
0038 NativeCRef<WavelengthShiftData> wls;
0039 NativeCRef<WavelengthShiftData> wls2;
0040 NativeRef<WlsGeneratorStateData> data;
0041 size_type buffer_size{};
0042
0043
0044
0045
0046 inline CELER_FUNCTION void operator()(ThreadId tid) const;
0047 };
0048
0049
0050
0051
0052
0053
0054
0055 CELER_FUNCTION void WlsGeneratorExecutor::operator()(ThreadId tid) const
0056 {
0057 CELER_EXPECT(state);
0058 CELER_EXPECT(data);
0059
0060 using DistId = ItemId<WlsDistributionData>;
0061
0062 auto* counters = state->init.counters.data().get();
0063
0064
0065
0066
0067
0068 if (!(tid < counters->num_vacancies))
0069 {
0070 return;
0071 }
0072
0073
0074
0075 auto offsets = data.offsets[ItemRange<size_type>(
0076 ItemId<size_type>(0), ItemId<size_type>(buffer_size))];
0077
0078
0079 size_type dist_idx = find_distribution_index(offsets, tid.get());
0080 CELER_ASSERT(dist_idx < data.distributions.size());
0081 auto& dist = data.distributions[DistId(dist_idx)];
0082 CELER_ASSERT(dist);
0083
0084
0085 CoreTrackView vacancy{
0086 *params, *state, [&] {
0087
0088
0089 TrackSlotId idx{
0090 index_before(counters->num_vacancies, ThreadId(tid.get()))};
0091 return state->init.vacancies[idx];
0092 }()};
0093
0094
0095 auto rng = vacancy.rng();
0096 if (dist.type == GeneratorType::wls)
0097 {
0098 CELER_ASSERT(wls);
0099 vacancy = WavelengthShiftGenerator(wls, dist)(rng);
0100 }
0101 else
0102 {
0103 CELER_ASSERT(wls2);
0104 vacancy = WavelengthShiftGenerator(wls2, dist)(rng);
0105 }
0106
0107
0108 atomic_add(&dist.num_photons, size_type(-1));
0109 }
0110
0111
0112 }
0113 }
0114 }