queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::LinearLagrangeInterpolationSurrogate< V, M > Class Template Reference

Linear Lagrange interpolation surrogate. More...

#include <LinearLagrangeInterpolationSurrogate.h>

Inheritance diagram for QUESO::LinearLagrangeInterpolationSurrogate< V, M >:
QUESO::InterpolationSurrogateBase< V, M > QUESO::SurrogateBase< V >

Public Member Functions

 LinearLagrangeInterpolationSurrogate (const InterpolationSurrogateData< V, M > &data)
 Constructor. More...
 
virtual ~LinearLagrangeInterpolationSurrogate ()
 
virtual double evaluate (const V &domainVector) const
 Evaluates value of the interpolant for the given domainVector. More...
 
unsigned int n_coeffs () const
 The number of coeffs for interpolating. More...
 
- Public Member Functions inherited from QUESO::InterpolationSurrogateBase< V, M >
 InterpolationSurrogateBase (const InterpolationSurrogateData< V, M > &data)
 Constructor. More...
 
virtual ~InterpolationSurrogateBase ()
 
- Public Member Functions inherited from QUESO::SurrogateBase< V >
 SurrogateBase ()
 
virtual ~SurrogateBase ()
 

Protected Member Functions

void compute_interval_indices (const V &domainVector, std::vector< unsigned int > &indices) const
 Helper function to get lower bound indices for each dimension. More...
 
void compute_interval_values (const std::vector< unsigned int > &indices, std::vector< double > &x_min, std::vector< double > &x_max, std::vector< double > &values) const
 Helper function to populate bounding values for the intervals in each dimension. More...
 
double eval_interpolant (const std::vector< double > &x_min, const std::vector< double > &x_max, const std::vector< double > &values, const V &domainVector) const
 Evaluate multidimensional linear Lagrange interpolant. More...
 
unsigned int coordsToSingle (const std::vector< unsigned int > &indices) const
 Convert local indices to single "global" index. More...
 
void singleToCoords (unsigned int global, std::vector< unsigned int > &indices) const
 Inverse of map computed in coordsToSingle. More...
 
double tensor_product_lagrange (const std::vector< double > &x_min, const std::vector< double > &x_max, const std::vector< unsigned int > &indices, const V &domainVector) const
 Compute multidimensional Lagrange polynomial as tensor product of 1D polynomials. More...
 
double lagrange_poly (double x0, double x1, double x, unsigned int index) const
 Evaluate a 1-D Lagrange polynomial at point x. More...
 

Private Member Functions

 LinearLagrangeInterpolationSurrogate ()
 

Additional Inherited Members

- Protected Attributes inherited from QUESO::InterpolationSurrogateBase< V, M >
const
InterpolationSurrogateData< V,
M > & 
m_data
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::LinearLagrangeInterpolationSurrogate< V, M >

Linear Lagrange interpolation surrogate.

Aribritary dimension linear Lagrange interpolant. Uses a structured grid to interpolate values given by data passed to the constructor.

Definition at line 44 of file LinearLagrangeInterpolationSurrogate.h.

Constructor & Destructor Documentation

Constructor.

The data object should be already fully populated when constructing this object. The user can directly set values or use the InterpolationSurrogateBuilder object to populate the data.

Definition at line 37 of file LinearLagrangeInterpolationSurrogate.C.

38  : InterpolationSurrogateBase<V,M>(data)
39  {}
template<class V = GslVector, class M = GslMatrix>
virtual QUESO::LinearLagrangeInterpolationSurrogate< V, M >::~LinearLagrangeInterpolationSurrogate ( )
inlinevirtual

Definition at line 54 of file LinearLagrangeInterpolationSurrogate.h.

54 {};
template<class V = GslVector, class M = GslMatrix>
QUESO::LinearLagrangeInterpolationSurrogate< V, M >::LinearLagrangeInterpolationSurrogate ( )
private

Member Function Documentation

template<class V , class M >
void QUESO::LinearLagrangeInterpolationSurrogate< V, M >::compute_interval_indices ( const V &  domainVector,
std::vector< unsigned int > &  indices 
) const
protected

