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 );
223#if DUNE_ALBERTA_VERSION >= 0x300
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 )
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 );
237#if DUNE_ALBERTA_VERSION == 0x200
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 )
245 return ALBERTA get_fe_space( mesh, name.c_str(), ndof, NULL, 1 );
250#if DUNE_ALBERTA_VERSION >= 0x300
253 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
255 ALBERTA free_fe_space( dofSpace );
259#if DUNE_ALBERTA_VERSION == 0x200
262 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
265 ALBERTA free_fe_space(
const_cast< DofSpace *
>( dofSpace ) );
275 template<
int codim >
276 struct HierarchyDofNumbering< dim >::CreateDofSpace
278 static void apply (
const MeshPointer &mesh,
const DofSpace *(&dofSpace)[ dim+1 ] )
280 int ndof[ nNodeTypes ];
281 for(
int i = 0; i < nNodeTypes; ++i )
283 ndof[ CodimType< dim, codim >::value ] = 1;
285 std::string name =
"Codimension ";
286 name += (char)(codim +
'0');
288 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
289 assert( dofSpace[ codim ] );
299 template<
int codim >
300 struct HierarchyDofNumbering< dim >::CacheDofSpace
302 static void apply (
const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
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 ];
provides a wrapper for ALBERTA's el_info structure
Dune namespace.
Definition: alignment.hh:14