3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
2p/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_2P_INCOMPRESSIBLE_TEST_LOCAL_RESIDUAL_HH
27#define DUMUX_2P_INCOMPRESSIBLE_TEST_LOCAL_RESIDUAL_HH
28
29#include <cmath>
30
33
36
39
40namespace Dumux {
41
47template<class TypeTag>
49{
54 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
57 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
60 using FVElementGeometry = typename GridGeometry::LocalView;
61 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
62 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
64 using Element = typename GridView::template Codim<0>::Entity;
67
68 static constexpr int numPhases = ModelTraits::numFluidPhases();
69 static constexpr int pressureIdx = ModelTraits::Indices::pressureIdx;
70 static constexpr int saturationIdx = ModelTraits::Indices::saturationIdx;
71 static constexpr int conti0EqIdx = ModelTraits::Indices::conti0EqIdx;
72
73public:
74 using ParentType::ParentType;
75
89 template<class PartialDerivativeMatrix>
90 void addStorageDerivatives(PartialDerivativeMatrix& partialDerivatives,
91 const Problem& problem,
92 const Element& element,
93 const FVElementGeometry& fvGeometry,
94 const VolumeVariables& curVolVars,
95 const SubControlVolume& scv) const
96 {
97 static_assert(!FluidSystem::isCompressible(0),
98 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
99 static_assert(!FluidSystem::isCompressible(1),
100 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
101 static_assert(ModelTraits::numFluidPhases() == 2,
102 "2p/incompressiblelocalresidual.hh: Only two-phase models are allowed!");
103 static_assert(ModelTraits::priVarFormulation() == TwoPFormulation::p0s1,
104 "2p/incompressiblelocalresidual.hh: Analytic differentiation has to be checked for p1-s0 formulation!");
105
106 const auto poreVolume = scv.volume()*curVolVars.porosity();
107 const auto dt = this->timeLoop().timeStepSize();
108
109 // partial derivative of the phase storage terms w.r.t. S_n
110 partialDerivatives[conti0EqIdx+0][saturationIdx] -= poreVolume*curVolVars.density(0)/dt;
111 partialDerivatives[conti0EqIdx+1][saturationIdx] += poreVolume*curVolVars.density(1)/dt;
112 }
113
124 template<class PartialDerivativeMatrix>
125 void addSourceDerivatives(PartialDerivativeMatrix& partialDerivatives,
126 const Problem& problem,
127 const Element& element,
128 const FVElementGeometry& fvGeometry,
129 const VolumeVariables& curVolVars,
130 const SubControlVolume& scv) const
131 { /* TODO maybe forward to problem for the user to implement the source derivatives?*/ }
132
147 template<class PartialDerivativeMatrices, class T = TypeTag>
148 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethod::cctpfa, void>
149 addFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
150 const Problem& problem,
151 const Element& element,
152 const FVElementGeometry& fvGeometry,
153 const ElementVolumeVariables& curElemVolVars,
154 const ElementFluxVariablesCache& elemFluxVarsCache,
155 const SubControlVolumeFace& scvf) const
156 {
157 static_assert(!FluidSystem::isCompressible(0),
158 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
159 static_assert(!FluidSystem::isCompressible(1),
160 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
161 static_assert(FluidSystem::viscosityIsConstant(0),
162 "2p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
163 static_assert(FluidSystem::viscosityIsConstant(1),
164 "2p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
165 static_assert(ModelTraits::numFluidPhases() == 2,
166 "2p/incompressiblelocalresidual.hh: Only two-phase models are allowed!");
167 static_assert(ModelTraits::priVarFormulation() == TwoPFormulation::p0s1,
168 "2p/incompressiblelocalresidual.hh: Analytic differentiation has to be checked for p1-s0 formulation!");
169
170 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
172
173 // evaluate the current wetting phase Darcy flux and resulting upwind weights
174 static const Scalar upwindWeight = getParamFromGroup<Scalar>(problem.paramGroup(), "Flux.UpwindWeight");
175 const auto flux_w = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 0, elemFluxVarsCache);
176 const auto flux_n = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 1, elemFluxVarsCache);
177 const auto insideWeight_w = std::signbit(flux_w) ? (1.0 - upwindWeight) : upwindWeight;
178 const auto outsideWeight_w = 1.0 - insideWeight_w;
179 const auto insideWeight_n = std::signbit(flux_n) ? (1.0 - upwindWeight) : upwindWeight;
180 const auto outsideWeight_n = 1.0 - insideWeight_n;
181
182 // get references to the two participating vol vars & parameters
183 const auto insideScvIdx = scvf.insideScvIdx();
184 const auto outsideScvIdx = scvf.outsideScvIdx();
185 const auto outsideElement = fvGeometry.gridGeometry().element(outsideScvIdx);
186 const auto& insideScv = fvGeometry.scv(insideScvIdx);
187 const auto& outsideScv = fvGeometry.scv(outsideScvIdx);
188 const auto& insideVolVars = curElemVolVars[insideScvIdx];
189 const auto& outsideVolVars = curElemVolVars[outsideScvIdx];
190 const auto& insideMaterialParams = problem.spatialParams().materialLawParams(element,
191 insideScv,
192 elementSolution<FVElementGeometry>(insideVolVars.priVars()));
193 const auto& outsideMaterialParams = problem.spatialParams().materialLawParams(outsideElement,
194 outsideScv,
195 elementSolution<FVElementGeometry>(outsideVolVars.priVars()));
196
197 // get references to the two participating derivative matrices
198 auto& dI_dI = derivativeMatrices[insideScvIdx];
199 auto& dI_dJ = derivativeMatrices[outsideScvIdx];
200
201 // some quantities to be reused (rho & mu are constant and thus equal for all cells)
202 static const auto rho_w = insideVolVars.density(0);
203 static const auto rho_n = insideVolVars.density(1);
204 static const auto rhow_muw = rho_w/insideVolVars.viscosity(0);
205 static const auto rhon_mun = rho_n/insideVolVars.viscosity(1);
206 const auto rhowKrw_muw_inside = rho_w*insideVolVars.mobility(0);
207 const auto rhonKrn_mun_inside = rho_n*insideVolVars.mobility(1);
208 const auto rhowKrw_muw_outside = rho_w*outsideVolVars.mobility(0);
209 const auto rhonKrn_mun_outside = rho_n*outsideVolVars.mobility(1);
210
211 // derivative w.r.t. to Sn is the negative of the one w.r.t. Sw
212 const auto insideSw = insideVolVars.saturation(0);
213 const auto outsideSw = outsideVolVars.saturation(0);
214 const auto dKrw_dSn_inside = -1.0*MaterialLaw::dkrw_dsw(insideMaterialParams, insideSw);
215 const auto dKrw_dSn_outside = -1.0*MaterialLaw::dkrw_dsw(outsideMaterialParams, outsideSw);
216 const auto dKrn_dSn_inside = -1.0*MaterialLaw::dkrn_dsw(insideMaterialParams, insideSw);
217 const auto dKrn_dSn_outside = -1.0*MaterialLaw::dkrn_dsw(outsideMaterialParams, outsideSw);
218 const auto dpc_dSn_inside = -1.0*MaterialLaw::dpc_dsw(insideMaterialParams, insideSw);
219 const auto dpc_dSn_outside = -1.0*MaterialLaw::dpc_dsw(outsideMaterialParams, outsideSw);
220
221 const auto tij = elemFluxVarsCache[scvf].advectionTij();
222
223 // precalculate values
224 const auto up_w = rhowKrw_muw_inside*insideWeight_w + rhowKrw_muw_outside*outsideWeight_w;
225 const auto up_n = rhonKrn_mun_inside*insideWeight_n + rhonKrn_mun_outside*outsideWeight_n;
226 const auto rho_mu_flux_w = rhow_muw*flux_w;
227 const auto rho_mu_flux_n = rhon_mun*flux_n;
228 const auto tij_up_w = tij*up_w;
229 const auto tij_up_n = tij*up_n;
230
231 // partial derivative of the wetting phase flux w.r.t. p_w
232 dI_dI[conti0EqIdx+0][pressureIdx] += tij_up_w;
233 dI_dJ[conti0EqIdx+0][pressureIdx] -= tij_up_w;
234
235 // partial derivative of the wetting phase flux w.r.t. S_n
236 dI_dI[conti0EqIdx+0][saturationIdx] += rho_mu_flux_w*dKrw_dSn_inside*insideWeight_w;
237 dI_dJ[conti0EqIdx+0][saturationIdx] += rho_mu_flux_w*dKrw_dSn_outside*outsideWeight_w;
238
239 // partial derivative of the non-wetting phase flux w.r.t. p_w
240 dI_dI[conti0EqIdx+1][pressureIdx] += tij_up_n;
241 dI_dJ[conti0EqIdx+1][pressureIdx] -= tij_up_n;
242
243 // partial derivative of the non-wetting phase flux w.r.t. S_n (relative permeability derivative contribution)
244 dI_dI[conti0EqIdx+1][saturationIdx] += rho_mu_flux_n*dKrn_dSn_inside*insideWeight_n;
245 dI_dJ[conti0EqIdx+1][saturationIdx] += rho_mu_flux_n*dKrn_dSn_outside*outsideWeight_n;
246
247 // partial derivative of the non-wetting phase flux w.r.t. S_n (capillary pressure derivative contribution)
248 dI_dI[conti0EqIdx+1][saturationIdx] += tij_up_n*dpc_dSn_inside;
249 dI_dJ[conti0EqIdx+1][saturationIdx] -= tij_up_n*dpc_dSn_outside;
250 }
251
266 template<class JacobianMatrix, class T = TypeTag>
267 std::enable_if_t<GetPropType<T, Properties::GridGeometry>::discMethod == DiscretizationMethod::box, void>
268 addFluxDerivatives(JacobianMatrix& A,
269 const Problem& problem,
270 const Element& element,
271 const FVElementGeometry& fvGeometry,
272 const ElementVolumeVariables& curElemVolVars,
273 const ElementFluxVariablesCache& elemFluxVarsCache,
274 const SubControlVolumeFace& scvf) const
275 {
276 static_assert(!FluidSystem::isCompressible(0),
277 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
278 static_assert(!FluidSystem::isCompressible(1),
279 "2p/incompressiblelocalresidual.hh: Only incompressible fluids are allowed!");
280 static_assert(FluidSystem::viscosityIsConstant(0),
281 "2p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
282 static_assert(FluidSystem::viscosityIsConstant(1),
283 "2p/incompressiblelocalresidual.hh: Only fluids with constant viscosities are allowed!");
284 static_assert(ModelTraits::numFluidPhases() == 2,
285 "2p/incompressiblelocalresidual.hh: Only two-phase models are allowed!");
286 static_assert(ModelTraits::priVarFormulation() == TwoPFormulation::p0s1,
287 "2p/incompressiblelocalresidual.hh: Analytic differentiation has to be checked for p0-s1 formulation!");
288
289 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
291
292 // evaluate the current wetting phase Darcy flux and resulting upwind weights
293 static const Scalar upwindWeight = getParamFromGroup<Scalar>(problem.paramGroup(), "Flux.UpwindWeight");
294 const auto flux_w = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 0, elemFluxVarsCache);
295 const auto flux_n = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 1, elemFluxVarsCache);
296 const auto insideWeight_w = std::signbit(flux_w) ? (1.0 - upwindWeight) : upwindWeight;
297 const auto outsideWeight_w = 1.0 - insideWeight_w;
298 const auto insideWeight_n = std::signbit(flux_n) ? (1.0 - upwindWeight) : upwindWeight;
299 const auto outsideWeight_n = 1.0 - insideWeight_n;
300
301 // get references to the two participating vol vars & parameters
302 const auto insideScvIdx = scvf.insideScvIdx();
303 const auto outsideScvIdx = scvf.outsideScvIdx();
304 const auto& insideScv = fvGeometry.scv(insideScvIdx);
305 const auto& outsideScv = fvGeometry.scv(outsideScvIdx);
306 const auto& insideVolVars = curElemVolVars[insideScv];
307 const auto& outsideVolVars = curElemVolVars[outsideScv];
308
309 const auto elemSol = elementSolution(element, curElemVolVars, fvGeometry);
310
311 const auto& insideMaterialParams = problem.spatialParams().materialLawParams(element, insideScv, elemSol);
312 const auto& outsideMaterialParams = problem.spatialParams().materialLawParams(element, outsideScv, elemSol);
313
314 // some quantities to be reused (rho & mu are constant and thus equal for all cells)
315 static const auto rho_w = insideVolVars.density(0);
316 static const auto rho_n = insideVolVars.density(1);
317 static const auto rhow_muw = rho_w/insideVolVars.viscosity(0);
318 static const auto rhon_mun = rho_n/insideVolVars.viscosity(1);
319 const auto rhowKrw_muw_inside = rho_w*insideVolVars.mobility(0);
320 const auto rhonKrn_mun_inside = rho_n*insideVolVars.mobility(1);
321 const auto rhowKrw_muw_outside = rho_w*outsideVolVars.mobility(0);
322 const auto rhonKrn_mun_outside = rho_n*outsideVolVars.mobility(1);
323
324 // let the Law for the advective fluxes calculate the transmissibilities
325 const auto ti = AdvectionType::calculateTransmissibilities(problem,
326 element,
327 fvGeometry,
328 curElemVolVars,
329 scvf,
330 elemFluxVarsCache[scvf]);
331
332 // get the rows of the jacobian matrix for the inside/outside scv
333 auto& dI_dJ_inside = A[insideScv.dofIndex()];
334 auto& dI_dJ_outside = A[outsideScv.dofIndex()];
335
336 // precalculate values
337 const auto up_w = rhowKrw_muw_inside*insideWeight_w + rhowKrw_muw_outside*outsideWeight_w;
338 const auto up_n = rhonKrn_mun_inside*insideWeight_n + rhonKrn_mun_outside*outsideWeight_n;
339 const auto rho_mu_flux_w = rhow_muw*flux_w;
340 const auto rho_mu_flux_n = rhon_mun*flux_n;
341
342 // add the partial derivatives w.r.t all scvs in the element
343 for (const auto& scvJ : scvs(fvGeometry))
344 {
345 const auto globalJ = scvJ.dofIndex();
346 const auto localJ = scvJ.indexInElement();
347
348 // the transmissibily associated with the scvJ
349 const auto tj = ti[localJ];
350
351 // partial derivative of the wetting phase flux w.r.t. p_w
352 const auto tj_up_w = tj*up_w;
353 dI_dJ_inside[globalJ][conti0EqIdx+0][pressureIdx] += tj_up_w;
354 dI_dJ_outside[globalJ][conti0EqIdx+0][pressureIdx] -= tj_up_w;
355
356 // partial derivative of the non-wetting phase flux w.r.t. p_w
357 const auto tj_up_n = tj*up_n;
358 dI_dJ_inside[globalJ][conti0EqIdx+1][pressureIdx] += tj_up_n;
359 dI_dJ_outside[globalJ][conti0EqIdx+1][pressureIdx] -= tj_up_n;
360
361 // partial derivatives w.r.t. S_n (are the negative of those w.r.t sw)
362 // relative permeability contributions only for inside/outside
363 if (localJ == insideScvIdx)
364 {
365 // partial derivative of the wetting phase flux w.r.t. S_n
366 const auto insideSw = insideVolVars.saturation(0);
367 const auto dKrw_dSn_inside = -1.0*MaterialLaw::dkrw_dsw(insideMaterialParams, insideSw);
368 const auto dFluxW_dSnJ = rho_mu_flux_w*dKrw_dSn_inside*insideWeight_w;
369 dI_dJ_inside[globalJ][conti0EqIdx+0][saturationIdx] += dFluxW_dSnJ;
370 dI_dJ_outside[globalJ][conti0EqIdx+0][saturationIdx] -= dFluxW_dSnJ;
371
372 // partial derivative of the non-wetting phase flux w.r.t. S_n (k_rn contribution)
373 const auto dKrn_dSn_inside = -1.0*MaterialLaw::dkrn_dsw(insideMaterialParams, insideSw);
374 const auto dFluxN_dSnJ_krn = rho_mu_flux_n*dKrn_dSn_inside*insideWeight_n;
375 dI_dJ_inside[globalJ][conti0EqIdx+1][saturationIdx] += dFluxN_dSnJ_krn;
376 dI_dJ_outside[globalJ][conti0EqIdx+1][saturationIdx] -= dFluxN_dSnJ_krn;
377
378 // partial derivative of the non-wetting phase flux w.r.t. S_n (p_c contribution)
379 const auto dFluxN_dSnJ_pc = -1.0*tj_up_n*MaterialLaw::dpc_dsw(insideMaterialParams, insideSw);
380 dI_dJ_inside[globalJ][conti0EqIdx+1][saturationIdx] += dFluxN_dSnJ_pc;
381 dI_dJ_outside[globalJ][conti0EqIdx+1][saturationIdx] -= dFluxN_dSnJ_pc;
382 }
383 else if (localJ == outsideScvIdx)
384 {
385 // see comments for (globalJ == insideScvIdx)
386 const auto outsideSw = outsideVolVars.saturation(0);
387 const auto dKrw_dSn_outside = -1.0*MaterialLaw::dkrw_dsw(outsideMaterialParams, outsideSw);
388 const auto dFluxW_dSnJ = rho_mu_flux_w*dKrw_dSn_outside*outsideWeight_w;
389 dI_dJ_inside[globalJ][conti0EqIdx+0][saturationIdx] += dFluxW_dSnJ;
390 dI_dJ_outside[globalJ][conti0EqIdx+0][saturationIdx] -= dFluxW_dSnJ;
391
392 const auto dKrn_dSn_outside = -1.0*MaterialLaw::dkrn_dsw(outsideMaterialParams, outsideSw);
393 const auto dFluxN_dSnJ_krn = rho_mu_flux_n*dKrn_dSn_outside*outsideWeight_n;
394 dI_dJ_inside[globalJ][conti0EqIdx+1][saturationIdx] += dFluxN_dSnJ_krn;
395 dI_dJ_outside[globalJ][conti0EqIdx+1][saturationIdx] -= dFluxN_dSnJ_krn;
396
397 const auto dFluxN_dSnJ_pc = -1.0*tj_up_n*MaterialLaw::dpc_dsw(outsideMaterialParams, outsideSw);
398 dI_dJ_inside[globalJ][conti0EqIdx+1][saturationIdx] += dFluxN_dSnJ_pc;
399 dI_dJ_outside[globalJ][conti0EqIdx+1][saturationIdx] -= dFluxN_dSnJ_pc;
400 }
401 else
402 {
403 const auto& paramsJ = problem.spatialParams().materialLawParams(element, scvJ, elemSol);
404 const auto swJ = curElemVolVars[scvJ].saturation(0);
405 const auto dFluxN_dSnJ_pc = tj_up_n*MaterialLaw::dpc_dsw(paramsJ, swJ);
406 dI_dJ_inside[globalJ][conti0EqIdx+1][saturationIdx] -= dFluxN_dSnJ_pc;
407 dI_dJ_outside[globalJ][conti0EqIdx+1][saturationIdx] += dFluxN_dSnJ_pc;
408 }
409 }
410 }
411
426 template<class PartialDerivativeMatrices>
427 void addCCDirichletFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
428 const Problem& problem,
429 const Element& element,
430 const FVElementGeometry& fvGeometry,
431 const ElementVolumeVariables& curElemVolVars,
432 const ElementFluxVariablesCache& elemFluxVarsCache,
433 const SubControlVolumeFace& scvf) const
434 {
435 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
437
438 // evaluate the current wetting phase Darcy flux and resulting upwind weights
439 static const Scalar upwindWeight = getParamFromGroup<Scalar>(problem.paramGroup(), "Flux.UpwindWeight");
440 const auto flux_w = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 0, elemFluxVarsCache);
441 const auto flux_n = AdvectionType::flux(problem, element, fvGeometry, curElemVolVars, scvf, 1, elemFluxVarsCache);
442 const auto insideWeight_w = std::signbit(flux_w) ? (1.0 - upwindWeight) : upwindWeight;
443 const auto outsideWeight_w = 1.0 - insideWeight_w;
444 const auto insideWeight_n = std::signbit(flux_n) ? (1.0 - upwindWeight) : upwindWeight;
445 const auto outsideWeight_n = 1.0 - insideWeight_n;
446
447 // get references to the two participating vol vars & parameters
448 const auto insideScvIdx = scvf.insideScvIdx();
449 const auto& insideScv = fvGeometry.scv(insideScvIdx);
450 const auto& insideVolVars = curElemVolVars[insideScvIdx];
451 const auto& outsideVolVars = curElemVolVars[scvf.outsideScvIdx()];
452 const auto& insideMaterialParams = problem.spatialParams().materialLawParams(element,
453 insideScv,
454 elementSolution<FVElementGeometry>(insideVolVars.priVars()));
455
456 // some quantities to be reused (rho & mu are constant and thus equal for all cells)
457 static const auto rho_w = insideVolVars.density(0);
458 static const auto rho_n = insideVolVars.density(1);
459 static const auto rhow_muw = rho_w/insideVolVars.viscosity(0);
460 static const auto rhon_mun = rho_n/insideVolVars.viscosity(1);
461 const auto rhowKrw_muw_inside = rho_w*insideVolVars.mobility(0);
462 const auto rhonKrn_mun_inside = rho_n*insideVolVars.mobility(1);
463 const auto rhowKrw_muw_outside = rho_w*outsideVolVars.mobility(0);
464 const auto rhonKrn_mun_outside = rho_n*outsideVolVars.mobility(1);
465
466 // get reference to the inside derivative matrix
467 auto& dI_dI = derivativeMatrices[insideScvIdx];
468
469 // derivative w.r.t. to Sn is the negative of the one w.r.t. Sw
470 const auto insideSw = insideVolVars.saturation(0);
471 const auto dKrw_dSn_inside = -1.0*MaterialLaw::dkrw_dsw(insideMaterialParams, insideSw);
472 const auto dKrn_dSn_inside = -1.0*MaterialLaw::dkrn_dsw(insideMaterialParams, insideSw);
473 const auto dpc_dSn_inside = -1.0*MaterialLaw::dpc_dsw(insideMaterialParams, insideSw);
474
475 const auto tij = elemFluxVarsCache[scvf].advectionTij();
476 // partial derivative of the wetting phase flux w.r.t. p_w
477 const auto up_w = rhowKrw_muw_inside*insideWeight_w + rhowKrw_muw_outside*outsideWeight_w;
478 dI_dI[conti0EqIdx+0][pressureIdx] += tij*up_w;
479
480 // partial derivative of the wetting phase flux w.r.t. S_n
481 dI_dI[conti0EqIdx+0][saturationIdx] += rhow_muw*flux_w*dKrw_dSn_inside*insideWeight_w;
482
483 // partial derivative of the non-wetting phase flux w.r.t. p_w
484 const auto up_n = rhonKrn_mun_inside*insideWeight_n + rhonKrn_mun_outside*outsideWeight_n;
485 dI_dI[conti0EqIdx+1][pressureIdx] += tij*up_n;
486
487 // partial derivative of the non-wetting phase flux w.r.t. S_n (relative permeability derivative contribution)
488 dI_dI[conti0EqIdx+1][saturationIdx] += rhon_mun*flux_n*dKrn_dSn_inside*insideWeight_n;
489
490 // partial derivative of the non-wetting phase flux w.r.t. S_n (capillary pressure derivative contribution)
491 dI_dI[conti0EqIdx+1][saturationIdx] += tij*dpc_dSn_inside*up_n;
492 }
493
505 template<class PartialDerivativeMatrices>
506 void addRobinFluxDerivatives(PartialDerivativeMatrices& derivativeMatrices,
507 const Problem& problem,
508 const Element& element,
509 const FVElementGeometry& fvGeometry,
510 const ElementVolumeVariables& curElemVolVars,
511 const ElementFluxVariablesCache& elemFluxVarsCache,
512 const SubControlVolumeFace& scvf) const
513 { /* TODO maybe forward to problem for the user to implement the Robin derivatives?*/ }
514};
515
516} // end namespace Dumux
517
518#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Element solution classes and factory functions.
The available discretization methods in Dumux.
Defines an enumeration for the formulations accepted by the two-phase model.
@ p0s1
first phase pressure and second phase saturation as primary variables
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Element-wise calculation of the residual and its derivatives for a two-phase, incompressible test pro...
Definition: 2p/incompressiblelocalresidual.hh:49
void addStorageDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Adds storage derivatives for wetting and non-wetting phase.
Definition: 2p/incompressiblelocalresidual.hh:90
void addRobinFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Adds Robin flux derivatives for wetting and non-wetting phase.
Definition: 2p/incompressiblelocalresidual.hh:506
void addSourceDerivatives(PartialDerivativeMatrix &partialDerivatives, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const VolumeVariables &curVolVars, const SubControlVolume &scv) const
Adds source derivatives for wetting and non-wetting phase.
Definition: 2p/incompressiblelocalresidual.hh:125
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethod::cctpfa, void > addFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Adds flux derivatives for wetting and non-wetting phase for cell-centered FVM using TPFA.
Definition: 2p/incompressiblelocalresidual.hh:149
std::enable_if_t< GetPropType< T, Properties::GridGeometry >::discMethod==DiscretizationMethod::box, void > addFluxDerivatives(JacobianMatrix &A, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Adds flux derivatives for wetting and non-wetting phase for box method.
Definition: 2p/incompressiblelocalresidual.hh:268
void addCCDirichletFluxDerivatives(PartialDerivativeMatrices &derivativeMatrices, const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const SubControlVolumeFace &scvf) const
Adds cell-centered Dirichlet flux derivatives for wetting and non-wetting phase.
Definition: 2p/incompressiblelocalresidual.hh:427
Element-wise calculation of the residual for problems using the n-phase immiscible fully implicit mod...
Definition: porousmediumflow/immiscible/localresidual.hh:39
Declares all properties used in Dumux.
Element-wise calculation of the residual for problems using the n-phase immiscible fully implicit mod...