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>
32#include <dune/grid/common/mcmgmapper.hh>
63 template<
class GridView,
65 class CodimOneGridView,
68 const GridView& gridView,
69 const VertexMapper& vertexMapper,
70 const CodimOneGridView& codimOneGridView,
73 static constexpr int dim = GridView::dimension;
74 static_assert(CodimOneGridView::dimension == dim-1,
"Grid dimension mismatch");
77 vertexMarkers.assign(gridView.size(dim),
false);
80 std::vector<bool> isOnBoundary(gridView.size(dim),
false);
81 for (
const auto& e : elements(gridView))
83 const auto refElem = referenceElement(e);
84 for (
const auto& is : intersections(gridView, e))
86 for (
int i = 0; i < is.geometry().corners(); ++i)
87 isOnBoundary[ vertexMapper.subIndex( e,
88 refElem.subEntity(is.indexInInside(), 1, i, dim),
93 for (
const auto& vertex : vertices(codimOneGridView))
97 for (
const auto& codimOneElement : elements(codimOneGridView))
101 for (
int i = 0; i < codimOneElement.subEntities(dim-1); ++i)
102 vertexMarkers[ codimOneGridAdapter.
bulkGridVertexIndex(codimOneElement.template subEntity<dim-1>(i)) ] =
false;
107 const auto refElem = referenceElement(codimOneElement);
108 for (
const auto& intersection : intersections(codimOneGridView, codimOneElement))
111 if (!intersection.boundary())
115 const auto numCorners = intersection.geometry().corners();
116 std::vector<typename GridView::IndexSet::IndexType> vertexIndices(
numCorners);
119 const auto vIdxLocal = refElem.subEntity(intersection.indexInInside(), 1, i, dim-1);
120 vertexIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex( codimOneElement.template subEntity<dim-1>(vIdxLocal) );
124 if (std::any_of(vertexIndices.begin(), vertexIndices.end(), [&isOnBoundary] (
auto idx) { return !isOnBoundary[idx]; }))
125 std::for_each(vertexIndices.begin(), vertexIndices.end(), [&vertexMarkers] (
auto idx) { vertexMarkers[idx] = false; });
143 static constexpr int dim = GV::dimension;
144 static_assert(dim > 1,
"Vertex dof enrichment mapper currently only works for dim > 1!");
146 using GIType =
typename GV::IndexSet::IndexType;
147 using Vertex =
typename GV::template Codim<dim>::Entity;
148 using Element =
typename GV::template Codim<0>::Entity;
149 using MCMGMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GV>;
159 : gridView_(gridView)
160 , elementMapper_(gridView,
Dune::mcmgElementLayout())
161 , vertexMapper_(gridView,
Dune::mcmgVertexLayout())
170 if ( !(
static_cast<bool>(layout(Dune::GeometryTypes::vertex, dim)) ) )
171 DUNE_THROW(Dune::InvalidStateException,
"Vertex mapper only makes sense for vertex layout!");
177 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
178 return indexMap_[elementMapper_.index(e)][i];
184 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
185 return vertexMapper_.subIndex(e, i, codim);
191 assert(Vertex::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
192 return vertexMapper_.index(v);
199 template<
class EntityType >
202 if (hasEnrichedVertices_)
203 DUNE_THROW(Dune::InvalidStateException,
"Index map contains enriched vertex dofs. Direct mapping from vertex to index not possible.");
205 assert(EntityType::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
206 return vertexMapper_.index(e);
215 {
return isEnriched_[ vertexMapper_.index(v) ]; }
221 gridView_ = gridView;
227 gridView_ = std::move(gridView);
231 [[deprecated(
"Use update(gridView) instead! Will be removed after release 2.8.")]]
248 template<
class CodimOneGr
idView,
class CodimOneGr
idAdapter>
249 void enrich(
const CodimOneGridView& codimOneGridView,
251 bool verbose =
false)
253 static const int codimOneDim = CodimOneGridView::dimension;
254 static_assert(codimOneDim == dim-1,
"Grid dimension mismatch!");
255 static_assert(codimOneDim == 2 || codimOneDim == 1,
"Inadmissible codimension one grid dimension");
256 static_assert(int(CodimOneGridView::dimensionworld) == int(GV::dimensionworld),
"Grid world dimension mismatch");
271 codimOneGridAdapter);
274 hasEnrichedVertices_ = std::any_of(isEnriched_.begin(), isEnriched_.end(), [] (
bool isEnriched) { return isEnriched; });
277 std::cout <<
"Vertex dof enrichment took " << watch.elapsed() <<
" seconds." << std::endl;
285 size_ = gridView_.size(dim);
286 hasEnrichedVertices_ =
false;
287 indexMap_.resize(gridView_.size(0));
288 isEnriched_.resize(gridView_.size(dim),
false);
289 for (
const auto& e : elements(gridView_))
291 const auto numCorners = e.geometry().corners();
292 const auto eIdxGlobal = elementMapper_.index(e);
295 indexMap_[eIdxGlobal][i] = vertexMapper_.subIndex(e, i, dim);
302 MCMGMapper elementMapper_;
303 MCMGMapper vertexMapper_;
304 bool hasEnrichedVertices_;
305 std::vector<bool> isEnriched_;
306 std::vector< std::vector<GIType> > indexMap_;
Definition: common/pdesolver.hh:36
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:215
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:52
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:238
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:145
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:89
An indicator class used to mark vertices for enrichment. This implementation marks all vertices of a ...
Definition: vertexmapper.hh:46
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:67
A vertex mapper that allows for enrichment of nodes. Indication on where to enrich the nodes is done ...
Definition: vertexmapper.hh:142
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:249
std::size_t size() const
returns the number of dofs managed by this mapper
Definition: vertexmapper.hh:210
void update()
Definition: vertexmapper.hh:232
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:182
GridIndexType index(const EntityType &e) const
Definition: vertexmapper.hh:200
void update(const GV &gridView)
Definition: vertexmapper.hh:219
EnrichedVertexDofMapper(const GV &gridView)
the constructor
Definition: vertexmapper.hh:158
GridIndexType vertexIndex(const Vertex &v) const
map nodal entity to the grid vertex index
Definition: vertexmapper.hh:189
GIType GridIndexType
export the grid index type
Definition: vertexmapper.hh:155
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:175
GV GridView
export the underlying grid view type
Definition: vertexmapper.hh:153
EnrichedVertexDofMapper(const GV &gridView, Dune::MCMGLayout layout)
constructor taking a layout as additional argument (for compatibility)
Definition: vertexmapper.hh:167
bool isEnriched(const Vertex &v)
returns true if a vertex dof had been enriched
Definition: vertexmapper.hh:214
void update(GV &&gridView)
Definition: vertexmapper.hh:225