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 std::vector<typename GridView::IndexSet::IndexType> vertexIndicesStorage;
82 for (
const auto& codimOneElement : elements(codimOneGridView))
87 for (
int i = 0; i < codimOneElement.subEntities(dim-1); ++i)
88 vertexMarkers[ codimOneGridAdapter.
bulkGridVertexIndex(codimOneElement.template subEntity<dim-1>(i)) ] =
true;
91 const auto refElem = referenceElement(codimOneElement);
92 for (
const auto& intersection : intersections(codimOneGridView, codimOneElement))
95 if (!intersection.boundary())
99 const auto numCorners = intersection.geometry().corners();
103 const auto vIdxLocal = refElem.subEntity(intersection.indexInInside(), 1, i, dim-1);
104 vertexIndicesStorage[i] = codimOneGridAdapter.
bulkGridVertexIndex( codimOneElement.template subEntity<dim-1>(vIdxLocal) );
108 if (std::any_of(vertexIndicesStorage.begin(), vertexIndicesStorage.end(), [&isOnBoundary] (
auto idx) { return !isOnBoundary[idx]; }))
109 std::for_each(vertexIndicesStorage.begin(), vertexIndicesStorage.end(), [&vertexMarkers] (
auto idx) { vertexMarkers[idx] = false; });
127 static constexpr int dim = GV::dimension;
128 static_assert(dim > 1,
"Vertex dof enrichment mapper currently only works for dim > 1!");
130 using GIType =
typename GV::IndexSet::IndexType;
131 using Vertex =
typename GV::template Codim<dim>::Entity;
132 using Element =
typename GV::template Codim<0>::Entity;
133 using MCMGMapper = Dune::MultipleCodimMultipleGeomTypeMapper<GV>;
143 : gridView_(gridView)
144 , elementMapper_(gridView,
Dune::mcmgElementLayout())
145 , vertexMapper_(gridView,
Dune::mcmgVertexLayout())
154 if ( !(
static_cast<bool>(layout(Dune::GeometryTypes::vertex, dim)) ) )
155 DUNE_THROW(Dune::InvalidStateException,
"Vertex mapper only makes sense for vertex layout!");
161 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
162 return indexMap_[elementMapper_.index(e)][i];
168 assert(codim == dim &&
"Only element corners can be mapped by this mapper");
169 return vertexMapper_.subIndex(e, i, codim);
175 assert(Vertex::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
176 return vertexMapper_.index(v);
183 template<
class EntityType >
186 if (hasEnrichedVertices_)
187 DUNE_THROW(Dune::InvalidStateException,
"Index map contains enriched vertex dofs. Direct mapping from vertex to index not possible.");
189 assert(EntityType::Geometry::mydimension == 0 &&
"Only vertices can be mapped by this mapper");
190 return vertexMapper_.index(e);
199 {
return isEnriched_[ vertexMapper_.index(v) ]; }
205 gridView_ = gridView;
211 gridView_ = std::move(gridView);
226 template<
class CodimOneGr
idView,
class CodimOneGr
idAdapter>
227 void enrich(
const CodimOneGridView& codimOneGridView,
229 bool verbose =
false)
231 static const int codimOneDim = CodimOneGridView::dimension;
232 static_assert(codimOneDim == dim-1,
"Grid dimension mismatch!");
233 static_assert(codimOneDim == 2 || codimOneDim == 1,
"Inadmissible codimension one grid dimension");
234 static_assert(int(CodimOneGridView::dimensionworld) == int(GV::dimensionworld),
"Grid world dimension mismatch");
249 codimOneGridAdapter);
252 hasEnrichedVertices_ = std::any_of(isEnriched_.begin(), isEnriched_.end(), [] (
bool isEnriched) { return isEnriched; });
255 std::cout <<
"Vertex dof enrichment took " << watch.elapsed() <<
" seconds." << std::endl;
263 size_ = gridView_.size(dim);
264 hasEnrichedVertices_ =
false;
265 indexMap_.resize(gridView_.size(0));
266 isEnriched_.resize(gridView_.size(dim),
false);
267 for (
const auto& e : elements(gridView_))
269 const auto numCorners = e.geometry().corners();
270 const auto eIdxGlobal = elementMapper_.index(e);
273 indexMap_[eIdxGlobal][i] = vertexMapper_.subIndex(e, i, dim);
280 MCMGMapper elementMapper_;
281 MCMGMapper vertexMapper_;
282 bool hasEnrichedVertices_;
283 std::vector<bool> isEnriched_;
284 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:126
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:227
std::size_t size() const
returns the number of dofs managed by this mapper
Definition: vertexmapper.hh:194
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:166
GridIndexType index(const EntityType &e) const
Definition: vertexmapper.hh:184
void update(const GV &gridView)
Definition: vertexmapper.hh:203
EnrichedVertexDofMapper(const GV &gridView)
the constructor
Definition: vertexmapper.hh:142
GridIndexType vertexIndex(const Vertex &v) const
map nodal entity to the grid vertex index
Definition: vertexmapper.hh:173
GIType GridIndexType
export the grid index type
Definition: vertexmapper.hh:139
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:159
GV GridView
export the underlying grid view type
Definition: vertexmapper.hh:137
EnrichedVertexDofMapper(const GV &gridView, Dune::MCMGLayout layout)
constructor taking a layout as additional argument (for compatibility)
Definition: vertexmapper.hh:151
bool isEnriched(const Vertex &v)
returns true if a vertex dof had been enriched
Definition: vertexmapper.hh:198
void update(GV &&gridView)
Definition: vertexmapper.hh:209
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