Loading [MathJax]/extensions/tex2jax.js

Dune Core Modules (2.3.1)

dofadmin.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_ALBERTA_DOFADMIN_HH
4#define DUNE_ALBERTA_DOFADMIN_HH
5
6#include <dune/grid/albertagrid/misc.hh>
8
9#if HAVE_ALBERTA
10
11namespace Dune
12{
13
14 namespace Alberta
15 {
16
17 // External Forward Declarations
18 // -----------------------------
19
20 template< int dim >
21 class MeshPointer;
22
23
24
25 // DofAccess
26 // ---------
27
28 template< int dim, int codim >
29 class DofAccess
30 {
31 static const int codimtype = CodimType< dim, codim >::value;
32
33 public:
34 static const int numSubEntities = NumSubEntities< dim, codim >::value;
35
36 static const int dimension = dim;
37 static const int codimension = codim;
38
39 typedef Alberta::ElementInfo< dimension > ElementInfo;
40
41 DofAccess ()
42 : node_( -1 )
43 {}
44
45 explicit DofAccess ( const DofSpace *dofSpace )
46 {
47 assert( dofSpace );
48 node_ = dofSpace->admin->mesh->node[ codimtype ];
49 index_ = dofSpace->admin->n0_dof[ codimtype ];
50 }
51
52 int operator() ( const Element *element, int subEntity, int i ) const
53 {
54 assert( element );
55 assert( node_ != -1 );
56 assert( subEntity < numSubEntities );
57 return element->dof[ node_ + subEntity ][ index_ + i ];
58 }
59
60 int operator() ( const Element *element, int subEntity ) const
61 {
62 return (*this)( element, subEntity, 0 );
63 }
64
65 int operator() ( const ElementInfo &elementInfo, int subEntity, int i ) const
66 {
67 return (*this)( elementInfo.el(), subEntity, i );
68 }
69
70 int operator() ( const ElementInfo &elementInfo, int subEntity ) const
71 {
72 return (*this)( elementInfo.el(), subEntity );
73 }
74
75 private:
76 int node_;
77 int index_;
78 };
79
80
81
82 // HierarchyDofNumbering
83 // ---------------------
84
85 template< int dim >
86 class HierarchyDofNumbering
87 {
88 typedef HierarchyDofNumbering< dim > This;
89
90 public:
91 static const int dimension = dim;
92
93 typedef Alberta::MeshPointer< dimension > MeshPointer;
94 typedef Alberta::ElementInfo< dimension > ElementInfo;
95
96 private:
97 static const int nNodeTypes = N_NODE_TYPES;
98
99 template< int codim >
100 struct CreateDofSpace;
101
102 template< int codim >
103 struct CacheDofSpace;
104
105 typedef std::pair< int, int > Cache;
106
107 public:
108 HierarchyDofNumbering ()
109 {}
110
111 private:
112 HierarchyDofNumbering ( const This & );
113 This &operator= ( const This & );
114
115 public:
116 ~HierarchyDofNumbering ()
117 {
118 release();
119 }
120
121 int operator() ( const Element *element, int codim, unsigned int subEntity ) const
122 {
123 assert( !(*this) == false );
124 assert( (codim >= 0) && (codim <= dimension) );
125 const Cache &cache = cache_[ codim ];
126 return element->dof[ cache.first + subEntity ][ cache.second ];
127 }
128
129 int operator() ( const ElementInfo &element, int codim, unsigned int subEntity ) const
130 {
131 return (*this)( element.el(), codim, subEntity );
132 }
133
134 operator bool () const
135 {
136 return (bool)mesh_;
137 }
138
139 const DofSpace *dofSpace ( int codim ) const
140 {
141 assert( *this );
142 assert( (codim >= 0) && (codim <= dimension) );
143 return dofSpace_[ codim ];
144 }
145
146 const DofSpace *emptyDofSpace () const
147 {
148 assert( *this );
149 return emptySpace_;
150 }
151
152 const MeshPointer &mesh () const
153 {
154 return mesh_;
155 }
156
157 int size ( int codim ) const
158 {
159 return dofSpace( codim )->admin->size;
160 }
161
162 void create ( const MeshPointer &mesh );
163
164 void release ()
165 {
166 if( *this )
167 {
168 for( int codim = 0; codim <= dimension; ++codim )
169 freeDofSpace( dofSpace_[ codim ] );
170 freeDofSpace( emptySpace_ );
171 mesh_ = MeshPointer();
172 }
173 }
174
175 private:
176 static const DofSpace *createEmptyDofSpace ( const MeshPointer &mesh );
177 static const DofSpace *createDofSpace ( const MeshPointer &mesh,
178 const std::string &name,
179 const int (&ndof)[ nNodeTypes ],
180 const bool periodic = false );
181 static void freeDofSpace ( const DofSpace *dofSpace );
182
183 MeshPointer mesh_;
184 const DofSpace *emptySpace_;
185 const DofSpace *dofSpace_[ dimension+1 ];
186 Cache cache_[ dimension+1 ];
187 };
188
189
190
191 template< int dim >
192 inline void
193 HierarchyDofNumbering< dim >::create ( const MeshPointer &mesh )
194 {
195 release();
196
197 if( !mesh )
198 return;
199
200 mesh_ = mesh;
201 ForLoop< CreateDofSpace, 0, dimension >::apply( mesh_, dofSpace_ );
202 ForLoop< CacheDofSpace, 0, dimension >::apply( dofSpace_, cache_ );
203
204 emptySpace_ = createEmptyDofSpace( mesh_ );
205 for( int i = 0; i < nNodeTypes; ++i )
206 assert( emptySpace_->admin->n_dof[ i ] == 0 );
207 }
208
209
210
211 template< int dim >
212 inline const DofSpace *
213 HierarchyDofNumbering< dim >::createEmptyDofSpace ( const MeshPointer &mesh )
214 {
215 int ndof[ nNodeTypes ];
216 for( int i = 0; i < nNodeTypes; ++i )
217 ndof[ i ] = 0;
218 std::string name = "Empty";
219 return createDofSpace( mesh, name, ndof );
220 }
221
222
223#if DUNE_ALBERTA_VERSION >= 0x300
224 template< int dim >
225 inline const DofSpace *
226 HierarchyDofNumbering< dim >::createDofSpace ( const MeshPointer &mesh,
227 const std::string &name,
228 const int (&ndof)[ nNodeTypes ],
229 const bool periodic )
230 {
231 const ALBERTA FLAGS flags
232 = ADM_PRESERVE_COARSE_DOFS | (periodic ? ADM_PERIODIC : 0);
233 return ALBERTA get_dof_space ( mesh, name.c_str(), ndof, flags );
234 }
235#endif // #if DUNE_ALBERTA_VERSION >= 0x300
236
237#if DUNE_ALBERTA_VERSION == 0x200
238 template< int dim >
239 inline const DofSpace *
240 HierarchyDofNumbering< dim >::createDofSpace ( const MeshPointer &mesh,
241 const std::string &name,
242 const int (&ndof)[ nNodeTypes ],
243 const bool periodic )
244 {
245 return ALBERTA get_fe_space( mesh, name.c_str(), ndof, NULL, 1 );
246 }
247#endif // #if DUNE_ALBERTA_VERSION == 0x200
248
249
250#if DUNE_ALBERTA_VERSION >= 0x300
251 template< int dim >
252 inline void
253 HierarchyDofNumbering< dim >::freeDofSpace ( const DofSpace *dofSpace )
254 {
255 ALBERTA free_fe_space( dofSpace );
256 }
257#endif // #if DUNE_ALBERTA_VERSION >= 0x300
258
259#if DUNE_ALBERTA_VERSION == 0x200
260 template< int dim >
261 inline void
262 HierarchyDofNumbering< dim >::freeDofSpace ( const DofSpace *dofSpace )
263 {
264 // the const cast is needed due to a bug in ALBERTA 2.0
265 ALBERTA free_fe_space( const_cast< DofSpace * >( dofSpace ) );
266 }
267#endif // #if DUNE_ALBERTA_VERSION == 0x200
268
269
270
271 // HierarchyDofNumbering::CreateDofSpace
272 // -------------------------------------
273
274 template< int dim >
275 template< int codim >
276 struct HierarchyDofNumbering< dim >::CreateDofSpace
277 {
278 static void apply ( const MeshPointer &mesh, const DofSpace *(&dofSpace)[ dim+1 ] )
279 {
280 int ndof[ nNodeTypes ];
281 for( int i = 0; i < nNodeTypes; ++i )
282 ndof[ i ] = 0;
283 ndof[ CodimType< dim, codim >::value ] = 1;
284
285 std::string name = "Codimension ";
286 name += (char)(codim + '0');
287
288 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
289 assert( dofSpace[ codim ] );
290 }
291 };
292
293
294
295 // HierarchyDofNumbering::CacheDofSpace
296 // ------------------------------------
297
298 template< int dim >
299 template< int codim >
300 struct HierarchyDofNumbering< dim >::CacheDofSpace
301 {
302 static void apply ( const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
303 {
304 assert( dofSpace[ codim ] );
305 const int codimtype = CodimType< dim, codim >::value;
306 cache[ codim ].first = dofSpace[ codim ]->mesh->node[ codimtype ];
307 cache[ codim ].second = dofSpace[ codim ]->admin->n0_dof[ codimtype ];
308 }
309 };
310
311 } // namespace Alberta
312
313} // namespace Dune
314
315#endif // #if HAVE_ALBERTA
316
317#endif // #ifndef DUNE_ALBERTA_DOFADMIN_HH
provides a wrapper for ALBERTA's el_info structure
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 11, 22:45, 2025)