GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/multidomain/facet/cellcentered/tpfa/couplingmapper.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 34 35 97.1%
Functions: 18 18 100.0%
Branches: 78 173 45.1%

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 FacetCoupling
10 * \copydoc Dumux::FacetCouplingMapper
11 */
12 #ifndef DUMUX_CCTPFA_FACETCOUPLING_MAPPER_HH
13 #define DUMUX_CCTPFA_FACETCOUPLING_MAPPER_HH
14
15 #include <dune/common/indices.hh>
16 #include <dune/common/float_cmp.hh>
17
18 #include <dumux/common/indextraits.hh>
19 #include <dumux/discretization/method.hh>
20 #include <dumux/multidomain/facet/couplingmapper.hh>
21 #include <dumux/multidomain/facet/couplingmapperbase.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup FacetCoupling
27 * \brief Base class for the coupling mapper that sets up and stores
28 * the coupling maps between two domains of dimension d and (d-1).
29 * This specialization is for the bulk domain using the cell-centered
30 * scheme with two-point flux approximation.
31 *
32 * \tparam BulkFVG The d-dimensional finite-volume grid geometry
33 * \tparam LowDimFVG The (d-1)-dimensional finite-volume grid geometry
34 * \tparam bulkId The index of the bulk grid within the hierarchy of grids
35 * \tparam lowDimId The index of the facet grid within the hierarchy of grids
36 */
37 template<class BulkFVG, class LowDimFVG, std::size_t bulkId, std::size_t lowDimId>
38 62 class FacetCouplingMapper<BulkFVG, LowDimFVG, bulkId, lowDimId, DiscretizationMethods::CCTpfa>
39 : public virtual FacetCouplingMapperBase<BulkFVG, LowDimFVG, bulkId, lowDimId>
40 {
41 using ParentType = FacetCouplingMapperBase<BulkFVG, LowDimFVG, bulkId, lowDimId>;
42 using LowDimElement = typename LowDimFVG::GridView::template Codim<0>::Entity;
43 using GlobalPosition = typename LowDimElement::Geometry::GlobalCoordinate;
44
45 public:
46 //! export domain ids
47 using ParentType::bulkGridId;
48 using ParentType::facetGridId;
49
50 /*!
51 * \brief Update coupling maps. This is the standard
52 * interface required by any mapper implementation.
53 *
54 * \param bulkFvGridGeometry The finite-volume grid geometry of the bulk grid
55 * \param lowDimFvGridGeometry The finite-volume grid geometry of the lower-dimensional grid
56 * \param embeddings Class that contains the embedments among the grids and entity insertion indices
57 */
58 template< class Embeddings >
59 52 void update(const BulkFVG& bulkFvGridGeometry,
60 const LowDimFVG& lowDimFvGridGeometry,
61 std::shared_ptr<const Embeddings> embeddings)
62 {
63 // define the policy how to add map entries for given lowdim element and adjoined entity indices
64 1720 auto addCouplingEntryPolicy = [&] (auto&& adjoinedEntityIndices,
65 const LowDimElement& lowDimElement,
66 const LowDimFVG& lowDimFvGridGeometry,
67 1178 const BulkFVG& bulkFvGridGeometry)
68 {
69 using LowDimIndexType = typename IndexTraits<typename LowDimFVG::GridView>::GridIndex;
70 using BulkIndexType = typename IndexTraits<typename BulkFVG::GridView>::GridIndex;
71
72 1178 const auto lowDimGeometry = lowDimElement.geometry();
73 2356 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
74 2356 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
75
76
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1244 auto fvGeometry = localView(bulkFvGridGeometry);
77 // find the scvfs in the adjoined entities coinciding with the low dim element
78 // since the bulk domain uses tpfa, there is always only going to be one scvf
79
8/8
✓ Branch 0 taken 1956 times.
✓ Branch 1 taken 962 times.
✓ Branch 2 taken 1956 times.
✓ Branch 3 taken 962 times.
✓ Branch 4 taken 432 times.
✓ Branch 5 taken 216 times.
✓ Branch 6 taken 432 times.
✓ Branch 7 taken 216 times.
8310 for (auto bulkElemIdx : adjoinedEntityIndices)
80 {
81
3/5
✓ Branch 1 taken 1860 times.
✓ Branch 2 taken 256 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 176 times.
✗ Branch 5 not taken.
4534 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
82
3/5
✓ Branch 1 taken 1860 times.
✓ Branch 2 taken 256 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 176 times.
✗ Branch 5 not taken.
2388 fvGeometry.bindElement(bulkElement);
83
84 2388 bool found = false;
85 BulkIndexType embeddedScvfIdx;
86
7/12
✓ Branch 0 taken 3270 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3270 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 452 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 912 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 608 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 608 times.
✗ Branch 11 not taken.
6570 for (const auto& scvf : scvfs(fvGeometry))
87 {
88 // for non-boundary faces, it suffices to check if one
89 // of the outside scv indices is in the set of embedments
90
3/4
✓ Branch 0 taken 3237 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 912 times.
✗ Branch 3 not taken.
4182 if (!scvf.boundary())
91 {
92 12447 if ( std::find(adjoinedEntityIndices.begin(),
93 adjoinedEntityIndices.end(),
94
8/8
✓ Branch 2 taken 1932 times.
✓ Branch 3 taken 1305 times.
✓ Branch 4 taken 1932 times.
✓ Branch 5 taken 1305 times.
✓ Branch 8 taken 432 times.
✓ Branch 9 taken 480 times.
✓ Branch 10 taken 432 times.
✓ Branch 11 taken 480 times.
8298 scvf.outsideScvIdx()) != adjoinedEntityIndices.end() )
95 {
96 2364 embeddedScvfIdx = scvf.index();
97 2364 found = true; break;
98 }
99 }
100
101 // otherwise, do float comparison of element and scvf center
102 else
103 {
104 33 const auto eps = lowDimGeometry.volume()*1e-8;
105 68 const auto diffVec = lowDimGeometry.center()-scvf.center();
106
107
2/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
66 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
108 {
109 24 embeddedScvfIdx = scvf.index();
110 24 found = true; break;
111 }
112 }
113 }
114
115 // Error tracking. The boundary scvf detection might has to be improved for very fine grids!?
116 if (!found)
117 DUNE_THROW(Dune::InvalidStateException, "Could not find coupling scvf in embedment");
118
119 // add each dof in the low dim element to coupling stencil of the bulk element
120
4/8
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1956 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 432 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 432 times.
✗ Branch 11 not taken.
4776 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
121
4/8
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1956 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 432 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 432 times.
✗ Branch 11 not taken.
7164 const auto lowDimElementDofs = LowDimFVG::discMethod == DiscretizationMethods::box
122 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
123 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
124
125
8/8
✓ Branch 0 taken 1956 times.
✓ Branch 1 taken 1956 times.
✓ Branch 2 taken 1956 times.
✓ Branch 3 taken 1956 times.
✓ Branch 4 taken 432 times.
✓ Branch 5 taken 432 times.
✓ Branch 6 taken 432 times.
✓ Branch 7 taken 432 times.
9552 for (auto dofIdx : lowDimElementDofs)
126 {
127
2/4
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 432 times.
✗ Branch 5 not taken.
2388 bulkData.couplingStencil.push_back( dofIdx );
128
4/8
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1956 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 432 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 432 times.
✗ Branch 11 not taken.
2388 bulkData.dofToCouplingScvfMap[dofIdx].push_back( embeddedScvfIdx );
129 }
130
131 // add info on which scvfs coincide with which low dim element
132
2/4
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 432 times.
✗ Branch 5 not taken.
2388 bulkData.couplingElementStencil.push_back(lowDimElemIdx);
133
4/8
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1956 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 432 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 432 times.
✗ Branch 11 not taken.
2388 bulkData.elementToScvfMap[lowDimElemIdx].push_back( embeddedScvfIdx );
134
135 // add embedment (coupling stencil will be done below)
136
12/32
✓ Branch 1 taken 1956 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1956 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1956 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1956 times.
✓ Branch 11 taken 1956 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1956 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✓ Branch 20 taken 432 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 432 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 432 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 432 times.
✓ Branch 30 taken 432 times.
✗ Branch 31 not taken.
✓ Branch 32 taken 432 times.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
4776 lowDimData.embedments.emplace_back( bulkElemIdx, std::vector<BulkIndexType>({embeddedScvfIdx}) );
137 }
138
139 // adjoint entity indices = coupling stencil for tpfa
140
2/3
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
1178 lowDimData.couplingStencil = std::move(adjoinedEntityIndices);
141 };
142
143 // let the parent do the update subject to the execution policy defined above
144
2/6
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
52 ParentType::update_(bulkFvGridGeometry, lowDimFvGridGeometry, embeddings, addCouplingEntryPolicy);
145
146 // coupling stencils might not be unique if box is used in lowdim domain
147 if (LowDimFVG::discMethod == DiscretizationMethods::box)
148 {
149 auto makeStencilUnique = [] (auto& data)
150 {
151 auto& cs = data.second.couplingStencil;
152 std::sort(cs.begin(), cs.end());
153 cs.erase( std::unique(cs.begin(), cs.end()), cs.end() );
154 };
155
156 auto& bulkCouplingData = this->couplingMap_(bulkGridId, facetGridId);
157 std::for_each(bulkCouplingData.begin(), bulkCouplingData.end(), makeStencilUnique);
158 }
159 52 }
160 };
161
162 } // end namespace Dumux
163
164 #endif
165