Helper function to get lower bound indices for each dimension.

domainVector contains the current value at which want want to interpolate. We use that to figure out the bounding values in each dimension. Then we populate indices with the lower index.

Definition at line 66 of file LinearLagrangeInterpolationSurrogate.C.

68  {
69  queso_assert_equal_to( domainVector.sizeGlobal(), this->m_data.dim() );
70  queso_assert_equal_to( indices.size(), this->m_data.dim() );
71 
72  for( unsigned int d = 0; d < this->m_data.dim(); d++ )
73  {
74  double spacing = this->m_data.spacing(d);
75  indices[d] = std::floor( (domainVector[d] - this->m_data.x_min(d))/spacing );
76 
77  // Index should be less than the number of point along this dimension
78  queso_assert_less( indices[d], this->m_data.get_n_points()[d] );
79  }
80  }
const InterpolationSurrogateData< V, M > & m_data
template<class V , class M >
void QUESO::LinearLagrangeInterpolationSurrogate< V, M >::compute_interval_values ( const std::vector< unsigned int > &  indices,
std::vector< double > &  x_min,
std::vector< double > &  x_max,
std::vector< double > &  values 
) const
protected

Helper function to populate bounding values for the intervals in each dimension.

By convention, it is assumed that the indices vector contains the lower bound index. See compute_interval_indices.

Definition at line 83 of file LinearLagrangeInterpolationSurrogate.C.

References QUESO::MultiDimensionalIndexing::coordToGlobal().

87  {
88  queso_assert_equal_to( x_min.size(), this->m_data.dim() );
89  queso_assert_equal_to( x_max.size(), this->m_data.dim() );
90  queso_assert_equal_to( values.size(), this->n_coeffs() );
91  queso_assert_equal_to( indices.size(), this->m_data.dim() );
92 
93  // First, use the lower bound (global) indices to populate x_min, x_max
94  for( unsigned int d = 0; d < this->m_data.dim(); d++ )
95  {
96  x_min[d] = this->m_data.get_x( d, indices[d] );
97  x_max[d] = x_min[d] + this->m_data.spacing( d );
98  }
99 
100  // Now populate the values.
101  std::vector<unsigned int> local_indices(this->m_data.dim());
102  std::vector<unsigned int> global_indices(this->m_data.dim());
103  for( unsigned int n = 0 ; n < this->n_coeffs(); n++ )
104  {
105  // Figure out local indices (each coordinate is 0 or 1)
106  this->singleToCoords(n,local_indices);
107 
108  /* For each dimension, if the local index is 0, use the lower
109  bound of the global index. If the local index is 1, use the
110  "upper" global index.
111 
112  In 2-D:
113  The lower left corner of the element will have local_indices = [0,0];
114  Then, global_indices = [ indices[0], indices[1] ];
115  The upper right corner will have local_indices = [1,1];
116  Then, global_indices = [ indices[0]+1, indices[1]+1 ]; */
117  for( unsigned int d = 0; d < this->m_data.dim(); d++ )
118  {
119  if( local_indices[d] == 0 )
120  global_indices[d] = indices[d];
121 
122  else if( local_indices[d] == 1 )
123  global_indices[d] = indices[d]+1;
124 
125  // This shouldn't happen
126  else
127  queso_error();
128  }
129 
130  /* Now that we have the global indices for each coordinate,
131  we get the "global" index. This is the index into the global
132  values array */
133  unsigned int global = MultiDimensionalIndexing::coordToGlobal( global_indices, this->m_data.get_n_points() );
134  values[n] = this->m_data.get_value(global);
135  }
136  }
const InterpolationSurrogateData< V, M > & m_data
void singleToCoords(unsigned int global, std::vector< unsigned int > &indices) const
Inverse of map computed in coordsToSingle.
unsigned int n_coeffs() const
The number of coeffs for interpolating.
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.
template<class V , class M >
unsigned int QUESO::LinearLagrangeInterpolationSurrogate< V, M >::coordsToSingle ( const std::vector< unsigned int > &  indices) const
protected

