dune-grid  2.3.1
objectfactory.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALUGRIDOBJECTFACTORY_HH
4 #define DUNE_ALUGRIDOBJECTFACTORY_HH
5 
7 
8 #if defined USE_PTHREADS || defined _OPENMP
9 #define USE_SMP_PARALLEL
10 #endif
11 
12 #ifdef _OPENMP
13 #include <omp.h>
14 #endif
15 
16 #if HAVE_DUNE_FEM
17 #include <dune/fem/misc/threads/threadmanager.hh>
18 #endif
19 
20 namespace Dune
21 {
22  template <class InterfaceType>
23  struct MakeableInterfaceObject ;
24 
25  template <class GridImp>
27  {
28  template <class OF, int codim>
29  class ALUGridEntityFactory;
30 
32  //
33  // partial specialization of method getNewEntity
34  //
36  template <class GridObjectFactory>
37  class ALUGridEntityFactory<GridObjectFactory,0>
38  {
39  public:
40  enum { codim = 0 };
41  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
43  typedef typename EntityObject :: ImplementationType EntityImp;
44 
45  inline static EntityObject *
46  getNewEntity (const GridObjectFactory& factory, int level)
47  {
48  return factory.entityProvider_.getEntityObject( factory, level, (EntityImp *) 0);
49  }
50 
51  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
52  {
53  factory.entityProvider_.freeObject( e );
54  }
55  };
56 
57  template <class GridObjectFactory>
58  class ALUGridEntityFactory<GridObjectFactory,1>
59  {
60  public:
61  enum { codim = 1 };
62  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
64  typedef typename EntityObject :: ImplementationType EntityImp;
65 
66  inline static EntityObject *
67  getNewEntity (const GridObjectFactory& factory, int level)
68  {
69  return factory.faceProvider_.getEntityObject( factory, level, (EntityImp *) 0);
70  }
71 
72  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
73  {
74  factory.faceProvider_.freeObject( e );
75  }
76  };
77 
78  template <class GridObjectFactory>
79  class ALUGridEntityFactory<GridObjectFactory,2>
80  {
81  public:
82  enum { codim = 2 };
83  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
85  typedef typename EntityObject :: ImplementationType EntityImp;
86 
87  inline static EntityObject *
88  getNewEntity (const GridObjectFactory& factory, int level)
89  {
90  return factory.edgeProvider_.getEntityObject( factory, level, (EntityImp *) 0);
91  }
92 
93  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
94  {
95  factory.edgeProvider_.freeObject( e );
96  }
97  };
98 
99  template <class GridObjectFactory>
100  class ALUGridEntityFactory<GridObjectFactory,3>
101  {
102  public:
103  enum { codim = 3 };
104  typedef typename GridImp :: template Codim<codim> :: Entity Entity;
106  typedef typename EntityObject :: ImplementationType EntityImp;
107 
108  inline static EntityObject *
109  getNewEntity (const GridObjectFactory& factory, int level)
110  {
111  return factory.vertexProvider_.getEntityObject( factory, level, (EntityImp *) 0);
112  }
113 
114  inline static void freeEntity(const GridObjectFactory& factory, EntityObject * e )
115  {
116  factory.vertexProvider_.freeObject( e );
117  }
118  }; // end of ALUGridEntityFactory
119 
120  enum { vxCodim = GridImp :: dimension };
121  public:
122  typedef GridImp GridType;
124 
129 
130  typedef typename GridType :: LeafIntersectionIteratorImp LeafIntersectionIteratorImp ;
131  typedef typename GridType :: LevelIntersectionIteratorImp LevelIntersectionIteratorImp ;
132 
133  // declare friendship
134  friend class ALUGridEntityFactory<FactoryType,0>;
135  friend class ALUGridEntityFactory<FactoryType,1>;
136  friend class ALUGridEntityFactory<FactoryType,2>;
137  friend class ALUGridEntityFactory<FactoryType,3>;
138 
139  protected:
144 
149 
152 
155 
156  const GridType& grid_ ;
157 
158 #ifdef USE_SMP_PARALLEL
159  public:
160 #endif
161  ALUGridObjectFactory( const ALUGridObjectFactory& other ) : grid_( other.grid_ ) {}
162 
163  public:
164  const GridType& grid() const { return grid_; }
165 
166  ALUGridObjectFactory( const GridType& grid ) : grid_( grid ) {}
167 
168  template <int codim>
170  getNewEntity ( int level = -1 ) const
171  {
173  }
174 
175  template <int codim>
176  inline void freeEntity (MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * en) const
177  {
179  }
180 
182  {
183  return * (leafInterItProvider_.getObject( *this, wLevel ));
184  }
185 
187  {
188  return * (levelInterItProvider_.getObject( *this, wLevel ));
189  }
190 
194 
195  // return thread number
196  static inline int threadNumber()
197  {
198 #ifdef _OPENMP
199  return omp_get_thread_num();
200 #elif HAVE_DUNE_FEM
202 #else
203  return 0;
204 #endif
205  }
206 
207  // return maximal possible number of threads
208  static inline int maxThreads() {
209 #ifdef _OPENMP
210  return omp_get_max_threads();
211 #elif HAVE_DUNE_FEM
213 #else
214  return 1;
215 #endif
216  }
217  };
218 
219 } // end namespace Dune
220 #endif