87 void update(
const BulkFVG& bulkFvGridGeometry,
88 const LowDimFVG& lowDimFvGridGeometry,
89 std::shared_ptr<const Embeddings> embeddings,
93 auto addCouplingEntryPolicy = [&] (
auto&& adjoinedEntityIndices,
94 const LowDimElement& lowDimElement,
95 const LowDimFVG& lowDimFvGridGeometry,
96 const BulkFVG& bulkFvGridGeometry)
98 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
99 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
102 const auto& lowDimGeometry = lowDimElement.geometry();
103 const auto numElementCorners = lowDimElement.subEntities(lowDimDim);
104 std::vector<BulkIndexType> elemCornerIndices(numElementCorners);
105 for (
int i = 0; i < numElementCorners; ++i)
106 elemCornerIndices[i] = codimOneGridAdapter.
bulkGridVertexIndex(lowDimElement.template subEntity<lowDimDim>(i));
109 auto fvGeometry =
localView(bulkFvGridGeometry);
110 for (
auto bulkElemIdx : adjoinedEntityIndices)
112 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
113 fvGeometry.bind(bulkElement);
115 std::vector<BulkIndexType> embeddedScvfIndices;
116 for (
const auto& scvf : scvfs(fvGeometry))
120 if (!scvf.boundary())
122 if ( std::count(adjoinedEntityIndices.begin(), adjoinedEntityIndices.end(), scvf.outsideScvIdx()) )
123 embeddedScvfIndices.push_back(scvf.index());
129 const auto eps = lowDimGeometry.volume()*1e-8;
130 const auto diffVec = lowDimGeometry.center()-fvGeometry.facetCorner(scvf);
132 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
133 embeddedScvfIndices.push_back(scvf.index());
138 if ( embeddedScvfIndices.size() != numElementCorners )
139 DUNE_THROW(Dune::InvalidStateException,
"Could not find all coupling scvfs in embedment");
142 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
144 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
145 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
148 for (
auto dofIdx : lowDimElementDofs)
149 for (
auto scvfIdx : embeddedScvfIndices)
150 this->addCouplingsFromIV_(bulkFvGridGeometry, fvGeometry.scvf(scvfIdx), fvGeometry, lowDimElemIdx, dofIdx);
156 const auto copy = embeddedScvfIndices;
158 for (
unsigned int i = 0; i < numElementCorners; ++i)
160 const auto& scvf = fvGeometry.scvf(copy[i]);
161 auto it = std::find(elemCornerIndices.begin(), elemCornerIndices.end(), scvf.vertexIndex());
162 assert(it != elemCornerIndices.end());
163 embeddedScvfIndices[ std::distance(elemCornerIndices.begin(), it) ] = copy[i];
168 auto& elemToScvfMap = bulkData.elementToScvfMap[lowDimElemIdx];
169 elemToScvfMap.insert(elemToScvfMap.end(), embeddedScvfIndices.begin(), embeddedScvfIndices.end());
172 lowDimData.embedments.emplace_back( bulkElemIdx, std::move(embeddedScvfIndices) );
177 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
180 auto makeUnique = [] (
auto& c)
182 std::sort(c.begin(), c.end());
183 c.erase( std::unique(c.begin(), c.end()), c.end() );
187 auto makeBulkMapEntryUnique = [&makeUnique] (
auto& data)
189 makeUnique(data.second.couplingStencil);
190 makeUnique(data.second.couplingElementStencil);
191 std::for_each(data.second.dofToCouplingScvfMap.begin(),
192 data.second.dofToCouplingScvfMap.end(),
193 [&makeUnique] (
auto& pair) { makeUnique(pair.second); });
197 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
198 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeBulkMapEntryUnique);
201 auto& lowDimCouplingData = this->couplingMap_(facetGridId, bulkGridId);
202 std::for_each(lowDimCouplingData.begin(),
203 lowDimCouplingData.end(),
204 [&makeUnique] (
auto& pair) { makeUnique(pair.second.couplingStencil); });