dune-localfunctions
2.1.1
|
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=8 sw=2 sts=2: 00003 00004 #ifndef DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH 00005 #define DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH 00006 00007 #include <algorithm> 00008 #include <cassert> 00009 #include <cstddef> 00010 #include <vector> 00011 00012 // #include <dune/common/array.hh> 00013 // #include <dune/common/geometrytype.hh> 00014 #include <dune/common/static_assert.hh> 00015 00016 // #include <dune/localfunctions/common/localkey.hh> 00017 00018 namespace Dune { 00019 00022 00028 template<class Backend, class BasisTraits> 00029 class PowerInterpolation { 00030 dune_static_assert(Backend::Traits::dimRange == 1, "PowerInterpolation " 00031 "works only with scalar backends"); 00032 00033 const Backend *backend; 00034 00035 public: 00037 typedef BasisTraits Traits; 00038 00040 00046 PowerInterpolation(const Backend &backend_) : backend(&backend_) { } 00047 00048 private: 00049 template<class F> 00050 class ComponentEvaluator { 00051 const F &f; 00052 std::size_t comp; 00053 00054 public: 00055 ComponentEvaluator(const F &f_, std::size_t comp_) : 00056 f(f_), comp(comp_) 00057 { } 00058 00059 void evaluate(const typename Backend::Traits::DomainLocal &x, 00060 typename Backend::Traits::Range &y) const 00061 { 00062 typename Traits::Range fy; 00063 f.evaluate(x, fy); 00064 y[0] = fy[comp]; 00065 } 00066 }; 00067 00068 public: 00070 00079 template<typename F, typename C> 00080 void interpolate(const F& f, std::vector<C>& out) const { 00081 out.clear(); 00082 std::vector<C> cout; 00083 for(std::size_t d = 0; d < Traits::dimRange; ++d) { 00084 backend->interpolate(ComponentEvaluator<F>(f, d), cout); 00085 if(d == 0) 00086 out.resize(cout.size()*Traits::dimRange); 00087 // make sure the size of cout does not change surprisingly 00088 assert(out.size() == cout.size()*Traits::dimRange); 00089 std::copy(cout.begin(), cout.end(), out.begin() + d*cout.size()); 00090 } 00091 } 00092 }; 00093 00094 } // namespace Dune 00095 00096 #endif // DUNE_LOCALFUNCTIONS_META_POWER_INTERPOLATION_HH