26 #include <queso/MultiDimensionalIndexing.h>
29 #include <queso/asserts.h>
35 const std::vector<unsigned int>& n_points )
38 queso_assert_equal_to( coord_indices.size(), n_points.size() );
41 unsigned int dim = coord_indices.size();
46 queso_assert_less( coord_indices[0], n_points[0] );
48 unsigned int global_index = coord_indices[0];
50 for(
unsigned int d = 1; d <
dim; d++ )
52 queso_assert_less( coord_indices[d], n_points[d] );
55 unsigned int idx = coord_indices[d];
57 for(
int local_d = d-1; local_d >=0; local_d -= 1)
59 idx *= n_points[local_d];
69 const std::vector<unsigned int>& n_points,
70 std::vector<unsigned int>& coord_indices )
73 unsigned int dim = n_points.size();
75 coord_indices.resize(dim);
79 unsigned int tmp = global;
81 for(
int d = dim-1; d > 0; d -= 1 )
84 coord_indices[d] = tmp/np;
85 tmp -= coord_indices[d]*np;
89 coord_indices[0] = tmp;
92 queso_assert_equal_to( global,
coordToGlobal(coord_indices,n_points) );
98 unsigned int value = 1;
100 for(
unsigned int d = 0; d < term; d++ )
102 value *= n_points[d];
static void globalToCoord(unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
Inverse of coordToGlobal map.
static unsigned int coordToGlobal(const std::vector< unsigned int > &coord_indices, const std::vector< unsigned int > &n_points)
Map coordinate indices to a singal global index.
static unsigned int compute_npoints_factor(const std::vector< unsigned int > &n_points, unsigned int term)
Helper function.