25#ifndef DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
26#define DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
31#include <dune/grid/common/mcmgmapper.hh>
32#include <dune/geometry/referenceelements.hh>
50template<
class Embeddings,
int bulkGr
idId = 0,
int facetGr
idId = 1>
54 using FacetGridView =
typename Embeddings::template GridView<facetGridId>;
55 using FacetGridVertex =
typename FacetGridView::template Codim<FacetGridView::dimension>::Entity;
56 using FacetGridElement =
typename FacetGridView::template Codim<0>::Entity;
60 using BulkGridView =
typename Embeddings::template GridView<bulkGridId>;
61 using BulkMapper = Dune::MultipleCodimMultipleGeomTypeMapper<BulkGridView>;
62 using BulkReferenceElements =
typename Dune::ReferenceElements<typename BulkGridView::ctype, BulkGridView::dimension>;
63 using BulkGridElement =
typename BulkGridView::template Codim<0>::Entity;
64 using BulkGridIntersection =
typename BulkGridView::Intersection;
65 using BulkGridVertex =
typename BulkGridView::template Codim<BulkGridView::dimension>::Entity;
69 static_assert( int(FacetGridView::dimension) == int(BulkGridView::dimension) - 1,
70 "Grid dimension mismatch! Please check the provided domain ids!" );
71 static_assert( int(FacetGridView::dimensionworld) == int(BulkGridView::dimensionworld),
72 "Grid world dimension mismatch! All grids must have the same world dimension" );
78 : embeddingsPtr_(embeddings)
79 , bulkVertexMapper_(embeddings->template gridView<bulkGridId>(),
Dune::mcmgVertexLayout())
82 const auto& bulkGridView = embeddings->template gridView<bulkGridId>();
83 bulkInsertionToGridVIdx_.resize(bulkGridView.size(BulkGridView::dimension));
84 for (
const auto& v : vertices(bulkGridView))
85 bulkInsertionToGridVIdx_[embeddings->template insertionIndex<bulkGridId>(v)] = bulkVertexMapper_.index(v);
91 hierarchyToBulkInsertionIdx_.resize(embeddingsPtr_->numVerticesInHierarchy());
92 bulkGridHasHierarchyVertex_.resize(embeddingsPtr_->numVerticesInHierarchy(),
false);
93 const auto& bulkHierarchyIndices = embeddingsPtr_->gridHierarchyIndices(bulkGridId);
94 for (std::size_t insIdx = 0; insIdx < bulkHierarchyIndices.size(); ++insIdx)
96 hierarchyToBulkInsertionIdx_[ bulkHierarchyIndices[insIdx] ] = insIdx;
97 bulkGridHasHierarchyVertex_[ bulkHierarchyIndices[insIdx] ] =
true;
101 bulkVertexIsOnFacetGrid_.resize(bulkGridView.size(BulkGridView::dimension),
false);
102 const auto& facetGridView = embeddings->template gridView<facetGridId>();
103 for (
const auto& v : vertices(facetGridView))
105 const auto insIdx = embeddings->template insertionIndex<facetGridId>(v);
106 const auto hierarchyInsIdx = embeddings->gridHierarchyIndices(facetGridId)[insIdx];
108 if (bulkGridHasHierarchyVertex_[hierarchyInsIdx])
109 bulkVertexIsOnFacetGrid_[ getBulkGridVertexIndex_(hierarchyInsIdx) ] =
true;
113 facetElementCorners_.resize(facetGridView.size(0));
114 facetElementsAtBulkVertex_.resize(bulkGridView.size(BulkGridView::dimension));
116 std::size_t facetElementCounter = 0;
117 for (
const auto& element : elements(facetGridView))
122 const auto numCorners = element.subEntities(FacetGridView::dimension);
123 std::vector<BulkIndexType> cornerIndices(numCorners);
124 for (
int i = 0; i < numCorners; ++i)
125 cornerIndices[i] =
bulkGridVertexIndex(element.template subEntity<FacetGridView::dimension>(i));
128 for (
auto bulkVIdx : cornerIndices)
129 facetElementsAtBulkVertex_[bulkVIdx].push_back(facetElementCounter);
132 std::sort(cornerIndices.begin(), cornerIndices.end());
133 facetElementCorners_[facetElementCounter] = std::move(cornerIndices);
136 facetElementCounter++;
148 const auto insIdx = embeddingsPtr_->template insertionIndex<facetGridId>(v);
149 const auto hierarchyInsIdx = embeddingsPtr_->gridHierarchyIndices(facetGridId)[insIdx];
150 return getBulkGridVertexIndex_(hierarchyInsIdx);
159 const auto bulkInsIdx = embeddingsPtr_->template insertionIndex<bulkGridId>(v);
160 const auto bulkVIdx = bulkInsertionToGridVIdx_[bulkInsIdx];
161 return bulkVertexIsOnFacetGrid_[bulkVIdx];
170 bool isOnFacetGrid(
const BulkGridElement& element,
const BulkGridIntersection& intersection)
const
173 const auto refElement = BulkReferenceElements::general(element.type());
174 const auto numCorners = intersection.geometry().corners();
175 const auto facetIdx = intersection.indexInInside();
177 std::vector<BulkIndexType> cornerIndices(numCorners);
178 for (
int i = 0; i < numCorners; ++i)
179 cornerIndices[i] = bulkVertexMapper_.subIndex( element,
180 refElement.subEntity(facetIdx, 1, i, BulkGridView::dimension),
181 BulkGridView::dimension );
192 template<
class IndexStorage>
196 std::vector<std::size_t> facetElemIndices;
197 for (
auto bulkVIdx : bulkVertexIndices)
198 facetElemIndices.insert( facetElemIndices.end(),
199 facetElementsAtBulkVertex_[bulkVIdx].begin(),
200 facetElementsAtBulkVertex_[bulkVIdx].end() );
203 if (facetElemIndices.size() == 0)
207 std::sort(facetElemIndices.begin(), facetElemIndices.end());
208 facetElemIndices.erase(std::unique(facetElemIndices.begin(), facetElemIndices.end()), facetElemIndices.end());
211 auto cornerIndexCopy = bulkVertexIndices;
212 std::sort(cornerIndexCopy.begin(), cornerIndexCopy.end());
213 for (
const auto& facetElemIdx : facetElemIndices)
215 const auto& facetElemCorners = facetElementCorners_[facetElemIdx];
216 if (facetElemCorners.size() != cornerIndexCopy.size())
219 if ( std::equal(cornerIndexCopy.begin(), cornerIndexCopy.end(),
220 facetElemCorners.begin(), facetElemCorners.end()) )
240 {
return embeddingsPtr_->template adjoinedEntityIndices<facetGridId>(e).size(); }
244 BulkIndexType getBulkGridVertexIndex_(BulkIndexType hierarchyInsertionIdx)
const
246 assert(bulkGridHasHierarchyVertex_[hierarchyInsertionIdx]);
247 return bulkInsertionToGridVIdx_[ hierarchyToBulkInsertionIdx_[hierarchyInsertionIdx] ];
251 std::shared_ptr<const Embeddings> embeddingsPtr_;
254 BulkMapper bulkVertexMapper_;
257 std::vector<bool> bulkVertexIsOnFacetGrid_;
258 std::vector<BulkIndexType> bulkInsertionToGridVIdx_;
259 std::vector<BulkIndexType> hierarchyToBulkInsertionIdx_;
260 std::vector<bool> bulkGridHasHierarchyVertex_;
263 std::vector< std::vector<BulkIndexType> > facetElementsAtBulkVertex_;
264 std::vector< std::vector<BulkIndexType> > facetElementCorners_;
Defines the index types used for grid and local indices.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Definition: common/properties/model.hh:34
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:52
bool composeFacetElement(const IndexStorage &bulkVertexIndices) const
Returns true if a given set of bulk vertex indices make up a facet grid element.
Definition: codimonegridadapter.hh:193
bool isOnFacetGrid(const BulkGridVertex &v) const
Returns true if the vertex of the d-dimensional grid with the given vertex index also exists on the (...
Definition: codimonegridadapter.hh:157
CodimOneGridAdapter(std::shared_ptr< const Embeddings > embeddings)
The constructor.
Definition: codimonegridadapter.hh:77
bool isEmbedded(const FacetGridElement &e) const
Returns true if a (d-1)-dimensional element is embedded in the d-dimensional domain.
Definition: codimonegridadapter.hh:232
bool isOnFacetGrid(const BulkGridElement &element, const BulkGridIntersection &intersection) const
Returns true if the given intersection coincides with a facet grid.
Definition: codimonegridadapter.hh:170
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:239
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:146