blackoillocalresidualtpfa.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 This file is part of the Open Porous Media project (OPM).
5
6 OPM 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 2 of the License, or
9 (at your option) any later version.
10
11 OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef EWOMS_BLACK_OIL_LOCAL_TPFA_RESIDUAL_HH
29#define EWOMS_BLACK_OIL_LOCAL_TPFA_RESIDUAL_HH
30
31#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
32#include <opm/input/eclipse/Schedule/BCProp.hpp>
33
34#include <opm/material/common/MathToolbox.hpp>
35#include <opm/material/fluidstates/BlackOilFluidState.hpp>
36#include <opm/material/common/ConditionalStorage.hpp>
37
49
50#include <array>
51#include <cassert>
52#include <stdexcept>
53#include <string>
54
55namespace Opm {
61template <class TypeTag>
62class BlackOilLocalResidualTPFA : public GetPropType<TypeTag, Properties::DiscLocalResidual>
63{
75 using FluidState = typename IntensiveQuantities::FluidState;
76
77 enum { conti0EqIdx = Indices::conti0EqIdx };
78 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
79 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
80 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
81
82 enum { dimWorld = GridView::dimensionworld };
83 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
84 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
85 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
86
87 enum { gasCompIdx = FluidSystem::gasCompIdx };
88 enum { oilCompIdx = FluidSystem::oilCompIdx };
89 enum { waterCompIdx = FluidSystem::waterCompIdx };
90 enum { compositionSwitchIdx = Indices::compositionSwitchIdx };
91
92 static constexpr bool waterEnabled = Indices::waterEnabled;
93 static constexpr bool gasEnabled = Indices::gasEnabled;
94 static constexpr bool oilEnabled = Indices::oilEnabled;
95 static constexpr bool compositionSwitchEnabled = compositionSwitchIdx >= 0;
96
97 static constexpr bool blackoilConserveSurfaceVolume =
98 getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
99
100 static constexpr bool enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>();
101 static constexpr bool enableExtbo = getPropValue<TypeTag, Properties::EnableExtbo>();
102 static constexpr bool enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>();
103 static constexpr bool enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>();
104 static constexpr bool enableFoam = getPropValue<TypeTag, Properties::EnableFoam>();
105 static constexpr bool enableBrine = getPropValue<TypeTag, Properties::EnableBrine>();
106 static constexpr bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
107 static constexpr bool enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>();
108 static constexpr bool enableConvectiveMixing = getPropValue<TypeTag, Properties::EnableConvectiveMixing>();
109 static constexpr bool enableMICP = getPropValue<TypeTag, Properties::EnableMICP>();
110
119 using ConvectiveMixingModuleParam = typename ConvectiveMixingModule::ConvectiveMixingModuleParam;
120
123
124 using Toolbox = MathToolbox<Evaluation>;
125
126public:
128 {
129 double trans;
130 double faceArea;
131 double thpres;
132 double dZg;
133 FaceDir::DirEnum faceDir;
134 double Vin;
135 double Vex;
136 ConditionalStorage<enableEnergy, double> inAlpha;
137 ConditionalStorage<enableEnergy, double> outAlpha;
138 ConditionalStorage<enableDiffusion, double> diffusivity;
139 ConditionalStorage<enableDispersion, double> dispersivity;
140 };
141
143 {
144 ConvectiveMixingModuleParam convectiveMixingModuleParam;
145 };
146
150 template <class LhsEval>
151 void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
152 const ElementContext& elemCtx,
153 unsigned dofIdx,
154 unsigned timeIdx) const
155 {
156 const IntensiveQuantities& intQuants = elemCtx.intensiveQuantities(dofIdx, timeIdx);
157 computeStorage(storage, intQuants);
158 }
159
160 template <class LhsEval>
161 static void computeStorage(Dune::FieldVector<LhsEval, numEq>& storage,
162 const IntensiveQuantities& intQuants)
163 {
164 OPM_TIMEBLOCK_LOCAL(computeStorage);
165 // retrieve the intensive quantities for the SCV at the specified point in time
166 const auto& fs = intQuants.fluidState();
167 storage = 0.0;
168
169 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
170 if (!FluidSystem::phaseIsActive(phaseIdx)) {
171 continue;
172 }
173 unsigned activeCompIdx =
174 Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
175 LhsEval surfaceVolume =
176 Toolbox::template decay<LhsEval>(fs.saturation(phaseIdx)) *
177 Toolbox::template decay<LhsEval>(fs.invB(phaseIdx)) *
178 Toolbox::template decay<LhsEval>(intQuants.porosity());
179
180 storage[conti0EqIdx + activeCompIdx] += surfaceVolume;
181
182 // account for dissolved gas
183 if (phaseIdx == oilPhaseIdx && FluidSystem::enableDissolvedGas()) {
184 unsigned activeGasCompIdx = Indices::canonicalToActiveComponentIndex(gasCompIdx);
185 storage[conti0EqIdx + activeGasCompIdx] +=
186 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rs()) *
187 surfaceVolume;
188 }
189
190 // account for dissolved gas in water
191 if (phaseIdx == waterPhaseIdx && FluidSystem::enableDissolvedGasInWater()) {
192 unsigned activeGasCompIdx = Indices::canonicalToActiveComponentIndex(gasCompIdx);
193 storage[conti0EqIdx + activeGasCompIdx] +=
194 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rsw()) *
195 surfaceVolume;
196 }
197
198 // account for vaporized oil
199 if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedOil()) {
200 unsigned activeOilCompIdx = Indices::canonicalToActiveComponentIndex(oilCompIdx);
201 storage[conti0EqIdx + activeOilCompIdx] +=
202 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rv()) *
203 surfaceVolume;
204 }
205
206 // account for vaporized water
207 if (phaseIdx == gasPhaseIdx && FluidSystem::enableVaporizedWater()) {
208 unsigned activeWaterCompIdx = Indices::canonicalToActiveComponentIndex(waterCompIdx);
209 storage[conti0EqIdx + activeWaterCompIdx] +=
210 Toolbox::template decay<LhsEval>(intQuants.fluidState().Rvw()) *
211 surfaceVolume;
212 }
213 }
214
215 adaptMassConservationQuantities_(storage, intQuants.pvtRegionIndex());
216
217 // deal with solvents (if present)
218 SolventModule::addStorage(storage, intQuants);
219
220 // deal with zFracton (if present)
221 ExtboModule::addStorage(storage, intQuants);
222
223 // deal with polymer (if present)
224 PolymerModule::addStorage(storage, intQuants);
225
226 // deal with energy (if present)
227 EnergyModule::addStorage(storage, intQuants);
228
229 // deal with foam (if present)
230 FoamModule::addStorage(storage, intQuants);
231
232 // deal with salt (if present)
233 BrineModule::addStorage(storage, intQuants);
234
235 // deal with micp (if present)
236 MICPModule::addStorage(storage, intQuants);
237 }
238
244 static void computeFlux(RateVector& flux,
245 RateVector& darcy,
246 const unsigned globalIndexIn,
247 const unsigned globalIndexEx,
248 const IntensiveQuantities& intQuantsIn,
249 const IntensiveQuantities& intQuantsEx,
250 const ResidualNBInfo& nbInfo,
251 const ModuleParams& moduleParams)
252 {
253 OPM_TIMEBLOCK_LOCAL(computeFlux);
254 flux = 0.0;
255 darcy = 0.0;
256
257 calculateFluxes_(flux,
258 darcy,
259 intQuantsIn,
260 intQuantsEx,
261 globalIndexIn,
262 globalIndexEx,
263 nbInfo,
264 moduleParams);
265 }
266
267 // This function demonstrates compatibility with the ElementContext-based interface.
268 // Actually using it will lead to double work since the element context already contains
269 // fluxes through its stored ExtensiveQuantities.
270 static void computeFlux(RateVector& flux,
271 const ElementContext& elemCtx,
272 unsigned scvfIdx,
273 unsigned timeIdx)
274 {
275 OPM_TIMEBLOCK_LOCAL(computeFlux);
276 assert(timeIdx == 0);
277
278 flux = 0.0;
279 RateVector darcy = 0.0;
280 // need for dary flux calculation
281 const auto& problem = elemCtx.problem();
282 const auto& stencil = elemCtx.stencil(timeIdx);
283 const auto& scvf = stencil.interiorFace(scvfIdx);
284
285 unsigned interiorDofIdx = scvf.interiorIndex();
286 unsigned exteriorDofIdx = scvf.exteriorIndex();
287 assert(interiorDofIdx != exteriorDofIdx);
288
289 // unsigned I = stencil.globalSpaceIndex(interiorDofIdx);
290 // unsigned J = stencil.globalSpaceIndex(exteriorDofIdx);
291 Scalar Vin = elemCtx.dofVolume(interiorDofIdx, /*timeIdx=*/0);
292 Scalar Vex = elemCtx.dofVolume(exteriorDofIdx, /*timeIdx=*/0);
293 const auto& globalIndexIn = stencil.globalSpaceIndex(interiorDofIdx);
294 const auto& globalIndexEx = stencil.globalSpaceIndex(exteriorDofIdx);
295 Scalar trans = problem.transmissibility(elemCtx, interiorDofIdx, exteriorDofIdx);
296 Scalar faceArea = scvf.area();
297 const auto faceDir = faceDirFromDirId(scvf.dirId());
298 Scalar thpres = problem.thresholdPressure(globalIndexIn, globalIndexEx);
299
300 // estimate the gravity correction: for performance reasons we use a simplified
301 // approach for this flux module that assumes that gravity is constant and always
302 // acts into the downwards direction. (i.e., no centrifuge experiments, sorry.)
303 const Scalar g = problem.gravity()[dimWorld - 1];
304 const auto& intQuantsIn = elemCtx.intensiveQuantities(interiorDofIdx, timeIdx);
305 const auto& intQuantsEx = elemCtx.intensiveQuantities(exteriorDofIdx, timeIdx);
306
307 // this is quite hacky because the dune grid interface does not provide a
308 // cellCenterDepth() method (so we ask the problem to provide it). The "good"
309 // solution would be to take the Z coordinate of the element centroids, but since
310 // ECL seems to like to be inconsistent on that front, it needs to be done like
311 // here...
312 const Scalar zIn = problem.dofCenterDepth(elemCtx, interiorDofIdx, timeIdx);
313 const Scalar zEx = problem.dofCenterDepth(elemCtx, exteriorDofIdx, timeIdx);
314 // the distances from the DOF's depths. (i.e., the additional depth of the
315 // exterior DOF)
316 const Scalar distZ = zIn - zEx;
317 // for thermal harmonic mean of half trans
318 const Scalar inAlpha = problem.thermalHalfTransmissibility(globalIndexIn, globalIndexEx);
319 const Scalar outAlpha = problem.thermalHalfTransmissibility(globalIndexEx, globalIndexIn);
320 const Scalar diffusivity = problem.diffusivity(globalIndexEx, globalIndexIn);
321 const Scalar dispersivity = problem.dispersivity(globalIndexEx, globalIndexIn);
322
323 const ResidualNBInfo res_nbinfo {
324 trans, faceArea, thpres, distZ * g, faceDir, Vin, Vex,
325 inAlpha, outAlpha, diffusivity, dispersivity
326 };
327
328 calculateFluxes_(flux,
329 darcy,
330 intQuantsIn,
331 intQuantsEx,
332 globalIndexIn,
333 globalIndexEx,
334 res_nbinfo,
335 problem.moduleParams());
336 }
337
338 static void calculateFluxes_(RateVector& flux,
339 RateVector& darcy,
340 const IntensiveQuantities& intQuantsIn,
341 const IntensiveQuantities& intQuantsEx,
342 const unsigned& globalIndexIn,
343 const unsigned& globalIndexEx,
344 const ResidualNBInfo& nbInfo,
345 const ModuleParams& moduleParams)
346 {
347 OPM_TIMEBLOCK_LOCAL(calculateFluxes);
348 const Scalar Vin = nbInfo.Vin;
349 const Scalar Vex = nbInfo.Vex;
350 const Scalar distZg = nbInfo.dZg;
351 const Scalar thpres = nbInfo.thpres;
352 const Scalar trans = nbInfo.trans;
353 const Scalar faceArea = nbInfo.faceArea;
354 FaceDir::DirEnum facedir = nbInfo.faceDir;
355
356 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
357 if (!FluidSystem::phaseIsActive(phaseIdx)) {
358 continue;
359 }
360 // darcy flux calculation
361 short dnIdx;
362 //
363 short upIdx;
364 // fake intices should only be used to get upwind anc compatibility with old functions
365 short interiorDofIdx = 0; // NB
366 short exteriorDofIdx = 1; // NB
367 Evaluation pressureDifference;
368 ExtensiveQuantities::calculatePhasePressureDiff_(upIdx,
369 dnIdx,
370 pressureDifference,
371 intQuantsIn,
372 intQuantsEx,
373 phaseIdx, // input
374 interiorDofIdx, // input
375 exteriorDofIdx, // input
376 Vin,
377 Vex,
378 globalIndexIn,
379 globalIndexEx,
380 distZg,
381 thpres,
382 moduleParams);
383
384 const IntensiveQuantities& up = (upIdx == interiorDofIdx) ? intQuantsIn : intQuantsEx;
385 unsigned globalUpIndex = (upIdx == interiorDofIdx) ? globalIndexIn : globalIndexEx;
386 // Use arithmetic average (more accurate with harmonic, but that requires recomputing the transmissbility)
387 Evaluation transMult = (intQuantsIn.rockCompTransMultiplier() +
388 Toolbox::value(intQuantsEx.rockCompTransMultiplier())) / 2;
389 if constexpr (enableMICP) {
390 transMult *= (intQuantsIn.permFactor() + Toolbox::value(intQuantsEx.permFactor())) / 2;
391 }
392 Evaluation darcyFlux;
393 if (globalUpIndex == globalIndexIn) {
394 darcyFlux = pressureDifference * up.mobility(phaseIdx, facedir) * transMult * (-trans / faceArea);
395 } else {
396 darcyFlux = pressureDifference *
397 (Toolbox::value(up.mobility(phaseIdx, facedir)) * transMult * (-trans / faceArea));
398 }
399
400 unsigned activeCompIdx =
401 Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
402 // NB! For the FLORES fluxes without derivatives
403 darcy[conti0EqIdx + activeCompIdx] = darcyFlux.value() * faceArea;
404
405 unsigned pvtRegionIdx = up.pvtRegionIndex();
406 // if (upIdx == globalFocusDofIdx){
407 if (globalUpIndex == globalIndexIn) {
408 const auto& invB
409 = getInvB_<FluidSystem, FluidState, Evaluation>(up.fluidState(), phaseIdx, pvtRegionIdx);
410 const auto& surfaceVolumeFlux = invB * darcyFlux;
411 evalPhaseFluxes_<Evaluation>(flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
412 if constexpr (enableEnergy) {
413 EnergyModule::template
414 addPhaseEnthalpyFluxes_<Evaluation>(flux, phaseIdx, darcyFlux, up.fluidState());
415 }
416 if constexpr (enableMICP) {
417 MICPModule::template
418 addMICPFluxes_<Evaluation>(flux, darcyFlux, intQuantsIn);
419 }
420 } else {
421 const auto& invB = getInvB_<FluidSystem, FluidState, Scalar>(up.fluidState(), phaseIdx, pvtRegionIdx);
422 const auto& surfaceVolumeFlux = invB * darcyFlux;
423 evalPhaseFluxes_<Scalar>(flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, up.fluidState());
424 if constexpr (enableEnergy) {
425 EnergyModule::template
426 addPhaseEnthalpyFluxes_<Scalar>(flux,phaseIdx,darcyFlux, up.fluidState());
427 }
428 if constexpr (enableMICP) {
429 MICPModule::template
430 addMICPFluxes_<Scalar>(flux, darcyFlux, intQuantsEx);
431 }
432 }
433
434 }
435
436 // deal with solvents (if present)
437 static_assert(!enableSolvent,
438 "Relevant computeFlux() method must be implemented for this module before enabling.");
439 // SolventModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
440
441 // deal with zFracton (if present)
442 static_assert(!enableExtbo,
443 "Relevant computeFlux() method must be implemented for this module before enabling.");
444 // ExtboModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
445
446 // deal with polymer (if present)
447 static_assert(!enablePolymer,
448 "Relevant computeFlux() method must be implemented for this module before enabling.");
449 // PolymerModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
450
451 // deal with convective mixing
452 if constexpr (enableConvectiveMixing) {
453 ConvectiveMixingModule::addConvectiveMixingFlux(flux,
454 intQuantsIn,
455 intQuantsEx,
456 globalIndexIn,
457 globalIndexEx,
458 nbInfo.dZg,
459 nbInfo.trans,
460 nbInfo.faceArea,
461 moduleParams.convectiveMixingModuleParam);
462 }
463
464 // deal with energy (if present)
465 if constexpr (enableEnergy) {
466 const Scalar inAlpha = nbInfo.inAlpha;
467 const Scalar outAlpha = nbInfo.outAlpha;
468 Evaluation heatFlux;
469
470 short interiorDofIdx = 0; // NB
471 short exteriorDofIdx = 1; // NB
472
473 EnergyModule::ExtensiveQuantities::updateEnergy(heatFlux,
474 interiorDofIdx, // focusDofIndex,
475 interiorDofIdx,
476 exteriorDofIdx,
477 intQuantsIn,
478 intQuantsEx,
479 intQuantsIn.fluidState(),
480 intQuantsEx.fluidState(),
481 inAlpha,
482 outAlpha,
483 faceArea);
484 EnergyModule::addHeatFlux(flux, heatFlux);
485 }
486 // NB need to be tha last energy call since it does scaling
487 // EnergyModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
488
489 // deal with foam (if present)
490 static_assert(!enableFoam,
491 "Relevant computeFlux() method must be implemented for this module before enabling.");
492 // FoamModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
493
494 // deal with salt (if present)
495 static_assert(!enableBrine,
496 "Relevant computeFlux() method must be implemented for this module before enabling.");
497 // BrineModule::computeFlux(flux, elemCtx, scvfIdx, timeIdx);
498
499 // deal with diffusion (if present). opm-models expects per area flux (added in the tmpdiffusivity).
500 if constexpr (enableDiffusion) {
501 typename DiffusionModule::ExtensiveQuantities::EvaluationArray effectiveDiffusionCoefficient;
502 DiffusionModule::ExtensiveQuantities::update(effectiveDiffusionCoefficient, intQuantsIn, intQuantsEx);
503 const Scalar diffusivity = nbInfo.diffusivity;
504 const Scalar tmpdiffusivity = diffusivity / faceArea;
505 DiffusionModule::addDiffusiveFlux(flux,
506 intQuantsIn,
507 intQuantsEx,
508 tmpdiffusivity,
509 effectiveDiffusionCoefficient);
510 }
511
512 // deal with dispersion (if present). opm-models expects per area flux (added in the tmpdispersivity).
513 if constexpr (enableDispersion) {
514 typename DispersionModule::ExtensiveQuantities::ScalarArray normVelocityAvg;
515 DispersionModule::ExtensiveQuantities::update(normVelocityAvg, intQuantsIn, intQuantsEx);
516 const Scalar dispersivity = nbInfo.dispersivity;
517 const Scalar tmpdispersivity = dispersivity / faceArea;
518 DispersionModule::addDispersiveFlux(flux,
519 intQuantsIn,
520 intQuantsEx,
521 tmpdispersivity,
522 normVelocityAvg);
523 }
524
525 // apply the scaling for the urea equation in MICP
526 if constexpr (enableMICP) {
528 }
529 }
530
531 template <class BoundaryConditionData>
532 static void computeBoundaryFlux(RateVector& bdyFlux,
533 const Problem& problem,
534 const BoundaryConditionData& bdyInfo,
535 const IntensiveQuantities& insideIntQuants,
536 unsigned globalSpaceIdx)
537 {
538 switch (bdyInfo.type) {
539 case BCType::NONE:
540 bdyFlux = 0.0;
541 break;
542 case BCType::RATE:
543 computeBoundaryFluxRate(bdyFlux, bdyInfo);
544 break;
545 case BCType::FREE:
546 case BCType::DIRICHLET:
547 computeBoundaryFluxFree(problem, bdyFlux, bdyInfo, insideIntQuants, globalSpaceIdx);
548 break;
549 case BCType::THERMAL:
550 computeBoundaryThermal(problem, bdyFlux, bdyInfo, insideIntQuants, globalSpaceIdx);
551 break;
552 default:
553 throw std::logic_error("Unknown boundary condition type " +
554 std::to_string(static_cast<int>(bdyInfo.type)) +
555 " in computeBoundaryFlux()." );
556 }
557 }
558
559 template <class BoundaryConditionData>
560 static void computeBoundaryFluxRate(RateVector& bdyFlux,
561 const BoundaryConditionData& bdyInfo)
562 {
563 bdyFlux.setMassRate(bdyInfo.massRate, bdyInfo.pvtRegionIdx);
564 }
565
566 template <class BoundaryConditionData>
567 static void computeBoundaryFluxFree(const Problem& problem,
568 RateVector& bdyFlux,
569 const BoundaryConditionData& bdyInfo,
570 const IntensiveQuantities& insideIntQuants,
571 unsigned globalSpaceIdx)
572 {
573 OPM_TIMEBLOCK_LOCAL(computeBoundaryFluxFree);
574 std::array<short, numPhases> upIdx;
575 std::array<short, numPhases> dnIdx;
576 std::array<Evaluation, numPhases> volumeFlux;
577 std::array<Evaluation, numPhases> pressureDifference;
578
579 ExtensiveQuantities::calculateBoundaryGradients_(problem,
580 globalSpaceIdx,
581 insideIntQuants,
582 bdyInfo.boundaryFaceIndex,
583 bdyInfo.faceArea,
584 bdyInfo.faceZCoord,
585 bdyInfo.exFluidState,
586 upIdx,
587 dnIdx,
588 volumeFlux,
589 pressureDifference);
590
592 // advective fluxes of all components in all phases
594 bdyFlux = 0.0;
595 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
596 if (!FluidSystem::phaseIsActive(phaseIdx)) {
597 continue;
598 }
599 const auto& pBoundary = bdyInfo.exFluidState.pressure(phaseIdx);
600 const Evaluation& pInside = insideIntQuants.fluidState().pressure(phaseIdx);
601 const unsigned pvtRegionIdx = insideIntQuants.pvtRegionIndex();
602
603 RateVector tmp(0.0);
604 const auto& darcyFlux = volumeFlux[phaseIdx];
605 // mass conservation
606 if (pBoundary < pInside) {
607 // outflux
608 const auto& invB =
609 getInvB_<FluidSystem, FluidState, Evaluation>(insideIntQuants.fluidState(), phaseIdx, pvtRegionIdx);
610 Evaluation surfaceVolumeFlux = invB * darcyFlux;
611 evalPhaseFluxes_<Evaluation>(tmp,
612 phaseIdx,
613 insideIntQuants.pvtRegionIndex(),
614 surfaceVolumeFlux,
615 insideIntQuants.fluidState());
616 if constexpr (enableEnergy) {
617 EnergyModule::template
618 addPhaseEnthalpyFluxes_<Evaluation>(tmp, phaseIdx, darcyFlux, insideIntQuants.fluidState());
619 }
620 } else if (pBoundary > pInside) {
621 // influx
622 using ScalarFluidState = decltype(bdyInfo.exFluidState);
623 const auto& invB =
624 getInvB_<FluidSystem, ScalarFluidState, Scalar>(bdyInfo.exFluidState, phaseIdx, pvtRegionIdx);
625 Evaluation surfaceVolumeFlux = invB * darcyFlux;
626 evalPhaseFluxes_<Scalar>(tmp,
627 phaseIdx,
628 insideIntQuants.pvtRegionIndex(),
629 surfaceVolumeFlux,
630 bdyInfo.exFluidState);
631 if constexpr (enableEnergy) {
632 EnergyModule::template
633 addPhaseEnthalpyFluxes_<Scalar>(tmp, phaseIdx, darcyFlux, bdyInfo.exFluidState);
634 }
635 }
636
637 for (unsigned i = 0; i < tmp.size(); ++i) {
638 bdyFlux[i] += tmp[i];
639 }
640 }
641
642 // conductive heat flux from boundary
643 if constexpr (enableEnergy) {
644 Evaluation heatFlux;
645 // avoid overload of functions with same number of elements in eclproblem
646 Scalar alpha =
647 problem.eclTransmissibilities().thermalHalfTransBoundary(globalSpaceIdx, bdyInfo.boundaryFaceIndex);
648 unsigned inIdx = 0; // dummy
649 // always calculated with derivatives of this cell
650 EnergyModule::ExtensiveQuantities::updateEnergyBoundary(heatFlux,
651 insideIntQuants,
652 /*focusDofIndex*/ inIdx,
653 inIdx,
654 alpha,
655 bdyInfo.exFluidState);
656 EnergyModule::addHeatFlux(bdyFlux, heatFlux);
657 }
658
659 static_assert(!enableSolvent,
660 "Relevant treatment of boundary conditions must be implemented before enabling.");
661 static_assert(!enablePolymer,
662 "Relevant treatment of boundary conditions must be implemented before enabling.");
663
664 // make sure that the right mass conservation quantities are used
665 adaptMassConservationQuantities_(bdyFlux, insideIntQuants.pvtRegionIndex());
666
667#ifndef NDEBUG
668 for (unsigned i = 0; i < numEq; ++i) {
669 Valgrind::CheckDefined(bdyFlux[i]);
670 }
671 Valgrind::CheckDefined(bdyFlux);
672#endif
673 }
674
675 template <class BoundaryConditionData>
676 static void computeBoundaryThermal(const Problem& problem,
677 RateVector& bdyFlux,
678 const BoundaryConditionData& bdyInfo,
679 const IntensiveQuantities& insideIntQuants,
680 [[maybe_unused]] unsigned globalSpaceIdx)
681 {
682 OPM_TIMEBLOCK_LOCAL(computeBoundaryThermal);
683 // only heat is allowed to flow through this boundary
684 bdyFlux = 0.0;
685
686 // conductive heat flux from boundary
687 if constexpr (enableEnergy) {
688 Evaluation heatFlux;
689 // avoid overload of functions with same numeber of elements in eclproblem
690 Scalar alpha =
691 problem.eclTransmissibilities().thermalHalfTransBoundary(globalSpaceIdx, bdyInfo.boundaryFaceIndex);
692 unsigned inIdx = 0;//dummy
693 // always calculated with derivatives of this cell
694 EnergyModule::ExtensiveQuantities::updateEnergyBoundary(heatFlux,
695 insideIntQuants,
696 /*focusDofIndex*/ inIdx,
697 inIdx,
698 alpha,
699 bdyInfo.exFluidState);
700 EnergyModule::addHeatFlux(bdyFlux, heatFlux);
701 }
702
703#ifndef NDEBUG
704 for (unsigned i = 0; i < numEq; ++i) {
705 Valgrind::CheckDefined(bdyFlux[i]);
706 }
707 Valgrind::CheckDefined(bdyFlux);
708#endif
709 }
710
711 static void computeSource(RateVector& source,
712 const Problem& problem,
713 const IntensiveQuantities& insideIntQuants,
714 unsigned globalSpaceIdex,
715 unsigned timeIdx)
716 {
717 OPM_TIMEBLOCK_LOCAL(computeSource);
718 // retrieve the source term intrinsic to the problem
719 problem.source(source, globalSpaceIdex, timeIdx);
720
721 // deal with MICP (if present)
722 MICPModule::addSource(source, problem, insideIntQuants, globalSpaceIdex);
723
724 // scale the source term of the energy equation
725 if constexpr (enableEnergy) {
726 source[Indices::contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
727 }
728 }
729
730 static void computeSourceDense(RateVector& source,
731 const Problem& problem,
732 const IntensiveQuantities& insideIntQuants,
733 unsigned globalSpaceIdex,
734 unsigned timeIdx)
735 {
736 source = 0.0;
737 problem.addToSourceDense(source, globalSpaceIdex, timeIdx);
738
739 // deal with MICP (if present)
740 MICPModule::addSource(source, problem, insideIntQuants, globalSpaceIdex);
741
742 // scale the source term of the energy equation
743 if constexpr (enableEnergy) {
744 source[Indices::contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
745 }
746 }
747
751 void computeSource(RateVector& source,
752 const ElementContext& elemCtx,
753 unsigned dofIdx,
754 unsigned timeIdx) const
755 {
756 OPM_TIMEBLOCK_LOCAL(computeSource);
757 // retrieve the source term intrinsic to the problem
758 elemCtx.problem().source(source, elemCtx, dofIdx, timeIdx);
759
760 // deal with MICP (if present)
761 MICPModule::addSource(source, elemCtx, dofIdx, timeIdx);
762
763 // scale the source term of the energy equation
764 if constexpr (enableEnergy) {
765 source[Indices::contiEnergyEqIdx] *= getPropValue<TypeTag, Properties::BlackOilEnergyScalingFactor>();
766 }
767 }
768
769 template <class UpEval, class FluidState>
770 static void evalPhaseFluxes_(RateVector& flux,
771 unsigned phaseIdx,
772 unsigned pvtRegionIdx,
773 const ExtensiveQuantities& extQuants,
774 const FluidState& upFs)
775 {
776 const auto& invB = getInvB_<FluidSystem, FluidState, UpEval>(upFs, phaseIdx, pvtRegionIdx);
777 const auto& surfaceVolumeFlux = invB * extQuants.volumeFlux(phaseIdx);
778 evalPhaseFluxes_<UpEval>(flux, phaseIdx, pvtRegionIdx, surfaceVolumeFlux, upFs);
779 }
780
785 template <class UpEval, class Eval,class FluidState>
786 static void evalPhaseFluxes_(RateVector& flux,
787 unsigned phaseIdx,
788 unsigned pvtRegionIdx,
789 const Eval& surfaceVolumeFlux,
790 const FluidState& upFs)
791 {
792 unsigned activeCompIdx =
793 Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
794
795 if constexpr (blackoilConserveSurfaceVolume) {
796 flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux;
797 }
798 else {
799 flux[conti0EqIdx + activeCompIdx] += surfaceVolumeFlux *
800 FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
801 }
802
803 if (phaseIdx == oilPhaseIdx) {
804 // dissolved gas (in the oil phase).
805 if (FluidSystem::enableDissolvedGas()) {
806 const auto& Rs = BlackOil::getRs_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
807
808 unsigned activeGasCompIdx = Indices::canonicalToActiveComponentIndex(gasCompIdx);
809 if constexpr (blackoilConserveSurfaceVolume) {
810 flux[conti0EqIdx + activeGasCompIdx] += Rs * surfaceVolumeFlux;
811 }
812 else {
813 flux[conti0EqIdx + activeGasCompIdx] +=
814 Rs * surfaceVolumeFlux *
815 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
816 }
817 }
818 }
819 else if (phaseIdx == waterPhaseIdx) {
820 // dissolved gas (in the water phase).
821 if (FluidSystem::enableDissolvedGasInWater()) {
822 const auto& Rsw = BlackOil::getRsw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
823
824 unsigned activeGasCompIdx = Indices::canonicalToActiveComponentIndex(gasCompIdx);
825 if constexpr (blackoilConserveSurfaceVolume) {
826 flux[conti0EqIdx + activeGasCompIdx] += Rsw * surfaceVolumeFlux;
827 }
828 else {
829 flux[conti0EqIdx + activeGasCompIdx] +=
830 Rsw * surfaceVolumeFlux *
831 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
832 }
833 }
834 }
835 else if (phaseIdx == gasPhaseIdx) {
836 // vaporized oil (in the gas phase).
837 if (FluidSystem::enableVaporizedOil()) {
838 const auto& Rv = BlackOil::getRv_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
839
840 unsigned activeOilCompIdx = Indices::canonicalToActiveComponentIndex(oilCompIdx);
841 if constexpr (blackoilConserveSurfaceVolume) {
842 flux[conti0EqIdx + activeOilCompIdx] += Rv * surfaceVolumeFlux;
843 }
844 else {
845 flux[conti0EqIdx + activeOilCompIdx] +=
846 Rv * surfaceVolumeFlux *
847 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
848 }
849 }
850 // vaporized water (in the gas phase).
851 if (FluidSystem::enableVaporizedWater()) {
852 const auto& Rvw = BlackOil::getRvw_<FluidSystem, FluidState, UpEval>(upFs, pvtRegionIdx);
853
854 unsigned activeWaterCompIdx = Indices::canonicalToActiveComponentIndex(waterCompIdx);
855 if constexpr (blackoilConserveSurfaceVolume) {
856 flux[conti0EqIdx + activeWaterCompIdx] += Rvw * surfaceVolumeFlux;
857 }
858 else {
859 flux[conti0EqIdx + activeWaterCompIdx] +=
860 Rvw * surfaceVolumeFlux *
861 FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
862 }
863 }
864 }
865 }
866
878 template <class Scalar>
879 static void adaptMassConservationQuantities_(Dune::FieldVector<Scalar, numEq>& container,
880 unsigned pvtRegionIdx)
881 {
882 if constexpr (!blackoilConserveSurfaceVolume) {
883 // convert "surface volume" to mass. this is complicated a bit by the fact that
884 // not all phases are necessarily enabled. (we here assume that if a fluid phase
885 // is disabled, its respective "main" component is not considered as well.)
886
887 if constexpr (waterEnabled) {
888 unsigned activeWaterCompIdx = Indices::canonicalToActiveComponentIndex(waterCompIdx);
889 container[conti0EqIdx + activeWaterCompIdx] *=
890 FluidSystem::referenceDensity(waterPhaseIdx, pvtRegionIdx);
891 }
892
893 if constexpr (gasEnabled) {
894 unsigned activeGasCompIdx = Indices::canonicalToActiveComponentIndex(gasCompIdx);
895 container[conti0EqIdx + activeGasCompIdx] *=
896 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx);
897 }
898
899 if constexpr (oilEnabled) {
900 unsigned activeOilCompIdx = Indices::canonicalToActiveComponentIndex(oilCompIdx);
901 container[conti0EqIdx + activeOilCompIdx] *=
902 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx);
903 }
904 }
905 }
906
907 // NNC does not have a direction
908 static FaceDir::DirEnum faceDirFromDirId(const int dirId)
909 { return dirId < 0 ? FaceDir::DirEnum::Unknown : FaceDir::FromIntersectionIndex(dirId); }
910};
911
912} // namespace Opm
913
914#endif
Contains the classes required to extend the black-oil model by brine.
Classes required for dynamic convective mixing.
Classes required for molecular diffusion.
Classes required for mechanical dispersion.
Contains the classes required to extend the black-oil model by energy.
Contains the classes required to extend the black-oil model by solvent component. For details,...
Contains the classes required to extend the black-oil model to include the effects of foam.
Contains the classes required to extend the black-oil model by MICP.
Contains the classes required to extend the black-oil model by polymer.
Declares the properties required by the black oil model.
Contains the classes required to extend the black-oil model by solvents.
Contains the high level supplements required to extend the black oil model by brine.
Definition: blackoilbrinemodules.hh:55
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilbrinemodules.hh:162
Definition: blackoilconvectivemixingmodule.hh:64
Provides the auxiliary methods required for consideration of the diffusion equation.
Definition: blackoildiffusionmodule.hh:50
Provides the auxiliary methods required for consideration of the dispersion equation.
Definition: blackoildispersionmodule.hh:58
Contains the high level supplements required to extend the black oil model by energy.
Definition: blackoilenergymodules.hh:58
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilenergymodules.hh:153
static void addHeatFlux(RateVector &flux, const Evaluation &heatFlux)
Definition: blackoilenergymodules.hh:211
Contains the high level supplements required to extend the black oil model.
Definition: blackoilextbomodules.hh:62
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilextbomodules.hh:162
Contains the high level supplements required to extend the black oil model to include the effects of ...
Definition: blackoilfoammodules.hh:58
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilfoammodules.hh:166
Calculates the local residual of the black oil model.
Definition: blackoillocalresidualtpfa.hh:63
void computeSource(RateVector &source, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Calculate the source term of the equation.
Definition: blackoillocalresidualtpfa.hh:751
static void computeBoundaryFlux(RateVector &bdyFlux, const Problem &problem, const BoundaryConditionData &bdyInfo, const IntensiveQuantities &insideIntQuants, unsigned globalSpaceIdx)
Definition: blackoillocalresidualtpfa.hh:532
static void computeBoundaryFluxFree(const Problem &problem, RateVector &bdyFlux, const BoundaryConditionData &bdyInfo, const IntensiveQuantities &insideIntQuants, unsigned globalSpaceIdx)
Definition: blackoillocalresidualtpfa.hh:567
static void computeBoundaryFluxRate(RateVector &bdyFlux, const BoundaryConditionData &bdyInfo)
Definition: blackoillocalresidualtpfa.hh:560
static FaceDir::DirEnum faceDirFromDirId(const int dirId)
Definition: blackoillocalresidualtpfa.hh:908
static void evalPhaseFluxes_(RateVector &flux, unsigned phaseIdx, unsigned pvtRegionIdx, const ExtensiveQuantities &extQuants, const FluidState &upFs)
Definition: blackoillocalresidualtpfa.hh:770
static void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoillocalresidualtpfa.hh:270
static void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoillocalresidualtpfa.hh:161
static void computeFlux(RateVector &flux, RateVector &darcy, const unsigned globalIndexIn, const unsigned globalIndexEx, const IntensiveQuantities &intQuantsIn, const IntensiveQuantities &intQuantsEx, const ResidualNBInfo &nbInfo, const ModuleParams &moduleParams)
Definition: blackoillocalresidualtpfa.hh:244
static void computeBoundaryThermal(const Problem &problem, RateVector &bdyFlux, const BoundaryConditionData &bdyInfo, const IntensiveQuantities &insideIntQuants, unsigned globalSpaceIdx)
Definition: blackoillocalresidualtpfa.hh:676
static void adaptMassConservationQuantities_(Dune::FieldVector< Scalar, numEq > &container, unsigned pvtRegionIdx)
Helper function to convert the mass-related parts of a Dune::FieldVector that stores conservation qua...
Definition: blackoillocalresidualtpfa.hh:879
static void evalPhaseFluxes_(RateVector &flux, unsigned phaseIdx, unsigned pvtRegionIdx, const Eval &surfaceVolumeFlux, const FluidState &upFs)
Helper function to calculate the flux of mass in terms of conservation quantities via specific fluid ...
Definition: blackoillocalresidualtpfa.hh:786
void computeStorage(Dune::FieldVector< LhsEval, numEq > &storage, const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx) const
Evaluate the amount all conservation quantities (e.g. phase mass) within a finite sub-control volume.
Definition: blackoillocalresidualtpfa.hh:151
static void calculateFluxes_(RateVector &flux, RateVector &darcy, const IntensiveQuantities &intQuantsIn, const IntensiveQuantities &intQuantsEx, const unsigned &globalIndexIn, const unsigned &globalIndexEx, const ResidualNBInfo &nbInfo, const ModuleParams &moduleParams)
Definition: blackoillocalresidualtpfa.hh:338
static void computeSource(RateVector &source, const Problem &problem, const IntensiveQuantities &insideIntQuants, unsigned globalSpaceIdex, unsigned timeIdx)
Definition: blackoillocalresidualtpfa.hh:711
static void computeSourceDense(RateVector &source, const Problem &problem, const IntensiveQuantities &insideIntQuants, unsigned globalSpaceIdex, unsigned timeIdx)
Definition: blackoillocalresidualtpfa.hh:730
Contains the high level supplements required to extend the black oil model by MICP.
Definition: blackoilmicpmodules.hh:54
static void applyScaling(RateVector &flux)
Definition: blackoilmicpmodules.hh:200
static void addSource(RateVector &source, const Problem &problem, const IntensiveQuantities &intQuants, unsigned globalSpaceIdex)
Definition: blackoilmicpmodules.hh:243
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilmicpmodules.hh:144
Contains the high level supplements required to extend the black oil model by polymer.
Definition: blackoilpolymermodules.hh:64
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilpolymermodules.hh:238
Contains the high level supplements required to extend the black oil model by solvents.
Definition: blackoilsolventmodules.hh:66
static void addStorage(Dune::FieldVector< LhsEval, numEq > &storage, const IntensiveQuantities &intQuants)
Definition: blackoilsolventmodules.hh:183
@ NONE
Definition: DeferredLogger.hpp:46
Definition: blackoilboundaryratevector.hh:39
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:233
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Definition: blackoillocalresidualtpfa.hh:143
ConvectiveMixingModuleParam convectiveMixingModuleParam
Definition: blackoillocalresidualtpfa.hh:144
Definition: blackoillocalresidualtpfa.hh:128
FaceDir::DirEnum faceDir
Definition: blackoillocalresidualtpfa.hh:133
double faceArea
Definition: blackoillocalresidualtpfa.hh:130
ConditionalStorage< enableEnergy, double > inAlpha
Definition: blackoillocalresidualtpfa.hh:136
ConditionalStorage< enableDiffusion, double > diffusivity
Definition: blackoillocalresidualtpfa.hh:138
double dZg
Definition: blackoillocalresidualtpfa.hh:132
double Vin
Definition: blackoillocalresidualtpfa.hh:134
ConditionalStorage< enableDispersion, double > dispersivity
Definition: blackoillocalresidualtpfa.hh:139
double thpres
Definition: blackoillocalresidualtpfa.hh:131
ConditionalStorage< enableEnergy, double > outAlpha
Definition: blackoillocalresidualtpfa.hh:137
double trans
Definition: blackoillocalresidualtpfa.hh:129
double Vex
Definition: blackoillocalresidualtpfa.hh:135