queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::MultiDimensionalIndexing Class Reference

#include <MultiDimensionalIndexing.h>

Public Member Functions

 MultiDimensionalIndexing ()
 
 ~MultiDimensionalIndexing ()
 

Static Public Member Functions

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. More...
 
static void globalToCoord (unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
 Inverse of coordToGlobal map. More...
 

Static Private Member Functions

static unsigned int compute_npoints_factor (const std::vector< unsigned int > &n_points, unsigned int term)
 Helper function. More...
 

Detailed Description

Definition at line 33 of file MultiDimensionalIndexing.h.

Constructor & Destructor Documentation

QUESO::MultiDimensionalIndexing::MultiDimensionalIndexing ( )
inline

Definition at line 37 of file MultiDimensionalIndexing.h.

37 {};
QUESO::MultiDimensionalIndexing::~MultiDimensionalIndexing ( )
inline

Definition at line 39 of file MultiDimensionalIndexing.h.

39 {};

Member Function Documentation

unsigned int QUESO::MultiDimensionalIndexing::compute_npoints_factor ( const std::vector< unsigned int > &  n_points,
unsigned int  term 
)
staticprivate

Helper function.

coordToGlobal computes: i + j*n_points[0] + k*n_points[0]*n_points[1] + ... To compute inverse we need the product of n_points terms, depending on which term we are computing. So, given n_points and the current term, we compute the correct number of products of n_points.

Definition at line 95 of file MultiDimensionalIndexing.C.

Referenced by globalToCoord().

97  {
98  unsigned int value = 1;
99 
100  for( unsigned int d = 0; d < term; d++ )
101  {
102  value *= n_points[d];
103  }
104 
105  return value;
106  }
unsigned int QUESO::MultiDimensionalIndexing::coordToGlobal ( const std::vector< unsigned int > &  coord_indices,
const std::vector< unsigned int > &  n_points 
)
static

Map coordinate indices to a singal global index.

e.g. in 3-D, you pass in i,j,k and the n_points in each of the 3 directions. This function will return the corresponding global index to which the value at i,j,k can be indexed. Ordering must be consistent between coord_indices and n_points. Must be ordered in increasing dimension. e.g. x,y,z,... The user shouldn't need to call this method, this is public mainly to facilitate testing.

Definition at line 34 of file MultiDimensionalIndexing.C.

References dim.

Referenced by QUESO::LinearLagrangeInterpolationSurrogate< V, M >::compute_interval_values(), QUESO::LinearLagrangeInterpolationSurrogate< V, M >::coordsToSingle(), and globalToCoord().

36  {
37  // Make sure the dimension is consisent
38  queso_assert_equal_to( coord_indices.size(), n_points.size() );
39 
40  // The input objects implicitly carry the dimension with them
41  unsigned int dim = coord_indices.size();
42 
43  /* Mapping is: i + j*n_i + k*n_i*n_j + l*n_i*n_j*n_k + ...
44  Initialize global_index to "i".
45  Then loop and build up each term.*/
46  queso_assert_less( coord_indices[0], n_points[0] );
47 
48  unsigned int global_index = coord_indices[0];
49 
50  for( unsigned int d = 1; d < dim; d++ )
51  {
52  queso_assert_less( coord_indices[d], n_points[d] );
53 
54  // Accumulate the current term
55  unsigned int idx = coord_indices[d];
56 
57  for( int local_d = d-1; local_d >=0; local_d -= 1)
58  {
59  idx *= n_points[local_d];
60  }
61 
62  global_index += idx;
63  }
64 
65  return global_index;
66  }
int dim
Definition: ann_test.cpp:472
void QUESO::MultiDimensionalIndexing::globalToCoord ( unsigned int  global,
const std::vector< unsigned int > &  n_points,
std::vector< unsigned int > &  coord_indices 
)
static

Inverse of coordToGlobal map.

Given the global index and the n_points in each direction, we back out the coordinate indices and return them in coord_indices.

Definition at line 68 of file MultiDimensionalIndexing.C.

References compute_npoints_factor(), coordToGlobal(), and dim.

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::set_domain_vector(), QUESO::LinearLagrangeInterpolationSurrogate< V, M >::singleToCoords(), and QUESO::TensorProductQuadrature< V, M >::TensorProductQuadrature().

71  {
72  // The input object implicitly carry's the dimension
73  unsigned int dim = n_points.size();
74 
75  coord_indices.resize(dim);
76 
77  /* coordToGlobal computes: i + j*n_points[0] + k*n_points[0]*n_points[1] + ...
78  so we use integer arithmetic and work backwards. */
79  unsigned int tmp = global;
80 
81  for( int d = dim-1; d > 0; d -= 1 )
82  {
83  unsigned int np = compute_npoints_factor( n_points, d );
84  coord_indices[d] = tmp/np;
85  tmp -= coord_indices[d]*np;
86  }
87 
88  // What's left should be our starting index
89  coord_indices[0] = tmp;
90 
91  // Sanity check: the indices we determined should map back to the global
92  queso_assert_equal_to( global, coordToGlobal(coord_indices,n_points) );
93  }
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.
int dim
Definition: ann_test.cpp:472
static unsigned int compute_npoints_factor(const std::vector< unsigned int > &n_points, unsigned int term)
Helper function.

The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:20 for queso-0.57.1 by  doxygen 1.8.5