13#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_COUPLINGMANAGER_1D3D_AVERAGE_HH
14#define DUMUX_MULTIDOMAIN_EMBEDDED_COUPLINGMANAGER_1D3D_AVERAGE_HH
18#include <dune/common/timer.hh>
19#include <dune/geometry/quadraturerules.hh>
34namespace Embedded1d3dCouplingMode {
36 static std::string
name() {
return "average"; }
43template<
class MDTraits,
class CouplingMode>
44class Embedded1d3dCouplingManager;
52template<
class MDTraits>
55 CircleAveragePointSourceTraits<MDTraits>>
59 using Scalar =
typename MDTraits::Scalar;
60 using SolutionVector =
typename MDTraits::SolutionVector;
61 using PointSourceData =
typename ParentType::PointSourceTraits::PointSourceData;
63 static constexpr auto bulkIdx =
typename MDTraits::template SubDomain<0>::Index();
64 static constexpr auto lowDimIdx =
typename MDTraits::template SubDomain<1>::Index();
67 template<std::
size_t id>
using SubDomainTypeTag =
typename MDTraits::template SubDomain<id>::TypeTag;
70 template<std::
size_t id>
using GridView =
typename GridGeometry<id>::GridView;
71 template<std::
size_t id>
using Element =
typename GridView<id>::template Codim<0>::Entity;
74 using GlobalPosition =
typename Element<bulkIdx>::Geometry::GlobalCoordinate;
76 template<std::
size_t id>
77 static constexpr bool isBox()
83 bulkDim = GridView<bulkIdx>::dimension,
84 lowDimDim = GridView<lowDimIdx>::dimension,
85 dimWorld = GridView<bulkIdx>::dimensionworld
90 using ParentType::ParentType;
98 template<std::
size_t id,
class JacobianPattern>
101 extendedSourceStencil_.extendJacobianPattern(*
this, domainI, pattern);
111 template<std::
size_t i,
class LocalAssemblerI,
class JacobianMatrixDiagBlock,
class Gr
idVariables>
113 const LocalAssemblerI& localAssemblerI,
114 const typename LocalAssemblerI::LocalResidual::ElementResidualVector&,
115 JacobianMatrixDiagBlock& A,
116 GridVariables& gridVariables)
118 extendedSourceStencil_.evalAdditionalDomainDerivatives(*
this, domainI, localAssemblerI, A, gridVariables);
133 const auto& bulkGridGeometry = this->problem(bulkIdx).gridGeometry();
134 const auto& lowDimGridGeometry = this->problem(lowDimIdx).gridGeometry();
135 const auto& bulkTree = bulkGridGeometry.boundingBoxTree();
140 std::cout <<
"Initializing the point sources..." << std::endl;
145 extendedSourceStencil_.clear();
148 this->precomputeVertexIndices(bulkIdx);
149 this->precomputeVertexIndices(lowDimIdx);
155 const auto& lowDimProblem = this->problem(lowDimIdx);
156 for (
const auto& is : intersections(this->glue()))
159 const auto& lowDimElement = is.targetEntity(0);
160 const auto lowDimElementIdx = lowDimGridGeometry.elementMapper().index(lowDimElement);
163 const auto intersectionGeometry = is.geometry();
165 const auto& quad = Dune::QuadratureRules<Scalar, lowDimDim>::rule(intersectionGeometry.type(), order);
174 for (
auto&& qp : quad)
177 const auto globalPos = intersectionGeometry.global(qp.position());
183 if (bulkElementIndices.empty())
190 static const auto numIp = getParam<int>(
"MixedDimension.NumCircleSegments");
191 const auto radius = lowDimProblem.spatialParams().radius(lowDimElementIdx);
192 const auto normal = intersectionGeometry.corner(1)-intersectionGeometry.corner(0);
193 const auto circleAvgWeight = 2*M_PI*radius/numIp;
194 const auto integrationElement = intersectionGeometry.integrationElement(qp.position());
195 const auto qpweight = qp.weight();
198 std::vector<Scalar> circleIpWeight; circleIpWeight.reserve(
circlePoints.size());
199 std::vector<GridIndex<bulkIdx>> circleStencil; circleStencil.reserve(
circlePoints.size());
202 std::vector<const std::vector<GridIndex<bulkIdx>>*> circleCornerIndices;
203 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
204 std::vector<ShapeValues> circleShapeValues;
207 int insideCirclePoints = 0;
211 if (circleBulkElementIndices.empty())
214 ++insideCirclePoints;
215 const auto localCircleAvgWeight = circleAvgWeight / circleBulkElementIndices.size();
216 for (
const auto bulkElementIdx : circleBulkElementIndices)
218 circleStencil.push_back(bulkElementIdx);
219 circleIpWeight.push_back(localCircleAvgWeight);
222 if constexpr (isBox<bulkIdx>())
224 const auto bulkElement = bulkGridGeometry.element(bulkElementIdx);
225 circleCornerIndices.push_back(&(this->vertexIndices(bulkIdx, bulkElementIdx)));
228 const auto bulkGeometry = bulkElement.geometry();
229 ShapeValues shapeValues;
230 this->getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry,
circlePoints[k], shapeValues);
231 circleShapeValues.emplace_back(std::move(shapeValues));
238 if (circleStencil.empty())
242 if constexpr (isBox<bulkIdx>())
245 for (
const auto& vertices : circleCornerIndices)
247 this->couplingStencils(lowDimIdx)[lowDimElementIdx].insert(this->couplingStencils(lowDimIdx)[lowDimElementIdx].end(),
248 vertices->begin(), vertices->end());
254 this->couplingStencils(lowDimIdx)[lowDimElementIdx].insert(this->couplingStencils(lowDimIdx)[lowDimElementIdx].end(),
255 circleStencil.begin(), circleStencil.end());
259 const auto surfaceFraction = Scalar(insideCirclePoints)/Scalar(
circlePoints.size());
262 for (
auto bulkElementIdx : bulkElementIndices)
264 const auto id = this->idCounter_++;
266 this->pointSources(bulkIdx).emplace_back(globalPos,
id, qpweight, integrationElement*surfaceFraction, bulkElementIdx);
267 this->pointSources(bulkIdx).back().setEmbeddings(bulkElementIndices.size());
268 this->pointSources(lowDimIdx).emplace_back(globalPos,
id, qpweight, integrationElement*surfaceFraction, lowDimElementIdx);
269 this->pointSources(lowDimIdx).back().setEmbeddings(bulkElementIndices.size());
273 PointSourceData psData;
275 if constexpr (isBox<lowDimIdx>())
277 ShapeValues shapeValues;
278 this->getShapeValues(lowDimIdx, lowDimGridGeometry, lowDimElement.geometry(), globalPos, shapeValues);
279 psData.addLowDimInterpolation(shapeValues, this->vertexIndices(lowDimIdx, lowDimElementIdx), lowDimElementIdx);
283 psData.addLowDimInterpolation(lowDimElementIdx);
287 if constexpr (isBox<bulkIdx>())
289 psData.addCircleInterpolation(circleCornerIndices, circleShapeValues, circleIpWeight, circleStencil);
291 const auto bulkGeometry = bulkGridGeometry.element(bulkElementIdx).geometry();
292 ShapeValues shapeValues;
293 this->getShapeValues(bulkIdx, bulkGridGeometry, bulkGeometry, globalPos, shapeValues);
294 psData.addBulkInterpolation(shapeValues, this->vertexIndices(bulkIdx, bulkElementIdx), bulkElementIdx);
298 psData.addCircleInterpolation(circleIpWeight, circleStencil);
299 psData.addBulkInterpolation(bulkElementIdx);
303 this->pointSourceData().emplace_back(std::move(psData));
306 const auto outsideGeometry = bulkGridGeometry.element(bulkElementIdx).geometry();
310 if constexpr (isBox<lowDimIdx>())
312 this->couplingStencils(bulkIdx)[bulkElementIdx].insert(this->couplingStencils(bulkIdx)[bulkElementIdx].end(),
313 this->vertexIndices(lowDimIdx, lowDimElementIdx).begin(),
314 this->vertexIndices(lowDimIdx, lowDimElementIdx).end());
319 this->couplingStencils(bulkIdx)[bulkElementIdx].push_back(lowDimElementIdx);
323 if constexpr (isBox<bulkIdx>())
326 for (
const auto& vertices : circleCornerIndices)
328 extendedSourceStencil_.stencil()[bulkElementIdx].insert(extendedSourceStencil_.stencil()[bulkElementIdx].end(),
329 vertices->begin(), vertices->end());
335 extendedSourceStencil_.stencil()[bulkElementIdx].insert(extendedSourceStencil_.stencil()[bulkElementIdx].end(),
336 circleStencil.begin(), circleStencil.end());
343 for (
auto&& stencil : extendedSourceStencil_.stencil())
345 std::sort(stencil.second.begin(), stencil.second.end());
346 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
349 if constexpr (isBox<bulkIdx>())
351 const auto& indices = this->vertexIndices(bulkIdx, stencil.first);
352 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
353 [&](
auto i){ return std::find(indices.begin(), indices.end(), i) != indices.end(); }),
354 stencil.second.end());
359 stencil.second.erase(std::remove_if(stencil.second.begin(), stencil.second.end(),
360 [&](
auto i){ return i == stencil.first; }),
361 stencil.second.end());
366 using namespace Dune::Hybrid;
367 forEach(integralRange(Dune::index_constant<2>{}), [&](
const auto domainIdx)
369 for (
auto&& stencil : this->couplingStencils(domainIdx))
371 std::sort(stencil.second.begin(), stencil.second.end());
372 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
376 std::cout <<
"took " << watch.elapsed() <<
" seconds." << std::endl;
382 const typename ParentType::template CouplingStencils<bulkIdx>::mapped_type&
385 const auto& sourceStencils = extendedSourceStencil_.stencil();
386 if (
auto stencil = sourceStencils.find(eIdx); stencil != sourceStencils.end())
387 return stencil->second;
389 return this->emptyStencil(bulkIdx);
399template<
class MDTraits>
401:
public std::true_type {};
Point source traits for average-based coupling modes.
Helper function to compute points on a circle.
Manages the coupling between bulk elements and lower dimensional elements Point sources on each integ...
Definition: couplingmanager1d3d_average.hh:56
void extendJacobianPattern(Dune::index_constant< id > domainI, JacobianPattern &pattern) const
extend the jacobian pattern of the diagonal block of domain i by those entries that are not already i...
Definition: couplingmanager1d3d_average.hh:99
const ParentType::template CouplingStencils< bulkIdx >::mapped_type & extendedSourceStencil(std::size_t eIdx) const
Extended source stencil (for the bulk domain)
Definition: couplingmanager1d3d_average.hh:383
void computePointSourceData(std::size_t order=1, bool verbose=false)
Definition: couplingmanager1d3d_average.hh:130
void evalAdditionalDomainDerivatives(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, const typename LocalAssemblerI::LocalResidual::ElementResidualVector &, JacobianMatrixDiagBlock &A, GridVariables &gridVariables)
evaluate additional derivatives of the element residual of a domain with respect to dofs in the same ...
Definition: couplingmanager1d3d_average.hh:112
Manages the coupling between bulk elements and lower dimensional elements Point sources on each integ...
Definition: couplingmanager1d3dbase.hh:35
Manages the coupling between bulk elements and lower dimensional elements Point sources on each integ...
Definition: couplingmanager1d3d.hh:24
A class managing an extended source stencil.
Definition: embedded/extendedsourcestencil.hh:36
Defines all properties used in Dumux.
Coupling manager for low-dimensional domains embedded in the bulk domain.
Helper functions for distance queries.
Extended source stencil helper class for coupling managers.
void circlePoints(std::vector< GlobalPosition > &points, const std::vector< Scalar > &sincos, const GlobalPosition ¢er, const GlobalPosition &normal, const Scalar radius)
Definition: circlepoints.hh:38
Vector normal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:26
std::vector< std::size_t > intersectingEntities(const Dune::FieldVector< ctype, dimworld > &point, const BoundingBoxTree< EntitySet > &tree, bool isCartesianGrid=false)
Compute all intersections between entities and a point.
Definition: intersectingentities.hh:102
static Geometry::ctype averageDistancePointGeometry(const typename Geometry::GlobalCoordinate &p, const Geometry &geometry, std::size_t integrationOrder=2)
Compute the average distance from a point to a geometry by integration.
Definition: distance.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
constexpr Box box
Definition: method.hh:147
constexpr Average average
Definition: couplingmanager1d3d_average.hh:39
Type trait that is specialized for coupling manager supporting multithreaded assembly.
Definition: multistagemultidomainfvassembler.hh:78
Definition: couplingmanager1d3d_average.hh:35
static std::string name()
Definition: couplingmanager1d3d_average.hh:36
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26
Helper class to create (named and comparable) tagged types Tags any given type. The tagged type is eq...
Definition: tag.hh:30
Helper class to create (named and comparable) tagged types.