version 3.10-dev
facet/cellcentered/tpfa/couplingmapper.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//
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
22
23namespace Dumux {
24
37template<class BulkFVG, class LowDimFVG, std::size_t bulkId, std::size_t lowDimId>
38class FacetCouplingMapper<BulkFVG, LowDimFVG, bulkId, lowDimId, DiscretizationMethods::CCTpfa>
39: public virtual FacetCouplingMapperBase<BulkFVG, LowDimFVG, bulkId, lowDimId>
40{
42 using LowDimElement = typename LowDimFVG::GridView::template Codim<0>::Entity;
43 using GlobalPosition = typename LowDimElement::Geometry::GlobalCoordinate;
44
45public:
47 using ParentType::bulkGridId;
48 using ParentType::facetGridId;
49
58 template< class Embeddings >
59 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 auto addCouplingEntryPolicy = [&] (auto&& adjoinedEntityIndices,
65 const LowDimElement& lowDimElement,
66 const LowDimFVG& lowDimFvGridGeometry,
67 const BulkFVG& bulkFvGridGeometry)
68 {
69 using LowDimIndexType = typename IndexTraits<typename LowDimFVG::GridView>::GridIndex;
70 using BulkIndexType = typename IndexTraits<typename BulkFVG::GridView>::GridIndex;
71
72 const auto lowDimGeometry = lowDimElement.geometry();
73 const auto lowDimElemIdx = lowDimFvGridGeometry.elementMapper().index(lowDimElement);
74 auto& lowDimData = this->couplingMap_(facetGridId, bulkGridId)[lowDimElemIdx];
75
76 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 for (auto bulkElemIdx : adjoinedEntityIndices)
80 {
81 const auto bulkElement = bulkFvGridGeometry.element(bulkElemIdx);
82 fvGeometry.bindElement(bulkElement);
83
84 bool found = false;
85 BulkIndexType embeddedScvfIdx;
86 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 if (!scvf.boundary())
91 {
92 if ( std::find(adjoinedEntityIndices.begin(),
93 adjoinedEntityIndices.end(),
94 scvf.outsideScvIdx()) != adjoinedEntityIndices.end() )
95 {
96 embeddedScvfIdx = scvf.index();
97 found = true; break;
98 }
99 }
100
101 // otherwise, do float comparison of element and scvf center
102 else
103 {
104 const auto eps = lowDimGeometry.volume()*1e-8;
105 const auto diffVec = lowDimGeometry.center()-scvf.center();
106
107 if ( Dune::FloatCmp::eq<GlobalPosition, Dune::FloatCmp::CmpStyle::absolute>(diffVec, GlobalPosition(0.0), eps) )
108 {
109 embeddedScvfIdx = scvf.index();
110 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 auto& bulkData = this->couplingMap_(bulkGridId, facetGridId)[bulkElemIdx];
121 const auto lowDimElementDofs = LowDimFVG::discMethod == DiscretizationMethods::box
122 ? this->extractNodalDofs_(lowDimElement, lowDimFvGridGeometry)
123 : std::vector<LowDimIndexType>( {lowDimElemIdx} );
124
125 for (auto dofIdx : lowDimElementDofs)
126 {
127 bulkData.couplingStencil.push_back( dofIdx );
128 bulkData.dofToCouplingScvfMap[dofIdx].push_back( embeddedScvfIdx );
129 }
130
131 // add info on which scvfs coincide with which low dim element
132 bulkData.couplingElementStencil.push_back(lowDimElemIdx);
133 bulkData.elementToScvfMap[lowDimElemIdx].push_back( embeddedScvfIdx );
134
135 // add embedment (coupling stencil will be done below)
136 lowDimData.embedments.emplace_back( bulkElemIdx, std::vector<BulkIndexType>({embeddedScvfIdx}) );
137 }
138
139 // adjoint entity indices = coupling stencil for tpfa
140 lowDimData.couplingStencil = std::move(adjoinedEntityIndices);
141 };
142
143 // let the parent do the update subject to the execution policy defined above
144 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 }
160};
161
162} // end namespace Dumux
163
164#endif
void update(const BulkFVG &bulkFvGridGeometry, const LowDimFVG &lowDimFvGridGeometry, std::shared_ptr< const Embeddings > embeddings)
Update coupling maps. This is the standard interface required by any mapper implementation.
Definition: facet/cellcentered/tpfa/couplingmapper.hh:59
Base class for the coupling mapper that sets up and stores the coupling maps between two domains of d...
Definition: couplingmapperbase.hh:41
Implementation for the coupling mapper that sets up and stores the coupling maps between two domains ...
Definition: facet/couplingmapper.hh:42
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
constexpr Box box
Definition: method.hh:147
Definition: adapt.hh:17
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:27