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