3#ifndef DUNE_ALBERTA_DOFADMIN_HH
4#define DUNE_ALBERTA_DOFADMIN_HH
6#include <dune/common/hybridutilities.hh>
7#include <dune/common/std/utility.hh>
9#include <dune/grid/albertagrid/misc.hh>
31 template<
int dim,
int codim >
34 static const int codimtype = CodimType< dim, codim >::value;
37 static const int numSubEntities = NumSubEntities< dim, codim >::value;
39 static const int dimension = dim;
40 static const int codimension = codim;
42 typedef Alberta::ElementInfo< dimension > ElementInfo;
48 explicit DofAccess (
const DofSpace *dofSpace )
51 node_ = dofSpace->admin->mesh->node[ codimtype ];
52 index_ = dofSpace->admin->n0_dof[ codimtype ];
55 int operator() (
const Element *element,
int subEntity,
int i )
const
58 assert( node_ != -1 );
59 assert( subEntity < numSubEntities );
60 return element->dof[ node_ + subEntity ][ index_ + i ];
63 int operator() (
const Element *element,
int subEntity )
const
65 return (*
this)( element, subEntity, 0 );
68 int operator() (
const ElementInfo &elementInfo,
int subEntity,
int i )
const
70 return (*
this)( elementInfo.el(), subEntity, i );
73 int operator() (
const ElementInfo &elementInfo,
int subEntity )
const
75 return (*
this)( elementInfo.el(), subEntity );
89 class HierarchyDofNumbering
91 typedef HierarchyDofNumbering< dim > This;
94 static const int dimension = dim;
96 typedef Alberta::MeshPointer< dimension > MeshPointer;
97 typedef Alberta::ElementInfo< dimension > ElementInfo;
100 static const int nNodeTypes = N_NODE_TYPES;
102 template<
int codim >
103 struct CreateDofSpace;
105 template<
int codim >
106 struct CacheDofSpace;
108 typedef std::pair< int, int > Cache;
111 HierarchyDofNumbering ()
115 HierarchyDofNumbering (
const This & );
116 This &operator= (
const This & );
119 ~HierarchyDofNumbering ()
124 int operator() (
const Element *element,
int codim,
unsigned int subEntity )
const
126 assert( !(*
this) ==
false );
127 assert( (codim >= 0) && (codim <= dimension) );
128 const Cache &cache = cache_[ codim ];
129 return element->dof[ cache.first + subEntity ][ cache.second ];
132 int operator() (
const ElementInfo &element,
int codim,
unsigned int subEntity )
const
134 return (*
this)( element.el(), codim, subEntity );
137 explicit operator bool ()
const
142 const DofSpace *dofSpace (
int codim )
const
145 assert( (codim >= 0) && (codim <= dimension) );
146 return dofSpace_[ codim ];
149 const DofSpace *emptyDofSpace ()
const
155 const MeshPointer &mesh ()
const
160 int size (
int codim )
const
162 return dofSpace( codim )->admin->size;
165 void create (
const MeshPointer &mesh );
171 for(
int codim = 0; codim <= dimension; ++codim )
172 freeDofSpace( dofSpace_[ codim ] );
173 freeDofSpace( emptySpace_ );
174 mesh_ = MeshPointer();
179 static const DofSpace *createEmptyDofSpace (
const MeshPointer &mesh );
180 static const DofSpace *createDofSpace (
const MeshPointer &mesh,
181 const std::string &name,
182 const int (&ndof)[ nNodeTypes ],
183 const bool periodic =
false );
184 static void freeDofSpace (
const DofSpace *dofSpace );
187 const DofSpace *emptySpace_;
188 const DofSpace *dofSpace_[ dimension+1 ];
189 Cache cache_[ dimension+1 ];
196 HierarchyDofNumbering< dim >::create (
const MeshPointer &mesh )
208 emptySpace_ = createEmptyDofSpace( mesh_ );
209 for(
int i = 0; i < nNodeTypes; ++i )
210 assert( emptySpace_->admin->n_dof[ i ] == 0 );
216 inline const DofSpace *
217 HierarchyDofNumbering< dim >::createEmptyDofSpace (
const MeshPointer &mesh )
219 int ndof[ nNodeTypes ];
220 for(
int i = 0; i < nNodeTypes; ++i )
222 std::string name =
"Empty";
223 return createDofSpace( mesh, name, ndof );
228 inline const DofSpace *
229 HierarchyDofNumbering< dim >::createDofSpace (
const MeshPointer &mesh,
230 const std::string &name,
231 const int (&ndof)[ nNodeTypes ],
232 const bool periodic )
234 const ALBERTA FLAGS flags
235 = ADM_PRESERVE_COARSE_DOFS | (periodic ? ADM_PERIODIC : 0);
236 return ALBERTA get_dof_space ( mesh, name.c_str(), ndof, flags );
242 HierarchyDofNumbering< dim >::freeDofSpace (
const DofSpace *dofSpace )
244 ALBERTA free_fe_space( dofSpace );
253 template<
int codim >
254 struct HierarchyDofNumbering< dim >::CreateDofSpace
256 static void apply (
const MeshPointer &mesh,
const DofSpace *(&dofSpace)[ dim+1 ] )
258 int ndof[ nNodeTypes ];
259 for(
int i = 0; i < nNodeTypes; ++i )
261 ndof[ CodimType< dim, codim >::value ] = 1;
263 std::string name =
"Codimension ";
264 name += (char)(codim +
'0');
266 dofSpace[ codim ] = createDofSpace( mesh, name, ndof );
267 assert( dofSpace[ codim ] );
277 template<
int codim >
278 struct HierarchyDofNumbering< dim >::CacheDofSpace
280 static void apply (
const DofSpace *(&dofSpace)[ dim+1 ], Cache (&cache)[ dim+1 ] )
282 assert( dofSpace[ codim ] );
283 const int codimtype = CodimType< dim, codim >::value;
284 cache[ codim ].first = dofSpace[ codim ]->mesh->node[ codimtype ];
285 cache[ codim ].second = dofSpace[ codim ]->admin->n0_dof[ codimtype ];
provides a wrapper for ALBERTA's el_info structure
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:58
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:308
Dune namespace.
Definition: alignedallocator.hh:10