version 3.8
ffmasspm/couplingmanager_staggered_cctpfa.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//
13#ifndef DUMUX_MULTIDOMAIN_BOUNDARY_FFPM_FFMASSPM_COUPLINGMANAGER_STAGGERED_TPFA_HH
14#define DUMUX_MULTIDOMAIN_BOUNDARY_FFPM_FFMASSPM_COUPLINGMANAGER_STAGGERED_TPFA_HH
15
16#include <utility>
17#include <memory>
18
19#include <dune/common/float_cmp.hh>
20#include <dune/common/exceptions.hh>
25
26namespace Dumux {
27
33template<class MDTraits>
35: public CouplingManager<MDTraits>
36{
37 using Scalar = typename MDTraits::Scalar;
39
40public:
41 static constexpr auto freeFlowMassIndex = typename MDTraits::template SubDomain<0>::Index();
42 static constexpr auto porousMediumIndex = typename MDTraits::template SubDomain<1>::Index();
43
45private:
46
47 // obtain the type tags of the sub problems
48 using FreeFlowMassTypeTag = typename MDTraits::template SubDomain<freeFlowMassIndex>::TypeTag;
49 using PorousMediumTypeTag = typename MDTraits::template SubDomain<porousMediumIndex>::TypeTag;
50
51 using CouplingStencils = std::unordered_map<std::size_t, std::vector<std::size_t> >;
52 using CouplingStencil = CouplingStencils::mapped_type;
53
54 // the sub domain type tags
55 template<std::size_t id>
56 using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
57
58 template<std::size_t id> using GridView = typename GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>::GridView;
59 template<std::size_t id> using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
60 template<std::size_t id> using ElementVolumeVariables = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>::LocalView;
61 template<std::size_t id> using GridVolumeVariables = GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>;
62 template<std::size_t id> using VolumeVariables = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>::VolumeVariables;
63 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
64 template<std::size_t id> using FVElementGeometry = typename GridGeometry<id>::LocalView;
65 template<std::size_t id> using GridVariables = GetPropType<SubDomainTypeTag<id>, Properties::GridVariables>;
66 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
67 template<std::size_t id> using PrimaryVariables = GetPropType<SubDomainTypeTag<id>, Properties::PrimaryVariables>;
68 template<std::size_t id> using SubControlVolumeFace = typename FVElementGeometry<id>::SubControlVolumeFace;
69 template<std::size_t id> using SubControlVolume = typename FVElementGeometry<id>::SubControlVolume;
70
71 using VelocityVector = typename Element<freeFlowMassIndex>::Geometry::GlobalCoordinate;
72
73 struct FreeFlowMassCouplingContext
74 {
75 Element<porousMediumIndex> element;
76 VolumeVariables<porousMediumIndex> volVars;
77 FVElementGeometry<porousMediumIndex> fvGeometry;
78 std::size_t dofIdx;
79 std::size_t freeFlowMassScvfIdx;
80 std::size_t porousMediumScvfIdx;
81 mutable VelocityVector velocity; // velocity needs to be set externally, not available in this class
82 };
83
84 struct PorousMediumCouplingContext
85 {
86 Element<freeFlowMassIndex> element;
87 VolumeVariables<freeFlowMassIndex> volVars;
88 FVElementGeometry<freeFlowMassIndex> fvGeometry;
89 std::size_t dofIdx;
90 std::size_t porousMediumScvfIdx;
91 std::size_t freeFlowMassScvfIdx;
92 mutable VelocityVector velocity; // velocity needs to be set externally, not available in this class
93 };
94
95 using CouplingMapper = DarcyDarcyBoundaryCouplingMapper<MDTraits>; // TODO rename/generalize class
96
97public:
98
102 // \{
103
105 void init(std::shared_ptr<Problem<freeFlowMassIndex>> freeFlowMassProblem,
106 std::shared_ptr<Problem<porousMediumIndex>> darcyProblem,
108 {
109 this->setSubProblems(std::make_tuple(freeFlowMassProblem, darcyProblem));
110 this->attachSolution(curSol);
111
112 couplingMapper_.update(*this);
113 }
114
115 // \}
116
120 // \{
121
125 template<std::size_t i, class Assembler>
126 void bindCouplingContext(Dune::index_constant<i> domainI, const Element<i>& element, const Assembler& assembler) const
127 {
128 bindCouplingContext_(domainI, element);
129 }
130
134 template<std::size_t i, std::size_t j, class LocalAssemblerI>
135 void updateCouplingContext(Dune::index_constant<i> domainI,
136 const LocalAssemblerI& localAssemblerI,
137 Dune::index_constant<j> domainJ,
138 std::size_t dofIdxGlobalJ,
139 const PrimaryVariables<j>& priVarsJ,
140 int pvIdxJ)
141 {
142 this->curSol(domainJ)[dofIdxGlobalJ][pvIdxJ] = priVarsJ[pvIdxJ];
143
144 // we need to update all solution-depenent components of the coupling context
145 // the dof of domain J has been deflected
146 // if domainJ == freeFlowMassIndex: update volvars in the PorousMediumCouplingContext
147 // if domainJ == porousMediumIndex: update volvars in the FreeFlowMassCouplingContext
148 // as the update is symmetric we only need to write this once
149 auto& context = std::get<1-j>(couplingContext_);
150 for (auto& c : context)
151 {
152 if (c.dofIdx == dofIdxGlobalJ)
153 {
154 const auto elemSol = elementSolution(c.element, this->curSol(domainJ), this->problem(domainJ).gridGeometry());
155 const auto& scv = *scvs(c.fvGeometry).begin();
156 c.volVars.update(elemSol, this->problem(domainJ), c.element, scv);
157 }
158 }
159 }
160
161 // \}
162
166 template<std::size_t i>
167 const auto& couplingContext(Dune::index_constant<i> domainI,
168 const FVElementGeometry<i>& fvGeometry,
169 const SubControlVolumeFace<i> scvf) const
170 {
171 auto& contexts = std::get<i>(couplingContext_);
172
173 if (contexts.empty() || couplingContextBoundForElement_[i] != scvf.insideScvIdx())
174 bindCouplingContext_(domainI, fvGeometry);
175
176 for (const auto& context : contexts)
177 {
178 const auto expectedScvfIdx = domainI == freeFlowMassIndex ? context.freeFlowMassScvfIdx : context.porousMediumScvfIdx;
179 if (scvf.index() == expectedScvfIdx)
180 return context;
181 }
182
183 DUNE_THROW(Dune::InvalidStateException, "No coupling context found at scvf " << scvf.center());
184 }
185
189 // \{
190
194 template<std::size_t i, std::size_t j>
195 const CouplingStencil& couplingStencil(Dune::index_constant<i> domainI,
196 const Element<i>& element,
197 Dune::index_constant<j> domainJ) const
198 {
199 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(element);
200 return couplingMapper_.couplingStencil(domainI, eIdx, domainJ);
201 }
202
203 // \}
204
208 template<std::size_t i>
209 bool isCoupled(Dune::index_constant<i> domainI, const SubControlVolumeFace<i>& scvf) const
210 { return couplingMapper_.isCoupled(domainI, scvf); }
211
212private:
216 template<std::size_t i>
217 bool isCoupledElement_(Dune::index_constant<i> domainI, std::size_t eIdx) const
218 { return couplingMapper_.isCoupledElement(domainI, eIdx); }
219
221 template<std::size_t i>
222 VolumeVariables<i> volVars_(Dune::index_constant<i> domainI,
223 const Element<i>& element,
224 const SubControlVolume<i>& scv) const
225 {
226 VolumeVariables<i> volVars;
227 const auto elemSol = elementSolution(
228 element, this->curSol(domainI), this->problem(domainI).gridGeometry()
229 );
230 volVars.update(elemSol, this->problem(domainI), element, scv);
231 return volVars;
232 }
233
237 template<std::size_t i>
238 void bindCouplingContext_(Dune::index_constant<i> domainI, const Element<i>& element) const
239 {
240 const auto fvGeometry = localView(this->problem(domainI).gridGeometry()).bindElement(element);
241 bindCouplingContext_(domainI, fvGeometry);
242 }
243
247 template<std::size_t i>
248 void bindCouplingContext_(Dune::index_constant<i> domainI, const FVElementGeometry<i>& fvGeometry) const
249 {
250 auto& context = std::get<domainI>(couplingContext_);
251 context.clear();
252
253 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(fvGeometry.element());
254
255 // do nothing if the element is not coupled to the other domain
256 if (!isCoupledElement_(domainI, eIdx))
257 return;
258
259 couplingContextBoundForElement_[domainI] = eIdx;
260
261 for (const auto& scvf : scvfs(fvGeometry))
262 {
263 if (isCoupled(domainI, scvf))
264 {
265 const auto otherElementIdx = couplingMapper_.outsideElementIndex(domainI, scvf);
266 constexpr auto domainJ = Dune::index_constant<1-domainI>();
267 const auto& otherGridGeometry = this->problem(domainJ).gridGeometry();
268 const auto& otherElement = otherGridGeometry.element(otherElementIdx);
269 auto otherFvGeometry = localView(otherGridGeometry).bindElement(otherElement);
270
271 // there is only one scv for TPFA
272 context.push_back({
273 otherElement,
274 volVars_(domainJ, otherElement, *std::begin(scvs(otherFvGeometry))),
275 std::move(otherFvGeometry),
276 otherElementIdx,
277 scvf.index(),
278 couplingMapper_.flipScvfIndex(domainI, scvf),
279 VelocityVector{}
280 });
281 }
282 }
283 }
284
285 mutable std::tuple<std::vector<FreeFlowMassCouplingContext>, std::vector<PorousMediumCouplingContext>> couplingContext_;
286 mutable std::array<std::size_t, 2> couplingContextBoundForElement_;
287
288 CouplingMapper couplingMapper_;
289};
290
291} // end namespace Dumux
292
293#endif
The interface of the coupling manager for multi domain problems.
Definition: multidomain/couplingmanager.hh:48
void attachSolution(SolutionVectorStorage &curSol)
Attach a solution vector stored outside of this class.
Definition: multidomain/couplingmanager.hh:322
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
typename Traits::template TupleOfSharedPtr< SubSolutionVector > SolutionVectorStorage
the type in which the solution vector is stored in the manager
Definition: multidomain/couplingmanager.hh:71
bool isCoupledElement(Dune::index_constant< i >, std::size_t eIdx) const
Return if an element residual with index eIdx of domain i is coupled to domain j.
Definition: boundary/darcydarcy/couplingmapper.hh:178
void update(const CouplingManager &couplingManager)
Main update routine.
Definition: boundary/darcydarcy/couplingmapper.hh:69
const std::vector< std::size_t > & couplingStencil(Dune::index_constant< i > domainI, const std::size_t eIdxI, Dune::index_constant< j > domainJ) const
returns an iterable container of all indices of degrees of freedom of domain j that couple with / inf...
Definition: boundary/darcydarcy/couplingmapper.hh:163
std::size_t outsideElementIndex(Dune::index_constant< i > domainI, const SubControlVolumeFace< i > &scvf) const
Return the outside element index (the element index of the other domain)
Definition: boundary/darcydarcy/couplingmapper.hh:211
bool isCoupled(Dune::index_constant< i > domainI, const SubControlVolumeFace< i > &scvf) const
If the boundary entity is on a coupling boundary.
Definition: boundary/darcydarcy/couplingmapper.hh:187
std::size_t flipScvfIndex(Dune::index_constant< i > domainI, const SubControlVolumeFace< i > &scvf) const
Return the scvf index of the flipped scvf in the other domain.
Definition: boundary/darcydarcy/couplingmapper.hh:199
Coupling manager for Stokes and Darcy domains with equal dimension. Specialization for staggered-cctp...
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:36
typename ParentType::SolutionVectorStorage SolutionVectorStorage
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:44
void updateCouplingContext(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ, const PrimaryVariables< j > &priVarsJ, int pvIdxJ)
Update the coupling context.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:135
void bindCouplingContext(Dune::index_constant< i > domainI, const Element< i > &element, const Assembler &assembler) const
Methods to be accessed by the assembly.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:126
static constexpr auto freeFlowMassIndex
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:41
const auto & couplingContext(Dune::index_constant< i > domainI, const FVElementGeometry< i > &fvGeometry, const SubControlVolumeFace< i > scvf) const
Access the coupling context needed for the Stokes domain.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:167
static constexpr auto porousMediumIndex
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:42
const CouplingStencil & couplingStencil(Dune::index_constant< i > domainI, const Element< i > &element, Dune::index_constant< j > domainJ) const
The coupling stencils.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:195
void init(std::shared_ptr< Problem< freeFlowMassIndex > > freeFlowMassProblem, std::shared_ptr< Problem< porousMediumIndex > > darcyProblem, SolutionVectorStorage &curSol)
Methods to be accessed by main.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:105
bool isCoupled(Dune::index_constant< i > domainI, const SubControlVolumeFace< i > &scvf) const
Returns whether a given scvf is coupled to the other domain.
Definition: ffmasspm/couplingmanager_staggered_cctpfa.hh:209
Defines all properties used in Dumux.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
The interface of the coupling manager for multi domain problems.
Definition: adapt.hh:17
The local element solution class for staggered methods.