6 #ifndef WONTON_SUPPORT_MOMENT_INDEX_ 7 #define WONTON_SUPPORT_MOMENT_INDEX_ 71 int const order, std::array<int,D>
const exponents);
75 int const order, std::array<int,3>
const exponents) {
78 for (
int d = 0; d < D; ++d) {
79 assert(exponents[d] >= 0);
80 exponent_sum += exponents[d];
82 assert(exponent_sum == order);
84 index += (order+2) * (order+1) * order / 6;
85 int order1 = order - exponents[0];
86 index += (order1+1) * order1 / 2;
87 index += order1 - exponents[1];
93 int const order, std::array<int,2>
const exponents) {
96 for (
int d = 0; d < D; ++d) {
97 assert(exponents[d] >= 0);
98 exponent_sum += exponents[d];
100 assert(exponent_sum == order);
102 index += (order+1) * order / 2;
103 index += order - exponents[0];
109 int const order, std::array<int,1>
const exponents) {
111 int exponent_sum = 0;
112 for (
int d = 0; d < D; ++d) {
113 assert(exponents[d] >= 0);
114 exponent_sum += exponents[d];
116 assert(exponent_sum == order);
131 return (order+3) * (order+2) * (order+1) / 6;
136 return (order+2) * (order+1) / 2;
153 inline std::pair<int,std::array<int,D>>
index_to_moment(
int const index);
162 std::array<int,D> exponents = {};
169 if (n < (order+2)*(order+1)*order/6)
175 n -= (order+2)*(order+1)*order/6;
177 exponents[0] = order - (int) floor((sqrt((
double)8*n+1) - 1) / 2);
178 auto order1 = order - exponents[0];
180 n -= (order1+1) * order1 / 2;
182 exponents[1] = order1 - n;
186 int exponent_sum = 0;
187 for (
int d = 0; d < D; ++d) {
188 assert(exponents[d] >= 0);
189 exponent_sum += exponents[d];
191 assert(exponent_sum == order);
193 return std::make_pair(order,exponents);
203 std::array<int,D> exponents = {};
205 order = (int) floor((sqrt((
double)8*n+1) - 1) / 2);
207 n -= (order+1) * order / 2;
209 exponents[0] = order - n;
213 int exponent_sum = 0;
214 for (
int d = 0; d < D; ++d) {
215 assert(exponents[d] >= 0);
216 exponent_sum += exponents[d];
218 assert(exponent_sum == order);
220 return std::make_pair(order,exponents);
229 std::array<int,D> exponents = {};
233 exponents[0] = index;
235 int exponent_sum = 0;
236 for (
int d = 0; d < D; ++d) {
237 assert(exponents[d] >= 0);
238 exponent_sum += exponents[d];
240 assert(exponent_sum == order);
242 return std::make_pair(order,exponents);
247 #endif // WONTON_SUPPORT_MOMENT_INDEX_ std::pair< int, std::array< int, 1 > > index_to_moment< 1 >(int const index)
Definition: moment_index.h:224
constexpr int moment_to_index(int const order, std::array< int, D > const exponents)
constexpr int count_moments< 1 >(int const order)
Definition: moment_index.h:140
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
constexpr int moment_to_index< 3 >(int const order, std::array< int, 3 > const exponents)
Definition: moment_index.h:74
constexpr int moment_to_index< 2 >(int const order, std::array< int, 2 > const exponents)
Definition: moment_index.h:92
constexpr int count_moments(int const order)
constexpr int count_moments< 3 >(int const order)
Definition: moment_index.h:130
std::pair< int, std::array< int, D > > index_to_moment(int const index)
std::pair< int, std::array< int, 2 > > index_to_moment< 2 >(int const index)
Definition: moment_index.h:197
std::pair< int, std::array< int, 3 > > index_to_moment< 3 >(int const index)
Definition: moment_index.h:156
constexpr int count_moments< 2 >(int const order)
Definition: moment_index.h:135
constexpr int moment_to_index< 1 >(int const order, std::array< int, 1 > const exponents)
Definition: moment_index.h:108