138 static const bool useCircleAverage = getParam<bool>(
"MixedDimension.UseCircleAverage",
true);
141 const auto& bulkGridGeometry = this->problem(bulkIdx).gridGeometry();
142 const auto& lowDimGridGeometry = this->problem(lowDimIdx).gridGeometry();
143 const auto& bulkTree = bulkGridGeometry.boundingBoxTree();
148 std::cout <<
"Initializing the point sources..." << std::endl;
153 extendedSourceStencil_.stencil().clear();
156 this->precomputeVertexIndices(bulkIdx);
157 this->precomputeVertexIndices(lowDimIdx);
163 const auto& lowDimProblem = this->problem(lowDimIdx);
164 for (
const auto& is : intersections(this->glue()))
167 const auto& lowDimElement = is.targetEntity(0);
168 const auto lowDimElementIdx = lowDimGridGeometry.elementMapper().index(lowDimElement);
171 const auto intersectionGeometry = is.geometry();
173 const auto& quad = Dune::QuadratureRules<Scalar, lowDimDim>::rule(intersectionGeometry.type(), order);
182 for (
auto&& qp : quad)
185 const auto globalPos = intersectionGeometry.global(qp.position());
191 if (bulkElementIndices.empty())
198 static const auto numIp = getParam<int>(
"MixedDimension.NumCircleSegments");
199 const auto radius = lowDimProblem.spatialParams().radius(lowDimElementIdx);
200 const auto normal = intersectionGeometry.corner(1)-intersectionGeometry.corner(0);
201 const auto integrationElement = intersectionGeometry.integrationElement(qp.position())*2*M_PI*radius/Scalar(numIp);
202 const auto qpweight = qp.weight()/(2*M_PI*radius);
203 const auto circleAvgWeight = 2*M_PI*radius/numIp;
206 std::vector<std::vector<std::size_t>> circleBulkElementIndices(circlePoints.size());
207 std::vector<Scalar> circleIpWeight; circleIpWeight.reserve(circlePoints.size());
208 std::vector<GridIndex<bulkIdx>> circleStencil; circleStencil.reserve(circlePoints.size());
210 std::vector<const std::vector<GridIndex<bulkIdx>>*> circleCornerIndices;
211 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
212 std::vector<ShapeValues> circleShapeValues;
215 for (
int k = 0; k < circlePoints.size(); ++k)
218 if (circleBulkElementIndices[k].empty())
221 const auto localCircleAvgWeight = circleAvgWeight / circleBulkElementIndices[k].size();
222 for (
const auto bulkElementIdx : circleBulkElementIndices[k])
224 circleStencil.push_back(bulkElementIdx);
225 circleIpWeight.push_back(localCircleAvgWeight);
228 if constexpr (isBox<bulkIdx>())
230 const auto bulkElement = bulkGridGeometry.element(bulkElementIdx);
231 circleCornerIndices.push_back(&(this->vertexIndices(bulkIdx, bulkElementIdx)));
234 const auto bulkGeometry = bulkElement.geometry();
235 ShapeValues shapeValues;
236 this->getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry, circlePoints[k], shapeValues);
237 circleShapeValues.emplace_back(std::move(shapeValues));
243 if constexpr (isBox<bulkIdx>())
246 for (
const auto& vertices : circleCornerIndices)
248 this->couplingStencils(lowDimIdx)[lowDimElementIdx].insert(this->couplingStencils(lowDimIdx)[lowDimElementIdx].end(),
249 vertices->begin(), vertices->end());
255 this->couplingStencils(lowDimIdx)[lowDimElementIdx].insert(this->couplingStencils(lowDimIdx)[lowDimElementIdx].end(),
256 circleStencil.begin(), circleStencil.end());
259 for (
int k = 0; k < circlePoints.size(); ++k)
261 const auto& circlePos = circlePoints[k];
264 if (circleBulkElementIndices[k].empty())
269 for (
const auto bulkElementIdx : circleBulkElementIndices[k])
271 const auto id = this->idCounter_++;
273 this->pointSources(bulkIdx).emplace_back(circlePos,
id, qpweight, integrationElement, bulkElementIdx);
274 this->pointSources(bulkIdx).back().setEmbeddings(circleBulkElementIndices[k].size());
275 this->pointSources(lowDimIdx).emplace_back(globalPos,
id, qpweight, integrationElement, lowDimElementIdx);
276 this->pointSources(lowDimIdx).back().setEmbeddings(circleBulkElementIndices[k].size());
280 PointSourceData psData;
282 if constexpr (isBox<lowDimIdx>())
284 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
285 ShapeValues shapeValues;
286 this->getShapeValues(lowDimIdx, lowDimGridGeometry, intersectionGeometry, globalPos, shapeValues);
287 psData.addLowDimInterpolation(shapeValues, this->vertexIndices(lowDimIdx, lowDimElementIdx), lowDimElementIdx);
291 psData.addLowDimInterpolation(lowDimElementIdx);
295 if constexpr (isBox<bulkIdx>())
297 if (useCircleAverage)
298 psData.addCircleInterpolation(circleCornerIndices, circleShapeValues, circleIpWeight, circleStencil);
300 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
301 const auto bulkGeometry = bulkGridGeometry.element(bulkElementIdx).geometry();
302 ShapeValues shapeValues;
303 this->getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry, circlePos, shapeValues);
304 psData.addBulkInterpolation(shapeValues, this->vertexIndices(bulkIdx, bulkElementIdx), bulkElementIdx);
308 if (useCircleAverage)
309 psData.addCircleInterpolation(circleIpWeight, circleStencil);
311 psData.addBulkInterpolation(bulkElementIdx);
315 this->pointSourceData().emplace_back(std::move(psData));
319 if constexpr (isBox<lowDimIdx>())
321 const auto& vertices = this->vertexIndices(lowDimIdx, lowDimElementIdx);
322 this->couplingStencils(bulkIdx)[bulkElementIdx].insert(this->couplingStencils(bulkIdx)[bulkElementIdx].end(),
323 vertices.begin(), vertices.end());
328 this->couplingStencils(bulkIdx)[bulkElementIdx].push_back(lowDimElementIdx);
332 if (useCircleAverage)
334 if constexpr (isBox<bulkIdx>())
337 for (
const auto& vertices : circleCornerIndices)
339 extendedSourceStencil_.stencil()[bulkElementIdx].insert(extendedSourceStencil_.stencil()[bulkElementIdx].end(),
340 vertices->begin(), vertices->end());
346 extendedSourceStencil_.stencil()[bulkElementIdx].insert(extendedSourceStencil_.stencil()[bulkElementIdx].end(),
347 circleStencil.begin(), circleStencil.end());
356 for (
auto&& stencil : extendedSourceStencil_.stencil())
358 std::sort(stencil.second.begin(), stencil.second.end());
359 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
362 if constexpr (isBox<bulkIdx>())
364 const auto& indices = this->vertexIndices(bulkIdx, stencil.first);
365 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
366 [&](
auto i){ return std::find(indices.begin(), indices.end(), i) != indices.end(); }),
367 stencil.second.end());
372 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
373 [&](
auto i){ return i == stencil.first; }),
374 stencil.second.end());
379 using namespace Dune::Hybrid;
380 forEach(integralRange(Dune::index_constant<2>{}), [&](
const auto domainIdx)
382 for (
auto&& stencil : this->couplingStencils(domainIdx))
384 std::sort(stencil.second.begin(), stencil.second.end());
385 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
389 std::cout <<
"took " << watch.elapsed() <<
" seconds." << std::endl;