25#ifndef DUMUX_ENRICHED_VERTEX_DOF_MAPPER_HH
26#define DUMUX_ENRICHED_VERTEX_DOF_MAPPER_HH
30#include <dune/common/exceptions.hh>
31#include <dune/common/timer.hh>
33#include <dune/grid/common/mcmgmapper.hh>
34#include <dune/geometry/referenceelements.hh>
65 template<
class GridView,
67 class CodimOneGridView,
70 const GridView& gridView,
71 const VertexMapper& vertexMapper,
72 const CodimOneGridView& codimOneGridView,
75 static constexpr int dim = GridView::dimension;
76 static_assert(CodimOneGridView::dimension == dim-1,
"Grid dimension mismatch");
79 vertexMarkers.assign(gridView.size(dim),
false);
82 std::vector<bool> isOnBoundary(gridView.size(dim),
false);
83 using ReferenceElements =
typename Dune::ReferenceElements<typename GridView::ctype, dim>;
84 for (
const auto& e : elements(gridView))
86 const auto refElem = ReferenceElements::general(e.type());
87 for (
const auto& is : intersections(gridView, e))
89 for (
int i = 0; i < is.geometry().corners(); ++i)
90 isOnBoundary[ vertexMapper.subIndex( e,
91 refElem.subEntity(is.indexInInside(), 1, i, dim),
96 for (
const auto& vertex : vertices(codimOneGridView))
100 using CodimOneReferenceElements =
typename Dune::ReferenceElements<
typename CodimOneGridView::ctype, dim-1>;
101 for (
const auto& codimOneElement : elements(codimOneGridView))
105 for (
int i = 0; i < codimOneElement.subEntities(dim-1); ++i)
106 vertexMarkers[ codimOneGridAdapter.
bulkGridVertexIndex(codimOneElement.template subEntity<dim-1>(i)) ] =
false;
111 const auto refElem = CodimOneReferenceElements::general(codimOneElement.type());
112 for (
const auto& intersection : intersections(codimOneGridView, codimOneElement))
115 if (!intersection.boundary())
119 const auto numCorners = intersection.geometry().corners();
120 std::vector<typename GridView::IndexSet::IndexType> vertexIndices(numCorners);
121 for (
int i = 0; i < numCorners; ++i)
123 const auto vIdxLocal = refElem.subEntity(intersection.indexInInside(), 1, i, dim-1);
124 vertexIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex( codimOneElement.template subEntity<dim-1>(vIdxLocal) );
128 if (std::any_of(vertexIndices.begin(), vertexIndices.end(), [&isOnBoundary] (
auto idx) { return !isOnBoundary[idx]; }))
129 std::for_each(vertexIndices.begin(), vertexIndices.end(), [&vertexMarkers] (
auto idx) { vertexMarkers[idx] = false; });
147 static constexpr int dim = GV::dimension;
148 static_assert(dim > 1,
"Vertex dof enrichment mapper currently only works for dim > 1!");
150 using GIType =
typename GV::IndexSet::IndexType;
151 using Vertex =
typename GV::template Codim<dim>::Entity;
152 using Element =
typename GV::template Codim<0>::Entity;
153 using MCMGMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GV>;
163 : gridView_(gridView)
164 , elementMapper_(gridView,
Dune::mcmgElementLayout())
165 , vertexMapper_(gridView,
Dune::mcmgVertexLayout())
174 if ( !(
static_cast<bool>(layout(Dune::GeometryTypes::vertex, dim)) ) )
175 DUNE_THROW(Dune::InvalidStateException,
"Vertex mapper only makes sense for vertex layout!");
181 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
182 return indexMap_[elementMapper_.index(e)][i];
188 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
189 return vertexMapper_.subIndex(e, i, codim);
195 assert(Vertex::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
196 return vertexMapper_.index(v);
203 template<
class EntityType >
206 if (hasEnrichedVertices_)
207 DUNE_THROW(Dune::InvalidStateException,
"Index map contains enriched vertex dofs. Direct mapping from vertex to index not possible.");
209 assert(EntityType::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
210 return vertexMapper_.index(e);
219 {
return isEnriched_[ vertexMapper_.index(v) ]; }
239 template<
class CodimOneGr
idView,
class CodimOneGr
idAdapter>
240 void enrich(
const CodimOneGridView& codimOneGridView,
242 bool verbose =
false)
244 static const int codimOneDim = CodimOneGridView::dimension;
245 static_assert(codimOneDim == dim-1,
"Grid dimension mismatch!");
246 static_assert(codimOneDim == 2 || codimOneDim == 1,
"Inadmissible codimension one grid dimension");
247 static_assert(int(CodimOneGridView::dimensionworld) == int(GV::dimensionworld),
"Grid world dimension mismatch");
262 codimOneGridAdapter);
265 hasEnrichedVertices_ = std::any_of(isEnriched_.begin(), isEnriched_.end(), [] (
bool isEnriched) { return isEnriched; });
268 std::cout <<
"Vertex dof enrichment took " << watch.elapsed() <<
" seconds." << std::endl;
276 size_ = gridView_.size(dim);
277 hasEnrichedVertices_ =
false;
278 indexMap_.resize(gridView_.size(0));
279 isEnriched_.resize(gridView_.size(dim),
false);
280 for (
const auto& e : elements(gridView_))
282 const auto numCorners = e.geometry().corners();
283 const auto eIdxGlobal = elementMapper_.index(e);
284 indexMap_[eIdxGlobal].resize(numCorners);
285 for (
unsigned int i = 0; i < numCorners; ++i)
286 indexMap_[eIdxGlobal][i] = vertexMapper_.subIndex(e, i, dim);
293 MCMGMapper elementMapper_;
294 MCMGMapper vertexMapper_;
295 bool hasEnrichedVertices_;
296 std::vector<bool> isEnriched_;
297 std::vector< std::vector<GIType> > indexMap_;
Definition: common/pdesolver.hh:35
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:53
std::size_t numEmbedments(const FacetGridElement &e) const
Returns the number of d-dimensional elements in which the given (d-1)-dimensional element is embedded...
Definition: codimonegridadapter.hh:240
BulkIndexType bulkGridVertexIndex(const FacetGridVertex &v) const
Returns the index within the d-dimensional grid of a vertex of the (d-1)-dimensional grid.
Definition: codimonegridadapter.hh:147
static std::size_t enrich(IndexMap &indexMap, const std::vector< bool > &vertexMarkers, const GridView &gridView, const MCMGMapper &vertexMapper, const MCMGMapper &elementMapper, const CodimOneGridView &codimOneGridView, const CodimOneGridAdapter &codimOneGridAdapter)
Enriches the dof map subject to a (dim-1)-dimensional grid.
Definition: enrichmenthelper.hh:91
An indicator class used to mark vertices for enrichment. This implementation marks all vertices of a ...
Definition: vertexmapper.hh:48
static void markVerticesForEnrichment(std::vector< bool > &vertexMarkers, const GridView &gridView, const VertexMapper &vertexMapper, const CodimOneGridView &codimOneGridView, const CodimOneGridAdapter &codimOneGridAdapter)
Function that marks vertices for enrichment. This implementation works on the basis of a facet-confor...
Definition: vertexmapper.hh:69
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...
Definition: vertexmapper.hh:146
void enrich(const CodimOneGridView &codimOneGridView, const CodimOneGridAdapter &codimOneGridAdapter, bool verbose=false)
Enriches the dof map subject to a (dim-1)-dimensional grid.
Definition: vertexmapper.hh:240
std::size_t size() const
returns the number of dofs managed by this mapper
Definition: vertexmapper.hh:214
void update()
Definition: vertexmapper.hh:223
GridIndexType vertexIndex(const Element &e, unsigned int i, unsigned int codim) const
map nodal subentity of codim 0 entity to the grid vertex index
Definition: vertexmapper.hh:186
GridIndexType index(const EntityType &e) const
Definition: vertexmapper.hh:204
EnrichedVertexDofMapper(const GV &gridView)
the constructor
Definition: vertexmapper.hh:162
GridIndexType vertexIndex(const Vertex &v) const
map nodal entity to the grid vertex index
Definition: vertexmapper.hh:193
GIType GridIndexType
export the grid index type
Definition: vertexmapper.hh:159
GridIndexType subIndex(const Element &e, unsigned int i, unsigned int codim) const
map nodal subentity of codim 0 entity to the grid dof
Definition: vertexmapper.hh:179
GV GridView
export the underlying grid view type
Definition: vertexmapper.hh:157
EnrichedVertexDofMapper(const GV &gridView, Dune::MCMGLayout layout)
constructor taking a layout as additional argument (for compatibility)
Definition: vertexmapper.hh:171
bool isEnriched(const Vertex &v)
returns true if a vertex dof had been enriched
Definition: vertexmapper.hh:218