// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception #ifndef GENERIC_INTERPOLATIONHELPER_HH #define GENERIC_INTERPOLATIONHELPER_HH #include #include #include #include namespace Dune { // A small helper class to avoid having to // write the interpolation twice (once for function // and once for a basis) template< class F, unsigned int dimension > struct InterpolationHelper { template struct Helper; }; template template struct InterpolationHelper::Helper // Func is of Function type { typedef std::vector< Dune::FieldVector > Result; Helper(const Func & func, Vector &vec) : func_(func), vec_(vec), tmp_(1) {} const typename Vector::value_type &operator()(unsigned int row,unsigned int col) { return vec_[row]; } template void set(unsigned int row,unsigned int col, const Fy &val) { assert(col==0); assert(row void add(unsigned int row,unsigned int col, const Fy &val) { assert(col==0); assert(row(val); } template const Result &evaluate(const DomainVector &x) const { field_cast(func_(x), tmp_[0] ); return tmp_; } unsigned int size() const { return 1; } const Func &func_; Vector &vec_; mutable Result tmp_; }; template template struct InterpolationHelper::Helper // Func is of Basis type { typedef std::vector< Dune::FieldVector > Result; Helper(const Basis & basis, Matrix &matrix) : basis_(basis), matrix_(matrix), tmp_(basis.size()) {} const F &operator()(unsigned int row,unsigned int col) const { return matrix_[row][col]; } F &operator()(unsigned int row,unsigned int col) { return matrix_[row][col]; } template void set(unsigned int row,unsigned int col, const Fy &val) { assert(col void add(unsigned int row,unsigned int col, const Fy &val) { assert(col const Result &evaluate(const DomainVector &x) const { basis_.template evaluate<0>(x,tmp_); return tmp_; } unsigned int size() const { return basis_.size(); } const Basis &basis_; Matrix &matrix_; mutable Result tmp_; }; } #endif // GENERIC_INTERPOLATIONHELPER_HH