queso-0.53.0
Public Member Functions | Static Public Member Functions | Static Private Member Functions | List of all members
QUESO::InterpolationSurrogateHelper Class Reference

#include <InterpolationSurrogateHelper.h>

Public Member Functions

 InterpolationSurrogateHelper ()
 
 ~InterpolationSurrogateHelper ()
 

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 InterpolationSurrogateHelper.h.

Constructor & Destructor Documentation

QUESO::InterpolationSurrogateHelper::InterpolationSurrogateHelper ( )
inline

Definition at line 37 of file InterpolationSurrogateHelper.h.

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

Definition at line 39 of file InterpolationSurrogateHelper.h.

39 {};

Member Function Documentation

unsigned int QUESO::InterpolationSurrogateHelper::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 InterpolationSurrogateHelper.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::InterpolationSurrogateHelper::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 InterpolationSurrogateHelper.C.

References dim, queso_assert_equal_to, and queso_assert_less.

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  }
#define queso_assert_equal_to(expr1, expr2)
Definition: asserts.h:149
#define queso_assert_less(expr1, expr2)
Definition: asserts.h:155
int dim
Definition: ann2fig.cpp:81
void QUESO::InterpolationSurrogateHelper::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 InterpolationSurrogateHelper.C.

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

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

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  }
#define queso_assert_equal_to(expr1, expr2)
Definition: asserts.h:149
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.
int dim
Definition: ann2fig.cpp:81

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

Generated on Thu Jun 11 2015 13:52:36 for queso-0.53.0 by  doxygen 1.8.5