139 const auto& bulkTree = bulkGridGeometry.boundingBoxTree();
144 std::cout <<
"Initializing the point sources..." << std::endl;
149 extendedSourceStencil_.clear();
159 const auto& lowDimProblem = this->
problem(lowDimIdx);
160 const auto numIp =
getParam<int>(
"MixedDimension.NumCircleSegments");
161 for (
const auto& is : intersections(this->
glue()))
164 const auto& lowDimElement = is.targetEntity(0);
165 const auto lowDimElementIdx = lowDimGridGeometry.elementMapper().index(lowDimElement);
168 const auto intersectionGeometry = is.geometry();
170 const auto& quad = Dune::QuadratureRules<Scalar, lowDimDim>::rule(intersectionGeometry.type(), order);
179 for (
auto&& qp : quad)
182 const auto globalPos = intersectionGeometry.global(qp.position());
188 if (bulkElementIndices.empty())
195 const auto radius = lowDimProblem.spatialParams().radius(lowDimElementIdx);
196 const auto normal = intersectionGeometry.corner(1)-intersectionGeometry.corner(0);
197 const auto circleAvgWeight = 2*M_PI*
radius/numIp;
198 const auto integrationElement = intersectionGeometry.integrationElement(qp.position());
199 const auto qpweight = qp.weight();
202 std::vector<Scalar> circleIpWeight; circleIpWeight.reserve(circlePoints.size());
203 std::vector<GridIndex<bulkIdx>> circleStencil; circleStencil.reserve(circlePoints.size());
206 std::vector<const std::vector<GridIndex<bulkIdx>>*> circleDofIndices;
207 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
208 std::vector<ShapeValues> circleShapeValues;
211 int insideCirclePoints = 0;
212 for (
int k = 0; k < circlePoints.size(); ++k)
215 if (circleBulkElementIndices.empty())
218 ++insideCirclePoints;
219 const auto localCircleAvgWeight = circleAvgWeight / circleBulkElementIndices.size();
220 for (
const auto bulkElementIdx : circleBulkElementIndices)
222 circleStencil.push_back(bulkElementIdx);
223 circleIpWeight.push_back(localCircleAvgWeight);
226 if constexpr (isCVFE<bulkIdx>())
228 const auto bulkElement = bulkGridGeometry.element(bulkElementIdx);
232 const auto bulkGeometry = bulkElement.geometry();
233 ShapeValues shapeValues;
234 this->
getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry, circlePoints[k], shapeValues);
235 circleShapeValues.emplace_back(std::move(shapeValues));
242 if (circleStencil.empty())
246 std::shared_ptr<const typename PointSourceData::CircleInterpolation> circleInterpolation;
247 if constexpr (isCVFE<bulkIdx>())
248 circleInterpolation = PointSourceData::makeCircleInterpolation(circleDofIndices, circleShapeValues, circleIpWeight, circleStencil);
250 circleInterpolation = PointSourceData::makeCircleInterpolation(circleIpWeight, circleStencil);
254 lowDimStencil.insert(lowDimStencil.end(), circleInterpolation->dofs.begin(), circleInterpolation->dofs.end());
257 const auto surfaceFraction = Scalar(insideCirclePoints)/Scalar(circlePoints.size());
260 for (
auto bulkElementIdx : bulkElementIndices)
264 this->
pointSources(bulkIdx).emplace_back(globalPos,
id, qpweight, integrationElement*surfaceFraction, bulkElementIdx);
265 this->
pointSources(bulkIdx).back().setEmbeddings(bulkElementIndices.size());
266 this->
pointSources(lowDimIdx).emplace_back(globalPos,
id, qpweight, integrationElement*surfaceFraction, lowDimElementIdx);
267 this->
pointSources(lowDimIdx).back().setEmbeddings(bulkElementIndices.size());
271 PointSourceData psData;
273 if constexpr (isCVFE<lowDimIdx>())
275 ShapeValues shapeValues;
276 this->
getShapeValues(lowDimIdx, lowDimGridGeometry, lowDimElement.geometry(), globalPos, shapeValues);
277 psData.addLowDimInterpolation(shapeValues, this->
elementDofIndices(lowDimIdx, lowDimElementIdx), lowDimElementIdx);
281 psData.addLowDimInterpolation(lowDimElementIdx);
285 psData.addCircleInterpolation(circleInterpolation);
286 if constexpr (isCVFE<bulkIdx>())
288 const auto bulkGeometry = bulkGridGeometry.element(bulkElementIdx).geometry();
289 ShapeValues shapeValues;
290 this->
getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry, globalPos, shapeValues);
291 psData.addBulkInterpolation(shapeValues, this->
elementDofIndices(bulkIdx, bulkElementIdx), bulkElementIdx);
295 psData.addBulkInterpolation(bulkElementIdx);
302 const auto outsideGeometry = bulkGridGeometry.element(bulkElementIdx).geometry();
306 if constexpr (isCVFE<lowDimIdx>())
315 this->
couplingStencils(bulkIdx)[bulkElementIdx].push_back(lowDimElementIdx);
319 auto& stencil = extendedSourceStencil_.stencil()[bulkElementIdx];
320 stencil.insert(stencil.end(), circleInterpolation->dofs.begin(), circleInterpolation->dofs.end());
326 for (
auto&& stencil : extendedSourceStencil_.stencil())
328 std::sort(stencil.second.begin(), stencil.second.end());
329 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
332 if constexpr (isCVFE<bulkIdx>())
335 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
336 [&](
auto i){ return std::find(indices.begin(), indices.end(), i) != indices.end(); }),
337 stencil.second.end());
342 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
343 [&](
auto i){ return i == stencil.first; }),
344 stencil.second.end());
349 using namespace Dune::Hybrid;
350 forEach(integralRange(Dune::index_constant<2>{}), [&](
const auto domainIdx)
354 std::sort(stencil.second.begin(), stencil.second.end());
355 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
359 std::cout <<
"took " << watch.elapsed() <<
" seconds." << std::endl;