File indexing completed on 2026-01-07 10:01:42
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/EnumArray.hh"
0012 #include "corecel/data/AuxInterface.hh"
0013 #include "corecel/data/CollectionStateStore.hh"
0014 #include "celeritas/Quantities.hh"
0015 #include "celeritas/Types.hh"
0016 #include "celeritas/phys/GeneratorInterface.hh"
0017
0018 #include "OffloadData.hh"
0019 #include "../Types.hh"
0020
0021 namespace celeritas
0022 {
0023
0024
0025
0026
0027
0028
0029
0030 struct PrimaryDistributionData
0031 {
0032 size_type num_photons{};
0033 units::MevEnergy energy;
0034 Real3 position{};
0035
0036
0037 explicit CELER_FUNCTION operator bool() const
0038 {
0039 return num_photons > 0 && energy > zero_quantity();
0040 }
0041 };
0042
0043
0044
0045
0046
0047 struct GeneratorStepData
0048 {
0049 units::LightSpeed speed;
0050 Real3 pos{};
0051
0052
0053 explicit CELER_FUNCTION operator bool() const
0054 {
0055 return speed > zero_quantity();
0056 }
0057 };
0058
0059
0060
0061
0062
0063
0064
0065
0066 struct GeneratorDistributionData
0067 {
0068 size_type num_photons{};
0069 real_type time{};
0070 real_type step_length{};
0071 units::ElementaryCharge charge;
0072 OptMatId material;
0073 EnumArray<StepPoint, GeneratorStepData> points;
0074
0075
0076 explicit CELER_FUNCTION operator bool() const
0077 {
0078 return num_photons > 0 && step_length > 0 && material;
0079 }
0080 };
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 template<Ownership W, MemSpace M>
0092 struct GeneratorStateData
0093 {
0094
0095
0096 template<class T>
0097 using Items = Collection<T, W, M>;
0098
0099
0100
0101
0102 Items<GeneratorDistributionData> distributions;
0103
0104
0105 Items<size_type> offsets;
0106
0107
0108
0109
0110 explicit CELER_FUNCTION operator bool() const
0111 {
0112 return !distributions.empty() && !offsets.empty();
0113 }
0114
0115
0116 template<Ownership W2, MemSpace M2>
0117 GeneratorStateData& operator=(GeneratorStateData<W2, M2>& other)
0118 {
0119 CELER_EXPECT(other);
0120 distributions = other.distributions;
0121 offsets = other.offsets;
0122 return *this;
0123 }
0124 };
0125
0126
0127
0128
0129
0130 template<MemSpace M>
0131 struct GeneratorState : public GeneratorStateBase
0132 {
0133 CollectionStateStore<GeneratorStateData, M> store;
0134
0135
0136 explicit operator bool() const { return static_cast<bool>(store); }
0137 };
0138
0139
0140
0141
0142
0143 template<template<Ownership, MemSpace> class P, MemSpace M>
0144 void resize(GeneratorStateData<Ownership::value, M>* state,
0145 HostCRef<P> const&,
0146 StreamId,
0147 size_type size)
0148 {
0149 CELER_EXPECT(size > 0);
0150 resize(&state->distributions, size);
0151 resize(&state->offsets, size);
0152 CELER_ENSURE(*state);
0153 }
0154
0155
0156 }