25#ifndef DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
26#define DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
32#include <dune/grid/common/mcmgmapper.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 BulkGridElement =
typename BulkGridView::template Codim<0>::Entity;
63 using BulkGridIntersection =
typename BulkGridView::Intersection;
64 using BulkGridVertex =
typename BulkGridView::template Codim<BulkGridView::dimension>::Entity;
68 static_assert( int(FacetGridView::dimension) == int(BulkGridView::dimension) - 1,
69 "Grid dimension mismatch! Please check the provided domain ids!" );
70 static_assert( int(FacetGridView::dimensionworld) == int(BulkGridView::dimensionworld),
71 "Grid world dimension mismatch! All grids must have the same world dimension" );
77 : embeddingsPtr_(embeddings)
78 , bulkVertexMapper_(embeddings->template gridView<bulkGridId>(),
Dune::mcmgVertexLayout())
81 const auto& bulkGridView = embeddings->template gridView<bulkGridId>();
82 bulkInsertionToGridVIdx_.resize(bulkGridView.size(BulkGridView::dimension));
83 for (
const auto& v : vertices(bulkGridView))
84 bulkInsertionToGridVIdx_[embeddings->template insertionIndex<bulkGridId>(v)] = bulkVertexMapper_.index(v);
90 hierarchyToBulkInsertionIdx_.resize(embeddingsPtr_->numVerticesInHierarchy());
91 bulkGridHasHierarchyVertex_.resize(embeddingsPtr_->numVerticesInHierarchy(),
false);
92 const auto& bulkHierarchyIndices = embeddingsPtr_->gridHierarchyIndices(bulkGridId);
93 for (std::size_t insIdx = 0; insIdx < bulkHierarchyIndices.size(); ++insIdx)
95 hierarchyToBulkInsertionIdx_[ bulkHierarchyIndices[insIdx] ] = insIdx;
96 bulkGridHasHierarchyVertex_[ bulkHierarchyIndices[insIdx] ] =
true;
100 bulkVertexIsOnFacetGrid_.resize(bulkGridView.size(BulkGridView::dimension),
false);
101 const auto& facetGridView = embeddings->template gridView<facetGridId>();
102 for (
const auto& v : vertices(facetGridView))
104 const auto insIdx = embeddings->template insertionIndex<facetGridId>(v);
105 const auto hierarchyInsIdx = embeddings->gridHierarchyIndices(facetGridId)[insIdx];
107 if (bulkGridHasHierarchyVertex_[hierarchyInsIdx])
108 bulkVertexIsOnFacetGrid_[ getBulkGridVertexIndex_(hierarchyInsIdx) ] =
true;
112 facetElementCorners_.resize(facetGridView.size(0));
113 facetElementsAtBulkVertex_.resize(bulkGridView.size(BulkGridView::dimension));
115 std::size_t facetElementCounter = 0;
116 for (
const auto& element : elements(facetGridView))
121 const auto numCorners = element.subEntities(FacetGridView::dimension);
122 std::vector<BulkIndexType> cornerIndices(numCorners);
123 for (
int i = 0; i < numCorners; ++i)
124 cornerIndices[i] =
bulkGridVertexIndex(element.template subEntity<FacetGridView::dimension>(i));
127 for (
auto bulkVIdx : cornerIndices)
128 facetElementsAtBulkVertex_[bulkVIdx].push_back(facetElementCounter);
131 std::sort(cornerIndices.begin(), cornerIndices.end());
132 facetElementCorners_[facetElementCounter] = std::move(cornerIndices);
135 facetElementCounter++;
147 const auto insIdx = embeddingsPtr_->template insertionIndex<facetGridId>(v);
148 const auto hierarchyInsIdx = embeddingsPtr_->gridHierarchyIndices(facetGridId)[insIdx];
149 return getBulkGridVertexIndex_(hierarchyInsIdx);
158 const auto bulkInsIdx = embeddingsPtr_->template insertionIndex<bulkGridId>(v);
159 const auto bulkVIdx = bulkInsertionToGridVIdx_[bulkInsIdx];
160 return bulkVertexIsOnFacetGrid_[bulkVIdx];
169 bool isOnFacetGrid(
const BulkGridElement& element,
const BulkGridIntersection& intersection)
const
172 const auto refElement = referenceElement(element);
173 const auto numCorners = intersection.geometry().corners();
174 const auto facetIdx = intersection.indexInInside();
176 std::vector<BulkIndexType> cornerIndices(numCorners);
177 for (
int i = 0; i < numCorners; ++i)
178 cornerIndices[i] = bulkVertexMapper_.subIndex( element,
179 refElement.subEntity(facetIdx, 1, i, BulkGridView::dimension),
180 BulkGridView::dimension );
191 template<
class IndexStorage>
195 std::vector<std::size_t> facetElemIndices;
196 for (
auto bulkVIdx : bulkVertexIndices)
197 facetElemIndices.insert( facetElemIndices.end(),
198 facetElementsAtBulkVertex_[bulkVIdx].begin(),
199 facetElementsAtBulkVertex_[bulkVIdx].end() );
202 if (facetElemIndices.size() == 0)
206 std::sort(facetElemIndices.begin(), facetElemIndices.end());
207 facetElemIndices.erase(std::unique(facetElemIndices.begin(), facetElemIndices.end()), facetElemIndices.end());
210 auto cornerIndexCopy = bulkVertexIndices;
211 std::sort(cornerIndexCopy.begin(), cornerIndexCopy.end());
212 for (
const auto& facetElemIdx : facetElemIndices)
214 const auto& facetElemCorners = facetElementCorners_[facetElemIdx];
215 if (facetElemCorners.size() != cornerIndexCopy.size())
218 if ( std::equal(cornerIndexCopy.begin(), cornerIndexCopy.end(),
219 facetElemCorners.begin(), facetElemCorners.end()) )
239 {
return embeddingsPtr_->template adjoinedEntityIndices<facetGridId>(e).size(); }
243 BulkIndexType getBulkGridVertexIndex_(BulkIndexType hierarchyInsertionIdx)
const
245 assert(bulkGridHasHierarchyVertex_[hierarchyInsertionIdx]);
246 return bulkInsertionToGridVIdx_[ hierarchyToBulkInsertionIdx_[hierarchyInsertionIdx] ];
250 std::shared_ptr<const Embeddings> embeddingsPtr_;
253 BulkMapper bulkVertexMapper_;
256 std::vector<bool> bulkVertexIsOnFacetGrid_;
257 std::vector<BulkIndexType> bulkInsertionToGridVIdx_;
258 std::vector<BulkIndexType> hierarchyToBulkInsertionIdx_;
259 std::vector<bool> bulkGridHasHierarchyVertex_;
262 std::vector< std::vector<BulkIndexType> > facetElementsAtBulkVertex_;
263 std::vector< std::vector<BulkIndexType> > facetElementCorners_;
Defines the index types used for grid and local indices.
Definition: common/pdesolver.hh:35
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:192
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:156
CodimOneGridAdapter(std::shared_ptr< const Embeddings > embeddings)
The constructor.
Definition: codimonegridadapter.hh:76
bool isEmbedded(const FacetGridElement &e) const
Returns true if a (d-1)-dimensional element is embedded in the d-dimensional domain.
Definition: codimonegridadapter.hh:231
bool isOnFacetGrid(const BulkGridElement &element, const BulkGridIntersection &intersection) const
Returns true if the given intersection coincides with a facet grid.
Definition: codimonegridadapter.hh:169
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