util_interpolator.hh 17.3 KB
Newer Older
Dion Haefner's avatar
Dion Haefner committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// -*- tab-width: 4; indent-tabs-mode: nil -*-
#ifndef DUNE_DORIE_UTIL_INTERPOLATOR_HH
#define DUNE_DORIE_UTIL_INTERPOLATOR_HH

namespace Dune {
  namespace Dorie {
    enum InterpolationMethod {nearest, linear, cubic};

    /// Base class for all interpolators
    template<typename T, const int dim>
    class InterpolatorBase
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Domain Domain;
      typedef typename T::Vector Vector;
      typedef typename T::Array Array;
      typedef typename T::Index Index;
      typedef typename T::IndexArray IndexArray;

    protected:
      const ParameterTree& config;
      const Dune::MPIHelper& helper;
      const int verbose;
      const RF eps;

      bool initialized;

      IndexArray N_RF;
      Domain extensions;
      Domain x;

    public:
      const InterpolationMethod method;

      explicit InterpolatorBase(InterpolationMethod method_, const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_):
37
      config(config_), helper(helper_), verbose(verbose_), eps(1e-9), initialized(false), method(method_)
Dion Haefner's avatar
Dion Haefner committed
38 39
      {}

40 41
      virtual ~InterpolatorBase () = default;

Dion Haefner's avatar
Dion Haefner committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
       RF evaluate(const Array& field, const Domain& pos)
      {
        for(Index i = 0; i < dim; i++)
        {
          if(std::abs(pos[i] - x[i]) > eps)
          {
            update_pos(pos);
            x = pos;
            break;
          }
        }
        return field_value(field);
      }

      void initialize(const IndexArray& N_RF_, const Domain& extensions_)
      {
        if(!initialized)
        {
          N_RF = N_RF_;
          extensions = extensions_;
          initialized = true;
        }
        else
          DUNE_THROW(Exception,"Interpolator has already been initialized");
      }

       Domain get_pos() const
      {
        return x;
      }

    protected:

      virtual void update_pos(const Domain& pos) =0;
      virtual RF field_value(const Array& field) const =0;
    };

    template<typename T, const int dim>
    class NearestNeighborInterpolator: public InterpolatorBase<T,dim>
    {
    public:
      explicit NearestNeighborInterpolator() {}
    };

    template<typename T> class NearestNeighborInterpolator<T,2>: public InterpolatorBase<T,2>
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Domain Domain;
      typedef typename T::Array Array;
      typedef typename T::Index Index;
      typedef typename T::IndexArray IndexArray;

      typedef InterpolatorBase<T,2> IB;

      Index ipos;
      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:
      explicit NearestNeighborInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::nearest, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
105 106 107
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
108 109 110

    private:

Lukas Riedel's avatar
Lukas Riedel committed
111
       void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
112 113 114 115 116 117 118 119 120 121 122
      {
        Domain unit_pos;
        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;

        Index ipos0 = std::min((Index)round(unit_pos[0]),N_RF[0]-1);
        Index ipos1 = std::min((Index)round(unit_pos[1]),N_RF[1]-1);

        ipos = ipos0 + ipos1*N_RF[0];
      }

Lukas Riedel's avatar
Lukas Riedel committed
123
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
      {
        return field[ipos];
      }
    };

    template<typename T> class NearestNeighborInterpolator<T,3>: public InterpolatorBase<T,3>
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Domain Domain;
      typedef typename T::Array Array;
      typedef typename T::Index Index;
      typedef typename T::IndexArray IndexArray;

      typedef InterpolatorBase<T,3> IB;

      Index ipos;
      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:
      explicit NearestNeighborInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::nearest, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
148 149 150
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
151 152 153

    private:

Lukas Riedel's avatar
Lukas Riedel committed
154
      void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
155 156 157 158 159 160 161 162 163 164 165 166 167
      {
        Domain unit_pos;
        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;
        unit_pos[2] = std::max(N_RF[2] * pos[2] / extensions[2] - 0.5, 0.0) + eps;

        Index ipos0 = std::min((Index)round(unit_pos[0]),N_RF[0]-1);
        Index ipos1 = std::min((Index)round(unit_pos[1]),N_RF[1]-1);
        Index ipos2 = std::min((Index)round(unit_pos[2]),N_RF[2]-1);

        ipos = ipos0 + ipos1*N_RF[0] + ipos2*N_RF[0]*N_RF[1];
      }

