localfiniteelement.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GENERIC_LOCALFINITEELEMENT_HH
00002 #define DUNE_GENERIC_LOCALFINITEELEMENT_HH
00003 
00004 #include <dune/common/geometrytype.hh>
00005 #include <dune/grid/genericgeometry/conversion.hh>
00006 
00007 #include <dune/localfunctions/common/localfiniteelementtraits.hh>
00008 #include <dune/localfunctions/utility/l2interpolation.hh>
00009 #include <dune/localfunctions/utility/dglocalcoefficients.hh>
00010 
00011 namespace Dune 
00012 {
00019   template< class BasisF, class CoeffF, class InterpolF>
00020   struct GenericLocalFiniteElement 
00021   {
00022     typedef GenericLocalFiniteElement<BasisF, CoeffF, InterpolF> This;
00023     typedef LocalFiniteElementTraits< typename BasisF::Object,
00024                                       typename CoeffF::Object,
00025                                       typename InterpolF::Object > Traits;
00026 
00027     typedef typename BasisF::Key Key;
00028     static const unsigned int dimDomain = BasisF::dimension;
00029 
00030     typedef BasisF BasisFactory;
00031     typedef CoeffF CoefficientFactory;
00032     typedef InterpolF InterpolationFactory;
00033 
00034     dune_static_assert( (Conversion<Key,typename CoeffF::Key>::sameType),
00035                    "incompatible keys between BasisCreator and CoefficientsCreator" );
00036     dune_static_assert( (Conversion<Key,typename InterpolF::Key>::sameType),
00037                    "incompatible keys between BasisCreator and InterpolationCreator" );
00038 
00041     GenericLocalFiniteElement ( unsigned int topologyId,
00042                                 const Key &key )
00043     : topologyId_(topologyId),
00044       key_(key),
00045       finiteElement_( )
00046     {
00047       GenericGeometry::IfTopology< FiniteElement::template Maker, dimDomain >::apply( topologyId_, key_, finiteElement_ );
00048     }
00049     GenericLocalFiniteElement ( const GenericLocalFiniteElement &other )
00050     : topologyId_(other.topologyId_),
00051       key_(other.key_),
00052       finiteElement_( )
00053     {
00054       GenericGeometry::IfTopology< FiniteElement::template Maker, dimDomain >::apply( topologyId_, key_, finiteElement_ );
00055     }
00056     ~GenericLocalFiniteElement()
00057     {
00058       finiteElement_.release(); 
00059     }
00060 
00063     const typename Traits::LocalBasisType& localBasis () const
00064     {
00065       return *(finiteElement_.basis_);
00066     }
00067         
00070     const typename Traits::LocalCoefficientsType& localCoefficients () const
00071     {
00072       return *(finiteElement_.coeff_);
00073     }
00074         
00077     const typename Traits::LocalInterpolationType& localInterpolation () const
00078     {
00079       return *(finiteElement_.interpol_);
00080     }
00081         
00084     GeometryType type () const
00085     {
00086       if ( GenericGeometry::hasGeometryType( topologyId_, dimDomain ) )
00087         return GenericGeometry::geometryType( topologyId_, dimDomain );
00088       return GeometryType();
00089     }
00090 
00093     unsigned int topologyId () const
00094     {
00095       return topologyId_;
00096     }
00097   private:
00098     struct FiniteElement
00099     {
00100       FiniteElement() : basis_(0), coeff_(0), interpol_(0) {}
00101       template <class Topology>
00102       void create( const Key &key )
00103       {
00104         release();
00105         basis_ = BasisF::template create<Topology>(key);
00106         coeff_ = CoeffF::template create<Topology>(key);
00107         interpol_ = InterpolF::template create<Topology>(key);
00108       }
00109       void release() 
00110       {
00111         if (basis_) 
00112           BasisF::release(basis_);
00113         if (coeff_)
00114           CoeffF::release(coeff_);
00115         if (interpol_)
00116           InterpolF::release(interpol_);
00117         basis_=0;
00118         coeff_=0;
00119         interpol_=0;
00120       }
00121       template< class Topology >
00122       struct Maker
00123       {
00124         static void apply ( const Key &key, FiniteElement &finiteElement )
00125         {
00126           finiteElement.template create<Topology>(key);
00127         };
00128       };
00129       typename Traits::LocalBasisType *basis_;
00130       typename Traits::LocalCoefficientsType *coeff_;
00131       typename Traits::LocalInterpolationType *interpol_;
00132     };
00133     unsigned int topologyId_;
00134     Key key_;
00135     FiniteElement finiteElement_;
00136   };
00137 
00144   template <class FE>
00145   struct DGLocalFiniteElement 
00146       : public GenericLocalFiniteElement< typename FE::BasisFactory,
00147                                           DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00148                                           typename FE::InterpolationFactory>
00149   {
00150     typedef GenericLocalFiniteElement< typename FE::BasisFactory,
00151                                        DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00152                                        typename FE::InterpolationFactory> Base;
00153   public:
00154     typedef typename Base::Traits Traits;
00155 
00158     DGLocalFiniteElement ( unsigned int topologyId, const typename Base::Key &key  )
00159     : Base( topologyId, key )
00160     {}
00161   };
00169   template <class FE>
00170   struct L2LocalFiniteElement 
00171       : public GenericLocalFiniteElement< typename FE::BasisFactory,
00172                                           DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00173                                           LocalL2InterpolationFactory< typename FE::BasisFactory, false > >
00174   {
00175     typedef GenericLocalFiniteElement< typename FE::BasisFactory,
00176                                        DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00177                                        LocalL2InterpolationFactory< typename FE::BasisFactory, false > > Base;
00178   public:
00179     typedef typename Base::Traits Traits;
00180 
00183     L2LocalFiniteElement ( unsigned int topologyId, const typename Base::Key &key  )
00184     : Base( topologyId, key )
00185     {}
00186   };
00187 }
00188 
00189 #endif
Generated on Sat Apr 24 11:15:34 2010 for dune-localfunctions by  doxygen 1.6.3