26 #include <queso/LinearLagrangeInterpolationSurrogate.h>
29 #include <queso/GslVector.h>
30 #include <queso/GslMatrix.h>
31 #include <queso/InterpolationSurrogateHelper.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
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 );
82 template<
class V,
class M>
84 std::vector<double>& x_min,
85 std::vector<double>& x_max,
86 std::vector<double>& values )
const
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
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
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>
221 value = (x-x1)/(x0-x1);
223 value = (x-x0)/(x1-x0);
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.
void compute_interval_indices(const V &domainVector, std::vector< unsigned int > &indices) const
Helper function to get lower bound indices for each dimension.
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.
#define queso_assert_equal_to(expr1, expr2)
Base class for interpolation-based surrogates.
#define queso_assert(asserted)
#define queso_assert_less_equal(expr1, expr2)
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.
LinearLagrangeInterpolationSurrogate()
#define queso_assert_greater_equal(expr1, expr2)
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.
#define queso_assert_less(expr1, expr2)
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. ...
double lagrange_poly(double x0, double x1, double x, unsigned int index) const
Evaluate a 1-D Lagrange polynomial at point x.
unsigned int coordsToSingle(const std::vector< unsigned int > &indices) const
Convert local indices to single "global" index.