File indexing completed on 2025-09-18 09:24:52
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Types.hh"
0011 #include "corecel/cont/Array.hh"
0012 #include "corecel/cont/Range.hh"
0013 #include "geocel/Types.hh"
0014 #include "orange/OrangeData.hh"
0015
0016 namespace celeritas
0017 {
0018 namespace detail
0019 {
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 template<size_type N>
0036 class RaggedRightIndexer
0037 {
0038 public:
0039
0040
0041 using Coords = Size2;
0042
0043
0044 public:
0045
0046 explicit inline CELER_FUNCTION
0047 RaggedRightIndexer(RaggedRightIndexerData<N> const& rrd);
0048
0049
0050
0051
0052 inline CELER_FUNCTION size_type operator()(Coords coords) const;
0053
0054 private:
0055
0056
0057 RaggedRightIndexerData<N> const& rrd_;
0058 };
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 template<size_type N>
0076 class RaggedRightInverseIndexer
0077 {
0078 public:
0079
0080
0081 using Coords = Array<size_type, 2>;
0082
0083
0084 public:
0085
0086 explicit inline CELER_FUNCTION
0087 RaggedRightInverseIndexer(RaggedRightIndexerData<N> const& rrd);
0088
0089
0090 inline CELER_FUNCTION Coords operator()(size_type index) const;
0091
0092 private:
0093 RaggedRightIndexerData<N> const& rrd_;
0094 };
0095
0096
0097
0098
0099
0100
0101
0102 template<size_type N>
0103 CELER_FUNCTION
0104 RaggedRightIndexer<N>::RaggedRightIndexer(RaggedRightIndexerData<N> const& rrd)
0105 : rrd_(rrd)
0106 {
0107 }
0108
0109
0110
0111
0112
0113 template<size_type N>
0114 CELER_FUNCTION size_type RaggedRightIndexer<N>::operator()(Coords coords) const
0115 {
0116 auto const& offsets = rrd_.offsets;
0117 CELER_EXPECT(coords[0] < N);
0118 CELER_EXPECT(coords[1] < offsets[coords[0] + 1] - offsets[coords[0]]);
0119
0120 return offsets[coords[0]] + coords[1];
0121 }
0122
0123
0124
0125
0126
0127 template<size_type N>
0128 CELER_FUNCTION RaggedRightInverseIndexer<N>::RaggedRightInverseIndexer(
0129 RaggedRightIndexerData<N> const& rrd)
0130 : rrd_(rrd)
0131 {
0132 }
0133
0134
0135
0136
0137
0138 template<size_type N>
0139 CELER_FUNCTION typename RaggedRightInverseIndexer<N>::Coords
0140 RaggedRightInverseIndexer<N>::operator()(size_type index) const
0141 {
0142 auto const& offsets = rrd_.offsets;
0143 CELER_EXPECT(index < offsets.back());
0144
0145 size_type i = 0;
0146 while (index >= offsets[i + 1])
0147 {
0148 ++i;
0149 }
0150
0151 return Coords{i, index - offsets[i]};
0152 }
0153
0154
0155 }
0156 }