Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup StokesDarcyCoupling | ||
10 | * \copydoc Dumux::StokesDarcyCouplingMapper | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_STOKES_DARCY_COUPLINGMAPPER_HH | ||
14 | #define DUMUX_STOKES_DARCY_COUPLINGMAPPER_HH | ||
15 | |||
16 | #include <type_traits> | ||
17 | #include <unordered_map> | ||
18 | #include <vector> | ||
19 | |||
20 | #include <dune/common/exceptions.hh> | ||
21 | #include <dumux/discretization/method.hh> | ||
22 | |||
23 | namespace Dumux { | ||
24 | |||
25 | /*! | ||
26 | * \ingroup StokesDarcyCoupling | ||
27 | * \brief Coupling mapper for Stokes and Darcy domains with equal dimension. | ||
28 | */ | ||
29 | 68 | class StokesDarcyCouplingMapper | |
30 | { | ||
31 | struct ElementMapInfo | ||
32 | { | ||
33 | std::size_t eIdx; | ||
34 | std::size_t scvfIdx; | ||
35 | std::size_t flipScvfIdx; | ||
36 | }; | ||
37 | |||
38 | public: | ||
39 | |||
40 | /*! | ||
41 | * \brief Main update routine | ||
42 | */ | ||
43 | template<class CouplingManager, class Stencils> | ||
44 | 17 | void computeCouplingMapsAndStencils(const CouplingManager& couplingManager, | |
45 | Stencils& darcyToStokesCellCenterStencils, | ||
46 | Stencils& darcyToStokesFaceStencils, | ||
47 | Stencils& stokesCellCenterToDarcyStencils, | ||
48 | Stencils& stokesFaceToDarcyStencils) | ||
49 | { | ||
50 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
|
17 | const auto& stokesFvGridGeometry = couplingManager.problem(CouplingManager::stokesIdx).gridGeometry(); |
51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | const auto& darcyFvGridGeometry = couplingManager.problem(CouplingManager::darcyIdx).gridGeometry(); |
52 | |||
53 | static_assert(std::decay_t<decltype(stokesFvGridGeometry)>::discMethod == DiscretizationMethods::staggered, | ||
54 | "The free flow domain must use the staggered discretization"); | ||
55 | |||
56 | static_assert(std::decay_t<decltype(darcyFvGridGeometry)>::discMethod == DiscretizationMethods::cctpfa, | ||
57 | "The Darcy domain must use the CCTpfa discretization"); | ||
58 | |||
59 | 17 | isCoupledDarcyScvf_.resize(darcyFvGridGeometry.numScvf(), false); | |
60 | |||
61 | 17 | const auto& stokesGridView = stokesFvGridGeometry.gridView(); | |
62 | 17 | auto stokesFvGeometry = localView(stokesFvGridGeometry); | |
63 |
1/2✓ Branch 1 taken 71073 times.
✗ Branch 2 not taken.
|
142129 | for (const auto& stokesElement : elements(stokesGridView)) |
64 | { | ||
65 | 71056 | stokesFvGeometry.bindElement(stokesElement); | |
66 | |||
67 |
6/6✓ Branch 0 taken 284224 times.
✓ Branch 1 taken 71056 times.
✓ Branch 2 taken 284224 times.
✓ Branch 3 taken 71056 times.
✓ Branch 4 taken 3056 times.
✓ Branch 5 taken 281168 times.
|
426336 | for (const auto& scvf : scvfs(stokesFvGeometry)) |
68 | { | ||
69 | // skip the DOF if it is not on the boundary | ||
70 |
2/2✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 281168 times.
|
284224 | if (!scvf.boundary()) |
71 | 283468 | continue; | |
72 | |||
73 | // get element intersecting with the scvf center | ||
74 | // for robustness, add epsilon in unit outer normal direction | ||
75 | 12224 | const auto eps = (scvf.center() - stokesElement.geometry().center()).two_norm()*1e-8; | |
76 | 6112 | auto globalPos = scvf.center(); globalPos.axpy(eps, scvf.unitOuterNormal()); | |
77 |
0/2✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6868 | const auto darcyElementIdx = intersectingEntities(globalPos, darcyFvGridGeometry.boundingBoxTree()); |
78 | |||
79 | // skip if no intersection was found | ||
80 |
4/4✓ Branch 0 taken 2300 times.
✓ Branch 1 taken 756 times.
✓ Branch 2 taken 2300 times.
✓ Branch 3 taken 756 times.
|
6112 | if (darcyElementIdx.empty()) |
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2300 times.
|
2300 | continue; |
82 | |||
83 | // sanity check | ||
84 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 756 times.
|
1512 | if (darcyElementIdx.size() > 1) |
85 | ✗ | DUNE_THROW(Dune::InvalidStateException, "Stokes face dof should only intersect with one Darcy element"); | |
86 | |||
87 | 1512 | const auto stokesElementIdx = stokesFvGridGeometry.elementMapper().index(stokesElement); | |
88 | |||
89 | 756 | const auto darcyDofIdx = darcyElementIdx[0]; | |
90 | |||
91 |
3/6✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 756 times.
✗ Branch 8 not taken.
|
1512 | stokesFaceToDarcyStencils[scvf.dofIndex()].push_back(darcyDofIdx); |
92 |
2/4✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
|
756 | stokesCellCenterToDarcyStencils[stokesElementIdx].push_back(darcyDofIdx); |
93 | |||
94 |
3/6✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 756 times.
✗ Branch 8 not taken.
|
756 | darcyToStokesFaceStencils[darcyElementIdx[0]].push_back(scvf.dofIndex()); |
95 |
2/4✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
|
756 | darcyToStokesCellCenterStencils[darcyElementIdx[0]].push_back(stokesElementIdx); |
96 | |||
97 |
1/2✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
|
756 | const auto& darcyElement = darcyFvGridGeometry.element(darcyElementIdx[0]); |
98 |
3/8✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 756 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
3024 | const auto darcyFvGeometry = localView(darcyFvGridGeometry).bindElement(darcyElement); |
99 | |||
100 | // find the corresponding Darcy sub control volume face | ||
101 |
4/4✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 756 times.
✓ Branch 2 taken 3024 times.
✓ Branch 3 taken 756 times.
|
4536 | for (const auto& darcyScvf : scvfs(darcyFvGeometry)) |
102 | { | ||
103 | 12096 | const auto distance = (darcyScvf.center() - scvf.center()).two_norm(); | |
104 | |||
105 |
2/2✓ Branch 0 taken 756 times.
✓ Branch 1 taken 2268 times.
|
3024 | if (distance < eps) |
106 | { | ||
107 |
2/4✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
|
1512 | isCoupledDarcyScvf_[darcyScvf.index()] = true; |
108 |
2/4✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
|
756 | darcyElementToStokesElementMap_[darcyElementIdx[0]].push_back({stokesElementIdx, scvf.index(), darcyScvf.index()}); |
109 |
2/4✓ Branch 1 taken 756 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 756 times.
✗ Branch 5 not taken.
|
756 | stokesElementToDarcyElementMap_[stokesElementIdx].push_back({darcyElementIdx[0], darcyScvf.index(), scvf.index()}); |
110 | } | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | 17 | } | |
115 | |||
116 | /*! | ||
117 | * \brief Returns whether a Darcy scvf is coupled to the other domain | ||
118 | */ | ||
119 | bool isCoupledDarcyScvf(std::size_t darcyScvfIdx) const | ||
120 | { | ||
121 |
16/20✓ Branch 0 taken 80540 times.
✓ Branch 1 taken 94928 times.
✓ Branch 2 taken 80540 times.
✓ Branch 3 taken 94928 times.
✓ Branch 4 taken 94372 times.
✓ Branch 5 taken 147456 times.
✓ Branch 6 taken 94372 times.
✓ Branch 7 taken 147456 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 11760 times.
✓ Branch 13 taken 11928 times.
✓ Branch 14 taken 11760 times.
✓ Branch 15 taken 11928 times.
✓ Branch 16 taken 3080 times.
✓ Branch 17 taken 9240 times.
✓ Branch 18 taken 3080 times.
✓ Branch 19 taken 9240 times.
|
906608 | return isCoupledDarcyScvf_[darcyScvfIdx]; |
122 | } | ||
123 | |||
124 | /*! | ||
125 | * \brief A map that returns all Stokes elements coupled to a Darcy element | ||
126 | */ | ||
127 | const auto& darcyElementToStokesElementMap() const | ||
128 | { | ||
129 | 410428 | return darcyElementToStokesElementMap_; | |
130 | } | ||
131 | |||
132 | /*! | ||
133 | * \brief A map that returns all Darcy elements coupled to a Stokes element | ||
134 | */ | ||
135 | const auto& stokesElementToDarcyElementMap() const | ||
136 | { | ||
137 | 848488 | return stokesElementToDarcyElementMap_; | |
138 | } | ||
139 | |||
140 | private: | ||
141 | std::unordered_map<std::size_t, std::vector<ElementMapInfo>> darcyElementToStokesElementMap_; | ||
142 | std::unordered_map<std::size_t, std::vector<ElementMapInfo>> stokesElementToDarcyElementMap_; | ||
143 | |||
144 | std::vector<bool> isCoupledDarcyScvf_; | ||
145 | }; | ||
146 | |||
147 | } // end namespace Dumux | ||
148 | |||
149 | #endif | ||
150 |