File indexing completed on 2025-09-18 09:09:15
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <vector>
0010
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.hh"
0014 #include "corecel/data/CollectionAlgorithms.hh"
0015 #include "corecel/data/CollectionBuilder.hh"
0016 #include "corecel/sys/ThreadId.hh"
0017 #include "celeritas/Quantities.hh"
0018 #include "celeritas/Types.hh"
0019
0020 namespace celeritas
0021 {
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 struct LoopingThreshold
0043 {
0044 using Energy = units::MevEnergy;
0045
0046 size_type max_subthreshold_steps{10};
0047 size_type max_steps{100};
0048 Energy threshold_energy{250};
0049
0050
0051 explicit CELER_FUNCTION operator bool() const
0052 {
0053 return max_subthreshold_steps > 0 && max_steps > 0
0054 && threshold_energy >= zero_quantity();
0055 }
0056 };
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069 template<Ownership W, MemSpace M>
0070 struct SimParamsData
0071 {
0072
0073
0074 template<class T>
0075 using ParticleItems = Collection<T, W, M, ParticleId>;
0076
0077
0078
0079 ParticleItems<LoopingThreshold> looping;
0080 size_type max_steps{};
0081
0082
0083
0084
0085 explicit CELER_FUNCTION operator bool() const { return max_steps > 0; }
0086
0087
0088 template<Ownership W2, MemSpace M2>
0089 SimParamsData& operator=(SimParamsData<W2, M2> const& other)
0090 {
0091 CELER_EXPECT(other);
0092 looping = other.looping;
0093 max_steps = other.max_steps;
0094 return *this;
0095 }
0096 };
0097
0098
0099
0100
0101
0102 struct SimTrackInitializer
0103 {
0104 TrackId track_id;
0105 TrackId parent_id;
0106 EventId event_id;
0107 real_type time{0};
0108
0109
0110 explicit CELER_FUNCTION operator bool() const
0111 {
0112 return track_id && event_id;
0113 }
0114 };
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126 template<Ownership W, MemSpace M>
0127 struct SimStateData
0128 {
0129
0130
0131 template<class T>
0132 using Items = celeritas::StateCollection<T, W, M>;
0133
0134
0135
0136 Items<TrackId> track_ids;
0137 Items<TrackId> parent_ids;
0138 Items<EventId> event_ids;
0139 Items<size_type> num_steps;
0140 Items<size_type> num_looping_steps;
0141
0142 Items<real_type> time;
0143
0144 Items<TrackStatus> status;
0145 Items<real_type> step_length;
0146 Items<ActionId> post_step_action;
0147 Items<ActionId> along_step_action;
0148
0149
0150
0151
0152 explicit CELER_FUNCTION operator bool() const
0153 {
0154 return !track_ids.empty() && !parent_ids.empty() && !event_ids.empty()
0155 && !num_steps.empty() && !time.empty() && !status.empty()
0156 && !step_length.empty() && !post_step_action.empty()
0157 && !along_step_action.empty();
0158 }
0159
0160
0161 CELER_FUNCTION TrackSlotId::size_type size() const
0162 {
0163 return track_ids.size();
0164 }
0165
0166
0167 template<Ownership W2, MemSpace M2>
0168 SimStateData& operator=(SimStateData<W2, M2>& other)
0169 {
0170 CELER_EXPECT(other);
0171 track_ids = other.track_ids;
0172 parent_ids = other.parent_ids;
0173 event_ids = other.event_ids;
0174 num_steps = other.num_steps;
0175 num_looping_steps = other.num_looping_steps;
0176 time = other.time;
0177 status = other.status;
0178 step_length = other.step_length;
0179 post_step_action = other.post_step_action;
0180 along_step_action = other.along_step_action;
0181 return *this;
0182 }
0183 };
0184
0185
0186
0187
0188
0189 template<MemSpace M>
0190 void resize(SimStateData<Ownership::value, M>* data,
0191 HostCRef<SimParamsData> const& params,
0192 size_type size)
0193 {
0194 CELER_EXPECT(size > 0);
0195
0196 resize(&data->track_ids, size);
0197 resize(&data->parent_ids, size);
0198 resize(&data->event_ids, size);
0199 resize(&data->num_steps, size);
0200 if (!params.looping.empty())
0201 {
0202 resize(&data->num_looping_steps, size);
0203 }
0204 resize(&data->time, size);
0205
0206 resize(&data->status, size);
0207 fill(TrackStatus::inactive, &data->status);
0208
0209 resize(&data->step_length, size);
0210 resize(&data->post_step_action, size);
0211 resize(&data->along_step_action, size);
0212
0213 CELER_ENSURE(*data);
0214 }
0215
0216
0217 }