dune-localfunctions  2.2.0
q2localinterpolation.hh
Go to the documentation of this file.
00001 // -*- tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=2 sw=2 sts=2:
00003 #ifndef DUNE_Q2_LOCALINTERPOLATION_HH
00004 #define DUNE_Q2_LOCALINTERPOLATION_HH
00005 
00006 #include <cstddef>
00007 #include <vector>
00008 
00009 namespace Dune 
00010 {
00011 template<class LB>
00012 class Q2LocalInterpolation
00013 {
00014 public:
00015 
00017   template<typename F, typename C>
00018   void interpolate (const F& f, std::vector<C>& out) const
00019   {
00020     typename LB::Traits::DomainType x;
00021     typename LB::Traits::RangeType y;
00022     static const int dim = LB::Traits::dimDomain;
00023    
00024     // Compute number of Lagrange points
00025     size_t size = 1;
00026       for (int i=0; i<dim; i++)
00027           size *= 3;
00028     
00029             out.resize(size);
00030             
00031             for (size_t i=0; i<size; i++) {
00032             
00033                 // Construct the i-th Lagrange point
00034                 size_t ternary = i;
00035                 for (int j=0; j<dim; j++) {
00036                     
00037                     int digit = ternary%3;
00038                     ternary /= 3;
00039                     
00040                     x[j] = digit*0.5;
00041                     
00042                 }
00043                     
00044                 // Evaluate the function at this point
00045                 f.evaluate(x,y);
00046                 out[i] = y;
00047                 
00048             }
00049             
00050   }
00051 };
00052 }
00053 
00054 #endif