dune-localfunctions  2.2.0
raviartthomas02dlocalinterpolation.hh
Go to the documentation of this file.
00001 #ifndef DUNE_RT02DLOCALINTERPOLATION_HH
00002 #define DUNE_RT02DLOCALINTERPOLATION_HH
00003 
00004 #include <cmath>
00005 #include <vector>
00006 #include <dune/common/exceptions.hh>
00007 
00008 namespace Dune 
00009 {
00010   template<class LB>
00011   class RT02DLocalInterpolation 
00012   {
00013   public:
00014 
00016         RT02DLocalInterpolation ()
00017         {
00018                 sign0 = sign1 = sign2 = 1.0;
00019         }
00020 
00022         RT02DLocalInterpolation (unsigned int s)
00023         {
00024           sign0 = sign1 = sign2 = 1.0;
00025           if (s&1) sign0 *= -1.0;
00026           if (s&2) sign1 *= -1.0;
00027           if (s&4) sign2 *= -1.0;
00028           m0[0] = 0.5; m0[1] = 0.0;
00029           m1[0] = 0.0; m1[1] = 0.5;
00030           m2[0] = 0.5; m2[1] = 0.5;
00031           n0[0] = 0.0;           n0[1] = -1.0;
00032           n1[0] = -1.0;          n1[1] = 0.0;
00033           n2[0] = 1.0/sqrt(2.0); n2[1] = 1.0/sqrt(2.0);
00034           c0 = ( 0.5*n0[0] - 1.0*n0[1]);
00035           c1 = (-1.0*n1[0] + 0.5*n1[1]);
00036           c2 = ( 0.5*n2[0] + 0.5*n2[1]);
00037         }
00038 
00039         template<typename F, typename C>
00040         void interpolate (const F& f, std::vector<C>& out) const
00041         {
00042           // f gives v*outer normal at a point on the edge!
00043           typename F::Traits::RangeType y;
00044 
00045           out.resize(3);
00046 
00047           f.evaluate(m0,y); out[0] = (y[0]*n0[0]+y[1]*n0[1])*sign0/c0;    
00048           f.evaluate(m1,y); out[1] = (y[0]*n1[0]+y[1]*n1[1])*sign1/c1;    
00049           f.evaluate(m2,y); out[2] = (y[0]*n2[0]+y[1]*n2[1])*sign2/c2;    
00050         }
00051 
00052   private:
00053         typename LB::Traits::RangeFieldType sign0,sign1,sign2;
00054         typename LB::Traits::DomainType m0,m1,m2;
00055         typename LB::Traits::DomainType n0,n1,n2;
00056         typename LB::Traits::RangeFieldType c0,c1,c2;
00057   };
00058 }
00059 
00060 #endif