26 #include <queso/LinearLagrangeInterpolationSurrogate.h> 
   29 #include <queso/GslVector.h> 
   30 #include <queso/GslMatrix.h> 
   31 #include <queso/MultiDimensionalIndexing.h> 
   32 #include <queso/InterpolationSurrogateData.h> 
   36   template<
class V, 
class M>
 
   41   template<
class V, 
class M>
 
   46     std::vector<unsigned int> indices(this->m_data.dim());
 
   47     this->compute_interval_indices(domainVector, indices);
 
   50     std::vector<double> x_min(this->m_data.dim());
 
   53     std::vector<double> x_max(this->m_data.dim());
 
   56     std::vector<double> values(this->n_coeffs());
 
   59     this->compute_interval_values( indices, x_min, x_max, values );
 
   62     return this->eval_interpolant( x_min, x_max, values, domainVector );
 
   65   template<
class V, 
class M>
 
   67                                                                            std::vector<unsigned int>& indices)
 const 
   69     queso_assert_equal_to( domainVector.sizeGlobal(), this->m_data.dim() );
 
   70     queso_assert_equal_to( indices.size(), this->m_data.dim() );
 
   72     for( 
unsigned int d = 0; d < this->m_data.dim(); d++ )
 
   74         double spacing = this->m_data.spacing(d);
 
   75         indices[d] = std::floor( (domainVector[d] - this->m_data.x_min(d))/spacing );
 
   78         queso_assert_less( indices[d], this->m_data.get_n_points()[d] );
 
   82   template<
class V, 
class M>
 
   84                                                                            std::vector<double>& x_min,
 
   85                                                                            std::vector<double>& x_max,
 
   86                                                                            std::vector<double>& values )
 const 
   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() );
 
   94     for( 
unsigned int d = 0; d < this->m_data.dim(); d++ )
 
   96         x_min[d] = this->m_data.get_x( d, indices[d] );
 
   97         x_max[d] = x_min[d] + this->m_data.spacing( d );
 
  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++ )
 
  106         this->singleToCoords(n,local_indices);
 
  117         for( 
unsigned int d = 0; d < this->m_data.dim(); d++ )
 
  119             if( local_indices[d] == 0 )
 
  120               global_indices[d] = indices[d];
 
  122             else if( local_indices[d] == 1 )
 
  123               global_indices[d] = indices[d]+1;
 
  134         values[n] = this->m_data.get_value(global);
 
  138   template<
class V, 
class M>
 
  140                                                                       const std::vector<double>& x_max,
 
  141                                                                       const std::vector<double>& values,
 
  142                                                                       const V & domainVector )
 const 
  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() );
 
  149     double interp_value = 0.0;
 
  151     std::vector<unsigned int> indices( this->m_data.dim() );
 
  153     for( 
unsigned int n = 0; n < this->n_coeffs(); n++ )
 
  155         this->singleToCoords( n, indices );
 
  157         double shape_fn = this->tensor_product_lagrange( x_min, x_max, indices, domainVector );
 
  159         interp_value += values[n]*shape_fn;
 
  165   template<
class V, 
class M>
 
  168     unsigned int local_dim = 2;
 
  169     std::vector<unsigned int> n_points( this->m_data.dim(), local_dim );
 
  176   template<
class V, 
class M>
 
  179     unsigned int local_dim = 2;
 
  180     std::vector<unsigned int> n_points( this->m_data.dim(), local_dim );
 
  187   template<
class V, 
class M>
 
  189                                                                              const std::vector<double>& x_max,
 
  190                                                                              const std::vector<unsigned int>& indices,
 
  191                                                                              const V & domainVector )
 const 
  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() );
 
  200     for( 
unsigned int d = 0; d < this->m_data.dim(); d++ )
 
  202         value *= this->lagrange_poly( x_min[d], x_max[d], domainVector[d], indices[d] );
 
  208   template<
class V, 
class M>
 
  212     queso_assert_less_equal( x, x1 );
 
  213     queso_assert_greater_equal( x, x0 );
 
  216     queso_assert( (index == 0) || (index == 1) );
 
  221       value = (x-x1)/(x0-x1);
 
  223       value = (x-x0)/(x1-x0);
 
virtual double evaluate(const V &domainVector) const 
Evaluates value of the interpolant for the given domainVector. 
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. 
Base class for interpolation-based surrogates. 
double lagrange_poly(double x0, double x1, double x, unsigned int index) const 
Evaluate a 1-D Lagrange polynomial at point x. 
Linear Lagrange interpolation surrogate. 
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. 
void singleToCoords(unsigned int global, std::vector< unsigned int > &indices) const 
Inverse of map computed in coordsToSingle. 
static void globalToCoord(unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
Inverse of coordToGlobal map. 
LinearLagrangeInterpolationSurrogate()
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. 
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. ...
void compute_interval_indices(const V &domainVector, std::vector< unsigned int > &indices) const 
Helper function to get lower bound indices for each dimension. 
unsigned int coordsToSingle(const std::vector< unsigned int > &indices) const 
Convert local indices to single "global" index.