monomlocalinterpolation.hh

Go to the documentation of this file.
00001 // -*- tab-width: 4; indent-tabs-mode: nil -*-
00002 #ifndef DUNE_MONOMLOCALINTERPOLATION_HH
00003 #define DUNE_MONOMLOCALINTERPOLATION_HH
00004 
00005 #include <vector>
00006 
00007 #include <dune/common/geometrytype.hh>
00008 #include <dune/common/fvector.hh>
00009 #include <dune/common/fmatrix.hh>
00010 #include <dune/grid/common/quadraturerules.hh>
00011 
00012 namespace Dune 
00013 {
00014 
00015   template<class LB, unsigned int size>
00016   class MonomLocalInterpolation 
00017   {
00018     typedef typename LB::Traits::DomainType D;
00019     typedef typename LB::Traits::DomainFieldType DF;
00020     static const int dimD=LB::Traits::dimDomain;
00021     typedef typename LB::Traits::RangeType R;
00022     typedef typename LB::Traits::RangeFieldType RF;
00023 
00024     typedef QuadratureRule<DF,dimD> QR;
00025     typedef typename QR::iterator QRiterator;
00026 
00027   public:
00028         MonomLocalInterpolation (const GeometryType::BasicType &bt_,
00029                              const LB &lb_)
00030       : bt(bt_), lb(lb_), Minv(0)
00031       , qr(QuadratureRules<DF,dimD>::rule(bt, 2*lb.order()))
00032         {
00033       if(size != lb.size())
00034         DUNE_THROW(Exception, "size template parameter does not match size of local basis");
00035 
00036       const QRiterator qrend = qr.end();
00037       for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
00038         std::vector<R> base;
00039         lb.evaluateFunction(qrit->position(),base);
00040         
00041         for(unsigned int i = 0; i < size; ++i)
00042           for(unsigned int j = 0; j < size; ++j)
00043             Minv[i][j] += qrit->weight() * base[i] * base[j];
00044       }
00045         Minv.invert();
00046     }
00047 
00049         template<typename F, typename C>
00050         void interpolate (const F& f, std::vector<C>& out) const
00051         {
00052           out.clear();
00053       out.resize(size, 0);
00054       
00055       const QRiterator qrend = qr.end();
00056       for(QRiterator qrit = qr.begin(); qrit != qrend; ++qrit) {
00057         //TODO: mass matrix
00058         R y;
00059         f.evaluate(qrit->position(),y);
00060 
00061         std::vector<R> base;
00062         lb.evaluateFunction(qrit->position(),base);
00063 
00064         for(unsigned int i = 0; i < size; ++i)
00065           for(unsigned int j = 0; j < size; ++j)
00066             out[i] += Minv[i][j] * qrit->weight() * y * base[j];
00067       }
00068         }
00069 
00070   private:
00071     GeometryType::BasicType bt;
00072     const LB &lb;
00073     FieldMatrix<RF, size, size> Minv;
00074     const QR &qr;
00075   };
00076 
00077 }
00078 
00079 #endif //DUNE_MONOMLOCALINTERPOLATION_HH
Generated on Sat Apr 24 11:15:34 2010 for dune-localfunctions by  doxygen 1.6.3