Loading [MathJax]/extensions/MathMenu.js

DUNE-ACFEM (unstable)

subentitymapper.hh
Go to the documentation of this file.
1
5#ifndef __DUNE_ACFEM_SUBENTITYMAPPER_HH__
6#define __DUNE_ACFEM_SUBENTITYMAPPER_HH__
7
8#include <dune/geometry/referenceelements.hh>
9#include <dune/grid/common/intersection.hh>
10#include <dune/common/version.hh> // DUNE_VERSION_NEWER
11#include <array>
12#include <unordered_map>
13#include "../mpl/foreach.hh"
14
15namespace Dune {
16
17 namespace ACFem {
18
23 namespace {
24
31 template<class DofMapper, int coDimension>
32 struct MapEntityHierarchyHelper
33 {
34 typedef DofMapper DofMapperType;
35 typedef typename DofMapperType::GridPartType GridPartType;
36 typedef typename GridPartType::ctype FieldType;
37 typedef typename DofMapperType::ElementType ElementType;
38 typedef typename DofMapperType::GlobalKeyType GlobalKeyType;
39 typedef ReferenceElements<FieldType, ElementType::dimension> ReferenceElementsType;
40 typedef typename ReferenceElementsType::ReferenceElement ReferenceElementType;
41
42 // Recurse into the entity hierarchy.
43 template<int codim>
44 struct SubSubEntityFunctor
45 {
46 enum {
47 subCoDimension = codim,
48 gridDimension = GridPartType::dimension,
49 subSubEntityDimension = gridDimension-subCoDimension
50 };
51 template<class RefElem, class Functor>
52 static void apply(const DofMapperType& mapper, const ElementType& element, const RefElem& refElem, int subIndex, Functor f,
53 const std::unordered_map<GlobalKeyType, unsigned>& globalToLocal)
54 {
55 const int numSubSubEntities = refElem.size(subIndex, coDimension, subCoDimension);
56
57 for (int i = 0; i < numSubSubEntities; ++i) {
58 const unsigned subSubEntityIndex = refElem.subEntity(subIndex, coDimension, i, subCoDimension);
59 const auto subSubEntity = element.template subEntity<subCoDimension>(subSubEntityIndex);
60
61 mapper.mapEachEntityDof(subSubEntity, [f, globalToLocal] (unsigned localIndex, const GlobalKeyType& globalIndex) {
62 f(globalToLocal.at(globalIndex), globalIndex);
63 });
64 }
65 }
66 };
67
68 };
69
70 }
71
92 template<class DofMapper, int coDimension, class Functor>
93 void mapEntityHierarchy(const DofMapper& mapper,
94 const typename DofMapper::ElementType& element,
95 int subIndex,
96 const std::integral_constant<int, coDimension>& dummy,
97 Functor f)
98 {
99 typedef DofMapper DofMapperType;
100 typedef MapEntityHierarchyHelper<DofMapperType, coDimension> HelperType;
101 typedef typename HelperType::GridPartType GridPartType;
102 typedef typename HelperType::GlobalKeyType GlobalKeyType;
103 typedef typename HelperType::ReferenceElementsType ReferenceElementsType;
104
105 enum { dimension = GridPartType::dimension };
106
107 // first construct a reverse lookup for the global keys
108 std::unordered_map<GlobalKeyType, unsigned> globalToLocal;
109 mapper.mapEach(element, [&globalToLocal] (unsigned local, const GlobalKeyType& global) {
110 globalToLocal[global] = local;
111 });
112
113 // get codim-0 reference element
114 const auto& refElem = ReferenceElementsType::general(element.type());
115
116 // Use ForLoop in order to generate a constant co-dimension as
117 // we need element.template subEntity<cdim>
118 forLoop<dimension-coDimension+1>([&](auto i){
119 HelperType::template SubSubEntityFunctor<i.value+coDimension>::apply(mapper, element, refElem, subIndex, f, globalToLocal);
120 });
121 }
122
142 template<class DofMapper, class Intersection, class Functor>
143 void mapEachFaceDof(const DofMapper& mapper,
144 const Intersection& intersection,
145 Functor f)
146 {
147 mapEntityHierarchy(mapper, intersection.inside(), intersection.indexInInside(),
148 std::integral_constant<int, 1>(), f);
149 }
150
172 template<class DofMapper, class Intersection, class LocalIndices, class GlobalIndices>
173 unsigned mapFaceDofs(const DofMapper& mapper, const Intersection& intersection,
174 LocalIndices& localIndices, GlobalIndices& globalIndices)
175 {
176 typedef typename DofMapper::GlobalKeyType GlobalKeyType;
177
178 unsigned count = 0;
179 mapEachFaceDof(mapper, intersection,
180 [&localIndices, &globalIndices, &count] (unsigned localIndex, GlobalKeyType globalIndex) {
181 localIndices[count] = localIndex;
182 globalIndices[count] = globalIndex;
183 ++count;
184 });
185
186 return count;
187 }
188
191 }
192
193}
194
195#endif // __DUNE_ACFEM_SUBENTITYMAPPER_HH__
void mapEachFaceDof(const DofMapper &mapper, const Intersection &intersection, Functor f)
Iterate over the codim-1 sub-entity hierarchy linked to the given intersection and call the dof-mappe...
Definition: subentitymapper.hh:143
void mapEntityHierarchy(const DofMapper &mapper, const typename DofMapper::ElementType &element, int subIndex, const std::integral_constant< int, coDimension > &dummy, Functor f)
Iterate over the entire sub-entity hierarchy below one given sub-entity (including the given one) and...
Definition: subentitymapper.hh:93
unsigned mapFaceDofs(const DofMapper &mapper, const Intersection &intersection, LocalIndices &localIndices, GlobalIndices &globalIndices)
Fetch all global DoFs of the codim-1 entity intersection belongs to.
Definition: subentitymapper.hh:173
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)