13#ifndef DUMUX_ENRICHED_VERTEX_DOF_MAPPER_HH
14#define DUMUX_ENRICHED_VERTEX_DOF_MAPPER_HH
18#include <dune/common/exceptions.hh>
19#include <dune/common/timer.hh>
20#include <dune/grid/common/mcmgmapper.hh>
51 template<
class GridView,
53 class CodimOneGridView,
56 const GridView& gridView,
57 const VertexMapper& vertexMapper,
58 const CodimOneGridView& codimOneGridView,
61 static constexpr int dim = GridView::dimension;
62 static_assert(CodimOneGridView::dimension == dim-1,
"Grid dimension mismatch");
65 vertexMarkers.assign(gridView.size(dim),
false);
68 std::vector<bool> isOnBoundary(gridView.size(dim),
false);
69 for (
const auto& e : elements(gridView))
71 const auto refElem = referenceElement(e);
72 for (
const auto& is : intersections(gridView, e))
74 for (
int i = 0; i < is.geometry().corners(); ++i)
75 isOnBoundary[ vertexMapper.subIndex( e,
76 refElem.subEntity(is.indexInInside(), 1, i, dim),
81 for (
const auto& vertex : vertices(codimOneGridView))
85 for (
const auto& codimOneElement : elements(codimOneGridView))
89 for (
int i = 0; i < codimOneElement.subEntities(dim-1); ++i)
90 vertexMarkers[ codimOneGridAdapter.
bulkGridVertexIndex(codimOneElement.template subEntity<dim-1>(i)) ] =
false;
95 const auto refElem = referenceElement(codimOneElement);
96 for (
const auto& intersection : intersections(codimOneGridView, codimOneElement))
99 if (!intersection.boundary())
103 const auto numCorners = intersection.geometry().corners();
104 std::vector<typename GridView::IndexSet::IndexType> vertexIndices(
numCorners);
107 const auto vIdxLocal = refElem.subEntity(intersection.indexInInside(), 1, i, dim-1);
108 vertexIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex( codimOneElement.template subEntity<dim-1>(vIdxLocal) );
112 if (std::any_of(vertexIndices.begin(), vertexIndices.end(), [&isOnBoundary] (
auto idx) { return !isOnBoundary[idx]; }))
113 std::for_each(vertexIndices.begin(), vertexIndices.end(), [&vertexMarkers] (
auto idx) { vertexMarkers[idx] = false; });
131 static constexpr int dim = GV::dimension;
132 static_assert(dim > 1,
"Vertex dof enrichment mapper currently only works for dim > 1!");
134 using GIType =
typename GV::IndexSet::IndexType;
135 using Vertex =
typename GV::template Codim<dim>::Entity;
136 using Element =
typename GV::template Codim<0>::Entity;
137 using MCMGMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GV>;
147 : gridView_(gridView)
148 , elementMapper_(gridView,
Dune::mcmgElementLayout())
149 , vertexMapper_(gridView,
Dune::mcmgVertexLayout())
158 if ( !(
static_cast<bool>(layout(Dune::GeometryTypes::vertex, dim)) ) )
159 DUNE_THROW(Dune::InvalidStateException,
"Vertex mapper only makes sense for vertex layout!");
165 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
166 return indexMap_[elementMapper_.index(e)][i];
172 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
173 return vertexMapper_.subIndex(e, i, codim);
179 assert(Vertex::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
180 return vertexMapper_.index(v);
187 template<
class EntityType >
190 if (hasEnrichedVertices_)
191 DUNE_THROW(Dune::InvalidStateException,
"Index map contains enriched vertex dofs. Direct mapping from vertex to index not possible.");
193 assert(EntityType::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
194 return vertexMapper_.index(e);
203 {
return isEnriched_[ vertexMapper_.index(v) ]; }
209 gridView_ = gridView;
215 gridView_ = std::move(gridView);
230 template<
class CodimOneGr
idView,
class CodimOneGr
idAdapter>
231 void enrich(
const CodimOneGridView& codimOneGridView,
233 bool verbose =
false)
235 static const int codimOneDim = CodimOneGridView::dimension;
236 static_assert(codimOneDim == dim-1,
"Grid dimension mismatch!");
237 static_assert(codimOneDim == 2 || codimOneDim == 1,
"Inadmissible codimension one grid dimension");
238 static_assert(int(CodimOneGridView::dimensionworld) == int(GV::dimensionworld),
"Grid world dimension mismatch");
253 codimOneGridAdapter);
256 hasEnrichedVertices_ = std::any_of(isEnriched_.begin(), isEnriched_.end(), [] (
bool isEnriched) { return isEnriched; });
259 std::cout <<
"Vertex dof enrichment took " << watch.elapsed() <<
" seconds." << std::endl;
267 size_ = gridView_.size(dim);
268 hasEnrichedVertices_ =
false;
269 indexMap_.resize(gridView_.size(0));
270 isEnriched_.resize(gridView_.size(dim),
false);
271 for (
const auto& e : elements(gridView_))
273 const auto numCorners = e.geometry().corners();
274 const auto eIdxGlobal = elementMapper_.index(e);
277 indexMap_[eIdxGlobal][i] = vertexMapper_.subIndex(e, i, dim);
284 MCMGMapper elementMapper_;
285 MCMGMapper vertexMapper_;
286 bool hasEnrichedVertices_;
287 std::vector<bool> isEnriched_;
288 std::vector< std::vector<GIType> > indexMap_;
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:40
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:226
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:133
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...
Definition: vertexmapper.hh:130
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:231
std::size_t size() const
returns the number of dofs managed by this mapper
Definition: vertexmapper.hh:198
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:170
GridIndexType index(const EntityType &e) const
Definition: vertexmapper.hh:188
void update(const GV &gridView)
Definition: vertexmapper.hh:207
EnrichedVertexDofMapper(const GV &gridView)
the constructor
Definition: vertexmapper.hh:146
GridIndexType vertexIndex(const Vertex &v) const
map nodal entity to the grid vertex index
Definition: vertexmapper.hh:177
GIType GridIndexType
export the grid index type
Definition: vertexmapper.hh:143
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:163
GV GridView
export the underlying grid view type
Definition: vertexmapper.hh:141
EnrichedVertexDofMapper(const GV &gridView, Dune::MCMGLayout layout)
constructor taking a layout as additional argument (for compatibility)
Definition: vertexmapper.hh:155
bool isEnriched(const Vertex &v)
returns true if a vertex dof had been enriched
Definition: vertexmapper.hh:202
void update(GV &&gridView)
Definition: vertexmapper.hh:213
An indicator class used to mark vertices for enrichment. This implementation marks all vertices of a ...
Definition: vertexmapper.hh:34
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:55
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:77
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
Definition: common/pdesolver.hh:24