File indexing completed on 2026-11-07 10:11:38
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/data/AuxInterface.hh"
0011 #include "corecel/data/AuxStateVec.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "corecel/sys/ActionInterface.hh"
0014 #include "celeritas/optical/action/ActionInterface.hh"
0015 #include "celeritas/phys/GeneratorInterface.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace optical
0020 {
0021
0022
0023
0024
0025 class GeneratorBase : virtual public optical::OpticalStepActionInterface,
0026 virtual public AuxParamsInterface,
0027 virtual public GeneratorInterface
0028 {
0029 public:
0030
0031 GeneratorBase(ActionId id,
0032 AuxId aux_id,
0033 GeneratorId gen_id,
0034 std::string_view label,
0035 std::string_view description) noexcept(!CELERITAS_DEBUG);
0036
0037
0038
0039
0040
0041 AuxId aux_id() const final { return aux_id_; }
0042
0043
0044
0045
0046
0047
0048 ActionId action_id() const final { return sad_.action_id(); }
0049
0050 std::string_view label() const final { return sad_.label(); }
0051
0052 std::string_view description() const final { return sad_.description(); }
0053
0054
0055
0056
0057
0058
0059 StepActionOrder order() const final { return StepActionOrder::generate; }
0060
0061
0062
0063
0064
0065
0066 GeneratorId generator_id() const final { return gen_id_; }
0067
0068 GeneratorStateBase& counters(AuxStateVec&) const final;
0069
0070 GeneratorStateBase const& counters(AuxStateVec const&) const final;
0071
0072
0073
0074 template<MemSpace M>
0075 inline void update_counters(optical::CoreState<M>&) const;
0076
0077 private:
0078 StaticActionData sad_;
0079 AuxId aux_id_;
0080 GeneratorId gen_id_;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089 template<MemSpace M>
0090 void GeneratorBase::update_counters(optical::CoreState<M>& state) const
0091 {
0092 CELER_EXPECT(state.aux());
0093
0094 auto counters = state.sync_get_counters();
0095 auto& gen_counters = this->counters(*state.aux());
0096
0097
0098 size_type num_gen
0099 = min(counters.num_vacancies, gen_counters.counters.num_pending);
0100
0101
0102 counters.num_pending -= num_gen;
0103 counters.num_generated += num_gen;
0104 counters.num_vacancies -= num_gen;
0105
0106
0107 gen_counters.counters.num_pending -= num_gen;
0108 gen_counters.counters.num_generated += num_gen;
0109 gen_counters.accum.num_generated += num_gen;
0110
0111
0112
0113 counters.num_active = state.size() - counters.num_vacancies;
0114 state.sync_put_counters(counters);
0115 }
0116
0117
0118 }
0119 }