5#ifndef DUNE_ALBERTA_DOFADMIN_HH
6#define DUNE_ALBERTA_DOFADMIN_HH
10#include <dune/common/hybridutilities.hh>
12#include <dune/grid/albertagrid/misc.hh>
34 template<
int dim,
int codim >
37 static const int codimtype = CodimType< dim, codim >::value;
40 static const int numSubEntities = NumSubEntities< dim, codim >::value;
42 static const int dimension = dim;
43 static const int codimension = codim;
45 typedef Alberta::ElementInfo< dimension > ElementInfo;
51 explicit DofAccess (
const DofSpace *dofSpace )
54 node_ = dofSpace->admin->mesh->node[ codimtype ];
55 index_ = dofSpace->admin->n0_dof[ codimtype ];
58 int operator() (
const Element *element,
int subEntity,
int i )
const
61 assert( node_ != -1 );
62 assert( subEntity < numSubEntities );
63 return element->dof[ node_ + subEntity ][ index_ + i ];
66 int operator() (
const Element *element,
int subEntity )
const
68 return (*
this)( element, subEntity, 0 );
71 int operator() (
const ElementInfo &elementInfo,
int subEntity,
int i )
const
73 return (*
this)( elementInfo.el(), subEntity, i );
76 int operator() (
const ElementInfo &elementInfo,
int subEntity )
const
78 return (*
this)( elementInfo.el(), subEntity );
92 class HierarchyDofNumbering
94 typedef HierarchyDofNumbering< dim > This;
97 static const int dimension = dim;
99 typedef Alberta::MeshPointer< dimension > MeshPointer;
100 typedef Alberta::ElementInfo< dimension > ElementInfo;
103 static const int nNodeTypes = N_NODE_TYPES;
105 template<
int codim >
106 struct CreateDofSpace;
108 template<
int codim >
109 struct CacheDofSpace;
111 typedef std::pair< int, int > Cache;
114 HierarchyDofNumbering ()
118 HierarchyDofNumbering (
const This & );
119 This &operator= (
const This & );
122 ~HierarchyDofNumbering ()
127 int operator() (
const Element *element,
int codim,
unsigned int subEntity )
const
129 assert( !(*
this) ==
false );
130 assert( (codim >= 0) && (codim <= dimension) );
131 const Cache &cache = cache_[ codim ];
132 return element->dof[ cache.first + subEntity ][ cache.second ];
135 int operator() (
const ElementInfo &element,
int codim,
unsigned int subEntity )
const
137 return (*
this)( element.el(), codim, subEntity );
140 explicit operator bool ()
const
145 const DofSpace *dofSpace (
int codim )
const
148 assert( (codim >= 0) && (codim <= dimension) );
149 return dofSpace_[ codim ];
152 const DofSpace *emptyDofSpace ()
const
158 const MeshPointer &mesh ()
const
163 int size (
int codim )
const
165 return dofSpace( codim )->admin->size;
168 void create (
const MeshPointer &mesh );
174 for(
int codim = 0; codim <= dimension; ++codim )
175 freeDofSpace( dofSpace_[ codim ] );
176 freeDofSpace( emptySpace_ );
177 mesh_ = MeshPointer();
182 static const DofSpace *createEmptyDofSpace (
const MeshPointer &mesh );
183 static const DofSpace *createDofSpace (
const MeshPointer &mesh,
184 const std::string &name,
185 const int (&ndof)[ nNodeTypes ],
186 const bool periodic =
false );
187 static void freeDofSpace (
const DofSpace *dofSpace );
190 const DofSpace *emptySpace_;
191 const DofSpace *dofSpace_[ dimension+1 ];
192 Cache cache_[ dimension+1 ];
199 HierarchyDofNumbering< dim >::create (
const MeshPointer &mesh )
208 Hybrid::forEach( std::make_index_sequence< dimension+1 >{}, [ & ](
auto i ){ CreateDofSpace< i >::apply( mesh_, dofSpace_ ); } );
209 Hybrid::forEach( std::make_index_sequence< dimension+1 >{}, [ & ](
auto i ){ CacheDofSpace< i >::apply( dofSpace_, cache_ ); } );
211 emptySpace_ = createEmptyDofSpace( mesh_ );
212 for(
int i = 0; i < nNodeTypes; ++i )
213 assert( emptySpace_->admin->n_dof[ i ] == 0 );
219 inline const DofSpace *
220 HierarchyDofNumbering< dim >::createEmptyDofSpace (
const MeshPointer &mesh )
222 int ndof[ nNodeTypes ];
223 for(
int i = 0; i < nNodeTypes; ++i )
225 std::string name =
"Empty";
226 return createDofSpace( mesh, name, ndof );
231 inline const DofSpace *
232 HierarchyDofNumbering< dim >::createDofSpace (
const MeshPointer &mesh,
233 const std::string &name,
234 const int (&ndof)[ nNodeTypes ],
235 const bool periodic )
237 const ALBERTA FLAGS flags
238 = ADM_PRESERVE_COARSE_DOFS | (periodic ? ADM_PERIODIC : 0);
239 return ALBERTA get_dof_space ( mesh, name.c_str(), ndof, flags );
245 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
247 ALBERTA free_fe_space( dofSpace );
256 template<
int codim >
257 struct HierarchyDofNumbering< dim >::CreateDofSpace
259 static void apply (
const MeshPointer &mesh,
const DofSpace *(&dofSpace)[ dim+1 ] )
261 int ndof[ nNodeTypes ];
262 for(
int i = 0; i < nNodeTypes; ++i )
264 ndof[ CodimType< dim, codim >::value ] = 1;
266 std::string name =
"Codimension ";
267 name += (char)(codim +
'0');
269 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
270 assert( dofSpace[ codim ] );
280 template<
int codim >
281 struct HierarchyDofNumbering< dim >::CacheDofSpace
283 static void apply (
const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
285 assert( dofSpace[ codim ] );
286 const int codimtype = CodimType< dim, codim >::value;
287 cache[ codim ].first = dofSpace[ codim ]->mesh->node[ codimtype ];
288 cache[ codim ].second = dofSpace[ codim ]->admin->n0_dof[ codimtype ];
provides a wrapper for ALBERTA's el_info structure
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:268
Dune namespace.
Definition: alignedallocator.hh:13