Convert local indices to single "global" index.

This is for handling the local ordering of an arbitrary dimensional linear Lagrange elements. The function will look like \( \sum_{ijkl...} f_{ijkl...} N_{ijkl...} \) so we want a convenient way to map \( ijkl... \) to a single integer. Then, we can order all our data this way and easily index into it. We can do this since each of \( ijkl... \) is either 0 or 1.

Definition at line 166 of file LinearLagrangeInterpolationSurrogate.C.

References QUESO::MultiDimensionalIndexing::coordToGlobal().

167  {
168  unsigned int local_dim = 2;
169  std::vector<unsigned int> n_points( this->m_data.dim(), local_dim );
170 
171  /* We're abusing this function as it does what we need to with local_dim = 2
172  for all entries of n_points. */
173  return MultiDimensionalIndexing::coordToGlobal( indices, n_points );
174  }
const InterpolationSurrogateData< V, M > & m_data
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.
template<class V , class M >
double QUESO::LinearLagrangeInterpolationSurrogate< V, M >::eval_interpolant ( const std::vector< double > &  x_min,
const std::vector< double > &  x_max,
const std::vector< double > &  values,
const V &  domainVector 
) const
protected

Evaluate multidimensional linear Lagrange interpolant.

This is just a tensor product of one-dimensional interpolants

Definition at line 139 of file LinearLagrangeInterpolationSurrogate.C.

143  {
144  queso_assert_equal_to( x_min.size(), this->m_data.dim() );
145  queso_assert_equal_to( x_max.size(), this->m_data.dim() );
146  queso_assert_equal_to( values.size(), this->n_coeffs() );
147  queso_assert_equal_to( domainVector.sizeGlobal(), this->m_data.dim() );
148 
149  double interp_value = 0.0;
150 
151  std::vector<unsigned int> indices( this->m_data.dim() );
152 
153  for( unsigned int n = 0; n < this->n_coeffs(); n++ )
154  {
155  this->singleToCoords( n, indices );
156 
157  double shape_fn = this->tensor_product_lagrange( x_min, x_max, indices, domainVector );
158 
159  interp_value += values[n]*shape_fn;
160  }
161 
162  return interp_value;
163  }
const InterpolationSurrogateData< V, M > & m_data
void singleToCoords(unsigned int global, std::vector< unsigned int > &indices) const
Inverse of map computed in coordsToSingle.
unsigned int n_coeffs() const
The number of coeffs for interpolating.
double tensor_product_lagrange(const std::vector< double > &x_min, const std::vector< double > &x_max, const std::vector< unsigned int > &indices, const V &domainVector) const
Compute multidimensional Lagrange polynomial as tensor product of 1D polynomials. ...
template<class V , class M >
double QUESO::LinearLagrangeInterpolationSurrogate< V, M >::evaluate ( const V &  domainVector) const
virtual

Evaluates value of the interpolant for the given domainVector.

Implements QUESO::SurrogateBase< V >.

Definition at line 42 of file LinearLagrangeInterpolationSurrogate.C.

43  {
44  /* Populate indices. These are the lower bound global indices for the
45  "element" containing the domainVector */
46  std::vector<unsigned int> indices(this->m_data.dim());
47  this->compute_interval_indices(domainVector, indices);
48 
49  // lower bound coordinates
50  std::vector<double> x_min(this->m_data.dim());
51 
52  // upper bound coordinates
53  std::vector<double> x_max(this->m_data.dim());
54 
55  // Function value at each of the "nodes" for the "element"
56  std::vector<double> values(this->n_coeffs());
57 
58  // Use the indices to populate the x_min, etc. structures
59  this->compute_interval_values( indices, x_min, x_max, values );
60 
61  // Now evaluate the interpolant
62  return this->eval_interpolant( x_min, x_max, values, domainVector );
63  }
void compute_interval_values(const std::vector< unsigned int > &indices, std::vector< double > &x_min, std::vector< double > &x_max, std::vector< double > &values) const
Helper function to populate bounding values for the intervals in each dimension.
double eval_interpolant(const std::vector< double > &x_min, const std::vector< double > &x_max, const std::vector< double > &values, const V &domainVector) const
Evaluate multidimensional linear Lagrange interpolant.
const InterpolationSurrogateData< V, M > & m_data
unsigned int n_coeffs() const
The number of coeffs for interpolating.
void compute_interval_indices(const V &domainVector, std::vector< unsigned int > &indices) const
Helper function to get lower bound indices for each dimension.
template<class V , class M >
double QUESO::LinearLagrangeInterpolationSurrogate< V, M >::lagrange_poly ( double  x0,
double  x1,
double  x,
unsigned int  index 
) const
protected