Lukas Riedel's avatar
Lukas Riedel committed
168
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
      {
        return field[ipos];
      }
    };


    template<typename T, const int dim>
    class LinearInterpolator: public InterpolatorBase<T,dim>
    {
    public:
      explicit LinearInterpolator() {}
    };

    template<typename T> class LinearInterpolator<T,2>: public InterpolatorBase<T,2>
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Vector Vector;
      typedef typename T::Domain Domain;
      typedef typename T::Array Array;
      typedef typename T::IndexArray IndexArray;
      typedef typename T::Index Index;
      typedef InterpolatorBase<T,2> IB;

      typedef Dune::FieldVector<IndexArray,2> MultiIndexArray;
      MultiIndexArray ipos;
      Domain dx;

      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:

      explicit LinearInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::linear, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
205 206 207
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
208 209 210

    private:

Lukas Riedel's avatar
Lukas Riedel committed
211
      void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
      {
        Domain unit_pos;
        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;

        Index ipos0_x = std::min((Index)floor(unit_pos[0]),N_RF[0]-1);
        Index ipos0_y = std::min((Index)floor(unit_pos[1]),N_RF[1]-1);
        Index ipos1_x = std::min((Index)ceil(unit_pos[0]),N_RF[0]-1);
        Index ipos1_y = std::min((Index)ceil(unit_pos[1]),N_RF[1]-1);

        ipos[0][0] = ipos0_x + ipos0_y * N_RF[0];
        ipos[0][1] = ipos1_x + ipos0_y * N_RF[0];
        ipos[1][0] = ipos0_x + ipos1_y * N_RF[0];
        ipos[1][1] = ipos1_x + ipos1_y * N_RF[0];

        dx[0] = ipos1_x - unit_pos[0];
        dx[1] = ipos1_y - unit_pos[1];
      }

Lukas Riedel's avatar
Lukas Riedel committed
231
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
      {
      return field[ipos[0][0]] * dx[0] * dx[1]
             + field[ipos[0][1]] * (1-dx[0]) * dx[1]
             + field[ipos[1][0]] * dx[0] * (1-dx[1])
             + field[ipos[1][1]] * (1-dx[0]) * (1-dx[1]);
      }
    };

    // for implementation see https://en.wikipedia.org/wiki/Trilinear_interpolation
    template<typename T> class LinearInterpolator<T,3>: public InterpolatorBase<T,3>
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Vector Vector;
      typedef typename T::Domain Domain;
      typedef typename T::Array Array;
      typedef typename T::Index Index;
      typedef typename T::IndexArray IndexArray;
      typedef InterpolatorBase<T,3> IB;

      typedef Dune::FieldVector<Dune::FieldVector<IndexArray,2>,2> MultiIndexArray;
      MultiIndexArray ipos;
      Domain dx;

      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:
      explicit LinearInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::linear, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
263 264 265
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
266 267

    private:
Lukas Riedel's avatar
Lukas Riedel committed
268
      void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
      {
        Domain unit_pos;

        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;
        unit_pos[2] = std::max(N_RF[2] * pos[2] / extensions[2] - 0.5, 0.0) + eps;

        Index ipos0_x = std::min((Index)floor(unit_pos[0]),N_RF[0]-1);
        Index ipos0_y = std::min((Index)floor(unit_pos[1]),N_RF[1]-1);
        Index ipos0_z = std::min((Index)floor(unit_pos[2]),N_RF[2]-1);
        Index ipos1_x = std::min((Index)ceil(unit_pos[0]),N_RF[0]-1);
        Index ipos1_y = std::min((Index)ceil(unit_pos[1]),N_RF[1]-1);
        Index ipos1_z = std::min((Index)ceil(unit_pos[2]),N_RF[2]-1);

        ipos[0][0][0] = ipos0_x + ipos0_y * N_RF[0] + ipos0_z * N_RF[0] * N_RF[1];
        ipos[0][0][1] = ipos1_x + ipos0_y * N_RF[0] + ipos0_z * N_RF[0] * N_RF[1];
        ipos[0][1][0] = ipos0_x + ipos1_y * N_RF[0] + ipos0_z * N_RF[0] * N_RF[1];
        ipos[0][1][1] = ipos1_x + ipos1_y * N_RF[0] + ipos0_z * N_RF[0] * N_RF[1];
        ipos[1][0][0] = ipos0_x + ipos0_y * N_RF[0] + ipos1_z * N_RF[0] * N_RF[1];
        ipos[1][0][1] = ipos1_x + ipos0_y * N_RF[0] + ipos1_z * N_RF[0] * N_RF[1];
        ipos[1][1][0] = ipos0_x + ipos1_y * N_RF[0] + ipos1_z * N_RF[0] * N_RF[1];
        ipos[1][1][1] = ipos1_x + ipos1_y * N_RF[0] + ipos1_z * N_RF[0] * N_RF[1];

        dx[0] = ipos1_x - unit_pos[0];
        dx[1] = ipos1_y - unit_pos[1];
        dx[2] = ipos1_z - unit_pos[2];
      }

