File indexing completed on 2025-02-22 10:31:23
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <memory>
0011 #include <vector>
0012
0013 #include "corecel/Types.hh"
0014 #include "corecel/cont/Span.hh"
0015 #include "corecel/data/CollectionStateStore.hh"
0016 #include "celeritas/Types.hh"
0017 #include "celeritas/geo/GeoFwd.hh"
0018 #include "celeritas/phys/Primary.hh"
0019 #include "celeritas/random/RngParamsFwd.hh"
0020 #include "celeritas/track/TrackInitData.hh"
0021
0022 #include "CoreState.hh"
0023 #include "CoreTrackData.hh"
0024
0025 namespace celeritas
0026 {
0027
0028 class CoreParams;
0029 struct Primary;
0030 class ExtendFromPrimariesAction;
0031
0032 class ActionSequence;
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 struct StepperInput
0044 {
0045 std::shared_ptr<CoreParams const> params;
0046 StreamId stream_id{};
0047 size_type num_track_slots{};
0048 bool action_times{false};
0049
0050
0051 explicit operator bool() const
0052 {
0053 return params && stream_id && num_track_slots > 0;
0054 }
0055 };
0056
0057
0058
0059
0060
0061 struct StepperResult
0062 {
0063 size_type generated{};
0064 size_type queued{};
0065 size_type active{};
0066 size_type alive{};
0067
0068
0069 explicit operator bool() const { return queued > 0 || alive > 0; }
0070 };
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 class StepperInterface
0083 {
0084 public:
0085
0086
0087 using Input = StepperInput;
0088 using ActionSequenceT = ActionSequence;
0089 using SpanConstPrimary = Span<Primary const>;
0090 using result_type = StepperResult;
0091 using SPState = std::shared_ptr<CoreStateInterface>;
0092
0093
0094 public:
0095
0096 virtual ~StepperInterface();
0097
0098
0099 virtual void warm_up() = 0;
0100
0101
0102 virtual StepperResult operator()() = 0;
0103
0104
0105 virtual StepperResult operator()(SpanConstPrimary primaries) = 0;
0106
0107
0108 virtual void reseed(EventId event_id) = 0;
0109
0110
0111 virtual ActionSequenceT const& actions() const = 0;
0112
0113
0114 virtual CoreStateInterface const& state() const = 0;
0115
0116
0117 virtual SPState sp_state() = 0;
0118
0119 protected:
0120 StepperInterface() = default;
0121 CELER_DEFAULT_COPY_MOVE(StepperInterface);
0122 };
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 template<MemSpace M>
0144 class Stepper final : public StepperInterface
0145 {
0146 public:
0147
0148
0149 using StateRef = CoreStateData<Ownership::reference, M>;
0150
0151
0152 public:
0153
0154 explicit Stepper(Input input);
0155
0156
0157 ~Stepper();
0158
0159
0160 void warm_up() final;
0161
0162
0163 StepperResult operator()() final;
0164
0165
0166 StepperResult operator()(SpanConstPrimary primaries) final;
0167
0168
0169 void reseed(EventId event_id) final;
0170
0171
0172 ActionSequenceT const& actions() const final { return *actions_; }
0173
0174
0175 StateRef const& state_ref() const { return state_->ref(); }
0176
0177
0178 CoreStateInterface const& state() const final { return *state_; }
0179
0180
0181 void reset_state() { state_->reset(); }
0182
0183
0184 SPState sp_state() final { return state_; }
0185
0186 private:
0187
0188 std::shared_ptr<CoreParams const> params_;
0189
0190 std::shared_ptr<ExtendFromPrimariesAction const> primaries_action_;
0191
0192 std::shared_ptr<CoreState<M>> state_;
0193
0194 std::shared_ptr<ActionSequenceT> actions_;
0195 };
0196
0197
0198
0199
0200
0201 extern template class Stepper<MemSpace::host>;
0202 extern template class Stepper<MemSpace::device>;
0203
0204
0205 }