3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
1p/incompressiblelocalresidual.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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_1P_INCOMPRESSIBLE_LOCAL_RESIDUAL_HH
27#define DUMUX_1P_INCOMPRESSIBLE_LOCAL_RESIDUAL_HH
28
31
32namespace Dumux {
33
39template<class TypeTag>
41{
46 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
49 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
50 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
51 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
52 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
54 using Element = typename GridView::template Codim<0>::Entity;
56 // first index for the mass balance
57 enum { conti0EqIdx = Indices::conti0EqIdx };
58 enum { pressureIdx = Indices::pressureIdx };
59
60 static constexpr int dim = GridView::dimension;
61 static constexpr int dimWorld = GridView::dimensionworld;
62
63public:
64 using ParentType::ParentType;
65
66 template<class PartialDerivativeMatrix>
67 void addStorageDerivatives(PartialDerivativeMatrix& partialDerivatives,
68 const Problem& problem,
69 const Element& element,
70 const FVElementGeometry& fvGeometry,
71 const VolumeVariables& curVolVars,
72 const SubControlVolume& scv) const {}
73
74 template<class PartialDerivativeMatrix>
75 void addSourceDerivatives(PartialDerivativeMatrix& partialDerivatives,
76 const Problem& problem,
77 const Element& element,
78 const FVElementGeometry& fvGeometry,
79 const VolumeVariables& curVolVars,
80 const SubControlVolume& scv) const
81 {
82 problem.addSourceDerivatives(partialDerivatives, element, fvGeometry, curVolVars, scv);
83 }
84
86 template<class PartialDerivativeMatrices, class T = TypeTag>
87 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethods::cctpfa, void>
88 addFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
89 const Problem& problem,
90 const Element& element,
91 const FVElementGeometry& fvGeometry,
92 const ElementVolumeVariables& curElemVolVars,
93 const ElementFluxVariablesCache& elemFluxVarsCache,
94 const SubControlVolumeFace& scvf) const
95 {
96 static_assert(!FluidSystem::isCompressible(0),
97 "1p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
98 static_assert(FluidSystem::viscosityIsConstant(0),
99 "1p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
100
101 // we know the "upwind factor" is constant, get inner one here and compute derivatives
102 static const Scalar up = curElemVolVars[scvf.insideScvIdx()].density()
103 / curElemVolVars[scvf.insideScvIdx()].viscosity();
104
105 // for network grids we have to do something else
106 if (dim < dimWorld && scvf.numOutsideScvs() > 1)
107 {
108 const auto insideTi = elemFluxVarsCache[scvf].advectionTij();
109 const auto sumTi = [&]
110 {
111 Scalar sumTi(insideTi);
112 for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
113 {
114 const auto& flippedScvf = fvGeometry.flipScvf(scvf.index(), i);
115 const auto& outsideFluxVarsCache = elemFluxVarsCache[flippedScvf];
116 sumTi += outsideFluxVarsCache.advectionTij();
117 }
118 return sumTi;
119 }();
120
121 // add partial derivatives to the respective given matrices
122 derivativeMatrices[scvf.insideScvIdx()][conti0EqIdx][pressureIdx]
123 += up*insideTi*(1.0 - insideTi/sumTi);
124 for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
125 derivativeMatrices[scvf.outsideScvIdx(i)][conti0EqIdx][pressureIdx]
126 += -up*insideTi*elemFluxVarsCache[fvGeometry.flipScvf(scvf.index(), i)].advectionTij()/sumTi;
127
128 }
129 else
130 {
131 const auto deriv = elemFluxVarsCache[scvf].advectionTij()*up;
132 // add partial derivatives to the respective given matrices
133 derivativeMatrices[scvf.insideScvIdx()][conti0EqIdx][pressureIdx] += deriv;
134 derivativeMatrices[scvf.outsideScvIdx()][conti0EqIdx][pressureIdx] -= deriv;
135 }
136 }
137
139 template<class PartialDerivativeMatrices, class T = TypeTag>
140 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethods::ccmpfa, void>
141 addFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
142 const Problem& problem,
143 const Element& element,
144 const FVElementGeometry& fvGeometry,
145 const ElementVolumeVariables& curElemVolVars,
146 const ElementFluxVariablesCache& elemFluxVarsCache,
147 const SubControlVolumeFace& scvf) const
148 {
149 static_assert(!FluidSystem::isCompressible(0),
150 "1p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
151 static_assert(FluidSystem::viscosityIsConstant(0),
152 "1p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
153
154 // we know the "upwind factor" is constant, get inner one here and compute derivatives
155 static const Scalar up = curElemVolVars[scvf.insideScvIdx()].density()
156 / curElemVolVars[scvf.insideScvIdx()].viscosity();
157
158 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
159 const auto localFaceIdx = fluxVarsCache.ivLocalFaceIndex();
160 const auto usesSecondary = fluxVarsCache.usesSecondaryIv();
161 const auto switchSign = fluxVarsCache.advectionSwitchFluxSign();
162
163 const auto& stencil = fluxVarsCache.advectionStencil();
164 const auto& tij = usesSecondary ? fluxVarsCache.advectionSecondaryDataHandle().T()[localFaceIdx]
165 : fluxVarsCache.advectionPrimaryDataHandle().T()[localFaceIdx];
166
167 // We assume same the tij are order as the stencil up to stencil.size()
168 // any contribution of Dirichlet BCs is assumed to be placed afterwards
169 assert(stencil.size() <= tij.size());
170 for (unsigned int i = 0; i < stencil.size();++i)
171 derivativeMatrices[stencil[i]][conti0EqIdx][pressureIdx] += switchSign ? -tij[i]*up
172 : tij[i]*up;
173 }
174
176 template<class JacobianMatrix, class T = TypeTag>
177 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethods::box, void>
178 addFluxDerivatives(JacobianMatrix& A,
179 const Problem& problem,
180 const Element& element,
181 const FVElementGeometry& fvGeometry,
182 const ElementVolumeVariables& curElemVolVars,
183 const ElementFluxVariablesCache& elemFluxVarsCache,
184 const SubControlVolumeFace& scvf) const
185 {
186 static_assert(!FluidSystem::isCompressible(0),
187 "1p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
188 static_assert(FluidSystem::viscosityIsConstant(0),
189 "1p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
190
191 using AdvectionType = GetPropType<T, Properties::AdvectionType>;
192 const auto ti = AdvectionType::calculateTransmissibilities(problem,
193 element,
194 fvGeometry,
195 curElemVolVars,
196 scvf,
197 elemFluxVarsCache[scvf]);
198
199 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
200 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
201
202 // we know the "upwind factor" is constant, get inner one here and compute derivatives
203 static const Scalar up = curElemVolVars[scvf.insideScvIdx()].density()
204 / curElemVolVars[scvf.insideScvIdx()].viscosity();
205 for (const auto& scv : scvs(fvGeometry))
206 {
207 auto d = up*ti[scv.indexInElement()];
208 A[insideScv.dofIndex()][scv.dofIndex()][conti0EqIdx][pressureIdx] += d;
209 A[outsideScv.dofIndex()][scv.dofIndex()][conti0EqIdx][pressureIdx] -= d;
210 }
211 }
212
214 template<class PartialDerivativeMatrices, class T = TypeTag>
215 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethods::cctpfa, void>
216 addCCDirichletFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
217 const Problem& problem,
218 const Element& element,
219 const FVElementGeometry& fvGeometry,
220 const ElementVolumeVariables& curElemVolVars,
221 const ElementFluxVariablesCache& elemFluxVarsCache,
222 const SubControlVolumeFace& scvf) const
223 {
224 // we know the "upwind factor" is constant, get inner one here
225 static const Scalar up = curElemVolVars[scvf.insideScvIdx()].density()
226 / curElemVolVars[scvf.insideScvIdx()].viscosity();
227 const auto deriv = elemFluxVarsCache[scvf].advectionTij()*up;
228
229 // compute and add partial derivative to the respective given matrices
230 derivativeMatrices[scvf.insideScvIdx()][conti0EqIdx][pressureIdx] += deriv;
231 }
232
234 template<class PartialDerivativeMatrices, class T = TypeTag>
235 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethods::ccmpfa, void>
236 addCCDirichletFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
237 const Problem& problem,
238 const Element& element,
239 const FVElementGeometry& fvGeometry,
240 const ElementVolumeVariables& curElemVolVars,
241 const ElementFluxVariablesCache& elemFluxVarsCache,
242 const SubControlVolumeFace& scvf) const
243 {
244 addFluxDerivatives(derivativeMatrices, problem, element, fvGeometry, curElemVolVars, elemFluxVarsCache, scvf);
245 }
246
248 template<class PartialDerivativeMatrices>
249 void addRobinFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
250 const Problem& problem,
251 const Element& element,
252 const FVElementGeometry& fvGeometry,
253 const ElementVolumeVariables& curElemVolVars,
254 const ElementFluxVariablesCache& elemFluxVarsCache,
255 const SubControlVolumeFace& scvf) const
256 {
260 }
261};
262
263} // end namespace Dumux
264
265#endif
The available discretization methods in Dumux.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
constexpr CCMpfa ccmpfa
Definition: method.hh:135
constexpr CCTpfa cctpfa
Definition: method.hh:134
constexpr Box box
Definition: method.hh:136
Element-wise calculation of the residual and its derivatives for a single-phase, incompressible,...
Definition: 1p/incompressiblelocalresidual.hh:41
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::box, void > addFluxDerivatives(JacobianMatrix &A, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Flux derivatives for the box scheme.
Definition: 1p/incompressiblelocalresidual.hh:178
void addStorageDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Definition: 1p/incompressiblelocalresidual.hh:67
void addSourceDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Definition: 1p/incompressiblelocalresidual.hh:75
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::cctpfa, void > addFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Flux derivatives for the cell-centered tpfa scheme.
Definition: 1p/incompressiblelocalresidual.hh:88
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::ccmpfa, void > addCCDirichletFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Dirichlet flux derivatives for the cell-centered mpfa scheme.
Definition: 1p/incompressiblelocalresidual.hh:236
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::cctpfa, void > addCCDirichletFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Dirichlet flux derivatives for the cell-centered tpfa scheme.
Definition: 1p/incompressiblelocalresidual.hh:216
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethods::ccmpfa, void > addFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Flux derivatives for the cell-centered mpfa scheme.
Definition: 1p/incompressiblelocalresidual.hh:141
void addRobinFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Robin-type flux derivatives.
Definition: 1p/incompressiblelocalresidual.hh:249
Element-wise calculation of the residual for problems using the n-phase immiscible fully implicit mod...
Definition: porousmediumflow/immiscible/localresidual.hh:40
Element-wise calculation of the residual for problems using the n-phase immiscible fully implicit mod...