traceprovider.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GENERICGEOMETRY_TRACEPROVIDER_HH
00002 #define DUNE_GENERICGEOMETRY_TRACEPROVIDER_HH
00003 
00004 #include <dune/common/forloop.hh>
00005 #include <dune/common/typetraits.hh>
00006 #include <dune/grid/genericgeometry/subtopologies.hh>
00007 
00008 namespace Dune
00009 {
00010 
00011   namespace GenericGeometry
00012   {
00013 
00014     // External Forward Declarations
00015     // -----------------------------
00016 
00017     template< class Topology, class GeometryTraits >
00018     class CachedMapping;
00019 
00020     template< unsigned int dim, class GeometryTraits >
00021     class HybridMapping;
00022 
00023     template< class Topology, class GeometryTraits >
00024     class VirtualMapping;
00025 
00026 
00027 
00028     // TraceProvider
00029     // -------------
00030 
00031     template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
00032     class TraceProvider
00033     {
00034       typedef TraceProvider< Topology, GeometryTraits, codim, forceHybrid > This;
00035 
00036     public:
00037       static const unsigned int dimension = Topology :: dimension;
00038       static const unsigned int codimension = codim;
00039       static const unsigned int mydimension = dimension - codimension;
00040 
00041       static const bool hybrid
00042         = (forceHybrid || IsCodimHybrid< Topology, codim > :: value);
00043 
00044       typedef typename CachedMapping< Topology, GeometryTraits > :: Mapping Mapping;
00045 
00046     private:
00047       static const unsigned int numSubTopologies
00048         = Mapping :: ReferenceElement :: template Codim< codimension > :: size;
00049 
00050       template< bool > class HybridFactory;
00051       template< bool > class NonHybridFactory;
00052 
00053       typedef typename SelectType< hybrid, HybridFactory<true>, NonHybridFactory<false> > :: Type Factory;
00054 
00055       template< int i > struct Builder;
00056 
00057     public:
00058       typedef typename Factory::Trace Trace;
00059 
00060       static Trace* construct ( const Mapping &mapping, unsigned int i, char *traceStorage )
00061       {
00062         return (*instance().construct_[ i ])( mapping, traceStorage );
00063       }
00064 
00065     private:
00066       typedef Trace* (*Construct) ( const Mapping &mapping, char *traceStorage );
00067 
00068       TraceProvider ()
00069       {
00070         ForLoop< Builder, 0, numSubTopologies-1 >::apply( construct_ );
00071       }
00072 
00073       static const This &instance ()
00074       {
00075         static This theInstance;
00076         return theInstance;
00077       }
00078 
00079       Construct construct_[ numSubTopologies ];
00080     };
00081 
00082 
00083 
00084     template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
00085     template< bool >
00086     class TraceProvider< Topology, GeometryTraits, codim, forceHybrid > :: HybridFactory
00087     {
00088       template< unsigned int i >
00089       struct VirtualTrace
00090       {
00091         typedef typename GenericGeometry :: SubTopology< Topology, codim, i > :: type
00092           SubTopology;
00093         typedef VirtualMapping< SubTopology, GeometryTraits > type;
00094       };
00095 
00096     public:
00097       typedef HybridMapping< mydimension, GeometryTraits > Trace;
00098 
00099       template< int i >
00100       static Trace* construct ( const Mapping &mapping, char *traceStorage )
00101       {
00102         typedef typename VirtualTrace< i >::type TraceImpl;
00103         return new( traceStorage ) TraceImpl( mapping.template trace< codim, i >() );
00104       }
00105     };
00106 
00107 
00108 
00109     template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
00110     template< bool >
00111     class TraceProvider< Topology, GeometryTraits, codim, forceHybrid > :: NonHybridFactory
00112     {
00113       typedef typename GenericGeometry :: SubTopology< Topology, codim, 0 > :: type
00114         SubTopology;
00115 
00116     public:
00117       typedef CachedMapping< SubTopology, GeometryTraits > Trace;
00118 
00119       template< int i >
00120       static Trace* construct ( const Mapping &mapping, char *traceStorage )
00121       {
00122         return new( traceStorage ) Trace( mapping.template trace< codim, i >() );
00123       }
00124     };
00125 
00126 
00127 
00128     template< class Topology, class GeometryTraits, unsigned int codim, bool forceHybrid >
00129     template< int i >
00130     struct TraceProvider< Topology, GeometryTraits, codim, forceHybrid > :: Builder
00131     {
00132       static void apply ( Construct (&construct)[ numSubTopologies ] )
00133       {
00134         construct[ i ] = &(Factory::template construct< i >);
00135       }
00136     };
00137 
00138   }
00139 
00140 }
00141 
00142 #endif // #ifndef DUNE_GENERICGEOMETRY_TRACEPROVIDER_HH

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