dune-grid  2.2.0
objectfactory.hh
Go to the documentation of this file.
1 #ifndef DUNE_ALUGRIDOBJECTFACTORY_HH
2 #define DUNE_ALUGRIDOBJECTFACTORY_HH
3 
5 
6 #if defined USE_PTHREADS || defined _OPENMP
7 #define USE_SMP_PARALLEL
8 #endif
9 
10 #ifdef _OPENMP
11 #include <omp.h>
12 #endif
13 
14 #if HAVE_DUNE_FEM
15 #include <dune/fem/misc/threadmanager.hh>
16 #endif
17 
18 namespace Dune
19 {
20  template <class InterfaceType>
21  struct MakeableInterfaceObject ;
22 
23  template <class GridImp>
25  {
26  template <class OF, int codim>
27  struct ALUGridEntityFactory;
28 
30  //
31  // partial specialization of method getNewEntity
32  //
34  template <class GridObjectFactory>
35  struct ALUGridEntityFactory<GridObjectFactory,0>
36  {
37  enum { codim = 0 };
38  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
40  typedef typename EntityObject :: ImplementationType EntityImp;
41 
42  inline static EntityObject *
43  getNewEntity (const GridObjectFactory& factory, int level)
44  {
45  return factory.entityProvider_.getEntityObject( factory, level, (EntityImp *) 0);
46  }
47 
48  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
49  {
50  factory.entityProvider_.freeObject( e );
51  }
52  };
53 
54  template <class GridObjectFactory>
55  struct ALUGridEntityFactory<GridObjectFactory,1>
56  {
57  enum { codim = 1 };
58  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
60  typedef typename EntityObject :: ImplementationType EntityImp;
61 
62  inline static EntityObject *
63  getNewEntity (const GridObjectFactory& factory, int level)
64  {
65  return factory.faceProvider_.getEntityObject( factory, level, (EntityImp *) 0);
66  }
67 
68  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
69  {
70  factory.faceProvider_.freeObject( e );
71  }
72  };
73 
74  template <class GridObjectFactory>
75  struct ALUGridEntityFactory<GridObjectFactory,2>
76  {
77  enum { codim = 2 };
78  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
80  typedef typename EntityObject :: ImplementationType EntityImp;
81 
82  inline static EntityObject *
83  getNewEntity (const GridObjectFactory& factory, int level)
84  {
85  return factory.edgeProvider_.getEntityObject( factory, level, (EntityImp *) 0);
86  }
87 
88  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
89  {
90  factory.edgeProvider_.freeObject( e );
91  }
92  };
93 
94  template <class GridObjectFactory>
95  struct ALUGridEntityFactory<GridObjectFactory,3>
96  {
97  enum { codim = 3 };
98  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
100  typedef typename EntityObject :: ImplementationType EntityImp;
101 
102  inline static EntityObject *
103  getNewEntity (const GridObjectFactory& factory, int level)
104  {
105  return factory.vertexProvider_.getEntityObject( factory, level, (EntityImp *) 0);
106  }
107 
108  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
109  {
110  factory.vertexProvider_.freeObject( e );
111  }
112  }; // end of ALUGridEntityFactory
113 
114  enum { vxCodim = GridImp :: dimension };
115  public:
116  typedef GridImp GridType;
118 
123 
124  typedef typename GridType :: LeafIntersectionIteratorImp LeafIntersectionIteratorImp ;
125  typedef typename GridType :: LevelIntersectionIteratorImp LevelIntersectionIteratorImp ;
126 
127  // declare friendship
128  friend class ALUGridEntityFactory<FactoryType,0>;
129  friend class ALUGridEntityFactory<FactoryType,1>;
130  friend class ALUGridEntityFactory<FactoryType,2>;
131  friend class ALUGridEntityFactory<FactoryType,3>;
132 
133  protected:
138 
143 
146 
149 
150  const GridType& grid_ ;
151 
152 #ifdef USE_SMP_PARALLEL
153  public:
154 #endif
155  ALUGridObjectFactory( const ALUGridObjectFactory& other ) : grid_( other.grid_ ) {}
156 
157  public:
158  const GridType& grid() const { return grid_; }
159 
160  ALUGridObjectFactory( const GridType& grid ) : grid_( grid ) {}
161 
162  template <int codim>
164  getNewEntity ( int level = -1 ) const
165  {
167  }
168 
169  template <int codim>
170  inline void freeEntity (MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * en) const
171  {
173  }
174 
176  {
177  return * (leafInterItProvider_.getObject( *this, wLevel ));
178  }
179 
181  {
182  return * (levelInterItProvider_.getObject( *this, wLevel ));
183  }
184 
188 
189  // return thread number
190  static inline int threadNumber()
191  {
192 #ifdef _OPENMP
193  return omp_get_thread_num();
194 #elif HAVE_DUNE_FEM
196 #else
197  return 0;
198 #endif
199  }
200 
201  // return maximal possible number of threads
202  static inline int maxThreads() {
203 #ifdef _OPENMP
204  return omp_get_max_threads();
205 #elif HAVE_DUNE_FEM
207 #else
208  return 1;
209 #endif
210  }
211  };
212 
213 } // end namespace Dune
214 #endif