13#ifndef DUMUX_MULTIDOMAIN_BOUNDARY_FFPM_FFMASSPM_COUPLINGMANAGER_STAGGERED_TPFA_HH
14#define DUMUX_MULTIDOMAIN_BOUNDARY_FFPM_FFMASSPM_COUPLINGMANAGER_STAGGERED_TPFA_HH
19#include <dune/common/float_cmp.hh>
20#include <dune/common/exceptions.hh>
33template<
class MDTraits>
37 using Scalar =
typename MDTraits::Scalar;
41 static constexpr auto freeFlowMassIndex =
typename MDTraits::template SubDomain<0>::Index();
42 static constexpr auto porousMediumIndex =
typename MDTraits::template SubDomain<1>::Index();
48 using FreeFlowMassTypeTag =
typename MDTraits::template SubDomain<freeFlowMassIndex>::TypeTag;
49 using PorousMediumTypeTag =
typename MDTraits::template SubDomain<porousMediumIndex>::TypeTag;
51 using CouplingStencils = std::unordered_map<std::size_t, std::vector<std::size_t> >;
52 using CouplingStencil = CouplingStencils::mapped_type;
55 template<std::
size_t id>
56 using SubDomainTypeTag =
typename MDTraits::template SubDomain<id>::TypeTag;
64 template<std::
size_t id>
using FVElementGeometry =
typename GridGeometry<id>::LocalView;
66 template<std::
size_t id>
using Element =
typename GridView<id>::template Codim<0>::Entity;
68 template<std::
size_t id>
using SubControlVolumeFace =
typename FVElementGeometry<id>::SubControlVolumeFace;
69 template<std::
size_t id>
using SubControlVolume =
typename FVElementGeometry<id>::SubControlVolume;
71 using VelocityVector =
typename Element<freeFlowMassIndex>::Geometry::GlobalCoordinate;
73 struct FreeFlowMassCouplingContext
75 Element<porousMediumIndex> element;
76 VolumeVariables<porousMediumIndex> volVars;
77 FVElementGeometry<porousMediumIndex> fvGeometry;
79 std::size_t freeFlowMassScvfIdx;
80 std::size_t porousMediumScvfIdx;
81 mutable VelocityVector velocity;
84 struct PorousMediumCouplingContext
86 Element<freeFlowMassIndex> element;
87 VolumeVariables<freeFlowMassIndex> volVars;
88 FVElementGeometry<freeFlowMassIndex> fvGeometry;
90 std::size_t porousMediumScvfIdx;
91 std::size_t freeFlowMassScvfIdx;
92 mutable VelocityVector velocity;
95 using CouplingMapper = DarcyDarcyBoundaryCouplingMapper<MDTraits>;
105 void init(std::shared_ptr<Problem<freeFlowMassIndex>> freeFlowMassProblem,
106 std::shared_ptr<Problem<porousMediumIndex>> darcyProblem,
109 this->
setSubProblems(std::make_tuple(freeFlowMassProblem, darcyProblem));
112 couplingMapper_.
update(*
this);
125 template<std::
size_t i,
class Assembler>
126 void bindCouplingContext(Dune::index_constant<i> domainI,
const Element<i>& element,
const Assembler& assembler)
const
128 bindCouplingContext_(domainI, element);
134 template<std::
size_t i, std::
size_t j,
class LocalAssemblerI>
136 const LocalAssemblerI& localAssemblerI,
137 Dune::index_constant<j> domainJ,
138 std::size_t dofIdxGlobalJ,
139 const PrimaryVariables<j>& priVarsJ,
142 this->
curSol(domainJ)[dofIdxGlobalJ][pvIdxJ] = priVarsJ[pvIdxJ];
149 auto& context = std::get<1-j>(couplingContext_);
150 for (
auto& c : context)
152 if (c.dofIdx == dofIdxGlobalJ)
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);
166 template<std::
size_t i>
168 const FVElementGeometry<i>& fvGeometry,
169 const SubControlVolumeFace<i> scvf)
const
171 auto& contexts = std::get<i>(couplingContext_);
173 if (contexts.empty() || couplingContextBoundForElement_[i] != scvf.insideScvIdx())
174 bindCouplingContext_(domainI, fvGeometry);
176 for (
const auto& context : contexts)
178 const auto expectedScvfIdx = domainI ==
freeFlowMassIndex ? context.freeFlowMassScvfIdx : context.porousMediumScvfIdx;
179 if (scvf.index() == expectedScvfIdx)
183 DUNE_THROW(Dune::InvalidStateException,
"No coupling context found at scvf " << scvf.center());
194 template<std::
size_t i, std::
size_t j>
196 const Element<i>& element,
197 Dune::index_constant<j> domainJ)
const
199 const auto eIdx = this->
problem(domainI).gridGeometry().elementMapper().index(element);
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); }
216 template<std::
size_t i>
217 bool isCoupledElement_(Dune::index_constant<i> domainI, std::size_t eIdx)
const
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
226 VolumeVariables<i> volVars;
228 element, this->
curSol(domainI), this->
problem(domainI).gridGeometry()
230 volVars.update(elemSol, this->
problem(domainI), element, scv);
237 template<std::
size_t i>
238 void bindCouplingContext_(Dune::index_constant<i> domainI,
const Element<i>& element)
const
240 const auto fvGeometry =
localView(this->
problem(domainI).gridGeometry()).bindElement(element);
241 bindCouplingContext_(domainI, fvGeometry);
247 template<std::
size_t i>
248 void bindCouplingContext_(Dune::index_constant<i> domainI,
const FVElementGeometry<i>& fvGeometry)
const
250 auto& context = std::get<domainI>(couplingContext_);
253 const auto eIdx = this->
problem(domainI).gridGeometry().elementMapper().index(fvGeometry.element());
256 if (!isCoupledElement_(domainI, eIdx))
259 couplingContextBoundForElement_[domainI] = eIdx;
261 for (
const auto& scvf : scvfs(fvGeometry))
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);
274 volVars_(domainJ, otherElement, *std::begin(scvs(otherFvGeometry))),
275 std::move(otherFvGeometry),
285 mutable std::tuple<std::vector<FreeFlowMassCouplingContext>, std::vector<PorousMediumCouplingContext>> couplingContext_;
286 mutable std::array<std::size_t, 2> couplingContextBoundForElement_;
288 CouplingMapper couplingMapper_;
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.
The local element solution class for staggered methods.