File indexing completed on 2025-09-17 08:53:34
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Span.hh"
0012 #include "corecel/sys/ThreadId.hh"
0013 #include "geocel/random/IsotropicDistribution.hh"
0014 #include "celeritas/Quantities.hh"
0015 #include "celeritas/em/data/AtomicRelaxationData.hh"
0016
0017 #include "AtomicRelaxation.hh"
0018
0019 namespace celeritas
0020 {
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 class AtomicRelaxationHelper
0053 {
0054 public:
0055
0056 inline CELER_FUNCTION
0057 AtomicRelaxationHelper(AtomicRelaxParamsRef const& shared,
0058 AtomicRelaxStateRef const& states,
0059 ElementId el_id,
0060 TrackSlotId tid);
0061
0062
0063 explicit inline CELER_FUNCTION operator bool() const;
0064
0065
0066 inline CELER_FUNCTION size_type max_secondaries() const;
0067
0068
0069 inline CELER_FUNCTION Span<SubshellId> scratch() const;
0070
0071
0072 inline CELER_FUNCTION AtomicRelaxation
0073 build_distribution(CutoffView const& cutoffs,
0074 SubshellId shell_id,
0075 Span<Secondary> secondaries) const;
0076
0077 private:
0078 AtomicRelaxParamsRef const& shared_;
0079 AtomicRelaxStateRef const& states_;
0080 ElementId const el_id_;
0081 TrackSlotId const track_slot_;
0082 };
0083
0084
0085
0086
0087
0088
0089
0090 CELER_FUNCTION
0091 AtomicRelaxationHelper::AtomicRelaxationHelper(
0092 AtomicRelaxParamsRef const& shared,
0093 AtomicRelaxStateRef const& states,
0094 ElementId el_id,
0095 TrackSlotId tid)
0096 : shared_(shared), states_(states), el_id_(el_id), track_slot_(tid)
0097 {
0098 CELER_EXPECT(!shared_ || el_id_ < shared_.elements.size());
0099 CELER_EXPECT(!states_ || track_slot_ < states.size());
0100 CELER_EXPECT(bool(shared_) == bool(states_));
0101 }
0102
0103
0104
0105
0106
0107 CELER_FUNCTION AtomicRelaxationHelper::operator bool() const
0108 {
0109
0110 return shared_ && shared_.elements[el_id_];
0111 }
0112
0113
0114
0115
0116
0117 CELER_FUNCTION size_type AtomicRelaxationHelper::max_secondaries() const
0118 {
0119 CELER_EXPECT(*this);
0120 return shared_.elements[el_id_].max_secondary;
0121 }
0122
0123
0124
0125
0126
0127
0128
0129
0130 CELER_FUNCTION Span<SubshellId> AtomicRelaxationHelper::scratch() const
0131 {
0132 CELER_EXPECT(*this);
0133 auto offset = track_slot_.get() * shared_.max_stack_size;
0134 Span<SubshellId> all_scratch
0135 = states_.scratch[AllItems<SubshellId, MemSpace::native>{}];
0136 CELER_ENSURE(offset + shared_.max_stack_size <= all_scratch.size());
0137 return {all_scratch.data() + offset, shared_.max_stack_size};
0138 }
0139
0140
0141
0142
0143
0144 CELER_FUNCTION AtomicRelaxation
0145 AtomicRelaxationHelper::build_distribution(CutoffView const& cutoffs,
0146 SubshellId shell_id,
0147 Span<Secondary> secondaries) const
0148 {
0149 CELER_EXPECT(*this);
0150 CELER_EXPECT(secondaries.size() == this->max_secondaries());
0151 return AtomicRelaxation{
0152 shared_, cutoffs, el_id_, shell_id, secondaries, this->scratch()};
0153 }
0154
0155
0156 }