version 3.9
couplingmanagerbase.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_MULTIDOMAIN_EMBEDDED_COUPLINGMANAGERBASE_HH
15#define DUMUX_MULTIDOMAIN_EMBEDDED_COUPLINGMANAGERBASE_HH
16
17#include <iostream>
18#include <fstream>
19#include <string>
20#include <utility>
21#include <unordered_map>
22
23#include <dune/common/timer.hh>
24#include <dune/geometry/quadraturerules.hh>
25
26#include <dumux/io/format.hh>
39
40namespace Dumux {
41
43template<class MDTraits>
45{
46private:
47 template<std::size_t i> using SubDomainTypeTag = typename MDTraits::template SubDomain<i>::TypeTag;
48 template<std::size_t i> using GridGeometry = GetPropType<SubDomainTypeTag<i>, Properties::GridGeometry>;
49 template<std::size_t i> using NumEqVector = Dumux::NumEqVector<GetPropType<SubDomainTypeTag<i>, Properties::PrimaryVariables>>;
50public:
52 template<std::size_t i>
54
56 template<std::size_t i>
58
61};
62
68template<class MDTraits, class Implementation, class PSTraits = DefaultPointSourceTraits<MDTraits>>
70: public CouplingManager<MDTraits>
71{
73 using Scalar = typename MDTraits::Scalar;
74 static constexpr auto bulkIdx = typename MDTraits::template SubDomain<0>::Index();
75 static constexpr auto lowDimIdx = typename MDTraits::template SubDomain<1>::Index();
76 using SolutionVector = typename MDTraits::SolutionVector;
77 using PointSourceData = typename PSTraits::PointSourceData;
78
79 // the sub domain type tags
80 template<std::size_t id> using PointSource = typename PSTraits::template PointSource<id>;
81 template<std::size_t id> using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
82 template<std::size_t id> using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
83 template<std::size_t id> using PrimaryVariables = GetPropType<SubDomainTypeTag<id>, Properties::PrimaryVariables>;
84 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
85 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
86 template<std::size_t id> using ElementMapper = typename GridGeometry<id>::ElementMapper;
87 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
88 template<std::size_t id> using ElementSeed = typename GridView<id>::Grid::template Codim<0>::EntitySeed;
89 template<std::size_t id> using GridIndex = typename IndexTraits<GridView<id>>::GridIndex;
90 template<std::size_t id> using CouplingStencil = std::vector<GridIndex<id>>;
91
92 static constexpr int bulkDim = GridView<bulkIdx>::dimension;
93 static constexpr int lowDimDim = GridView<lowDimIdx>::dimension;
94 static constexpr int dimWorld = GridView<bulkIdx>::dimensionworld;
95
96 template<std::size_t id>
97 static constexpr bool isBox()
98 { return GridGeometry<id>::discMethod == DiscretizationMethods::box; }
99
100 using GlobalPosition = typename Element<bulkIdx>::Geometry::GlobalCoordinate;
101 using GlueType = MultiDomainGlue<GridView<bulkIdx>, GridView<lowDimIdx>, ElementMapper<bulkIdx>, ElementMapper<lowDimIdx>>;
102
103public:
105 using MultiDomainTraits = MDTraits;
107 using PointSourceTraits = PSTraits;
109 template<std::size_t id> using CouplingStencils = std::unordered_map<GridIndex<id>, CouplingStencil<id>>;
110
114 void updateAfterGridAdaption(std::shared_ptr<const GridGeometry<bulkIdx>> bulkGridGeometry,
115 std::shared_ptr<const GridGeometry<lowDimIdx>> lowDimGridGeometry)
116 {
117 glue_ = std::make_shared<GlueType>();
118 }
119
123 EmbeddedCouplingManagerBase(std::shared_ptr<const GridGeometry<bulkIdx>> bulkGridGeometry,
124 std::shared_ptr<const GridGeometry<lowDimIdx>> lowDimGridGeometry)
125 {
126 updateAfterGridAdaption(bulkGridGeometry, lowDimGridGeometry);
127 }
128
132 // \{
133
134 void init(std::shared_ptr<Problem<bulkIdx>> bulkProblem,
135 std::shared_ptr<Problem<lowDimIdx>> lowDimProblem,
136 const SolutionVector& curSol)
137 {
138 this->updateSolution(curSol);
139 this->setSubProblems(std::make_tuple(bulkProblem, lowDimProblem));
140
141 integrationOrder_ = getParam<int>("MixedDimension.IntegrationOrder", 1);
142 asImp_().computePointSourceData(integrationOrder_);
143 }
144
145 // \}
146
150 // \{
151
166 template<std::size_t i, std::size_t j>
167 const CouplingStencil<j>& couplingStencil(Dune::index_constant<i> domainI,
168 const Element<i>& element,
169 Dune::index_constant<j> domainJ) const
170 {
171 static_assert(i != j, "A domain cannot be coupled to itself!");
172
173 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(element);
174 if (couplingStencils(domainI).count(eIdx))
175 return couplingStencils(domainI).at(eIdx);
176 else
177 return emptyStencil(domainI);
178 }
179
192 template<std::size_t i, std::size_t j, class LocalAssemblerI>
193 decltype(auto) evalCouplingResidual(Dune::index_constant<i> domainI,
194 const LocalAssemblerI& localAssemblerI,
195 Dune::index_constant<j> domainJ,
196 std::size_t dofIdxGlobalJ)
197 {
198 static_assert(i != j, "A domain cannot be coupled to itself!");
199
200 typename LocalAssemblerI::LocalResidual::ElementResidualVector residual;
201
202 const auto& element = localAssemblerI.element();
203 const auto& fvGeometry = localAssemblerI.fvGeometry();
204 const auto& curElemVolVars = localAssemblerI.curElemVolVars();
205
206 residual.resize(fvGeometry.numScv());
207 for (const auto& scv : scvs(fvGeometry))
208 {
209 auto couplingSource = this->problem(domainI).scvPointSources(element, fvGeometry, curElemVolVars, scv);
210 couplingSource += this->problem(domainI).source(element, fvGeometry, curElemVolVars, scv);
211 couplingSource *= -GridGeometry<i>::Extrusion::volume(fvGeometry, scv)*curElemVolVars[scv].extrusionFactor();
212 residual[scv.indexInElement()] = couplingSource;
213 }
214 return residual;
215 }
216
217 // \}
218
219 /* \brief Compute integration point point sources and associated data
220 *
221 * This method uses grid glue to intersect the given grids. Over each intersection
222 * we later need to integrate a source term. This method places point sources
223 * at each quadrature point and provides the point source with the necessary
224 * information to compute integrals (quadrature weight and integration element)
225 * \param order The order of the quadrature rule for integration of sources over an intersection
226 * \param verbose If the point source computation is verbose
227 */
228 void computePointSourceData(std::size_t order = 1, bool verbose = false)
229 {
230 // initialize the maps
231 // do some logging and profiling
232 Dune::Timer watch;
233 std::cout << "Initializing the point sources..." << std::endl;
234
235 // clear all internal members like pointsource vectors and stencils
236 // initializes the point source id counter
237 clear();
238
239 // precompute the vertex indices for efficiency for the box method
240 this->precomputeVertexIndices(bulkIdx);
241 this->precomputeVertexIndices(lowDimIdx);
242
243 const auto& bulkGridGeometry = this->problem(bulkIdx).gridGeometry();
244 const auto& lowDimGridGeometry = this->problem(lowDimIdx).gridGeometry();
245
246 // intersect the bounding box trees
247 glueGrids();
248
249 pointSourceData_.reserve(this->glue().size());
250 averageDistanceToBulkCell_.reserve(this->glue().size());
251 for (const auto& is : intersections(this->glue()))
252 {
253 // all inside elements are identical...
254 const auto& inside = is.targetEntity(0);
255 // get the intersection geometry for integrating over it
256 const auto intersectionGeometry = is.geometry();
257
258 // get the Gaussian quadrature rule for the local intersection
259 const auto& quad = Dune::QuadratureRules<Scalar, lowDimDim>::rule(intersectionGeometry.type(), order);
260 const std::size_t lowDimElementIdx = lowDimGridGeometry.elementMapper().index(inside);
261
262 // iterate over all quadrature points
263 for (auto&& qp : quad)
264 {
265 // compute the coupling stencils
266 for (std::size_t outsideIdx = 0; outsideIdx < is.numDomainNeighbors(); ++outsideIdx)
267 {
268 const auto& outside = is.domainEntity(outsideIdx);
269 const std::size_t bulkElementIdx = bulkGridGeometry.elementMapper().index(outside);
270
271 // each quadrature point will be a point source for the sub problem
272 const auto globalPos = intersectionGeometry.global(qp.position());
273 const auto id = idCounter_++;
274 const auto qpweight = qp.weight();
275 const auto ie = intersectionGeometry.integrationElement(qp.position());
276 pointSources(bulkIdx).emplace_back(globalPos, id, qpweight, ie, bulkElementIdx);
277 pointSources(bulkIdx).back().setEmbeddings(is.numDomainNeighbors());
278 pointSources(lowDimIdx).emplace_back(globalPos, id, qpweight, ie, lowDimElementIdx);
279 pointSources(lowDimIdx).back().setEmbeddings(is.numDomainNeighbors());
280
281 // pre compute additional data used for the evaluation of
282 // the actual solution dependent source term
283 PointSourceData psData;
284
285 if constexpr (isBox<lowDimIdx>())
286 {
287 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
288 const auto lowDimGeometry = this->problem(lowDimIdx).gridGeometry().element(lowDimElementIdx).geometry();
289 ShapeValues shapeValues;
290 this->getShapeValues(lowDimIdx, this->problem(lowDimIdx).gridGeometry(), lowDimGeometry, globalPos, shapeValues);
291 psData.addLowDimInterpolation(shapeValues, this->vertexIndices(lowDimIdx, lowDimElementIdx), lowDimElementIdx);
292 }
293 else
294 {
295 psData.addLowDimInterpolation(lowDimElementIdx);
296 }
297
298 // add data needed to compute integral over the circle
299 if constexpr (isBox<bulkIdx>())
300 {
301 using ShapeValues = std::vector<Dune::FieldVector<Scalar, 1> >;
302 const auto bulkGeometry = this->problem(bulkIdx).gridGeometry().element(bulkElementIdx).geometry();
303 ShapeValues shapeValues;
304 this->getShapeValues(bulkIdx, this->problem(bulkIdx).gridGeometry(), bulkGeometry, globalPos, shapeValues);
305 psData.addBulkInterpolation(shapeValues, this->vertexIndices(bulkIdx, bulkElementIdx), bulkElementIdx);
306 }
307 else
308 {
309 psData.addBulkInterpolation(bulkElementIdx);
310 }
311
312 // publish point source data in the global vector
313 this->pointSourceData().emplace_back(std::move(psData));
314
315 // compute average distance to bulk cell
316 averageDistanceToBulkCell_.push_back(averageDistancePointGeometry(globalPos, outside.geometry()));
317
318 // export the lowdim coupling stencil
319 // we insert all vertices / elements and make it unique later
320 if (isBox<bulkIdx>())
321 {
322 const auto& vertices = this->vertexIndices(bulkIdx, bulkElementIdx);
323 this->couplingStencils(lowDimIdx)[lowDimElementIdx].insert(this->couplingStencils(lowDimIdx)[lowDimElementIdx].end(),
324 vertices.begin(), vertices.end());
325 }
326 else
327 {
328 this->couplingStencils(lowDimIdx)[lowDimElementIdx].push_back(bulkElementIdx);
329 }
330
331 // export the bulk coupling stencil
332 // we insert all vertices / elements and make it unique later
333 if (isBox<lowDimIdx>())
334 {
335 const auto& vertices = this->vertexIndices(lowDimIdx, lowDimElementIdx);
336 this->couplingStencils(bulkIdx)[bulkElementIdx].insert(this->couplingStencils(bulkIdx)[bulkElementIdx].end(),
337 vertices.begin(), vertices.end());
338
339 }
340 else
341 {
342 this->couplingStencils(bulkIdx)[bulkElementIdx].push_back(lowDimElementIdx);
343 }
344 }
345 }
346 }
347
348 // make stencils unique
349 using namespace Dune::Hybrid;
350 forEach(integralRange(std::integral_constant<std::size_t, MDTraits::numSubDomains>{}), [&](const auto domainIdx)
351 {
352 for (auto&& stencil : this->couplingStencils(domainIdx))
353 {
354 std::sort(stencil.second.begin(), stencil.second.end());
355 stencil.second.erase(std::unique(stencil.second.begin(), stencil.second.end()), stencil.second.end());
356 }
357 });
358
359 std::cout << "took " << watch.elapsed() << " seconds." << std::endl;
360 }
361
365 // \{
366
368 const PointSourceData& pointSourceData(std::size_t id) const
369 { return pointSourceData_[id]; }
370
372 template<std::size_t id>
373 const GridView<id>& gridView(Dune::index_constant<id> domainIdx) const
374 { return this->problem(domainIdx).gridGeometry().gridView(); }
375
377 PrimaryVariables<bulkIdx> bulkPriVars(std::size_t id) const
378 { return pointSourceData_[id].interpolateBulk(this->curSol(bulkIdx)); }
379
381 PrimaryVariables<lowDimIdx> lowDimPriVars(std::size_t id) const
382 { return pointSourceData_[id].interpolateLowDim(this->curSol(lowDimIdx)); }
383
385 Scalar averageDistance(std::size_t id) const
386 { return averageDistanceToBulkCell_[id]; }
387
389 const std::vector<PointSource<bulkIdx>>& bulkPointSources() const
390 { return std::get<bulkIdx>(pointSources_); }
391
393 const std::vector<PointSource<lowDimIdx>>& lowDimPointSources() const
394 { return std::get<lowDimIdx>(pointSources_); }
395
397 template<std::size_t i>
398 const std::vector<PointSource<i>>& pointSources(Dune::index_constant<i> dom) const
399 { return std::get<i>(pointSources_); }
400
402 template<std::size_t i>
403 const CouplingStencils<i>& couplingStencils(Dune::index_constant<i> dom) const
404 { return std::get<i>(couplingStencils_); }
405
407 const std::vector<PointSourceData>& pointSourceData() const
408 { return pointSourceData_; }
409
411 template<std::size_t i>
412 const CouplingStencil<i>& emptyStencil(Dune::index_constant<i> dom) const
413 { return std::get<i>(emptyStencil_); }
414
420 template<std::size_t i>
421 auto& curSol(Dune::index_constant<i> domainIdx)
422 { return ParentType::curSol(domainIdx); }
423
429 template<std::size_t i>
430 const auto& curSol(Dune::index_constant<i> domainIdx) const
431 { return ParentType::curSol(domainIdx); }
432
437 {
438 Dune::Timer timer;
439
440 // start with elements connected within the subdomains
441 const auto& bulkGG = asImp_().problem(bulkIdx).gridGeometry();
442 const auto& lowDimGG = asImp_().problem(lowDimIdx).gridGeometry();
443
444 auto connectedElementsBulk = Detail::computeConnectedElements(bulkGG);
445 auto connectedElementsLowDim = Detail::computeConnectedElements(lowDimGG);
446
447 // to the elements from the own domain, we have to add the extended source stencil (non-local couplings)
448 // we consider this only in the bulk domain
449 for (const auto& element : elements(bulkGG.gridView()))
450 {
451 const auto eIdx = bulkGG.elementMapper().index(element);
452 const auto& extendedSourceStencil = asImp_().extendedSourceStencil(eIdx);
453 for (auto dofIdx : extendedSourceStencil)
454 {
455 const auto& elems = connectedElementsBulk[dofIdx];
456 if (std::find(elems.begin(), elems.end(), eIdx) == elems.end())
457 connectedElementsBulk[dofIdx].push_back(eIdx);
458 }
459 }
460
461 // then we also need a similar container that tells us
462 // which elements _from the other domain_ modify our dofs.
463 // That, we can obtain via the coupling stencils
464 std::array<std::vector<std::vector<std::size_t>>, 2> connectedElementsCoupling;
465
466 using namespace Dune::Hybrid;
467 forEach(integralRange(Dune::index_constant<MDTraits::numSubDomains>{}), [&](const auto i)
468 {
469 connectedElementsCoupling[i()].resize(asImp_().problem(i).gridGeometry().numDofs());
470 forEach(integralRange(Dune::index_constant<MDTraits::numSubDomains>{}), [&](const auto j)
471 {
472 if constexpr (i != j)
473 {
474 for (const auto& element : elements(asImp_().problem(j).gridGeometry().gridView()))
475 {
476 const auto eIdx = asImp_().problem(j).gridGeometry().elementMapper().index(element);
477 for (auto dofIdx : asImp_().couplingStencil(j, element, i))
478 {
479 const auto& elems = connectedElementsCoupling[i()][dofIdx];
480 if (std::find(elems.begin(), elems.end(), eIdx) == elems.end())
481 connectedElementsCoupling[i()][dofIdx].push_back(eIdx);
482 }
483 }
484 }
485 });
486 });
487
488 forEach(integralRange(Dune::index_constant<MDTraits::numSubDomains>{}), [&](const auto i)
489 {
490 const auto& gg = asImp_().problem(i).gridGeometry();
491
492 std::vector<int> colors(gg.gridView().size(0), -1);
493
494 // pre-reserve some memory for helper arrays to avoid reallocation
495 std::vector<int> neighborColors; neighborColors.reserve(200);
496 std::vector<bool> colorUsed; colorUsed.reserve(200);
497
498 auto& elementSets = std::get<i>(elementSets_);
499 const auto& connectedElements = std::get<i>(std::tie(connectedElementsBulk, connectedElementsLowDim));
500
501 for (const auto& element : elements(gg.gridView()))
502 {
503 // compute neighbor colors based on discretization-dependent stencil
504 neighborColors.clear();
505 Detail::addNeighborColors(gg, element, colors, connectedElements, neighborColors);
506
507 if constexpr (i == bulkIdx)
508 {
509 // make sure we also add all elements in the extended source stencil
510 // Detail::addNeighborColors only adds direct neighbors
511 // add everyone that also modifies the extended source stencil dofs
512 const auto eIdx = bulkGG.elementMapper().index(element);
513 const auto& extendedSourceStencil = asImp_().extendedSourceStencil(eIdx);
514 for (auto dofIdx : extendedSourceStencil)
515 for (const auto nIdx : connectedElementsBulk[dofIdx])
516 neighborColors.push_back(colors[nIdx]);
517 }
518
519 // add neighbor colors based on coupling stencil
520 forEach(integralRange(Dune::index_constant<MDTraits::numSubDomains>{}), [&](const auto j)
521 {
522 if constexpr (i != j)
523 {
524 // add all elements that manipulate the same coupled dofs
525 for (auto dofIdx : asImp_().couplingStencil(i, element, j))
526 for (auto eIdx : connectedElementsCoupling[j][dofIdx])
527 neighborColors.push_back(colors[eIdx]);
528 }
529 });
530
531 // find smallest color (positive integer) not in neighborColors
532 const auto color = Detail::smallestAvailableColor(neighborColors, colorUsed);
533
534 // assign color to element
535 colors[gg.elementMapper().index(element)] = color;
536
537 // add element to the set of elements with the same color
538 if (color < elementSets.size())
539 elementSets[color].push_back(element.seed());
540 else
541 elementSets.push_back(std::vector<ElementSeed<i>>{ element.seed() });
542 }
543 });
544
545 std::cout << Fmt::format("Colored in {} seconds:\n", timer.elapsed());
546 forEach(integralRange(Dune::index_constant<MDTraits::numSubDomains>{}), [&](const auto i)
547 {
548 std::cout << Fmt::format(
549 "-- {} elements in subdomain {} with {} colors\n",
550 asImp_().problem(i).gridGeometry().gridView().size(0),
551 i(), std::get<i>(elementSets_).size()
552 );
553 });
554 }
555
562 template<std::size_t i, class AssembleElementFunc>
563 void assembleMultithreaded(Dune::index_constant<i> domainId, AssembleElementFunc&& assembleElement) const
564 {
565 if (std::get<i>(elementSets_).empty())
566 DUNE_THROW(Dune::InvalidStateException, "Call computeColorsForAssembly before assembling in parallel!");
567
568 // make this element loop run in parallel
569 // for this we have to color the elements so that we don't get
570 // race conditions when writing into the global matrix or modifying grid variable caches
571 // each color can be assembled using multiple threads
572 const auto& grid = this->problem(domainId).gridGeometry().gridView().grid();
573 for (const auto& elements : std::get<i>(elementSets_))
574 {
575 Dumux::parallelFor(elements.size(), [&](const std::size_t n)
576 {
577 const auto element = grid.entity(elements[n]);
578 assembleElement(element);
579 });
580 }
581 }
582
588 const CouplingStencil<bulkIdx>& extendedSourceStencil(std::size_t eIdx) const
589 { return asImp_().emptyStencil(bulkIdx); }
590
591protected:
592 using ParentType::curSol;
593
595 template<std::size_t id>
596 void precomputeVertexIndices(Dune::index_constant<id> domainIdx)
597 {
598 // fill helper structure for box discretization
599 if constexpr (isBox<domainIdx>())
600 {
601 this->vertexIndices(domainIdx).resize(gridView(domainIdx).size(0));
602 for (const auto& element : elements(gridView(domainIdx)))
603 {
604 constexpr int dim = GridView<domainIdx>::dimension;
605 const auto eIdx = this->problem(domainIdx).gridGeometry().elementMapper().index(element);
606 this->vertexIndices(domainIdx, eIdx).resize(element.subEntities(dim));
607 for (int i = 0; i < element.subEntities(dim); ++i)
608 this->vertexIndices(domainIdx, eIdx)[i] = this->problem(domainIdx).gridGeometry().vertexMapper().subIndex(element, i, dim);
609 }
610 }
611 }
612
614 template<std::size_t i, class FVGG, class Geometry, class ShapeValues>
615 void getShapeValues(Dune::index_constant<i> domainI, const FVGG& gridGeometry, const Geometry& geo, const GlobalPosition& globalPos, ShapeValues& shapeValues)
616 {
617 if constexpr (FVGG::discMethod == DiscretizationMethods::box)
618 {
619 const auto ipLocal = geo.local(globalPos);
620 const auto& localBasis = this->problem(domainI).gridGeometry().feCache().get(geo.type()).localBasis();
621 localBasis.evaluateFunction(ipLocal, shapeValues);
622 }
623 else
624 DUNE_THROW(Dune::InvalidStateException, "Shape values requested for other discretization than box!");
625 }
626
628 void clear()
629 {
630 pointSources(bulkIdx).clear();
631 pointSources(lowDimIdx).clear();
632 couplingStencils(bulkIdx).clear();
633 couplingStencils(lowDimIdx).clear();
634 vertexIndices(bulkIdx).clear();
635 vertexIndices(lowDimIdx).clear();
636 pointSourceData_.clear();
637 averageDistanceToBulkCell_.clear();
638
639 idCounter_ = 0;
640 }
641
644 {
645 const auto& bulkGridGeometry = this->problem(bulkIdx).gridGeometry();
646 const auto& lowDimGridGeometry = this->problem(lowDimIdx).gridGeometry();
647
648 // intersect the bounding box trees
649 glue_->build(bulkGridGeometry.boundingBoxTree(), lowDimGridGeometry.boundingBoxTree());
650 }
651
653 std::vector<PointSourceData>& pointSourceData()
654 { return pointSourceData_; }
655
657 std::vector<Scalar>& averageDistanceToBulkCell()
658 { return averageDistanceToBulkCell_; }
659
661 template<std::size_t i>
662 std::vector<PointSource<i>>& pointSources(Dune::index_constant<i> dom)
663 { return std::get<i>(pointSources_); }
664
666 template<std::size_t i>
667 CouplingStencils<i>& couplingStencils(Dune::index_constant<i> dom)
668 { return std::get<i>(couplingStencils_); }
669
671 template<std::size_t i>
672 std::vector<GridIndex<i>>& vertexIndices(Dune::index_constant<i> dom, GridIndex<i> eIdx)
673 { return std::get<i>(vertexIndices_)[eIdx]; }
674
676 template<std::size_t i>
677 std::vector<std::vector<GridIndex<i>>>& vertexIndices(Dune::index_constant<i> dom)
678 { return std::get<i>(vertexIndices_); }
679
680 const GlueType& glue() const
681 { return *glue_; }
682
684 Implementation &asImp_()
685 { return *static_cast<Implementation *>(this); }
686
688 const Implementation &asImp_() const
689 { return *static_cast<const Implementation *>(this); }
690
692 std::size_t idCounter_ = 0;
693
694private:
695
697 std::tuple<std::vector<PointSource<bulkIdx>>, std::vector<PointSource<lowDimIdx>>> pointSources_;
698 std::vector<PointSourceData> pointSourceData_;
699 std::vector<Scalar> averageDistanceToBulkCell_;
700
702 std::tuple<std::vector<std::vector<GridIndex<bulkIdx>>>,
703 std::vector<std::vector<GridIndex<lowDimIdx>>>> vertexIndices_;
704 std::tuple<CouplingStencils<bulkIdx>, CouplingStencils<lowDimIdx>> couplingStencils_;
705 std::tuple<CouplingStencil<bulkIdx>, CouplingStencil<lowDimIdx>> emptyStencil_;
706
708 std::shared_ptr<GlueType> glue_;
709
711 int integrationOrder_ = 1;
712
714 std::tuple<
715 std::deque<std::vector<ElementSeed<bulkIdx>>>,
716 std::deque<std::vector<ElementSeed<lowDimIdx>>>
717 > elementSets_;
718};
719
720} // end namespace Dumux
721
722#endif
The interface of the coupling manager for multi domain problems.
Definition: multidomain/couplingmanager.hh:48
void setSubProblems(const std::tuple< std::shared_ptr< SubProblems >... > &problems)
set the pointers to the sub problems
Definition: multidomain/couplingmanager.hh:287
const Problem< i > & problem(Dune::index_constant< i > domainIdx) const
Return a reference to the sub problem.
Definition: multidomain/couplingmanager.hh:309
SubSolutionVector< i > & curSol(Dune::index_constant< i > domainIdx)
the solution vector of the subproblem
Definition: multidomain/couplingmanager.hh:338
void updateSolution(const SolutionVector &curSol)
Updates the entire solution vector, e.g. before assembly or after grid adaption Overload might want t...
Definition: multidomain/couplingmanager.hh:219
Manages the coupling between bulk elements and lower dimensional elements Point sources on each integ...
Definition: couplingmanagerbase.hh:71
std::vector< GridIndex< i > > & vertexIndices(Dune::index_constant< i > dom, GridIndex< i > eIdx)
Return a reference to the vertex indices.
Definition: couplingmanagerbase.hh:672
Scalar averageDistance(std::size_t id) const
return the average distance to the coupled bulk cell center
Definition: couplingmanagerbase.hh:385
Implementation & asImp_()
Returns the implementation of the problem (i.e. static polymorphism)
Definition: couplingmanagerbase.hh:684
const std::vector< PointSource< i > > & pointSources(Dune::index_constant< i > dom) const
Return the point source if domain i.
Definition: couplingmanagerbase.hh:398
const CouplingStencil< bulkIdx > & extendedSourceStencil(std::size_t eIdx) const
Extended source stencil (for the bulk domain)
Definition: couplingmanagerbase.hh:588
PSTraits PointSourceTraits
export the point source traits
Definition: couplingmanagerbase.hh:107
EmbeddedCouplingManagerBase(std::shared_ptr< const GridGeometry< bulkIdx > > bulkGridGeometry, std::shared_ptr< const GridGeometry< lowDimIdx > > lowDimGridGeometry)
Constructor.
Definition: couplingmanagerbase.hh:123
const CouplingStencils< i > & couplingStencils(Dune::index_constant< i > dom) const
Return reference to bulk coupling stencil member of domain i.
Definition: couplingmanagerbase.hh:403
void updateAfterGridAdaption(std::shared_ptr< const GridGeometry< bulkIdx > > bulkGridGeometry, std::shared_ptr< const GridGeometry< lowDimIdx > > lowDimGridGeometry)
call this after grid adaption
Definition: couplingmanagerbase.hh:114
const GridView< id > & gridView(Dune::index_constant< id > domainIdx) const
Return a reference to the bulk problem.
Definition: couplingmanagerbase.hh:373
const Implementation & asImp_() const
Returns the implementation of the problem (i.e. static polymorphism)
Definition: couplingmanagerbase.hh:688
std::vector< Scalar > & averageDistanceToBulkCell()
Return reference to average distances to bulk cell.
Definition: couplingmanagerbase.hh:657
const auto & curSol(Dune::index_constant< i > domainIdx) const
the solution vector of the subproblem
Definition: couplingmanagerbase.hh:430
const CouplingStencil< i > & emptyStencil(Dune::index_constant< i > dom) const
Return a reference to an empty stencil.
Definition: couplingmanagerbase.hh:412
const std::vector< PointSource< bulkIdx > > & bulkPointSources() const
Return reference to bulk point sources.
Definition: couplingmanagerbase.hh:389
auto & curSol(Dune::index_constant< i > domainIdx)
the solution vector of the subproblem
Definition: couplingmanagerbase.hh:421
const PointSourceData & pointSourceData(std::size_t id) const
Methods to be accessed by the subproblems.
Definition: couplingmanagerbase.hh:368
std::vector< std::vector< GridIndex< i > > > & vertexIndices(Dune::index_constant< i > dom)
Return a reference to the vertex indices container.
Definition: couplingmanagerbase.hh:677
void glueGrids()
compute the intersections between the two grids
Definition: couplingmanagerbase.hh:643
MDTraits MultiDomainTraits
export traits
Definition: couplingmanagerbase.hh:105
void computePointSourceData(std::size_t order=1, bool verbose=false)
Definition: couplingmanagerbase.hh:228
std::vector< PointSourceData > & pointSourceData()
Return reference to point source data vector member.
Definition: couplingmanagerbase.hh:653
const CouplingStencil< j > & couplingStencil(Dune::index_constant< i > domainI, const Element< i > &element, Dune::index_constant< j > domainJ) const
Methods to be accessed by the assembly.
Definition: couplingmanagerbase.hh:167
PrimaryVariables< lowDimIdx > lowDimPriVars(std::size_t id) const
Return data for a low dim point source with the identifier id.
Definition: couplingmanagerbase.hh:381
void getShapeValues(Dune::index_constant< i > domainI, const FVGG &gridGeometry, const Geometry &geo, const GlobalPosition &globalPos, ShapeValues &shapeValues)
compute the shape function for a given point and geometry
Definition: couplingmanagerbase.hh:615
const std::vector< PointSource< lowDimIdx > > & lowDimPointSources() const
Return reference to low dim point sources.
Definition: couplingmanagerbase.hh:393
void assembleMultithreaded(Dune::index_constant< i > domainId, AssembleElementFunc &&assembleElement) const
Execute assembly kernel in parallel.
Definition: couplingmanagerbase.hh:563
void clear()
Clear all internal data members.
Definition: couplingmanagerbase.hh:628
void computeColorsForAssembly()
Compute colors for multithreaded assembly.
Definition: couplingmanagerbase.hh:436
const GlueType & glue() const
Definition: couplingmanagerbase.hh:680
decltype(auto) evalCouplingResidual(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ)
evaluates the element residual of a coupled element of domain i which depends on the variables at the...
Definition: couplingmanagerbase.hh:193
void init(std::shared_ptr< Problem< bulkIdx > > bulkProblem, std::shared_ptr< Problem< lowDimIdx > > lowDimProblem, const SolutionVector &curSol)
Methods to be accessed by main.
Definition: couplingmanagerbase.hh:134
CouplingStencils< i > & couplingStencils(Dune::index_constant< i > dom)
Return reference to bulk coupling stencil member of domain i.
Definition: couplingmanagerbase.hh:667
std::vector< PointSource< i > > & pointSources(Dune::index_constant< i > dom)
Return the point source if domain i.
Definition: couplingmanagerbase.hh:662
std::unordered_map< GridIndex< id >, CouplingStencil< id > > CouplingStencils
export stencil types
Definition: couplingmanagerbase.hh:109
PrimaryVariables< bulkIdx > bulkPriVars(std::size_t id) const
Return data for a bulk point source with the identifier id.
Definition: couplingmanagerbase.hh:377
void precomputeVertexIndices(Dune::index_constant< id > domainIdx)
computes the vertex indices per element for the box method
Definition: couplingmanagerbase.hh:596
std::size_t idCounter_
id generator for point sources
Definition: couplingmanagerbase.hh:692
const std::vector< PointSourceData > & pointSourceData() const
Return reference to point source data vector member.
Definition: couplingmanagerbase.hh:407
A helper class calculating a DOF-index to point source map.
Definition: integrationpointsource.hh:100
An integration point source class with an identifier to attach data and a quadrature weight and integ...
Definition: integrationpointsource.hh:33
A class representing the intersection entities two geometric entity sets.
Definition: intersectionentityset.hh:43
A point source data class used for integration in multidimensional models.
Definition: pointsourcedata.hh:31
Coloring schemes for shared-memory-parallel assembly.
Defines all properties used in Dumux.
Helper functions for distance queries.
Formatting based on the fmt-library which implements std::format of C++20.
A class glueing two grids of potentially different dimension geometrically. Intersections are compute...
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition: numeqvector.hh:34
auto volume(const Geometry &geo, unsigned int integrationOrder=4)
The volume of a given geometry.
Definition: volume.hh:159
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
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:160
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
An integration point source class, i.e. sources located at a single point in space associated with a ...
Algorithms that finds which geometric entities intersect.
The available discretization methods in Dumux.
The interface of the coupling manager for multi domain problems.
A linear system assembler (residual and Jacobian) for finite volume schemes with multiple domains.
constexpr Box box
Definition: method.hh:147
Definition: adapt.hh:17
A helper to deduce a vector with the same size as numbers of equations.
Parallel for loop (multithreading)
Data associated with a point source.
the default point source traits
Definition: couplingmanagerbase.hh:45
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26