Dune Core Modules (2.4.1)

objectfactory.hh
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
6#include <dune/grid/alugrid/common/memory.hh>
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
20namespace Dune
21{
22 template <class InterfaceType>
23 struct MakeableInterfaceObject ;
24
25 template <class GridImp>
26 class ALUGridObjectFactory
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;
42 typedef MakeableInterfaceObject<Entity> EntityObject;
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;
63 typedef MakeableInterfaceObject<Entity> EntityObject;
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;
84 typedef MakeableInterfaceObject<Entity> EntityObject;
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;
105 typedef MakeableInterfaceObject<Entity> EntityObject;
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;
123 typedef ALUGridObjectFactory FactoryType;
124
125 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<0>::Entity> EntityObject;
126 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<1>::Entity> FaceObject;
127 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim<2>::Entity> EdgeObject;
128 typedef MakeableInterfaceObject<typename GridType :: Traits::template Codim< vxCodim >::Entity> VertexObject;
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:
140 typedef ALUMemoryProvider< EntityObject > EntityProvider;
141 typedef ALUMemoryProvider< FaceObject > FaceProvider;
142 typedef ALUMemoryProvider< EdgeObject > EdgeProvider;
143 typedef ALUMemoryProvider< VertexObject > VertexProvider;
144
145 mutable EntityProvider entityProvider_;
146 mutable FaceProvider faceProvider_;
147 mutable EdgeProvider edgeProvider_;
148 mutable VertexProvider vertexProvider_;
149
150 typedef ALUMemoryProvider< LeafIntersectionIteratorImp > LeafIntersectionIteratorProviderType;
151 typedef ALUMemoryProvider< LevelIntersectionIteratorImp > LevelIntersectionIteratorProviderType;
152
153 mutable LeafIntersectionIteratorProviderType leafInterItProvider_;
154 mutable LevelIntersectionIteratorProviderType levelInterItProvider_;
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>
169 inline MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> *
170 getNewEntity ( int level = -1 ) const
171 {
172 return ALUGridEntityFactory<FactoryType,codim>::getNewEntity( *this, level);
173 }
174
175 template <int codim>
176 inline void freeEntity (MakeableInterfaceObject<typename GridType :: Traits::template Codim<codim>::Entity> * en) const
177 {
178 ALUGridEntityFactory<FactoryType,codim>::freeEntity(*this, en);
179 }
180
181 LeafIntersectionIteratorImp& getIntersection( const int wLevel, const LeafIntersectionIteratorImp* ) const
182 {
183 return * (leafInterItProvider_.getObject( *this, wLevel ));
184 }
185
186 LevelIntersectionIteratorImp& getIntersection(const int wLevel, const LevelIntersectionIteratorImp* ) const
187 {
188 return * (levelInterItProvider_.getObject( *this, wLevel ));
189 }
190
192 void freeIntersection(LeafIntersectionIteratorImp & it) const { leafInterItProvider_.freeObject( &it ); }
193 void freeIntersection(LevelIntersectionIteratorImp & it) const { levelInterItProvider_.freeObject( &it ); }
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
201 return Fem :: ThreadManager :: thread() ;
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
212 return Fem :: ThreadManager :: maxThreads() ;
213#else
214 return 1;
215#endif
216 }
217 };
218
219} // end namespace Dune
220#endif
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)