3#ifndef DUNE_ALBERTA_DOFADMIN_HH
4#define DUNE_ALBERTA_DOFADMIN_HH
6#include <dune/grid/albertagrid/misc.hh>
28 template<
int dim,
int codim >
31 static const int codimtype = CodimType< dim, codim >::value;
34 static const int numSubEntities = NumSubEntities< dim, codim >::value;
36 static const int dimension = dim;
37 static const int codimension = codim;
39 typedef Alberta::ElementInfo< dimension > ElementInfo;
45 explicit DofAccess (
const DofSpace *dofSpace )
48 node_ = dofSpace->admin->mesh->node[ codimtype ];
49 index_ = dofSpace->admin->n0_dof[ codimtype ];
52 int operator() (
const Element *element,
int subEntity,
int i )
const
55 assert( node_ != -1 );
56 assert( subEntity < numSubEntities );
57 return element->dof[ node_ + subEntity ][ index_ + i ];
60 int operator() (
const Element *element,
int subEntity )
const
62 return (*
this)( element, subEntity, 0 );
65 int operator() (
const ElementInfo &elementInfo,
int subEntity,
int i )
const
67 return (*
this)( elementInfo.el(), subEntity, i );
70 int operator() (
const ElementInfo &elementInfo,
int subEntity )
const
72 return (*
this)( elementInfo.el(), subEntity );
86 class HierarchyDofNumbering
88 typedef HierarchyDofNumbering< dim > This;
91 static const int dimension = dim;
93 typedef Alberta::MeshPointer< dimension > MeshPointer;
94 typedef Alberta::ElementInfo< dimension > ElementInfo;
97 static const int nNodeTypes = N_NODE_TYPES;
100 struct CreateDofSpace;
102 template<
int codim >
103 struct CacheDofSpace;
105 typedef std::pair< int, int > Cache;
108 HierarchyDofNumbering ()
112 HierarchyDofNumbering (
const This & );
113 This &operator= (
const This & );
116 ~HierarchyDofNumbering ()
121 int operator() (
const Element *element,
int codim,
unsigned int subEntity )
const
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 ];
129 int operator() (
const ElementInfo &element,
int codim,
unsigned int subEntity )
const
131 return (*
this)( element.el(), codim, subEntity );
134 operator bool ()
const
139 const DofSpace *dofSpace (
int codim )
const
142 assert( (codim >= 0) && (codim <= dimension) );
143 return dofSpace_[ codim ];
146 const DofSpace *emptyDofSpace ()
const
152 const MeshPointer &mesh ()
const
157 int size (
int codim )
const
159 return dofSpace( codim )->admin->size;
162 void create (
const MeshPointer &mesh );
168 for(
int codim = 0; codim <= dimension; ++codim )
169 freeDofSpace( dofSpace_[ codim ] );
170 freeDofSpace( emptySpace_ );
171 mesh_ = MeshPointer();
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 );
184 const DofSpace *emptySpace_;
185 const DofSpace *dofSpace_[ dimension+1 ];
186 Cache cache_[ dimension+1 ];
193 HierarchyDofNumbering< dim >::create (
const MeshPointer &mesh )
201 ForLoop< CreateDofSpace, 0, dimension >::apply( mesh_, dofSpace_ );
202 ForLoop< CacheDofSpace, 0, dimension >::apply( dofSpace_, cache_ );
204 emptySpace_ = createEmptyDofSpace( mesh_ );
205 for(
int i = 0; i < nNodeTypes; ++i )
206 assert( emptySpace_->admin->n_dof[ i ] == 0 );
212 inline const DofSpace *
213 HierarchyDofNumbering< dim >::createEmptyDofSpace (
const MeshPointer &mesh )
215 int ndof[ nNodeTypes ];
216 for(
int i = 0; i < nNodeTypes; ++i )
218 std::string name =
"Empty";
219 return createDofSpace( mesh, name, ndof );
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 )
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 );
238 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
240 ALBERTA free_fe_space( dofSpace );
249 template<
int codim >
250 struct HierarchyDofNumbering< dim >::CreateDofSpace
252 static void apply (
const MeshPointer &mesh,
const DofSpace *(&dofSpace)[ dim+1 ] )
254 int ndof[ nNodeTypes ];
255 for(
int i = 0; i < nNodeTypes; ++i )
257 ndof[ CodimType< dim, codim >::value ] = 1;
259 std::string name =
"Codimension ";
260 name += (char)(codim +
'0');
262 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
263 assert( dofSpace[ codim ] );
273 template<
int codim >
274 struct HierarchyDofNumbering< dim >::CacheDofSpace
276 static void apply (
const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
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 ];
provides a wrapper for ALBERTA's el_info structure
Dune namespace.
Definition: alignment.hh:10