- Home
- About DUNE
- Download
- Documentation
- Community
- Development
00001 #ifndef DUNE_ALUGRIDOBJECTFACTORY_HH 00002 #define DUNE_ALUGRIDOBJECTFACTORY_HH 00003 00004 #include <dune/grid/alugrid/common/memory.hh> 00005 00006 #if defined USE_PTHREADS || defined _OPENMP 00007 #define USE_SMP_PARALLEL 00008 #endif 00009 00010 #ifdef _OPENMP 00011 #include <omp.h> 00012 #endif 00013 00014 #if HAVE_DUNE_FEM 00015 #include <dune/fem/misc/threadmanager.hh> 00016 #endif 00017 00018 namespace Dune 00019 { 00020 template <class GridImp> 00021 class ALUGridObjectFactory 00022 { 00023 template <class OF, int codim> 00024 struct ALUGridEntityFactory; 00025 00027 // 00028 // partial specialization of method getNewEntity 00029 // 00031 template <class GridObjectFactory> 00032 struct ALUGridEntityFactory<GridObjectFactory,0> 00033 { 00034 enum { codim = 0 }; 00035 typedef typename GridImp :: template Codim<codim> :: Entity Entity; 00036 typedef MakeableInterfaceObject<Entity> EntityObject; 00037 typedef typename EntityObject :: ImplementationType EntityImp; 00038 00039 inline static EntityObject * 00040 getNewEntity (const GridObjectFactory& factory, int level) 00041 { 00042 return factory.entityProvider_.getEntityObject( factory, level, (EntityImp *) 0); 00043 } 00044 00045 inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e ) 00046 { 00047 factory.entityProvider_.freeObject( e ); 00048 } 00049 }; 00050 00051 template <class GridObjectFactory> 00052 struct ALUGridEntityFactory<GridObjectFactory,1> 00053 { 00054 enum { codim = 1 }; 00055 typedef typename GridImp :: template Codim<codim> :: Entity Entity; 00056 typedef MakeableInterfaceObject<Entity> EntityObject; 00057 typedef typename EntityObject :: ImplementationType EntityImp; 00058 00059 inline static EntityObject * 00060 getNewEntity (const GridObjectFactory& factory, int level) 00061 { 00062 return factory.faceProvider_.getEntityObject( factory, level, (EntityImp *) 0); 00063 } 00064 00065 inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e ) 00066 { 00067 factory.faceProvider_.freeObject( e ); 00068 } 00069 }; 00070 00071 template <class GridObjectFactory> 00072 struct ALUGridEntityFactory<GridObjectFactory,2> 00073 { 00074 enum { codim = 2 }; 00075 typedef typename GridImp :: template Codim<codim> :: Entity Entity; 00076 typedef MakeableInterfaceObject<Entity> EntityObject; 00077 typedef typename EntityObject :: ImplementationType EntityImp; 00078 00079 inline static EntityObject * 00080 getNewEntity (const GridObjectFactory& factory, int level) 00081 { 00082 return factory.edgeProvider_.getEntityObject( factory, level, (EntityImp *) 0); 00083 } 00084 00085 inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e ) 00086 { 00087 factory.edgeProvider_.freeObject( e ); 00088 } 00089 }; 00090 00091 template <class GridObjectFactory> 00092 struct ALUGridEntityFactory<GridObjectFactory,3> 00093 { 00094 enum { codim = 3 }; 00095 typedef typename GridImp :: template Codim<codim> :: Entity Entity; 00096 typedef MakeableInterfaceObject<Entity> EntityObject; 00097 typedef typename EntityObject :: ImplementationType EntityImp; 00098 00099 inline static EntityObject * 00100 getNewEntity (const GridObjectFactory& factory, int level) 00101 { 00102 return factory.vertexProvider_.getEntityObject( factory, level, (EntityImp *) 0); 00103 } 00104 00105 inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e ) 00106 { 00107 factory.vertexProvider_.freeObject( e ); 00108 } 00109 }; // end of ALUGridEntityFactory 00110 00111 enum { vxCodim = GridImp :: dimension }; 00112 public: 00113 typedef GridImp GridType; 00114 typedef ALUGridObjectFactory FactoryType; 00115 00116 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<0>::Entity> EntityObject; 00117 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<1>::Entity> FaceObject; 00118 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<2>::Entity> EdgeObject; 00119 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim< vxCodim >::Entity> VertexObject; 00120 00121 typedef typename GridType :: LeafIntersectionIteratorImp LeafIntersectionIteratorImp ; 00122 typedef typename GridType :: LevelIntersectionIteratorImp LevelIntersectionIteratorImp ; 00123 00124 // declare friendship 00125 friend class ALUGridEntityFactory<FactoryType,0>; 00126 friend class ALUGridEntityFactory<FactoryType,1>; 00127 friend class ALUGridEntityFactory<FactoryType,2>; 00128 friend class ALUGridEntityFactory<FactoryType,3>; 00129 00130 protected: 00131 typedef ALUMemoryProvider< EntityObject > EntityProvider; 00132 typedef ALUMemoryProvider< FaceObject > FaceProvider; 00133 typedef ALUMemoryProvider< EdgeObject > EdgeProvider; 00134 typedef ALUMemoryProvider< VertexObject > VertexProvider; 00135 00136 mutable EntityProvider entityProvider_; 00137 mutable FaceProvider faceProvider_; 00138 mutable EdgeProvider edgeProvider_; 00139 mutable VertexProvider vertexProvider_; 00140 00141 typedef ALUMemoryProvider< LeafIntersectionIteratorImp > LeafIntersectionIteratorProviderType; 00142 typedef ALUMemoryProvider< LevelIntersectionIteratorImp > LevelIntersectionIteratorProviderType; 00143 00144 mutable LeafIntersectionIteratorProviderType leafInterItProvider_; 00145 mutable LevelIntersectionIteratorProviderType levelInterItProvider_; 00146 00147 const GridType& grid_ ; 00148 00149 #ifdef USE_SMP_PARALLEL 00150 public: 00151 #endif 00152 ALUGridObjectFactory( const ALUGridObjectFactory& other ) : grid_( other.grid_ ) {} 00153 00154 public: 00155 const GridType& grid() const { return grid_; } 00156 00157 ALUGridObjectFactory( const GridType& grid ) : grid_( grid ) {} 00158 00159 template <int codim> 00160 inline MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * 00161 getNewEntity ( int level = -1 ) const 00162 { 00163 return ALUGridEntityFactory<FactoryType,codim>::getNewEntity( *this, level); 00164 } 00165 00166 template <int codim> 00167 inline void freeEntity (MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * en) const 00168 { 00169 ALUGridEntityFactory<FactoryType,codim>::freeEntity(*this, en); 00170 } 00171 00172 LeafIntersectionIteratorImp& getIntersection( const int wLevel, const LeafIntersectionIteratorImp* ) const 00173 { 00174 return * (leafInterItProvider_.getObject( *this, wLevel )); 00175 } 00176 00177 LevelIntersectionIteratorImp& getIntersection(const int wLevel, const LevelIntersectionIteratorImp* ) const 00178 { 00179 return * (levelInterItProvider_.getObject( *this, wLevel )); 00180 } 00181 00183 void freeIntersection(LeafIntersectionIteratorImp & it) const { leafInterItProvider_.freeObject( &it ); } 00184 void freeIntersection(LevelIntersectionIteratorImp & it) const { levelInterItProvider_.freeObject( &it ); } 00185 00186 // return thread number 00187 static inline int threadNumber() 00188 { 00189 #ifdef _OPENMP 00190 return omp_get_thread_num(); 00191 #elif HAVE_DUNE_FEM 00192 return Fem :: ThreadManager :: thread() ; 00193 #else 00194 return 0; 00195 #endif 00196 } 00197 00198 // return maximal possible number of threads 00199 static inline int maxThreads() { 00200 #ifdef _OPENMP 00201 return omp_get_max_threads(); 00202 #elif HAVE_DUNE_FEM 00203 return Fem :: ThreadManager :: maxThreads() ; 00204 #else 00205 return 1; 00206 #endif 00207 } 00208 }; 00209 00210 } // end namespace Dune 00211 #endif
Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].