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       return GeometryType(topologyId_,dimDomain);
00087       /*
00088       if ( GenericGeometry::hasGeometryType( topologyId_, dimDomain ) )
00089         return GenericGeometry::geometryType( topologyId_, dimDomain );
00090       return GeometryType();
00091       */
00092     }
00093 
00096     unsigned int topologyId () const
00097     {
00098       return topologyId_;
00099     }
00100   private:
00101     struct FiniteElement
00102     {
00103       FiniteElement() : basis_(0), coeff_(0), interpol_(0) {}
00104       template <class Topology>
00105       void create( const Key &key )
00106       {
00107         release();
00108         basis_ = BasisF::template create<Topology>(key);
00109         coeff_ = CoeffF::template create<Topology>(key);
00110         interpol_ = InterpolF::template create<Topology>(key);
00111       }
00112       void release() 
00113       {
00114         if (basis_) 
00115           BasisF::release(basis_);
00116         if (coeff_)
00117           CoeffF::release(coeff_);
00118         if (interpol_)
00119           InterpolF::release(interpol_);
00120         basis_=0;
00121         coeff_=0;
00122         interpol_=0;
00123       }
00124       template< class Topology >
00125       struct Maker
00126       {
00127         static void apply ( const Key &key, FiniteElement &finiteElement )
00128         {
00129           finiteElement.template create<Topology>(key);
00130         };
00131       };
00132       typename Traits::LocalBasisType *basis_;
00133       typename Traits::LocalCoefficientsType *coeff_;
00134       typename Traits::LocalInterpolationType *interpol_;
00135     };
00136     unsigned int topologyId_;
00137     Key key_;
00138     FiniteElement finiteElement_;
00139   };
00140 
00147   template <class FE>
00148   struct DGLocalFiniteElement 
00149       : public GenericLocalFiniteElement< typename FE::BasisFactory,
00150                                           DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00151                                           typename FE::InterpolationFactory>
00152   {
00153     typedef GenericLocalFiniteElement< typename FE::BasisFactory,
00154                                        DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00155                                        typename FE::InterpolationFactory> Base;
00156   public:
00157     typedef typename Base::Traits Traits;
00158 
00161     DGLocalFiniteElement ( unsigned int topologyId, const typename Base::Key &key  )
00162     : Base( topologyId, key )
00163     {}
00164   };
00172   template <class FE>
00173   struct L2LocalFiniteElement 
00174       : public GenericLocalFiniteElement< typename FE::BasisFactory,
00175                                           DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00176                                           LocalL2InterpolationFactory< typename FE::BasisFactory, false > >
00177   {
00178     typedef GenericLocalFiniteElement< typename FE::BasisFactory,
00179                                        DGLocalCoefficientsFactory< typename FE::BasisFactory >,
00180                                        LocalL2InterpolationFactory< typename FE::BasisFactory, false > > Base;
00181   public:
00182     typedef typename Base::Traits Traits;
00183 
00186     L2LocalFiniteElement ( unsigned int topologyId, const typename Base::Key &key  )
00187     : Base( topologyId, key )
00188     {}
00189   };
00190 }
00191 
00192 #endif

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].