3#ifndef DUNE_ALBERTA_DOFADMIN_HH
4#define DUNE_ALBERTA_DOFADMIN_HH
8#include <dune/common/hybridutilities.hh>
10#include <dune/grid/albertagrid/misc.hh>
32 template<
int dim,
int codim >
35 static const int codimtype = CodimType< dim, codim >::value;
38 static const int numSubEntities = NumSubEntities< dim, codim >::value;
40 static const int dimension = dim;
41 static const int codimension = codim;
43 typedef Alberta::ElementInfo< dimension > ElementInfo;
49 explicit DofAccess (
const DofSpace *dofSpace )
52 node_ = dofSpace->admin->mesh->node[ codimtype ];
53 index_ = dofSpace->admin->n0_dof[ codimtype ];
56 int operator() (
const Element *element,
int subEntity,
int i )
const
59 assert( node_ != -1 );
60 assert( subEntity < numSubEntities );
61 return element->dof[ node_ + subEntity ][ index_ + i ];
64 int operator() (
const Element *element,
int subEntity )
const
66 return (*
this)( element, subEntity, 0 );
69 int operator() (
const ElementInfo &elementInfo,
int subEntity,
int i )
const
71 return (*
this)( elementInfo.el(), subEntity, i );
74 int operator() (
const ElementInfo &elementInfo,
int subEntity )
const
76 return (*
this)( elementInfo.el(), subEntity );
90 class HierarchyDofNumbering
92 typedef HierarchyDofNumbering< dim > This;
95 static const int dimension = dim;
97 typedef Alberta::MeshPointer< dimension > MeshPointer;
98 typedef Alberta::ElementInfo< dimension > ElementInfo;
101 static const int nNodeTypes = N_NODE_TYPES;
103 template<
int codim >
104 struct CreateDofSpace;
106 template<
int codim >
107 struct CacheDofSpace;
109 typedef std::pair< int, int > Cache;
112 HierarchyDofNumbering ()
116 HierarchyDofNumbering (
const This & );
117 This &operator= (
const This & );
120 ~HierarchyDofNumbering ()
125 int operator() (
const Element *element,
int codim,
unsigned int subEntity )
const
127 assert( !(*
this) ==
false );
128 assert( (codim >= 0) && (codim <= dimension) );
129 const Cache &cache = cache_[ codim ];
130 return element->dof[ cache.first + subEntity ][ cache.second ];
133 int operator() (
const ElementInfo &element,
int codim,
unsigned int subEntity )
const
135 return (*
this)( element.el(), codim, subEntity );
138 explicit operator bool ()
const
143 const DofSpace *dofSpace (
int codim )
const
146 assert( (codim >= 0) && (codim <= dimension) );
147 return dofSpace_[ codim ];
150 const DofSpace *emptyDofSpace ()
const
156 const MeshPointer &mesh ()
const
161 int size (
int codim )
const
163 return dofSpace( codim )->admin->size;
166 void create (
const MeshPointer &mesh );
172 for(
int codim = 0; codim <= dimension; ++codim )
173 freeDofSpace( dofSpace_[ codim ] );
174 freeDofSpace( emptySpace_ );
175 mesh_ = MeshPointer();
180 static const DofSpace *createEmptyDofSpace (
const MeshPointer &mesh );
181 static const DofSpace *createDofSpace (
const MeshPointer &mesh,
182 const std::string &name,
183 const int (&ndof)[ nNodeTypes ],
185 static void freeDofSpace (
const DofSpace *dofSpace );
188 const DofSpace *emptySpace_;
189 const DofSpace *dofSpace_[ dimension+1 ];
190 Cache cache_[ dimension+1 ];
197 HierarchyDofNumbering< dim >::create (
const MeshPointer &mesh )
206 Hybrid::forEach( std::make_index_sequence< dimension+1 >{}, [ & ](
auto i ){ CreateDofSpace< i >::apply( mesh_, dofSpace_ ); } );
207 Hybrid::forEach( std::make_index_sequence< dimension+1 >{}, [ & ](
auto i ){ CacheDofSpace< i >::apply( dofSpace_, cache_ ); } );
209 emptySpace_ = createEmptyDofSpace( mesh_ );
210 for(
int i = 0; i < nNodeTypes; ++i )
211 assert( emptySpace_->admin->n_dof[ i ] == 0 );
217 inline const DofSpace *
218 HierarchyDofNumbering< dim >::createEmptyDofSpace (
const MeshPointer &mesh )
220 int ndof[ nNodeTypes ];
221 for(
int i = 0; i < nNodeTypes; ++i )
223 std::string name =
"Empty";
224 return createDofSpace( mesh, name, ndof );
229 inline const DofSpace *
230 HierarchyDofNumbering< dim >::createDofSpace (
const MeshPointer &mesh,
231 const std::string &name,
232 const int (&ndof)[ nNodeTypes ],
235 const ALBERTA FLAGS flags
236 = ADM_PRESERVE_COARSE_DOFS | (
periodic ? ADM_PERIODIC : 0);
237 return ALBERTA get_dof_space ( mesh, name.c_str(), ndof, flags );
243 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
245 ALBERTA free_fe_space( dofSpace );
254 template<
int codim >
255 struct HierarchyDofNumbering< dim >::CreateDofSpace
257 static void apply (
const MeshPointer &mesh,
const DofSpace *(&dofSpace)[ dim+1 ] )
259 int ndof[ nNodeTypes ];
260 for(
int i = 0; i < nNodeTypes; ++i )
262 ndof[ CodimType< dim, codim >::value ] = 1;
264 std::string name =
"Codimension ";
265 name += (char)(codim +
'0');
267 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
268 assert( dofSpace[ codim ] );
278 template<
int codim >
279 struct HierarchyDofNumbering< dim >::CacheDofSpace
281 static void apply (
const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
283 assert( dofSpace[ codim ] );
284 const int codimtype = CodimType< dim, codim >::value;
285 cache[ codim ].first = dofSpace[ codim ]->mesh->node[ codimtype ];
286 cache[ codim ].second = dofSpace[ codim ]->admin->n0_dof[ codimtype ];
provides a wrapper for ALBERTA's el_info structure
auto periodic(RawPreBasisIndicator &&rawPreBasisIndicator, PIS &&periodicIndexSet)
Create a pre-basis factory that can create a periodic pre-basis.
Definition: periodicbasis.hh:195
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:266
Dune namespace.
Definition: alignedallocator.hh:11