Evaluate a 1-D Lagrange polynomial at point x.

index tells us which of the two Lagrange functions to use. index must be 0 or 1.

Definition at line 209 of file LinearLagrangeInterpolationSurrogate.C.

210  {
211  // Make sure we're trying to interpolate between the given points
212  queso_assert_less_equal( x, x1 );
213  queso_assert_greater_equal( x, x0 );
214 
215  // Make sure index is either 0 or 1
216  queso_assert( (index == 0) || (index == 1) );
217 
218  double value = 0.0;
219 
220  if( index == 0 )
221  value = (x-x1)/(x0-x1);
222  else
223  value = (x-x0)/(x1-x0);
224 
225  return value;
226  }
template<class V = GslVector, class M = GslMatrix>
unsigned int QUESO::LinearLagrangeInterpolationSurrogate< V, M >::n_coeffs ( ) const
inline

The number of coeffs for interpolating.

Definition at line 60 of file LinearLagrangeInterpolationSurrogate.h.

References QUESO::InterpolationSurrogateBase< V, M >::m_data.

61  { return std::pow( 2, this->m_data.dim() ); };
const InterpolationSurrogateData< V, M > & m_data
template<class V , class M >
void QUESO::LinearLagrangeInterpolationSurrogate< V, M >::singleToCoords ( unsigned int  global,
std::vector< unsigned int > &  indices 
) const
protected

Inverse of map computed in coordsToSingle.

Definition at line 177 of file LinearLagrangeInterpolationSurrogate.C.

References QUESO::MultiDimensionalIndexing::globalToCoord().

178  {
179  unsigned int local_dim = 2;
180  std::vector<unsigned int> n_points( this->m_data.dim(), local_dim );
181 
182  /* We're abusing this function as it does what we need to with local_dim = 2
183  for all entries of n_points. */
184  return MultiDimensionalIndexing::globalToCoord( global, n_points, indices );
185  }
const InterpolationSurrogateData< V, M > & m_data
static void globalToCoord(unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
Inverse of coordToGlobal map.
template<class V , class M >
double QUESO::LinearLagrangeInterpolationSurrogate< V, M >::tensor_product_lagrange ( const std::vector< double > &  x_min,
const std::vector< double > &  x_max,
const std::vector< unsigned int > &  indices,
const V &  domainVector 
) const
protected

Compute multidimensional Lagrange polynomial as tensor product of 1D polynomials.

\( N_{ijkl...} (\xi, \eta, \zeta,...) = N_i(\eta) N_j(\eta) N_k(\zeta) ... \) The indices vector contains the i,j,k,... values

Definition at line 188 of file LinearLagrangeInterpolationSurrogate.C.

192  {
193  queso_assert_equal_to( x_min.size(), this->m_data.dim() );
194  queso_assert_equal_to( x_max.size(), this->m_data.dim() );
195  queso_assert_equal_to( indices.size(), this->m_data.dim() );
196  queso_assert_equal_to( domainVector.sizeGlobal(), this->m_data.dim() );
197 
198  double value = 1.0;
199 
200  for( unsigned int d = 0; d < this->m_data.dim(); d++ )
201  {
202  value *= this->lagrange_poly( x_min[d], x_max[d], domainVector[d], indices[d] );
203  }
204 
205  return value;
206  }
double lagrange_poly(double x0, double x1, double x, unsigned int index) const
Evaluate a 1-D Lagrange polynomial at point x.
const InterpolationSurrogateData< V, M > & m_data

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

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