Lukas Riedel's avatar
Lukas Riedel committed
297
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
      {
        RF c00 = field[ipos[0][0][0]] * dx[0] + field[ipos[0][0][1]] * (1-dx[0]);
        RF c01 = field[ipos[1][0][0]] * dx[0] + field[ipos[1][0][1]] * (1-dx[0]);
        RF c10 = field[ipos[0][1][0]] * dx[0] + field[ipos[0][1][1]] * (1-dx[0]);
        RF c11 = field[ipos[1][1][0]] * dx[0] + field[ipos[1][1][1]] * (1-dx[0]);

        RF c0 = c00 * dx[1] + c10 * (1-dx[1]);
        RF c1 = c01 * dx[1] + c11 * (1-dx[1]);

        return c0 * dx[2] + c1 * (1-dx[2]);
      }
    };

    template<typename T, const int dim>
    class CubicInterpolator: public InterpolatorBase<T,dim>
    {
    public:
      explicit CubicInterpolator() {}
    };

    template<typename T> class CubicInterpolator<T,2>: public InterpolatorBase<T,2>
    {
    private:
      typedef typename T::RangeField RF;
      typedef typename T::Domain Domain;
      typedef typename T::Vector Vector;
      typedef typename T::Array Array;
      typedef typename T::IndexArray IndexArray;
      typedef typename T::Index Index;
      typedef InterpolatorBase<T,2> IB;

      typedef Dune::FieldVector<Index,4> FourIndexArray;
      typedef Dune::FieldVector<FourIndexArray,4> MultiFourIndexArray;
      MultiFourIndexArray ipos;
      Domain dx;

      typedef Dune::FieldVector<RF,4> FieldVector;
      typedef Dune::FieldVector<FieldVector,4> MultiFieldVector;

      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:

      explicit CubicInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::cubic, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
345 346 347
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
348 349 350 351

    private:

      // Implementation inspired by http://www.paulinternet.nl/?page=bicubic
Lukas Riedel's avatar
Lukas Riedel committed
352
      void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
      {
        Domain unit_pos;
        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;

        FourIndexArray ipos_x, ipos_y;
        for(Index i=0;i<4;i++)
        {
          ipos_x[i] = std::max((Index)std::min((Index)floor(unit_pos[0]) + i - 1, N_RF[0] - 1),(Index) 0);
          ipos_y[i] = std::max((Index)std::min((Index)floor(unit_pos[1]) + i - 1, N_RF[1] - 1),(Index) 0);
        }

        for(Index i=0;i<4;i++)
        {
          for(Index j=0;j<4;j++)
          {
            ipos[i][j] = ipos_x[i] + ipos_y[j] * N_RF[0];
          }
        }

        dx[0] = unit_pos[0] - ipos_x[1];
        dx[1] = unit_pos[1] - ipos_y[1];
      }

Lukas Riedel's avatar
Lukas Riedel committed
377
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
      {
        MultiFieldVector p1;
        for(Index i=0;i<4;i++)
        {
          for(Index j=0;j<4;j++)
          {
            p1[i][j] = field[ipos[i][j]];
          }
        }

        FieldVector p2;
        for(Index i=0;i<4;i++)
          p2[i] = cubic_interpolate(p1[i], dx[1]);

        return cubic_interpolate(p2, dx[0]);
      }

      RF cubic_interpolate (const FieldVector& p, const RF& x) const {
      	return p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
      }
    };

    template<typename T> class CubicInterpolator<T,3>: public InterpolatorBase<T,3>
    {
    private:
      typedef typename T::Domain Domain;
      typedef typename T::Array Array;
      typedef typename T::RangeField RF;
      typedef typename T::Index Index;
      typedef typename T::IndexArray IndexArray;
      typedef InterpolatorBase<T,3> IB;

      typedef Dune::FieldVector<Index,4> FourIndexArray;
      typedef Dune::FieldVector<FourIndexArray,4> FourIndexArray2D;
      typedef Dune::FieldVector<FourIndexArray2D,4> FourIndexArray3D;
      FourIndexArray3D ipos;
      Domain dx;

      typedef Dune::FieldVector<RF,4> FieldVector;
      typedef Dune::FieldVector<FieldVector,4> MultiFieldVector2D;
      typedef Dune::FieldVector<MultiFieldVector2D,4> MultiFieldVector3D;

      const IndexArray& N_RF;
      const Domain& extensions;
      const RF& eps;

    public:
      explicit CubicInterpolator(const ParameterTree& config_, const Dune::MPIHelper& helper_, const int verbose_)
      : IB(InterpolationMethod::cubic, config_, helper_, verbose_), N_RF(IB::N_RF), extensions(IB::extensions), eps(IB::eps)
Lukas Riedel's avatar
Lukas Riedel committed
427 428 429
      {
        update_pos(Domain(0.0));
      }
Dion Haefner's avatar
Dion Haefner committed
430 431 432 433

    private:

      // Implementation inspired by http://www.paulinternet.nl/?page=bicubic
Lukas Riedel's avatar
Lukas Riedel committed
434
      void update_pos(const Domain& pos) override
Dion Haefner's avatar
Dion Haefner committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
      {
        Domain unit_pos;
        unit_pos[0] = std::max(N_RF[0] * pos[0] / extensions[0] - 0.5, 0.0) + eps;
        unit_pos[1] = std::max(N_RF[1] * pos[1] / extensions[1] - 0.5, 0.0) + eps;
        unit_pos[2] = std::max(N_RF[2] * pos[2] / extensions[2] - 0.5, 0.0) + eps;

        FourIndexArray ipos_x, ipos_y, ipos_z;
        for(Index i=0;i<4;i++)
        {
          ipos_x[i] = std::max((Index)std::min((Index)floor(unit_pos[0]) + i - 1, N_RF[0] - 1),(Index) 0);
          ipos_y[i] = std::max((Index)std::min((Index)floor(unit_pos[1]) + i - 1, N_RF[1] - 1),(Index) 0);
          ipos_z[i] = std::max((Index)std::min((Index)floor(unit_pos[2]) + i - 1, N_RF[2] - 1),(Index) 0);
        }

        for(Index i=0;i<4;i++)
        {
          for(Index j=0;j<4;j++)
          {
            for(Index k=0;k<4;k++)
            {
              ipos[i][j][k] = ipos_x[i] + ipos_y[j] * N_RF[0] + ipos_z[k] * N_RF[0] * N_RF[1];
            }
          }
        }

        dx[0] = unit_pos[0] - ipos_x[1];
        dx[1] = unit_pos[1] - ipos_y[1];
        dx[2] = unit_pos[2] - ipos_z[1];
      }

Lukas Riedel's avatar
Lukas Riedel committed
465
      RF field_value(const Array& field) const override
Dion Haefner's avatar
Dion Haefner committed
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
      {
        MultiFieldVector3D p1;
        for(Index i=0;i<4;i++)
        {
          for(Index j=0;j<4;j++)
          {
            for(Index k=0;k<4;k++)
            {
              p1[i][j][k] = field[ipos[i][j][k]];
            }
          }
        }

        FieldVector p2;
        for(Index i=0;i<4;i++)
        {
          p2[i] = bicubic_interpolate(p1[i], dx[1], dx[2]);
        }
        return cubic_interpolate(p2, dx[0]);
      }

      RF bicubic_interpolate (const MultiFieldVector2D& p, const RF& x, const RF& y) const
      {
        FieldVector p1;
        for(Index i=0;i<4;i++)
          p1[i] = cubic_interpolate(p[i], y);
        return cubic_interpolate(p1, x);
      }

      RF cubic_interpolate (const FieldVector& p, const RF& x) const
      {
      	return p[1] + 0.5 * x*(p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
      }
    };

    template<typename T, const int dim>
    class InterpolatorFactory
    {
    private:
      typedef InterpolatorBase<T,dim> IB;

    protected:
      const ParameterTree& config;
      const Dune::MPIHelper& helper;
      const int verbose;
      const std::string interpMethod;

    public:
      explicit InterpolatorFactory(const ParameterTree& config_,
                          const Dune::MPIHelper& helper_, const int verbose_)
      : config(config_), helper(helper_), verbose(verbose_)
      , interpMethod(config.get<std::string>("parameters.interpolation"))
      {}

      std::unique_ptr<IB> create()
      {
        std::unique_ptr<IB> interp;
        if(interpMethod == "nearest")
          interp = std::make_unique<NearestNeighborInterpolator<T,dim>>(config, helper, verbose);
        else if (interpMethod == "linear")
          interp = std::make_unique<LinearInterpolator<T,dim>>(config, helper, verbose);
        else if (interpMethod == "cubic")
          interp = std::make_unique<CubicInterpolator<T,dim>>(config, helper, verbose);
        else
          DUNE_THROW(Dune::IOError,"Unrecognized interpolation method encountered: " + interpMethod);

        return interp;
      }
    };
  }
}

#endif