13#ifndef DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
14#define DUMUX_FACETCOUPLING_CODIM_ONE_GRID_ADAPTER_HH
20#include <dune/grid/common/mcmgmapper.hh>
38template<
class Embeddings,
int bulkGr
idId = 0,
int facetGr
idId = 1>
42 using FacetGridView =
typename Embeddings::template GridView<facetGridId>;
43 using FacetGridVertex =
typename FacetGridView::template Codim<FacetGridView::dimension>::Entity;
44 using FacetGridElement =
typename FacetGridView::template Codim<0>::Entity;
48 using BulkGridView =
typename Embeddings::template GridView<bulkGridId>;
49 using BulkMapper = Dune::MultipleCodimMultipleGeomTypeMapper<BulkGridView>;
50 using BulkGridElement =
typename BulkGridView::template Codim<0>::Entity;
51 using BulkGridIntersection =
typename BulkGridView::Intersection;
52 using BulkGridVertex =
typename BulkGridView::template Codim<BulkGridView::dimension>::Entity;
56 static_assert( int(FacetGridView::dimension) == int(BulkGridView::dimension) - 1,
57 "Grid dimension mismatch! Please check the provided domain ids!" );
58 static_assert( int(FacetGridView::dimensionworld) == int(BulkGridView::dimensionworld),
59 "Grid world dimension mismatch! All grids must have the same world dimension" );
65 : embeddingsPtr_(embeddings)
66 , bulkVertexMapper_(embeddings->template gridView<bulkGridId>(),
Dune::mcmgVertexLayout())
69 const auto& bulkGridView = embeddings->template gridView<bulkGridId>();
70 bulkInsertionToGridVIdx_.resize(bulkGridView.size(BulkGridView::dimension));
71 for (
const auto& v : vertices(bulkGridView))
72 bulkInsertionToGridVIdx_[embeddings->template insertionIndex<bulkGridId>(v)] = bulkVertexMapper_.index(v);
78 hierarchyToBulkInsertionIdx_.resize(embeddingsPtr_->numVerticesInHierarchy());
79 bulkGridHasHierarchyVertex_.resize(embeddingsPtr_->numVerticesInHierarchy(),
false);
80 const auto& bulkHierarchyIndices = embeddingsPtr_->gridHierarchyIndices(bulkGridId);
81 for (std::size_t insIdx = 0; insIdx < bulkHierarchyIndices.size(); ++insIdx)
83 hierarchyToBulkInsertionIdx_[ bulkHierarchyIndices[insIdx] ] = insIdx;
84 bulkGridHasHierarchyVertex_[ bulkHierarchyIndices[insIdx] ] =
true;
88 bulkVertexIsOnFacetGrid_.resize(bulkGridView.size(BulkGridView::dimension),
false);
89 const auto& facetGridView = embeddings->template gridView<facetGridId>();
90 for (
const auto& v : vertices(facetGridView))
92 const auto insIdx = embeddings->template insertionIndex<facetGridId>(v);
93 const auto hierarchyInsIdx = embeddings->gridHierarchyIndices(facetGridId)[insIdx];
95 if (bulkGridHasHierarchyVertex_[hierarchyInsIdx])
96 bulkVertexIsOnFacetGrid_[ getBulkGridVertexIndex_(hierarchyInsIdx) ] =
true;
100 facetElementCorners_.resize(facetGridView.size(0));
101 facetElementsAtBulkVertex_.resize(bulkGridView.size(BulkGridView::dimension));
103 std::size_t facetElementCounter = 0;
104 for (
const auto& element : elements(facetGridView))
109 const auto numCorners = element.subEntities(FacetGridView::dimension);
110 std::vector<BulkIndexType> cornerIndices(
numCorners);
112 cornerIndices[i] =
bulkGridVertexIndex(element.template subEntity<FacetGridView::dimension>(i));
115 for (
auto bulkVIdx : cornerIndices)
116 facetElementsAtBulkVertex_[bulkVIdx].push_back(facetElementCounter);
119 std::sort(cornerIndices.begin(), cornerIndices.end());
120 facetElementCorners_[facetElementCounter] = std::move(cornerIndices);
123 facetElementCounter++;
135 const auto insIdx = embeddingsPtr_->template insertionIndex<facetGridId>(v);
136 const auto hierarchyInsIdx = embeddingsPtr_->gridHierarchyIndices(facetGridId)[insIdx];
137 return getBulkGridVertexIndex_(hierarchyInsIdx);
146 const auto bulkInsIdx = embeddingsPtr_->template insertionIndex<bulkGridId>(v);
147 const auto bulkVIdx = bulkInsertionToGridVIdx_[bulkInsIdx];
148 return bulkVertexIsOnFacetGrid_[bulkVIdx];
157 bool isOnFacetGrid(
const BulkGridElement& element,
const BulkGridIntersection& intersection)
const
160 const auto refElement = referenceElement(element);
161 const auto numCorners = intersection.geometry().corners();
162 const auto facetIdx = intersection.indexInInside();
164 std::vector<BulkIndexType> cornerIndices(
numCorners);
166 cornerIndices[i] = bulkVertexMapper_.subIndex( element,
167 refElement.subEntity(facetIdx, 1, i, BulkGridView::dimension),
168 BulkGridView::dimension );
179 template<
class IndexStorage>
183 std::vector<std::size_t> facetElemIndices;
184 for (
auto bulkVIdx : bulkVertexIndices)
185 facetElemIndices.insert( facetElemIndices.end(),
186 facetElementsAtBulkVertex_[bulkVIdx].begin(),
187 facetElementsAtBulkVertex_[bulkVIdx].end() );
190 if (facetElemIndices.size() == 0)
194 std::sort(facetElemIndices.begin(), facetElemIndices.end());
195 facetElemIndices.erase(std::unique(facetElemIndices.begin(), facetElemIndices.end()), facetElemIndices.end());
198 auto cornerIndexCopy = bulkVertexIndices;
199 std::sort(cornerIndexCopy.begin(), cornerIndexCopy.end());
200 for (
const auto& facetElemIdx : facetElemIndices)
202 const auto& facetElemCorners = facetElementCorners_[facetElemIdx];
203 if (facetElemCorners.size() != cornerIndexCopy.size())
206 if ( std::equal(cornerIndexCopy.begin(), cornerIndexCopy.end(),
207 facetElemCorners.begin(), facetElemCorners.end()) )
227 {
return embeddingsPtr_->template adjoinedEntityIndices<facetGridId>(e).size(); }
231 BulkIndexType getBulkGridVertexIndex_(BulkIndexType hierarchyInsertionIdx)
const
233 assert(bulkGridHasHierarchyVertex_[hierarchyInsertionIdx]);
234 return bulkInsertionToGridVIdx_[ hierarchyToBulkInsertionIdx_[hierarchyInsertionIdx] ];
238 std::shared_ptr<const Embeddings> embeddingsPtr_;
241 BulkMapper bulkVertexMapper_;
244 std::vector<bool> bulkVertexIsOnFacetGrid_;
245 std::vector<BulkIndexType> bulkInsertionToGridVIdx_;
246 std::vector<BulkIndexType> hierarchyToBulkInsertionIdx_;
247 std::vector<bool> bulkGridHasHierarchyVertex_;
250 std::vector< std::vector<BulkIndexType> > facetElementsAtBulkVertex_;
251 std::vector< std::vector<BulkIndexType> > facetElementCorners_;
Adapter that allows retrieving information on a d-dimensional grid for entities of a (d-1)-dimensiona...
Definition: codimonegridadapter.hh:40
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:180
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:144
CodimOneGridAdapter(std::shared_ptr< const Embeddings > embeddings)
The constructor.
Definition: codimonegridadapter.hh:64
bool isEmbedded(const FacetGridElement &e) const
Returns true if a (d-1)-dimensional element is embedded in the d-dimensional domain.
Definition: codimonegridadapter.hh:219
bool isOnFacetGrid(const BulkGridElement &element, const BulkGridIntersection &intersection) const
Returns true if the given intersection coincides with a facet grid.
Definition: codimonegridadapter.hh:157
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
std::size_t numCorners(Shape shape)
Returns the number of corners of a given geometry.
Definition: throatproperties.hh:220
Definition: common/pdesolver.hh:24
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27