version 3.8
staggeredcouplingmanager.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//
14#ifndef DUMUX_STAGGERED_COUPLING_MANAGER_HH
15#define DUMUX_STAGGERED_COUPLING_MANAGER_HH
16
21
22namespace Dumux {
23
29template<class MDTraits>
30class StaggeredCouplingManager: virtual public CouplingManager<MDTraits>
31{
33
34 template<std::size_t id> using GridGeometry = typename MDTraits::template SubDomain<id>::GridGeometry;
35 template<std::size_t id> using GridView = typename GridGeometry<id>::GridView;
36
37 using FVElementGeometry = typename GridGeometry<0>::LocalView;
38 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
39 using Element = typename GridView<0>::template Codim<0>::Entity;
40
41 using GridIndexType = typename IndexTraits< GridView<0> >::GridIndex;
42 using CouplingStencil = std::vector<GridIndexType>;
43
44public:
45
47
48 using Traits = MDTraits;
49
50 static constexpr auto cellCenterIdx = GridGeometry<0>::cellCenterIdx();
51 static constexpr auto faceIdx = GridGeometry<0>::faceIdx();
52
56 template<std::size_t i, std::size_t j, class LocalAssemblerI, class PriVarsJ>
57 void updateCouplingContext(Dune::index_constant<i> domainI,
58 const LocalAssemblerI& localAssemblerI,
59 Dune::index_constant<j> domainJ,
60 const std::size_t dofIdxGlobalJ,
61 const PriVarsJ& priVarsJ,
62 int pvIdxJ)
63 {
64 auto& curSol = this->curSol(domainJ);
65
66 // only proceed if the solution vector has actually been set in the base class
67 // (which is not the case if the staggered model is not coupled to another domain)
68 if (curSol.size() > 0)
69 curSol[dofIdxGlobalJ][pvIdxJ] = priVarsJ[pvIdxJ];
70 }
71
82 const CouplingStencil& couplingStencil(Dune::index_constant<cellCenterIdx> domainI,
83 const Element& elementI,
84 Dune::index_constant<faceIdx> domainJ) const
85 {
86 const auto& connectivityMap = this->problem(domainI).gridGeometry().connectivityMap();
87 const auto eIdx = this->problem(domainI).gridGeometry().elementMapper().index(elementI);
88 return connectivityMap(domainI, domainJ, eIdx);
89 }
90
101 template<std::size_t i, std::size_t j>
102 const CouplingStencil couplingStencil(Dune::index_constant<i> domainI,
103 const SubControlVolumeFace& scvfI,
104 Dune::index_constant<j> domainJ) const
105 {
106 static_assert(i != j, "Domain i cannot be coupled to itself!");
107 static_assert(AlwaysFalse<Dune::index_constant<i>>::value,
108 "The coupling manager does not implement the couplingStencil() function" );
109
110 return CouplingStencil(); // suppress compiler warning of function having no return statement
111 }
112
123 const CouplingStencil& couplingStencil(Dune::index_constant<faceIdx> domainI,
124 const SubControlVolumeFace& scvfI,
125 Dune::index_constant<cellCenterIdx> domainJ) const
126 {
127 const auto& connectivityMap = this->problem(domainI).gridGeometry().connectivityMap();
128 return connectivityMap(domainI, domainJ, scvfI.index());
129 }
130
137 template<class LocalAssemblerI, std::size_t j>
138 decltype(auto) evalCouplingResidual(Dune::index_constant<cellCenterIdx> domainI,
139 const LocalAssemblerI& localAssemblerI,
140 Dune::index_constant<j> domainJ,
141 std::size_t dofIdxGlobalJ) const
142 {
143 static_assert(domainI != domainJ, "Domain i cannot be coupled to itself!");
144 return localAssemblerI.evalLocalResidualForCellCenter();
145 }
146
162 template<class LocalAssemblerI, std::size_t j>
163 decltype(auto) evalCouplingResidual(Dune::index_constant<faceIdx> domainI,
164 const SubControlVolumeFace& scvfI,
165 const LocalAssemblerI& localAssemblerI,
166 Dune::index_constant<j> domainJ,
167 std::size_t dofIdxGlobalJ) const
168 {
169 static_assert(domainI != domainJ, "Domain i cannot be coupled to itself!");
170 return localAssemblerI.evalLocalResidualForFace(scvfI);
171 }
172
177 template<std::size_t i, typename std::enable_if_t<(GridGeometry<i>::discMethod != DiscretizationMethods::staggered), int> = 0>
178 decltype(auto) numericEpsilon(Dune::index_constant<i> id,
179 const std::string& paramGroup) const
180 {
181 return ParentType::numericEpsilon(id, paramGroup);
182 }
183
188 template<std::size_t i, typename std::enable_if_t<(GridGeometry<i>::discMethod == DiscretizationMethods::staggered), int> = 0>
189 decltype(auto) numericEpsilon(Dune::index_constant<i>,
190 const std::string& paramGroup) const
191 {
192 constexpr std::size_t numEqCellCenter = Traits::template SubDomain<cellCenterIdx>::PrimaryVariables::dimension;
193 constexpr std::size_t numEqFace = Traits::template SubDomain<faceIdx>::PrimaryVariables::dimension;
194 constexpr bool isCellCenter = GridGeometry<i>::isCellCenter();
195 constexpr std::size_t numEq = isCellCenter ? numEqCellCenter : numEqFace;
196 constexpr auto prefix = isCellCenter ? "CellCenter" : "Face";
197
198 try {
199 if(paramGroup.empty())
201 else
202 return NumericEpsilon<typename Traits::Scalar, numEq>(paramGroup + "." + prefix);
203 }
204 catch (Dune::RangeError& e)
205 {
206 DUNE_THROW(Dumux::ParameterException, "For the staggered model, you can to specify \n\n"
207 " CellCenter.Assembly.NumericDifference.PriVarMagnitude = mCC\n"
208 " Face.Assembly.NumericDifference.PriVarMagnitude = mFace\n"
209 " CellCenter.Assembly.NumericDifference.BaseEpsilon = eCC_0 ... eCC_numEqCellCenter-1\n"
210 " Face.Assembly.NumericDifference.BaseEpsilon = eFace_0 ... eFace_numEqFace-1\n\n"
211 "Wrong number of values set for " << prefix << " (has " << numEq << " primary variable(s))\n\n" << e);
212 }
213
214 }
215
216};
217
218} //end namespace Dumux
219
220#endif
The interface of the coupling manager for multi domain problems.
Definition: multidomain/couplingmanager.hh:48
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
decltype(auto) numericEpsilon(Dune::index_constant< i >, const std::string &paramGroup) const
return the numeric epsilon used for deflecting primary variables of coupled domain i
Definition: multidomain/couplingmanager.hh:275
A helper class for local assemblers using numeric differentiation to determine the epsilon.
Definition: numericepsilon.hh:29
Exception thrown if a run-time parameter is not specified correctly.
Definition: exceptions.hh:48
Base coupling manager for the staggered discretization.
Definition: staggeredcouplingmanager.hh:31
const CouplingStencil & couplingStencil(Dune::index_constant< faceIdx > domainI, const SubControlVolumeFace &scvfI, Dune::index_constant< cellCenterIdx > domainJ) const
returns an iterable container of all indices of degrees of freedom of domain j that couple with / inf...
Definition: staggeredcouplingmanager.hh:123
const CouplingStencil couplingStencil(Dune::index_constant< i > domainI, const SubControlVolumeFace &scvfI, 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: staggeredcouplingmanager.hh:102
decltype(auto) evalCouplingResidual(Dune::index_constant< cellCenterIdx > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ) const
evaluates the element residual of a coupled element of domain i which depends on the variables at the...
Definition: staggeredcouplingmanager.hh:138
const CouplingStencil & couplingStencil(Dune::index_constant< cellCenterIdx > domainI, const Element &elementI, Dune::index_constant< faceIdx > domainJ) const
returns an iterable container of all indices of degrees of freedom of domain j that couple with / inf...
Definition: staggeredcouplingmanager.hh:82
decltype(auto) numericEpsilon(Dune::index_constant< i > id, const std::string &paramGroup) const
return the numeric epsilon used for deflecting primary variables of coupled domain i.
Definition: staggeredcouplingmanager.hh:178
void updateCouplingContext(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, const std::size_t dofIdxGlobalJ, const PriVarsJ &priVarsJ, int pvIdxJ)
updates all data and variables that are necessary to evaluate the residual of the element of domain i...
Definition: staggeredcouplingmanager.hh:57
decltype(auto) evalCouplingResidual(Dune::index_constant< faceIdx > domainI, const SubControlVolumeFace &scvfI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ) const
evaluates the face residual of a coupled face of domain i which depends on the variables at the degre...
Definition: staggeredcouplingmanager.hh:163
decltype(auto) numericEpsilon(Dune::index_constant< i >, const std::string &paramGroup) const
return the numeric epsilon used for deflecting primary variables of coupled domain i.
Definition: staggeredcouplingmanager.hh:189
static constexpr auto cellCenterIdx
Definition: staggeredcouplingmanager.hh:50
MDTraits Traits
Definition: staggeredcouplingmanager.hh:48
static constexpr auto faceIdx
Definition: staggeredcouplingmanager.hh:51
decltype(auto) evalCouplingResidual(Dune::index_constant< i > domainI, const LocalAssemblerI &localAssemblerI, Dune::index_constant< j > domainJ, std::size_t dofIdxGlobalJ) const
evaluates the element residual of a coupled element of domain i which depends on the variables at the...
Definition: multidomain/couplingmanager.hh:249
Defines the index types used for grid and local indices.
The available discretization methods in Dumux.
The interface of the coupling manager for multi domain problems.
Definition: adapt.hh:17
An adapter class for local assemblers using numeric differentiation.
Template which always yields a false value.
Definition: common/typetraits/typetraits.hh:24
Structure to define the index types used for grid and local indices.
Definition: indextraits.hh:26