Dune Core Modules (2.4.2)

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 template< int dim >
224 inline const DofSpace *
225 HierarchyDofNumbering< dim >::createDofSpace ( const MeshPointer &mesh,
226 const std::string &name,
227 const int (&ndof)[ nNodeTypes ],
228 const bool periodic )
229 {
230 const ALBERTA FLAGS flags
231 = ADM_PRESERVE_COARSE_DOFS | (periodic ? ADM_PERIODIC : 0);
232 return ALBERTA get_dof_space ( mesh, name.c_str(), ndof, flags );
233 }
234
235
236 template< int dim >
237 inline void
238 HierarchyDofNumbering< dim >::freeDofSpace ( const DofSpace *dofSpace )
239 {
240 ALBERTA free_fe_space( dofSpace );
241 }
242
243
244
245 // HierarchyDofNumbering::CreateDofSpace
246 // -------------------------------------
247
248 template< int dim >
249 template< int codim >
250 struct HierarchyDofNumbering< dim >::CreateDofSpace
251 {
252 static void apply ( const MeshPointer &mesh, const DofSpace *(&dofSpace)[ dim+1 ] )
253 {
254 int ndof[ nNodeTypes ];
255 for( int i = 0; i < nNodeTypes; ++i )
256 ndof[ i ] = 0;
257 ndof[ CodimType< dim, codim >::value ] = 1;
258
259 std::string name = "Codimension ";
260 name += (char)(codim + '0');
261
262 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
263 assert( dofSpace[ codim ] );
264 }
265 };
266
267
268
269 // HierarchyDofNumbering::CacheDofSpace
270 // ------------------------------------
271
272 template< int dim >
273 template< int codim >
274 struct HierarchyDofNumbering< dim >::CacheDofSpace
275 {
276 static void apply ( const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
277 {
278 assert( dofSpace[ codim ] );
279 const int codimtype = CodimType< dim, codim >::value;
280 cache[ codim ].first = dofSpace[ codim ]->mesh->node[ codimtype ];
281 cache[ codim ].second = dofSpace[ codim ]->admin->n0_dof[ codimtype ];
282 }
283 };
284
285 } // namespace Alberta
286
287} // namespace Dune
288
289#endif // #if HAVE_ALBERTA
290
291#endif // #ifndef DUNE_ALBERTA_DOFADMIN_HH
provides a wrapper for ALBERTA's el_info structure
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)