1 #ifndef VTESTBED_CORE_GRID_INTERPOLATION_HH     2 #define VTESTBED_CORE_GRID_INTERPOLATION_HH     4 #include <vtestbed/core/grid.hh>    10         template <
class T, 
int N, 
class Function, 
class Return=T>
    14             using vertex_type = blitz::TinyVector<T,N>;
    16             using index_type = blitz::TinyVector<int,N>;
    17             using function_type = Function;
    18             using return_type = Return;
    22             function_type _function;
    28             _grid(grid), _function(
function) {}
    31             operator()(
const vertex_type& x) {
    32                 #if defined(VTB_DEBUG_INTERPOLATION)    33                 this->detect_extrapolation(x);
    35                 const auto& grid = this->_grid;
    36                 index_type idx_max{grid.
shape()-1};
    37                 index_type i00{floor(grid.index(x))};
    38                 i00 = blitz::clamp(i00, grid.
begin(), index_type(idx_max-1));
    39                 return this->_function(x, i00);
    42             inline const grid_type& grid()
 const { 
return this->_grid; }
    43             inline const function_type& 
function() 
const { 
return this->_function; }
    47             #if defined(VTB_DEBUG_INTERPOLATION)    49             detect_extrapolation(
const vertex_type& x) {
    50                 const auto& grid = this->_grid;
    51                 if (!grid.contains(x)) {
    53                     for (
int i=0; i<2; ++i) {
    57                         if (x(i) < x_min && std::abs(x(i)-x_min) > T{1e-3}) {
    60                         if (x(i) > x_max && std::abs(x(i)-x_max) > T{1e-3}) {
    65                         std::clog << 
"_grid=" << _grid << std::endl;
    79             using vec3 = blitz::TinyVector<T,3>;
    80             using vec2 = blitz::TinyVector<T,2>;
    81             using vertex_matrix = blitz::Array<vec3,2>;
    82             using index_type = blitz::TinyVector<int,2>;
    85             vertex_matrix _points;
    92             T operator()(
const vec2& x, 
const index_type& i00);
    96         template <
class T,
int N>
   100             using array_type = blitz::Array<T,N>;
   101             using vertex_type = blitz::TinyVector<T,N>;
   102             using index_type = blitz::TinyVector<int,N>;
   113             _func(func), _grid(grid) {}
   115             T operator()(
const vertex_type& x, 
const index_type& i00);
   129             using vec3 = blitz::TinyVector<T,3>;
   130             using vec2 = blitz::TinyVector<T,2>;
   131             using vertex_matrix = blitz::Array<vec3,2>;
   132             using index_type = blitz::TinyVector<int,2>;
   135             vertex_matrix _points;
   142                 const vertex_matrix& points,
   145             ): _points(points), _order(order), _sigma(sigma) {}
   147             T operator()(
const vec2& x, 
const index_type& i00);
   151         template <
class T, 
int N>
   157             using array_type = blitz::Array<T,N>;
   164             using base_type::base_type;
   165             using base_type::operator();
   179         template <
class T, 
class Return=T>
   183             using return_type = Return;
   184             using vec3 = blitz::TinyVector<T,3>;
   185             using vertex_field = blitz::Array<return_type,3>;
   186             using index_type = blitz::TinyVector<int,3>;
   190             vertex_field _points;
   196             _points(points), _grid(grid) {}
   198             return_type operator()(
const vec3& x, 
const index_type& i00);
   206 #endif // vim:filetype=cpp 
const vec & lbound() const noexcept
Lower bound of the region.
 
Nearest neighbour weighted interpolation for 3-d fields.
 
const int_n shape() const noexcept
The number of points for all dimensions.
 
A region defined by start and end index and lower and upper bound for each dimension.
 
Radial basis function interpolation.
 
const int_n & begin() const noexcept
Start indices (inclusive).
 
const vec & ubound() const noexcept
Upper bound of the region.