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