dune-localfunctions  2.2.0
defaultbasisfactory.hh
Go to the documentation of this file.
00001 #ifndef DUNE_DEFAULTBASISFACTORY_HH
00002 #define DUNE_DEFAULTBASISFACTORY_HH
00003 
00004 #include <fstream>
00005 #include <dune/common/exceptions.hh>
00006 #include <dune/geometry/topologyfactory.hh>
00007 
00008 #include <dune/localfunctions/utility/basismatrix.hh>
00009 
00010 namespace Dune
00011 {
00012   struct Identity
00013   {
00014     template <class T>
00015     static T apply( const T &t )
00016     {
00017       return t;
00018     }
00019   };
00020   /************************************************
00021    * Class for providing a factory for basis 
00022    * functions over the set of reference elements.
00023    * Is based on the TopolgyFactory but additionaly
00024    * provides rebindes of the field type.
00025    * The user provides factories for the pre basis and the
00026    * interpolations. The default construction process of
00027    * the basis is performed in this class.
00028    ************************************************/
00029   template< class PreBFactory,
00030             class InterpolFactory,
00031             unsigned int dim, unsigned int dimR,
00032             class SF, class CF,
00033             class PreBasisKeyExtractor = Identity >
00034   struct DefaultBasisFactory;
00035 
00036   template< class PreBFactory,
00037             class InterpolFactory,
00038             unsigned int dim, unsigned int dimR,
00039             class SF, class CF,
00040             class PreBasisKeyExtractor >
00041   struct DefaultBasisFactoryTraits
00042   {
00043     static const unsigned int dimension = dim;
00044     static const unsigned int dimRange  = dimR;
00045 
00046     typedef PreBFactory PreBasisFactory;
00047     typedef typename PreBasisFactory::Object PreBasis;
00048     typedef InterpolFactory InterpolationFactory;
00049     typedef typename InterpolationFactory::Object Interpolation;
00050 
00051     typedef typename PreBasisFactory::template EvaluationBasisFactory<dim,SF>::Type MonomialBasisFactory;
00052     typedef typename MonomialBasisFactory::Object MonomialBasis;
00053     typedef StandardEvaluator< MonomialBasis > Evaluator;
00054     typedef PolynomialBasisWithMatrix< Evaluator, SparseCoeffMatrix< SF, dimRange > > Basis;
00055 
00056     typedef const Basis Object;
00057     typedef typename InterpolationFactory::Key Key; 
00058     typedef DefaultBasisFactory<PreBFactory,InterpolFactory,dim,dimR,SF,CF,PreBasisKeyExtractor> Factory;
00059   };
00060 
00061   template< class PreBFactory,
00062             class InterpolFactory,
00063             unsigned int dim, unsigned int dimR,
00064             class SF, class CF,
00065             class PreBasisKeyExtractor >
00066   struct DefaultBasisFactory
00067    : public TopologyFactory< 
00068               DefaultBasisFactoryTraits< PreBFactory,InterpolFactory,dim,dimR,SF,CF,PreBasisKeyExtractor > 
00069             >
00070   {
00071     typedef DefaultBasisFactoryTraits< PreBFactory,InterpolFactory,dim,dimR,SF,CF,PreBasisKeyExtractor > Traits;
00072     static const unsigned int dimension = Traits::dimension;
00073     static const unsigned int dimRange  = Traits::dimRange;
00074     typedef SF StorageField;
00075     typedef CF ComputeField;
00076     typedef typename Traits::Basis Basis;
00077     typedef typename Traits::PreBasisFactory PreBasisFactory;
00078 
00079     typedef typename Traits::Object Object;
00080     typedef typename Traits::Key Key;
00081     template <unsigned int dd, class FF>
00082     struct EvaluationBasisFactory
00083     {
00084       typedef typename Traits::PreBasisFactory::template EvaluationBasisFactory<dd,FF>::Type 
00085         Type;
00086     };
00087 
00088     template< class Topology >
00089     static Object *createObject ( const Key &key )
00090     {
00091       const typename PreBasisFactory::Key preBasisKey = PreBasisKeyExtractor::apply(key);
00092       const typename Traits::PreBasis *preBasis = Traits::PreBasisFactory::template create<Topology>( preBasisKey );
00093       const typename Traits::Interpolation *interpol = Traits::InterpolationFactory::template create<Topology>( key );
00094       BasisMatrix< typename Traits::PreBasis,
00095                    typename Traits::Interpolation,
00096                    ComputeField > matrix( *preBasis, *interpol );
00097 
00098       const typename Traits::MonomialBasis *monomialBasis = Traits::MonomialBasisFactory::template create< Topology >( preBasis->order() );
00099       
00100       Basis *basis = new Basis( *monomialBasis );
00101 
00102       basis->fill( matrix );
00103 
00104       Traits::InterpolationFactory::release(interpol);
00105       Traits::PreBasisFactory::release(preBasis);
00106 
00107       return basis;
00108     }
00110     static void release( Object *object) 
00111     {
00112       const typename Traits::MonomialBasis *monomialBasis = &(object->basis());
00113       delete object;
00114       Traits::MonomialBasisFactory::release( monomialBasis );
00115     }
00116   };
00117 }
00118 
00119 #endif // #ifndef DUNE_DEFAULTBASISFACTORY_HH
00120