Warning, file /include/orange/transform/SignedPermutation.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/cont/EnumArray.hh"
0010 #include "corecel/cont/Range.hh"
0011 #include "corecel/cont/Span.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "corecel/math/Turn.hh"
0014 #include "geocel/Types.hh"
0015 #include "orange/OrangeTypes.hh"
0016
0017 namespace celeritas
0018 {
0019
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
0053
0054
0055
0056 class SignedPermutation
0057 {
0058 public:
0059
0060
0061 using SignedAxis = std::pair<char, Axis>;
0062 using SignedAxes = EnumArray<Axis, SignedAxis>;
0063 using StorageSpan = Span<real_type const, 1>;
0064 using DataArray = Array<real_type, 1>;
0065 using UIntT = short unsigned int;
0066
0067
0068 public:
0069
0070 SignedPermutation();
0071
0072
0073 explicit SignedPermutation(SignedAxes permutation);
0074
0075
0076 explicit inline CELER_FUNCTION SignedPermutation(StorageSpan s);
0077
0078
0079
0080
0081 UIntT value() const { return compressed_; }
0082
0083
0084 SignedAxes permutation() const;
0085
0086
0087 DataArray data() const;
0088
0089
0090
0091
0092 [[nodiscard]] inline CELER_FUNCTION Real3
0093 transform_up(Real3 const& pos) const;
0094
0095
0096 [[nodiscard]] inline CELER_FUNCTION Real3
0097 transform_down(Real3 const& parent_pos) const;
0098
0099
0100 [[nodiscard]] inline CELER_FUNCTION Real3 rotate_up(Real3 const& dir) const;
0101
0102
0103 [[nodiscard]] inline CELER_FUNCTION Real3
0104 rotate_down(Real3 const& parent_dir) const;
0105
0106 private:
0107
0108
0109 UIntT compressed_;
0110
0111
0112
0113
0114 static CELER_CONSTEXPR_FUNCTION UIntT max_value() { return (1 << 9) - 1; }
0115 };
0116
0117
0118
0119
0120
0121
0122 SignedPermutation make_permutation(Axis ax, QuarterTurn qtr);
0123
0124
0125
0126 inline bool operator==(SignedPermutation const& a, SignedPermutation const& b)
0127 {
0128 return a.value() == b.value();
0129 }
0130
0131 inline bool operator!=(SignedPermutation const& a, SignedPermutation const& b)
0132 {
0133 return !(a == b);
0134 }
0135
0136
0137
0138
0139
0140
0141
0142
0143 CELER_FUNCTION SignedPermutation::SignedPermutation(StorageSpan s)
0144 : compressed_{static_cast<UIntT>(s[0])}
0145 {
0146 CELER_EXPECT(s[0] >= 0 && s[0] <= static_cast<real_type>(max_value()));
0147 }
0148
0149
0150
0151
0152
0153 CELER_FORCEINLINE_FUNCTION Real3
0154 SignedPermutation::transform_up(Real3 const& pos) const
0155 {
0156 return this->rotate_up(pos);
0157 }
0158
0159
0160
0161
0162
0163 CELER_FORCEINLINE_FUNCTION Real3
0164 SignedPermutation::transform_down(Real3 const& parent_pos) const
0165 {
0166 return this->rotate_down(parent_pos);
0167 }
0168
0169
0170
0171
0172
0173 CELER_FORCEINLINE_FUNCTION Real3 SignedPermutation::rotate_up(Real3 const& d) const
0174 {
0175 Real3 result;
0176
0177 UIntT temp = compressed_;
0178 for (auto ax : range(Axis::size_))
0179 {
0180
0181 unsigned int new_ax = temp & 0b11;
0182 result[to_int(ax)] = d[new_ax];
0183 temp >>= 2;
0184 if (temp & 0b1)
0185 {
0186
0187 result[to_int(ax)] = negate(result[to_int(ax)]);
0188 }
0189 temp >>= 1;
0190 }
0191
0192 return result;
0193 }
0194
0195
0196
0197
0198
0199 CELER_FORCEINLINE_FUNCTION Real3
0200 SignedPermutation::rotate_down(Real3 const& d) const
0201 {
0202 Real3 result;
0203
0204 UIntT temp = compressed_;
0205 for (auto ax : range(Axis::size_))
0206 {
0207
0208 unsigned int new_ax = temp & 0b11;
0209 result[new_ax] = d[to_int(ax)];
0210 temp >>= 2;
0211 if (temp & 0b1)
0212 {
0213
0214 result[new_ax] = negate(result[new_ax]);
0215 }
0216 temp >>= 1;
0217 }
0218
0219 return result;
0220 }
0221
0222
0223 }