version 3.7
multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.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_HH
14#define DUMUX_MULTIDOMAIN_BOUNDARY_FFPM_FFMASSPM_COUPLINGMANAGER_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
32template<class MDTraits>
34: public CouplingManager<MDTraits>
35{
36 using Scalar = typename MDTraits::Scalar;
38
39public:
40 static constexpr auto freeFlowMassIndex = typename MDTraits::template SubDomain<0>::Index();
41 static constexpr auto porousMediumIndex = typename MDTraits::template SubDomain<1>::Index();
42
44private:
45
46 // obtain the type tags of the sub problems
47 using FreeFlowMassTypeTag = typename MDTraits::template SubDomain<freeFlowMassIndex>::TypeTag;
48 using PorousMediumTypeTag = typename MDTraits::template SubDomain<porousMediumIndex>::TypeTag;
49
50 using CouplingStencils = std::unordered_map<std::size_t, std::vector<std::size_t> >;
51 using CouplingStencil = CouplingStencils::mapped_type;
52
53 // the sub domain type tags
54 template<std::size_t id>
55 using SubDomainTypeTag = typename MDTraits::template SubDomain<id>::TypeTag;
56
57 template<std::size_t id> using GridView = typename GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>::GridView;
58 template<std::size_t id> using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
59 template<std::size_t id> using ElementVolumeVariables = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>::LocalView;
60 template<std::size_t id> using GridVolumeVariables = GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>;
61 template<std::size_t id> using VolumeVariables = typename GetPropType<SubDomainTypeTag<id>, Properties::GridVolumeVariables>::VolumeVariables;
62 template<std::size_t id> using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
63 template<std::size_t id> using FVElementGeometry = typename GridGeometry<id>::LocalView;
64 template<std::size_t id> using GridVariables = GetPropType<SubDomainTypeTag<id>, Properties::GridVariables>;
65 template<std::size_t id> using Element = typename GridView<id>::template Codim<0>::Entity;
66 template<std::size_t id> using PrimaryVariables = GetPropType<SubDomainTypeTag<id>, Properties::PrimaryVariables>;
67 template<std::size_t id> using SubControlVolumeFace = typename FVElementGeometry<id>::SubControlVolumeFace;
68 template<std::size_t id> using SubControlVolume = typename FVElementGeometry<id>::SubControlVolume;
69
70 using VelocityVector = typename Element<freeFlowMassIndex>::Geometry::GlobalCoordinate;
71
72 struct FreeFlowMassCouplingContext
73 {
74 Element<porousMediumIndex> element;
75 VolumeVariables<porousMediumIndex> volVars;
76 FVElementGeometry<porousMediumIndex> fvGeometry;
77 std::size_t dofIdx;
78 std::size_t freeFlowMassScvfIdx;
79 std::size_t porousMediumScvfIdx;
80 mutable VelocityVector velocity; // velocity needs to be set externally, not available in this class
81 };
82
83 struct PorousMediumCouplingContext
84 {
85 Element<freeFlowMassIndex> element;
86 VolumeVariables<freeFlowMassIndex> volVars;
87 FVElementGeometry<freeFlowMassIndex> fvGeometry;
88 std::size_t dofIdx;
89 std::size_t porousMediumScvfIdx;
90 std::size_t freeFlowMassScvfIdx;
91 mutable VelocityVector velocity; // velocity needs to be set externally, not available in this class
92 };
93
94 using CouplingMapper = DarcyDarcyBoundaryCouplingMapper<MDTraits>; // TODO rename/generalize class
95
96public:
97
101 // \{
102
104 void init(std::shared_ptr<Problem<freeFlowMassIndex>> freeFlowMassProblem,
105 std::shared_ptr<Problem<porousMediumIndex>> darcyProblem,
107 {
108 this->setSubProblems(std::make_tuple(freeFlowMassProblem, darcyProblem));
109 this->attachSolution(curSol);
110
111 couplingMapper_.update(*this);
112 }
113
114 // \}
115
119 // \{
120
124 template<std::size_t i, class Assembler>
125 void bindCouplingContext(Dune::index_constant<i> domainI, const Element<i>& element, const Assembler& assembler) const
126 {
127 bindCouplingContext_(domainI, element);
128 }
129
133 template<std::size_t i, std::size_t j, class LocalAssemblerI>
134 void updateCouplingContext(Dune::index_constant<i> domainI,
135 const LocalAssemblerI& localAssemblerI,
136 Dune::index_constant<j> domainJ,
137 std::size_t dofIdxGlobalJ,
138 const PrimaryVariables<j>& priVarsJ,
139 int pvIdxJ)
140 {
141 this->curSol(domainJ)[dofIdxGlobalJ][pvIdxJ] = priVarsJ[pvIdxJ];
142
143 // we need to update all solution-depenent components of the coupling context
144 // the dof of domain J has been deflected
145 // if domainJ == freeFlowMassIndex: update volvars in the PorousMediumCouplingContext
146 // if domainJ == porousMediumIndex: update volvars in the FreeFlowMassCouplingContext
147 // as the update is symmetric we only need to write this once
148 auto& context = std::get<1-j>(couplingContext_);
149 for (auto& c : context)
150 {
151 if (c.dofIdx == dofIdxGlobalJ)
152 {
153 const auto elemSol = elementSolution(c.element, this->curSol(domainJ), this->problem(domainJ).gridGeometry());
154 const auto& scv = *scvs(c.fvGeometry).begin();
155 c.volVars.update(elemSol, this->problem(domainJ), c.element, scv);
156 }
157 }
158 }
159
160 // \}
161
165 template<std::size_t i>
166 const auto& couplingContext(Dune::index_constant<i> domainI,
167 const FVElementGeometry<i>& fvGeometry,
168 const SubControlVolumeFace<i> scvf) const
169 {
170 auto& contexts = std::get<i>(couplingContext_);
171
172 if (contexts.empty() || couplingContextBoundForElement_[i] != scvf.insideScvIdx())
173 bindCouplingContext_(domainI, fvGeometry);
174
175 for (const auto& context : contexts)
176 {
177 const auto expectedScvfIdx = domainI == freeFlowMassIndex ? context.freeFlowMassScvfIdx : context.porousMediumScvfIdx;
178 if (scvf.index() == expectedScvfIdx)
179 return context;
180 }
181
182 DUNE_THROW(Dune::InvalidStateException, "No coupling context found at scvf " << scvf.center());
183 }
184
188 // \{
189
193 template<std::size_t i, std::size_t j>
194 const CouplingStencil& couplingStencil(Dune::index_constant<i> domainI,
195 const Element<i>& element,
196 Dune::index_constant<j> domainJ) const
197 {
198 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(element);
199 return couplingMapper_.couplingStencil(domainI, eIdx, domainJ);
200 }
201
202 // \}
203
207 template<std::size_t i>
208 bool isCoupled(Dune::index_constant<i> domainI, const SubControlVolumeFace<i>& scvf) const
209 { return couplingMapper_.isCoupled(domainI, scvf); }
210
211private:
215 template<std::size_t i>
216 bool isCoupledElement_(Dune::index_constant<i> domainI, std::size_t eIdx) const
217 { return couplingMapper_.isCoupledElement(domainI, eIdx); }
218
220 template<std::size_t i>
221 VolumeVariables<i> volVars_(Dune::index_constant<i> domainI,
222 const Element<i>& element,
223 const SubControlVolume<i>& scv) const
224 {
225 VolumeVariables<i> volVars;
226 const auto elemSol = elementSolution(
227 element, this->curSol(domainI), this->problem(domainI).gridGeometry()
228 );
229 volVars.update(elemSol, this->problem(domainI), element, scv);
230 return volVars;
231 }
232
236 template<std::size_t i>
237 void bindCouplingContext_(Dune::index_constant<i> domainI, const Element<i>& element) const
238 {
239 const auto fvGeometry = localView(this->problem(domainI).gridGeometry()).bindElement(element);
240 bindCouplingContext_(domainI, fvGeometry);
241 }
242
246 template<std::size_t i>
247 void bindCouplingContext_(Dune::index_constant<i> domainI, const FVElementGeometry<i>& fvGeometry) const
248 {
249 auto& context = std::get<domainI>(couplingContext_);
250 context.clear();
251
252 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(fvGeometry.element());
253
254 // do nothing if the element is not coupled to the other domain
255 if (!isCoupledElement_(domainI, eIdx))
256 return;
257
258 couplingContextBoundForElement_[domainI] = eIdx;
259
260 for (const auto& scvf : scvfs(fvGeometry))
261 {
262 if (isCoupled(domainI, scvf))
263 {
264 const auto otherElementIdx = couplingMapper_.outsideElementIndex(domainI, scvf);
265 constexpr auto domainJ = Dune::index_constant<1-domainI>();
266 const auto& otherGridGeometry = this->problem(domainJ).gridGeometry();
267 const auto& otherElement = otherGridGeometry.element(otherElementIdx);
268 auto otherFvGeometry = localView(otherGridGeometry).bindElement(otherElement);
269
270 // there is only one scv for TPFA
271 context.push_back({
272 otherElement,
273 volVars_(domainJ, otherElement, *std::begin(scvs(otherFvGeometry))),
274 std::move(otherFvGeometry),
275 otherElementIdx,
276 scvf.index(),
277 couplingMapper_.flipScvfIndex(domainI, scvf),
278 VelocityVector{}
279 });
280 }
281 }
282 }
283
284 mutable std::tuple<std::vector<FreeFlowMassCouplingContext>, std::vector<PorousMediumCouplingContext>> couplingContext_;
285 mutable std::array<std::size_t, 2> couplingContextBoundForElement_;
286
287 CouplingMapper couplingMapper_;
288};
289
290} // end namespace Dumux
291
292#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.
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:35
void bindCouplingContext(Dune::index_constant< i > domainI, const Element< i > &element, const Assembler &assembler) const
Methods to be accessed by the assembly.
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:125
void init(std::shared_ptr< Problem< freeFlowMassIndex > > freeFlowMassProblem, std::shared_ptr< Problem< porousMediumIndex > > darcyProblem, SolutionVectorStorage &curSol)
Methods to be accessed by main.
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:104
static constexpr auto porousMediumIndex
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:41
const CouplingStencil & couplingStencil(Dune::index_constant< i > domainI, const Element< i > &element, Dune::index_constant< j > domainJ) const
The coupling stencils.
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:194
bool isCoupled(Dune::index_constant< i > domainI, const SubControlVolumeFace< i > &scvf) const
Returns whether a given scvf is coupled to the other domain.
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:208
static constexpr auto freeFlowMassIndex
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:40
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: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:166
typename ParentType::SolutionVectorStorage SolutionVectorStorage
Definition: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:43
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: multidomain/boundary/freeflowporousmedium/ffmasspm/couplingmanager.hh:134
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:267
The interface of the coupling manager for multi domain problems.
Definition: adapt.hh:17
The local element solution class for staggered methods.