dune-grid  2.2.1
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  class ALUGridEntityFactory;
28 
30  //
31  // partial specialization of method getNewEntity
32  //
34  template <class GridObjectFactory>
35  class ALUGridEntityFactory<GridObjectFactory,0>
36  {
37  public:
38  enum { codim = 0 };
39  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
41  typedef typename EntityObject :: ImplementationType EntityImp;
42 
43  inline static EntityObject *
44  getNewEntity (const GridObjectFactory& factory, int level)
45  {
46  return factory.entityProvider_.getEntityObject( factory, level, (EntityImp *) 0);
47  }
48 
49  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
50  {
51  factory.entityProvider_.freeObject( e );
52  }
53  };
54 
55  template <class GridObjectFactory>
56  class ALUGridEntityFactory<GridObjectFactory,1>
57  {
58  public:
59  enum { codim = 1 };
60  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
62  typedef typename EntityObject :: ImplementationType EntityImp;
63 
64  inline static EntityObject *
65  getNewEntity (const GridObjectFactory& factory, int level)
66  {
67  return factory.faceProvider_.getEntityObject( factory, level, (EntityImp *) 0);
68  }
69 
70  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
71  {
72  factory.faceProvider_.freeObject( e );
73  }
74  };
75 
76  template <class GridObjectFactory>
77  class ALUGridEntityFactory<GridObjectFactory,2>
78  {
79  public:
80  enum { codim = 2 };
81  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
83  typedef typename EntityObject :: ImplementationType EntityImp;
84 
85  inline static EntityObject *
86  getNewEntity (const GridObjectFactory& factory, int level)
87  {
88  return factory.edgeProvider_.getEntityObject( factory, level, (EntityImp *) 0);
89  }
90 
91  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
92  {
93  factory.edgeProvider_.freeObject( e );
94  }
95  };
96 
97  template <class GridObjectFactory>
98  class ALUGridEntityFactory<GridObjectFactory,3>
99  {
100  public:
101  enum { codim = 3 };
102  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
104  typedef typename EntityObject :: ImplementationType EntityImp;
105 
106  inline static EntityObject *
107  getNewEntity (const GridObjectFactory& factory, int level)
108  {
109  return factory.vertexProvider_.getEntityObject( factory, level, (EntityImp *) 0);
110  }
111 
112  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
113  {
114  factory.vertexProvider_.freeObject( e );
115  }
116  }; // end of ALUGridEntityFactory
117 
118  enum { vxCodim = GridImp :: dimension };
119  public:
120  typedef GridImp GridType;
122 
127 
128  typedef typename GridType :: LeafIntersectionIteratorImp LeafIntersectionIteratorImp ;
129  typedef typename GridType :: LevelIntersectionIteratorImp LevelIntersectionIteratorImp ;
130 
131  // declare friendship
132  friend class ALUGridEntityFactory<FactoryType,0>;
133  friend class ALUGridEntityFactory<FactoryType,1>;
134  friend class ALUGridEntityFactory<FactoryType,2>;
135  friend class ALUGridEntityFactory<FactoryType,3>;
136 
137  protected:
142 
147 
150 
153 
154  const GridType& grid_ ;
155 
156 #ifdef USE_SMP_PARALLEL
157  public:
158 #endif
159  ALUGridObjectFactory( const ALUGridObjectFactory& other ) : grid_( other.grid_ ) {}
160 
161  public:
162  const GridType& grid() const { return grid_; }
163 
164  ALUGridObjectFactory( const GridType& grid ) : grid_( grid ) {}
165 
166  template <int codim>
168  getNewEntity ( int level = -1 ) const
169  {
171  }
172 
173  template <int codim>
174  inline void freeEntity (MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * en) const
175  {
177  }
178 
180  {
181  return * (leafInterItProvider_.getObject( *this, wLevel ));
182  }
183 
185  {
186  return * (levelInterItProvider_.getObject( *this, wLevel ));
187  }
188 
192 
193  // return thread number
194  static inline int threadNumber()
195  {
196 #ifdef _OPENMP
197  return omp_get_thread_num();
198 #elif HAVE_DUNE_FEM
200 #else
201  return 0;
202 #endif
203  }
204 
205  // return maximal possible number of threads
206  static inline int maxThreads() {
207 #ifdef _OPENMP
208  return omp_get_max_threads();
209 #elif HAVE_DUNE_FEM
211 #else
212  return 1;
213 #endif
214  }
215  };
216 
217 } // end namespace Dune
218 #endif