blackoilsolventmodules.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_SOLVENT_MODULE_HH
29#define EWOMS_BLACK_OIL_SOLVENT_MODULE_HH
30
31#include <dune/common/fvector.hh>
32
33#include <opm/common/Exceptions.hpp>
34#include <opm/common/utility/gpuDecorators.hpp>
35
36#include <opm/material/common/MathToolbox.hpp>
37#include <opm/material/common/Valgrind.hpp>
38#include <opm/material/fluidsystems/blackoilpvt/SolventPvt.hpp>
39
43
46
48
50
51#include <algorithm>
52#include <array>
53#include <cassert>
54#include <cmath>
55#include <istream>
56#include <memory>
57#include <ostream>
58#include <string>
59
60namespace Opm {
61
67template <class TypeTag>
68class BlackOilSolventModule<TypeTag, true>
69{
81 using Toolbox = MathToolbox<Evaluation>;
82 using SolventPvt = typename BlackOilSolventParams<Scalar>::SolventPvt;
83 using Co2GasPvt = typename BlackOilSolventParams<Scalar>::Co2GasPvt;
84 using H2GasPvt = typename BlackOilSolventParams<Scalar>::H2GasPvt;
85 using BrineCo2Pvt = typename BlackOilSolventParams<Scalar>::BrineCo2Pvt;
86 using BrineH2Pvt = typename BlackOilSolventParams<Scalar>::BrineH2Pvt;
87
88 using TabulatedFunction = typename BlackOilSolventParams<Scalar>::TabulatedFunction;
89
90 static constexpr unsigned solventSaturationIdx = Indices::solventSaturationIdx;
91 static constexpr unsigned contiSolventEqIdx = Indices::contiSolventEqIdx;
92 static constexpr unsigned enableSolvent = true;
93 static constexpr unsigned numEq = getPropValue<TypeTag, Properties::NumEq>();
94 static constexpr bool blackoilConserveSurfaceVolume =
95 getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>();
96 static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
97
98public:
99 static constexpr double cutOff = 1e-12;
102 { params_ = params; }
103
107 static void setSolventPvt(const SolventPvt& value)
108 { params_.solventPvt_ = value; }
109
110 static void setIsMiscible(const bool isMiscible)
111 { params_.isMiscible_ = isMiscible; }
112
116 static void registerParameters()
117 {
119 }
120
124 static void registerOutputModules(Model& model,
125 Simulator& simulator)
126 {
127 model.addOutputModule(std::make_unique<VtkBlackOilSolventModule<TypeTag>>(simulator));
128 }
129
130 static bool primaryVarApplies(unsigned pvIdx)
131 {
132 return pvIdx == solventSaturationIdx;
133 }
134
135 static std::string primaryVarName([[maybe_unused]] unsigned pvIdx)
136 {
137 assert(primaryVarApplies(pvIdx));
138
139 return "saturation_solvent";
140 }
141
142 static Scalar primaryVarWeight([[maybe_unused]] unsigned pvIdx)
143 {
144 assert(primaryVarApplies(pvIdx));
145
146 // TODO: it may be beneficial to chose this differently.
147 return static_cast<Scalar>(1.0);
148 }
149
150 static bool eqApplies(unsigned eqIdx)
151 {
152 return eqIdx == contiSolventEqIdx;
153 }
154
155 static std::string eqName([[maybe_unused]] unsigned eqIdx)
156 {
157 assert(eqApplies(eqIdx));
158
159 return "conti^solvent";
160 }
161
162 static Scalar eqWeight([[maybe_unused]] unsigned eqIdx)
163 {
164 assert(eqApplies(eqIdx));
165
166 // TODO: it may be beneficial to chose this differently.
167 return static_cast<Scalar>(1.0);
168 }
169
170 template <class StorageType>
171 OPM_HOST_DEVICE static void addStorage(StorageType& storage,
172 const IntensiveQuantities& intQuants)
173 {
174 using LhsEval = typename StorageType::value_type;
175
176 if constexpr (blackoilConserveSurfaceVolume) {
177 storage[contiSolventEqIdx] +=
178 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
179 Toolbox::template decay<LhsEval>(intQuants.solventSaturation()) *
180 Toolbox::template decay<LhsEval>(intQuants.solventInverseFormationVolumeFactor());
181 if (isSolubleInWater()) {
182 storage[contiSolventEqIdx] +=
183 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
184 Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(waterPhaseIdx)) *
185 Toolbox::template decay<LhsEval>(intQuants.fluidState().invB(waterPhaseIdx)) *
186 Toolbox::template decay<LhsEval>(intQuants.rsSolw());
187 }
188 }
189 else {
190 storage[contiSolventEqIdx] +=
191 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
192 Toolbox::template decay<LhsEval>(intQuants.solventSaturation()) *
193 Toolbox::template decay<LhsEval>(intQuants.solventDensity());
194 if (isSolubleInWater()) {
195 storage[contiSolventEqIdx] +=
196 Toolbox::template decay<LhsEval>(intQuants.porosity()) *
197 Toolbox::template decay<LhsEval>(intQuants.fluidState().saturation(waterPhaseIdx)) *
198 Toolbox::template decay<LhsEval>(intQuants.fluidState().density(waterPhaseIdx)) *
199 Toolbox::template decay<LhsEval>(intQuants.rsSolw());
200 }
201 }
202 }
203
204 static void computeFlux(RateVector& flux,
205 const ElementContext& elemCtx,
206 unsigned scvfIdx,
207 unsigned timeIdx)
208
209 {
210 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
211
212 const unsigned upIdx = extQuants.solventUpstreamIndex();
213 const unsigned inIdx = extQuants.interiorIndex();
214 const auto& up = elemCtx.intensiveQuantities(upIdx, timeIdx);
215
216 if (upIdx == inIdx) {
217 addSolventFluxes_<Evaluation>(
218 flux, extQuants.solventVolumeFlux(), extQuants.volumeFlux(waterPhaseIdx), up);
219 } else {
220 addSolventFluxes_<Scalar>(
221 flux, extQuants.solventVolumeFlux(), extQuants.volumeFlux(waterPhaseIdx), up);
222 }
223 }
224
234 template <class UpEval>
235 static void addSolventFluxes_(RateVector& flux,
236 const Evaluation& solventVolumeFlux,
237 const Evaluation& waterVolumeFlux,
238 const IntensiveQuantities& up)
239 {
240 if constexpr (blackoilConserveSurfaceVolume) {
241 flux[contiSolventEqIdx]
242 = solventVolumeFlux * decay<UpEval>(up.solventInverseFormationVolumeFactor());
243
244 if (isSolubleInWater()) {
245 flux[contiSolventEqIdx] += waterVolumeFlux
246 * decay<UpEval>(up.fluidState().invB(waterPhaseIdx))
247 * decay<UpEval>(up.rsSolw());
248 }
249 } else {
250 flux[contiSolventEqIdx] = solventVolumeFlux * decay<UpEval>(up.solventDensity());
251
252 if (isSolubleInWater()) {
253 flux[contiSolventEqIdx] += waterVolumeFlux
254 * decay<UpEval>(up.fluidState().density(waterPhaseIdx))
255 * decay<UpEval>(up.rsSolw());
256 }
257 }
258 }
259
263 static void assignPrimaryVars(PrimaryVariables& priVars,
264 Scalar solventSaturation,
265 Scalar solventRsw)
266 {
267 // Determine the meaning of the solvent primary variables
268 if (solventSaturation > 0 || !isSolubleInWater()) {
269 priVars.setPrimaryVarsMeaningSolvent(PrimaryVariables::SolventMeaning::Ss);
270 priVars[solventSaturationIdx] = solventSaturation;
271 } else {
272 priVars.setPrimaryVarsMeaningSolvent(PrimaryVariables::SolventMeaning::Rsolw);
273 priVars[solventSaturationIdx] = solventRsw;
274 }
275 }
276
280 static void updatePrimaryVars(PrimaryVariables& newPv,
281 const PrimaryVariables& oldPv,
282 const EqVector& delta)
283 {
284 // do a plain unchopped Newton update
285 newPv[solventSaturationIdx] = oldPv[solventSaturationIdx] - delta[solventSaturationIdx];
286 }
287
291 static Scalar computeUpdateError(const PrimaryVariables&,
292 const EqVector&)
293 {
294 // do not consider consider the cange of solvent primary variables for
295 // convergence
296 // TODO: maybe this should be changed
297 return static_cast<Scalar>(0.0);
298 }
299
303 static Scalar computeResidualError(const EqVector& resid)
304 {
305 // do not weight the residual of solvents when it comes to convergence
306 return std::abs(Toolbox::scalarValue(resid[contiSolventEqIdx]));
307 }
308
309 template <class DofEntity>
310 static void serializeEntity(const Model& model, std::ostream& outstream, const DofEntity& dof)
311 {
312 const unsigned dofIdx = model.dofMapper().index(dof);
313
314 const PrimaryVariables& priVars = model.solution(/*timeIdx=*/0)[dofIdx];
315 outstream << priVars[solventSaturationIdx];
316 }
317
318 template <class DofEntity>
319 static void deserializeEntity(Model& model, std::istream& instream, const DofEntity& dof)
320 {
321 const unsigned dofIdx = model.dofMapper().index(dof);
322
323 PrimaryVariables& priVars0 = model.solution(/*timeIdx=*/0)[dofIdx];
324 PrimaryVariables& priVars1 = model.solution(/*timeIdx=*/1)[dofIdx];
325
326 instream >> priVars0[solventSaturationIdx];
327
328 // set the primary variables for the beginning of the current time step.
329 priVars1 = priVars0[solventSaturationIdx];
330 }
331
332 static const SolventPvt& solventPvt()
333 { return params_.solventPvt_; }
334
335 static const Co2GasPvt& co2GasPvt()
336 { return params_.co2GasPvt_; }
337
338 static const H2GasPvt& h2GasPvt()
339 { return params_.h2GasPvt_; }
340
341 static const BrineCo2Pvt& brineCo2Pvt()
342 { return params_.brineCo2Pvt_; }
343
344 static const BrineH2Pvt& brineH2Pvt()
345 { return params_.brineH2Pvt_; }
346
347 template <class ElemContext>
348 static const TabulatedFunction& ssfnKrg(const ElemContext& elemCtx,
349 unsigned scvIdx,
350 unsigned timeIdx)
351 {
352 const unsigned satnumRegionIdx =
353 elemCtx.problem().satnumRegionIndex(elemCtx, scvIdx, timeIdx);
354 return params_.ssfnKrg_[satnumRegionIdx];
355 }
356
357 template <class ElemContext>
358 static const TabulatedFunction& ssfnKrs(const ElemContext& elemCtx,
359 unsigned scvIdx,
360 unsigned timeIdx)
361 {
362 const unsigned satnumRegionIdx =
363 elemCtx.problem().satnumRegionIndex(elemCtx, scvIdx, timeIdx);
364 return params_.ssfnKrs_[satnumRegionIdx];
365 }
366
367 static const TabulatedFunction& ssfnKrg(const unsigned satnumRegionIdx)
368 {
369 return params_.ssfnKrg_[satnumRegionIdx];
370 }
371
372 static const TabulatedFunction& ssfnKrs(const unsigned satnumRegionIdx)
373 {
374 return params_.ssfnKrs_[satnumRegionIdx];
375 }
376
377 template <class ElemContext>
378 static const TabulatedFunction& sof2Krn(const ElemContext& elemCtx,
379 unsigned scvIdx,
380 unsigned timeIdx)
381 {
382 const unsigned satnumRegionIdx =
383 elemCtx.problem().satnumRegionIndex(elemCtx, scvIdx, timeIdx);
384 return params_.sof2Krn_[satnumRegionIdx];
385 }
386
387 template <class ElemContext>
388 static const TabulatedFunction& misc(const ElemContext& elemCtx,
389 unsigned scvIdx,
390 unsigned timeIdx)
391 {
392 const unsigned miscnumRegionIdx =
393 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
394 return params_.misc_[miscnumRegionIdx];
395 }
396
397 template <class ElemContext>
398 static const TabulatedFunction& pmisc(const ElemContext& elemCtx,
399 unsigned scvIdx,
400 unsigned timeIdx)
401 {
402 const unsigned miscnumRegionIdx =
403 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
404 return params_.pmisc_[miscnumRegionIdx];
405 }
406
407 template <class ElemContext>
408 static const TabulatedFunction& msfnKrsg(const ElemContext& elemCtx,
409 unsigned scvIdx,
410 unsigned timeIdx)
411 {
412 const unsigned satnumRegionIdx =
413 elemCtx.problem().satnumRegionIndex(elemCtx, scvIdx, timeIdx);
414 return params_.msfnKrsg_[satnumRegionIdx];
415 }
416
417 template <class ElemContext>
418 static const TabulatedFunction& msfnKro(const ElemContext& elemCtx,
419 unsigned scvIdx,
420 unsigned timeIdx)
421 {
422 const unsigned satnumRegionIdx =
423 elemCtx.problem().satnumRegionIndex(elemCtx, scvIdx, timeIdx);
424 return params_.msfnKro_[satnumRegionIdx];
425 }
426
427 template <class ElemContext>
428 static const TabulatedFunction& sorwmis(const ElemContext& elemCtx,
429 unsigned scvIdx,
430 unsigned timeIdx)
431 {
432 const unsigned miscnumRegionIdx =
433 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
434 return params_.sorwmis_[miscnumRegionIdx];
435 }
436
437 template <class ElemContext>
438 static const TabulatedFunction& sgcwmis(const ElemContext& elemCtx,
439 unsigned scvIdx,
440 unsigned timeIdx)
441 {
442 const unsigned miscnumRegionIdx =
443 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
444 return params_.sgcwmis_[miscnumRegionIdx];
445 }
446
447 template <class ElemContext>
448 static const TabulatedFunction& tlPMixTable(const ElemContext& elemCtx,
449 unsigned scvIdx,
450 unsigned timeIdx)
451 {
452 const unsigned miscnumRegionIdx =
453 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
454 return params_.tlPMixTable_[miscnumRegionIdx];
455 }
456
457 template <class ElemContext>
458 static Scalar tlMixParamViscosity(const ElemContext& elemCtx,
459 unsigned scvIdx,
460 unsigned timeIdx)
461 {
462 const unsigned miscnumRegionIdx =
463 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
464 return params_.tlMixParamViscosity_[miscnumRegionIdx];
465 }
466
467
468 template <class ElemContext>
469 static Scalar tlMixParamDensity(const ElemContext& elemCtx,
470 unsigned scvIdx,
471 unsigned timeIdx)
472 {
473 const unsigned miscnumRegionIdx =
474 elemCtx.problem().miscnumRegionIndex(elemCtx, scvIdx, timeIdx);
475 return params_.tlMixParamDensity_[miscnumRegionIdx];
476 }
477
478 static bool isMiscible()
479 { return params_.isMiscible_; }
480
481 template <class Value>
482 static Value solubilityLimit(unsigned pvtIdx, const Value& temperature,
483 const Value& pressure, const Value& saltConcentration)
484 {
485 if (!isSolubleInWater()) {
486 return 0.0;
487 }
488
489 assert(isCO2Sol() || isH2Sol());
490 if (isCO2Sol()) {
491 return brineCo2Pvt().saturatedGasDissolutionFactor(pvtIdx, temperature,
492 pressure, saltConcentration);
493 }
494 else {
495 return brineH2Pvt().saturatedGasDissolutionFactor(pvtIdx, temperature,
496 pressure, saltConcentration);
497 }
498 }
499
500 static bool isSolubleInWater()
501 { return params_.rsSolw_active_; }
502
503 static bool isCO2Sol()
504 { return params_.co2sol_; }
505
506 static bool isH2Sol()
507 { return params_.h2sol_; }
508
509private:
510 static BlackOilSolventParams<Scalar> params_; // the krg(Fs) column of the SSFN table
511};
512
513template <class TypeTag>
514BlackOilSolventParams<typename BlackOilSolventModule<TypeTag, true>::Scalar>
515BlackOilSolventModule<TypeTag, true>::params_;
516
524template <class TypeTag>
525class BlackOilSolventIntensiveQuantities<TypeTag, /*enableSolventV=*/true>
526{
528
537
539
540 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
541 static constexpr unsigned solventSaturationIdx = Indices::solventSaturationIdx;
542 static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
543 static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
544 static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
545 static constexpr double cutOff = SolventModule::cutOff;
546
547public:
548
555 void solventPreSatFuncUpdate_(const ElementContext& elemCtx,
556 unsigned dofIdx,
557 unsigned timeIdx)
558 {
559 const PrimaryVariables& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
560 this->solventPreSatFuncUpdate_(priVars, timeIdx, elemCtx.linearizationType());
561 }
562
563 void solventPreSatFuncUpdate_(const PrimaryVariables& priVars,
564 const unsigned timeIdx,
565 const LinearizationType linearizationType)
566 {
567 auto& fs = asImp_().fluidState_;
568 Evaluation solventSat{0.0};
569 if (priVars.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
570 solventSat = priVars.makeEvaluation(solventSaturationIdx, timeIdx, linearizationType);
571 }
572
573 fs.setSolventSaturation(solventSat);
574
575 hydrocarbonSaturation_ = fs.saturation(gasPhaseIdx);
576
577 // apply a cut-off. Don't waste calculations if no solvent
578 if (solventSaturation().value() < cutOff) {
579 return;
580 }
581
582 // make the saturation of the gas phase which is used by the saturation functions
583 // the sum of the solvent "saturation" and the saturation the hydrocarbon gas.
584 fs.setSaturation(gasPhaseIdx, hydrocarbonSaturation_ + solventSat);
585 }
586
594 void solventPostSatFuncUpdate_(const ElementContext& elemCtx,
595 unsigned dofIdx,
596 unsigned timeIdx)
597 {
598 const PrimaryVariables& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
599 this->solventPostSatFuncUpdate_(elemCtx.problem(),
600 priVars,
601 elemCtx.globalSpaceIndex(dofIdx, timeIdx),
602 timeIdx,
603 elemCtx.linearizationType());
604 }
605
606private:
607 // This class is a private implementation detail.
608 template <class Problem>
609 struct ProblemAndCellIndexOnlyContext
610 {
611 const Problem& problem_;
612 unsigned int index_;
613 const Problem& problem() const { return problem_; }
614 unsigned int globalSpaceIndex([[maybe_unused]] const unsigned int spaceIdx,
615 [[maybe_unused]] const unsigned int timeIdx) const
616 {
617 return index_;
618 }
619 };
620
621public:
622 void solventPostSatFuncUpdate_(const Problem& problem,
623 const PrimaryVariables& priVars,
624 const unsigned globalSpaceIdx,
625 const unsigned timeIdx,
626 const LinearizationType linearizationType)
627 {
628 // revert the gas "saturation" of the fluid state back to the saturation of the
629 // hydrocarbon gas.
630 auto& fs = asImp_().fluidState_;
631 fs.setSaturation(gasPhaseIdx, hydrocarbonSaturation_);
632
633 // update rsSolw. This needs to be done after the pressure is defined in the fluid state.
634 Evaluation rsSolw{0.0};
635 if (priVars.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Ss) {
636 rsSolw = SolventModule::solubilityLimit(asImp_().pvtRegionIndex(),
637 fs.temperature(waterPhaseIdx),
638 fs.pressure(waterPhaseIdx),
639 fs.saltConcentration());
640 }
641 else if (priVars.primaryVarsMeaningSolvent() == PrimaryVariables::SolventMeaning::Rsolw) {
642 rsSolw = priVars.makeEvaluation(solventSaturationIdx, timeIdx, linearizationType);
643 }
644
645 fs.setRsSolw(rsSolw);
646
647 solventMobility_ = 0.0;
648
649 // apply a cut-off. Don't waste calculations if no solvent
650 if (solventSaturation().value() < cutOff) {
651 return;
652 }
653
654 ProblemAndCellIndexOnlyContext<Problem> elemCtx{problem, globalSpaceIdx};
655 unsigned dofIdx = 0; // Dummy
656
657 // Pressure effects on capillary pressure miscibility
658 if (SolventModule::isMiscible()) {
659 const Evaluation& p =
660 FluidSystem::phaseIsActive(oilPhaseIdx)
661 ? fs.pressure(oilPhaseIdx)
662 : fs.pressure(gasPhaseIdx);
663 const Evaluation pmisc =
664 SolventModule::pmisc(elemCtx, dofIdx, timeIdx).eval(p, /*extrapolate=*/true);
665 const Evaluation& pgImisc = fs.pressure(gasPhaseIdx);
666
667 // compute capillary pressure for miscible fluid
668 Evaluation pgMisc = 0.0;
669 std::array<Evaluation, numPhases> pC;
670 const auto& materialParams = problem.materialLawParams(elemCtx, dofIdx, timeIdx);
671 MaterialLaw::capillaryPressures(pC, materialParams, fs);
672
673 // oil is the reference phase for pressure
674 if (priVars.primaryVarsMeaningPressure() == PrimaryVariables::PressureMeaning::Pg) {
675 pgMisc = priVars.makeEvaluation(Indices::pressureSwitchIdx, timeIdx,
676 linearizationType);
677 }
678 else {
679 const Evaluation& po =
680 priVars.makeEvaluation(Indices::pressureSwitchIdx,
681 timeIdx, linearizationType);
682 pgMisc = po + (pC[gasPhaseIdx] - pC[oilPhaseIdx]);
683 }
684
685 fs.setPressure(gasPhaseIdx, pmisc * pgMisc + (1.0 - pmisc) * pgImisc);
686 }
687
688 const Evaluation gasSolventSat = hydrocarbonSaturation_ + solventSaturation();
689
690 if (gasSolventSat.value() < cutOff) { // avoid division by zero
691 return;
692 }
693
694 const Evaluation Fhydgas = hydrocarbonSaturation_ / gasSolventSat;
695 const Evaluation Fsolgas = solventSaturation() / gasSolventSat;
696
697 // account for miscibility of oil and solvent
698 if (SolventModule::isMiscible() && FluidSystem::phaseIsActive(oilPhaseIdx)) {
699 const auto& misc = SolventModule::misc(elemCtx, dofIdx, timeIdx);
700 const auto& pmisc = SolventModule::pmisc(elemCtx, dofIdx, timeIdx);
701 const Evaluation& p =
702 FluidSystem::phaseIsActive(oilPhaseIdx)
703 ? fs.pressure(oilPhaseIdx)
704 : fs.pressure(gasPhaseIdx);
705 const Evaluation miscibility =
706 misc.eval(Fsolgas, /*extrapolate=*/true) *
707 pmisc.eval(p, /*extrapolate=*/true);
708
709 // TODO adjust endpoints of sn and ssg
710 const unsigned cellIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
711 const auto& materialLawManager = elemCtx.problem().materialLawManager();
712 const auto& scaledDrainageInfo =
713 materialLawManager.oilWaterScaledEpsInfoDrainage(cellIdx);
714
715 const Scalar sogcr = scaledDrainageInfo.Sogcr;
716 Evaluation sor = sogcr;
717 if (FluidSystem::phaseIsActive(waterPhaseIdx)) {
718 const Evaluation& sw = fs.saturation(waterPhaseIdx);
719 const auto& sorwmis = SolventModule::sorwmis(elemCtx, dofIdx, timeIdx);
720 sor = miscibility *
721 sorwmis.eval(sw, /*extrapolate=*/true) + (1.0 - miscibility) * sogcr;
722 }
723 const Scalar sgcr = scaledDrainageInfo.Sgcr;
724 Evaluation sgc = sgcr;
725 if (FluidSystem::phaseIsActive(waterPhaseIdx)) {
726 const Evaluation& sw = fs.saturation(waterPhaseIdx);
727 const auto& sgcwmis = SolventModule::sgcwmis(elemCtx, dofIdx, timeIdx);
728 sgc = miscibility * sgcwmis.eval(sw, /*extrapolate=*/true) + (1.0 - miscibility) * sgcr;
729 }
730
731 Evaluation oilGasSolventSat = gasSolventSat;
732 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
733 oilGasSolventSat += fs.saturation(oilPhaseIdx);
734 }
735 const Evaluation zero = 0.0;
736 const Evaluation oilGasSolventEffSat = std::max(oilGasSolventSat - sor - sgc, zero);
737
738 Evaluation F_totalGas = 0.0;
739 if (oilGasSolventEffSat.value() > cutOff) {
740 const Evaluation gasSolventEffSat = std::max(gasSolventSat - sgc, zero);
741 F_totalGas = gasSolventEffSat / oilGasSolventEffSat;
742 }
743 const auto& msfnKro = SolventModule::msfnKro(elemCtx, dofIdx, timeIdx);
744 const auto& msfnKrsg = SolventModule::msfnKrsg(elemCtx, dofIdx, timeIdx);
745 const auto& sof2Krn = SolventModule::sof2Krn(elemCtx, dofIdx, timeIdx);
746
747 const Evaluation mkrgt = msfnKrsg.eval(F_totalGas, /*extrapolate=*/true) *
748 sof2Krn.eval(oilGasSolventSat, /*extrapolate=*/true);
749 const Evaluation mkro = msfnKro.eval(F_totalGas, /*extrapolate=*/true) *
750 sof2Krn.eval(oilGasSolventSat, /*extrapolate=*/true);
751
752 Evaluation& kro = asImp_().mobility_[oilPhaseIdx];
753 Evaluation& krg = asImp_().mobility_[gasPhaseIdx];
754
755 // combine immiscible and miscible part of the relperm
756 krg *= 1.0 - miscibility;
757 krg += miscibility * mkrgt;
758 kro *= 1.0 - miscibility;
759 kro += miscibility * mkro;
760 }
761
762 // compute the mobility of the solvent "phase" and modify the gas phase
763 const auto& ssfnKrg = SolventModule::ssfnKrg(elemCtx, dofIdx, timeIdx);
764 const auto& ssfnKrs = SolventModule::ssfnKrs(elemCtx, dofIdx, timeIdx);
765
766 Evaluation& krg = asImp_().mobility_[gasPhaseIdx];
767 solventMobility_ = krg * ssfnKrs.eval(Fsolgas, /*extrapolate=*/true);
768 krg *= ssfnKrg.eval(Fhydgas, /*extrapolate=*/true);
769 }
770
777 template <class ElemContext>
778 void solventPvtUpdate_(const ElemContext& elemCtx,
779 unsigned scvIdx,
780 unsigned timeIdx)
781 {
782 const auto& iq = asImp_();
783 auto& fs = asImp_().fluidState_;
784 const unsigned pvtRegionIdx = iq.pvtRegionIndex();
785 const Evaluation& T = iq.fluidState().temperature(gasPhaseIdx);
786 const Evaluation& p = iq.fluidState().pressure(gasPhaseIdx);
787
788 Evaluation solventInvB;
789 const Evaluation rv = 0.0;
790 const Evaluation rvw = 0.0;
791 if (SolventModule::isCO2Sol() || SolventModule::isH2Sol() ){
792 if (SolventModule::isCO2Sol()) {
793 const auto& co2gasPvt = SolventModule::co2GasPvt();
794 solventInvB =
795 co2gasPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p, rv, rvw);
796 solventRefDensity_ = co2gasPvt.gasReferenceDensity(pvtRegionIdx);
797 solventViscosity_ = co2gasPvt.viscosity(pvtRegionIdx, T, p, rv, rvw);
798
799 const auto& brineCo2Pvt = SolventModule::brineCo2Pvt();
800 const auto& bw = brineCo2Pvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p, rsSolw());
801
802 const auto denw = bw * brineCo2Pvt.waterReferenceDensity(pvtRegionIdx) +
803 rsSolw() * bw * brineCo2Pvt.gasReferenceDensity(pvtRegionIdx);
804 fs.setDensity(waterPhaseIdx, denw);
805 fs.setInvB(waterPhaseIdx, bw);
806 Evaluation& mobw = asImp_().mobility_[waterPhaseIdx];
807 const auto& muWat = fs.viscosity(waterPhaseIdx);
808 const auto& muWatEff = brineCo2Pvt.viscosity(pvtRegionIdx, T, p, rsSolw());
809 mobw *= muWat / muWatEff;
810 } else {
811 const auto& h2gasPvt = SolventModule::h2GasPvt();
812 solventInvB =
813 h2gasPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p, rv, rvw);
814 solventRefDensity_ = h2gasPvt.gasReferenceDensity(pvtRegionIdx);
815 solventViscosity_ = h2gasPvt.viscosity(pvtRegionIdx, T, p, rv, rvw);
816
817 const auto& brineH2Pvt = SolventModule::brineH2Pvt();
818 const auto& bw = brineH2Pvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p, rsSolw());
819
820 const auto denw = bw * brineH2Pvt.waterReferenceDensity(pvtRegionIdx) +
821 rsSolw() * bw * brineH2Pvt.gasReferenceDensity(pvtRegionIdx);
822 fs.setDensity(waterPhaseIdx, denw);
823 fs.setInvB(waterPhaseIdx, bw);
824 Evaluation& mobw = asImp_().mobility_[waterPhaseIdx];
825 const auto& muWat = fs.viscosity(waterPhaseIdx);
826 const auto& muWatEff = brineH2Pvt.viscosity(pvtRegionIdx, T, p, rsSolw());
827 mobw *= muWat / muWatEff;
828 }
829 } else {
830 const auto& solventPvt = SolventModule::solventPvt();
831 solventInvB = solventPvt.inverseFormationVolumeFactor(pvtRegionIdx, T, p);
832 solventRefDensity_ = solventPvt.referenceDensity(pvtRegionIdx);
833 solventViscosity_ = solventPvt.viscosity(pvtRegionIdx, T, p);
834 }
835
836 // store solvent PVT properties on the fluid state before effectiveProperties
837 fs.setSolventInvB(solventInvB);
838 fs.setSolventDensity(solventInvB * solventRefDensity_);
839
840 effectiveProperties(elemCtx, scvIdx, timeIdx);
841
842 solventMobility_ /= solventViscosity_;
843 }
844
845 void solventPvtUpdate_(const Problem& problem,
846 const unsigned globalSpaceIdx,
847 const unsigned timeIdx)
848 {
849 // minimal context so effectiveProperties can look up the cell MISCNUM solvent tables
850 ProblemAndCellIndexOnlyContext<Problem> elemCtx{problem, globalSpaceIdx};
851 unsigned dofIdx = 0; // Dummy
852 this->solventPvtUpdate_(elemCtx, dofIdx, timeIdx);
853 }
854
855 Evaluation solventSaturation() const
856 { return asImp_().fluidState_.solventSaturation(); }
857
858 Evaluation rsSolw() const
859 { return asImp_().fluidState_.rsSolw(); }
860
861 Evaluation solventDensity() const
862 { return asImp_().fluidState_.solventDensity(); }
863
864 const Evaluation& solventViscosity() const
865 { return solventViscosity_; }
866
867 const Evaluation& solventMobility() const
868 { return solventMobility_; }
869
871 { return asImp_().fluidState_.solventInvB(); }
872
873 // This could be stored pr pvtRegion instead
874 Scalar solventRefDensity() const
875 { return solventRefDensity_; }
876
877private:
878 // Computes the effective properties based on
879 // Todd-Longstaff mixing model.
880 template <class ElemContext>
881 void effectiveProperties(const ElemContext& elemCtx,
882 unsigned scvIdx,
883 unsigned timeIdx)
884 {
885 if (!SolventModule::isMiscible()) {
886 return;
887 }
888
889 // Don't waste calculations if no solvent
890 // Apply a cut-off for small and negative solvent saturations
891 if (solventSaturation() < cutOff) {
892 return;
893 }
894
895 // We plan to update the fluidstate with the effective
896 // properties
897 auto& fs = asImp_().fluidState_;
898
899 // Compute effective saturations
900 Evaluation oilEffSat = 0.0;
901 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
902 oilEffSat = fs.saturation(oilPhaseIdx);
903 }
904 Evaluation gasEffSat = fs.saturation(gasPhaseIdx);
905 Evaluation solventEffSat = solventSaturation();
906 if (FluidSystem::phaseIsActive(waterPhaseIdx)) {
907 const auto& sorwmis = SolventModule::sorwmis(elemCtx, scvIdx, timeIdx);
908 const auto& sgcwmis = SolventModule::sgcwmis(elemCtx, scvIdx, timeIdx);
909 const Evaluation zero = 0.0;
910 const Evaluation& sw = fs.saturation(waterPhaseIdx);
911 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
912 oilEffSat = std::max(oilEffSat - sorwmis.eval(sw, /*extrapolate=*/true), zero);
913 }
914 gasEffSat = std::max(gasEffSat - sgcwmis.eval(sw, /*extrapolate=*/true), zero);
915 solventEffSat = std::max(solventEffSat - sgcwmis.eval(sw, /*extrapolate=*/true), zero);
916 }
917 const Evaluation oilGasSolventEffSat = oilEffSat + gasEffSat + solventEffSat;
918 const Evaluation oilSolventEffSat = oilEffSat + solventEffSat;
919 const Evaluation solventGasEffSat = solventEffSat + gasEffSat;
920
921 // Compute effective viscosities
922
923 // Mixing parameter for viscosity
924 // The pressureMixingParameter represent the miscibility of the solvent while the mixingParameterViscosity the effect of the porous media.
925 // The pressureMixingParameter is not implemented in ecl100.
926 const Evaluation& p =
927 FluidSystem::phaseIsActive(oilPhaseIdx)
928 ? fs.pressure(oilPhaseIdx)
929 : fs.pressure(gasPhaseIdx);
930 // account for pressure effects
931 const auto& pmiscTable = SolventModule::pmisc(elemCtx, scvIdx, timeIdx);
932 const Evaluation pmisc = pmiscTable.eval(p, /*extrapolate=*/true);
933 const auto& tlPMixTable = SolventModule::tlPMixTable(elemCtx, scvIdx, timeIdx);
934 const Evaluation tlMixParamMu = SolventModule::tlMixParamViscosity(elemCtx, scvIdx, timeIdx) *
935 tlPMixTable.eval(p, /*extrapolate=*/true);
936
937 const Evaluation& muGas = fs.viscosity(gasPhaseIdx);
938 const Evaluation& muSolvent = solventViscosity_;
939
940 assert(muGas.value() > 0);
941 assert(muSolvent.value() > 0);
942 const Evaluation muGasPow = pow(muGas, 0.25);
943 const Evaluation muSolventPow = pow(muSolvent, 0.25);
944
945 Evaluation muMixSolventGas = muGas;
946 if (solventGasEffSat > cutOff) {
947 muMixSolventGas *= muSolvent / pow(((gasEffSat / solventGasEffSat) * muSolventPow) +
948 ((solventEffSat / solventGasEffSat) * muGasPow), 4.0);
949 }
950
951 Evaluation muOil = 1.0;
952 Evaluation muOilPow = 1.0;
953 Evaluation muMixOilSolvent = 1.0;
954 Evaluation muOilEff = 1.0;
955 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
956 muOil = fs.viscosity(oilPhaseIdx);
957 assert(muOil.value() > 0);
958 muOilPow = pow(muOil, 0.25);
959 muMixOilSolvent = muOil;
960 if (oilSolventEffSat > cutOff) {
961 muMixOilSolvent *= muSolvent / pow(((oilEffSat / oilSolventEffSat) * muSolventPow) +
962 ((solventEffSat / oilSolventEffSat) * muOilPow), 4.0);
963 }
964
965 muOilEff = pow(muOil,1.0 - tlMixParamMu) * pow(muMixOilSolvent, tlMixParamMu);
966 }
967 Evaluation muMixSolventGasOil = muOil;
968 if (oilGasSolventEffSat > cutOff) {
969 muMixSolventGasOil *= muSolvent * muGas / pow(((oilEffSat / oilGasSolventEffSat) *
970 muSolventPow * muGasPow) +
971 ((solventEffSat / oilGasSolventEffSat) *
972 muOilPow * muGasPow) +
973 ((gasEffSat / oilGasSolventEffSat) *
974 muSolventPow * muOilPow), 4.0);
975 }
976
977 Evaluation muGasEff = pow(muGas,1.0 - tlMixParamMu) * pow(muMixSolventGas, tlMixParamMu);
978 const Evaluation muSolventEff = pow(muSolvent,1.0 - tlMixParamMu) * pow(muMixSolventGasOil, tlMixParamMu);
979
980 // Compute effective densities
981 const Evaluation& rhoGas = fs.density(gasPhaseIdx);
982 Evaluation rhoOil = 0.0;
983 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
984 rhoOil = fs.density(oilPhaseIdx);
985 }
986
987 Evaluation rhoSolvent = solventDensity();
988
989 // Mixing parameter for density
990 // The pressureMixingParameter represent the miscibility of the
991 // solvent while the mixingParameterDenisty the effect of the porous media.
992 // The pressureMixingParameter is not implemented in ecl100.
993 const Evaluation tlMixParamRho = SolventModule::tlMixParamDensity(elemCtx, scvIdx, timeIdx) *
994 tlPMixTable.eval(p, /*extrapolate=*/true);
995
996 // compute effective viscosities for density calculations. These have to
997 // be recomputed as a different mixing parameter may be used.
998 const Evaluation muOilEffPow = pow(pow(muOil, 1.0 - tlMixParamRho) *
999 pow(muMixOilSolvent, tlMixParamRho), 0.25);
1000 const Evaluation muGasEffPow = pow(pow(muGas, 1.0 - tlMixParamRho) *
1001 pow(muMixSolventGas, tlMixParamRho), 0.25);
1002 const Evaluation muSolventEffPow = pow(pow(muSolvent, 1.0 - tlMixParamRho) *
1003 pow(muMixSolventGasOil, tlMixParamRho), 0.25);
1004
1005 const Evaluation oilGasEffSaturation = oilEffSat + gasEffSat;
1006 Evaluation sof = 0.0;
1007 Evaluation sgf = 0.0;
1008 if (oilGasEffSaturation.value() > cutOff) {
1009 sof = oilEffSat / oilGasEffSaturation;
1010 sgf = gasEffSat / oilGasEffSaturation;
1011 }
1012
1013 const Evaluation muSolventOilGasPow = muSolventPow * ((sgf * muOilPow) + (sof * muGasPow));
1014
1015 Evaluation rhoMixSolventGasOil = 0.0;
1016 if (oilGasSolventEffSat.value() > cutOff) {
1017 rhoMixSolventGasOil = (rhoOil * oilEffSat / oilGasSolventEffSat) +
1018 (rhoGas * gasEffSat / oilGasSolventEffSat) +
1019 (rhoSolvent * solventEffSat / oilGasSolventEffSat);
1020 }
1021
1022 Evaluation rhoGasEff = 0.0;
1023 if (std::abs(muSolventPow.value() - muGasPow.value()) < cutOff) {
1024 rhoGasEff = ((1.0 - tlMixParamRho) * rhoGas) +
1025 (tlMixParamRho * rhoMixSolventGasOil);
1026 }
1027 else {
1028 const Evaluation solventGasEffFraction = (muGasPow * (muSolventPow - muGasEffPow)) /
1029 (muGasEffPow * (muSolventPow - muGasPow));
1030 rhoGasEff = (rhoGas * solventGasEffFraction) + (rhoSolvent * (1.0 - solventGasEffFraction));
1031 }
1032
1033 Evaluation rhoSolventEff = 0.0;
1034 if (std::abs((muSolventOilGasPow.value() - (muOilPow.value() * muGasPow.value()))) < cutOff) {
1035 rhoSolventEff = ((1.0 - tlMixParamRho) * rhoSolvent) + (tlMixParamRho * rhoMixSolventGasOil);
1036 }
1037 else {
1038 const Evaluation sfraction_se = (muSolventOilGasPow -
1039 muOilPow * muGasPow * muSolventPow / muSolventEffPow) /
1040 (muSolventOilGasPow - (muOilPow * muGasPow));
1041 rhoSolventEff = (rhoSolvent * sfraction_se) +
1042 (rhoGas * sgf * (1.0 - sfraction_se)) +
1043 (rhoOil * sof * (1.0 - sfraction_se));
1044 }
1045
1046 // compute invB from densities.
1047 const unsigned pvtRegionIdx = asImp_().pvtRegionIndex();
1048 Evaluation bGasEff = rhoGasEff;
1049 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
1050 bGasEff /= (FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) +
1051 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) * fs.Rv());
1052 } else {
1053 bGasEff /= (FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx));
1054 }
1055 const Evaluation bSolventEff = rhoSolventEff / solventRefDensity();
1056
1057 // copy the unmodified invB factors
1058 const Evaluation bg = fs.invB(gasPhaseIdx);
1059 const Evaluation bs = solventInverseFormationVolumeFactor();
1060 const Evaluation bg_eff = pmisc * bGasEff + (1.0 - pmisc) * bg;
1061 const Evaluation bs_eff = pmisc * bSolventEff + (1.0 - pmisc) * bs;
1062
1063 // set the densities
1064 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
1065 fs.setDensity(gasPhaseIdx,
1066 bg_eff *
1067 (FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) +
1068 FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx)*fs.Rv()));
1069 } else {
1070 fs.setDensity(gasPhaseIdx,
1071 bg_eff * FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx));
1072 }
1073 rhoSolvent = bs_eff * solventRefDensity();
1074 fs.setSolventDensity(rhoSolvent);
1075
1076 // set the mobility
1077 Evaluation& mobg = asImp_().mobility_[gasPhaseIdx];
1078 muGasEff = bg_eff / (pmisc * bGasEff / muGasEff + (1.0 - pmisc) * bg / muGas);
1079 mobg *= muGas / muGasEff;
1080
1081 // Update viscosity of solvent
1082 solventViscosity_ = bs_eff / (pmisc * bSolventEff / muSolventEff +
1083 (1.0 - pmisc) * bs / muSolvent);
1084
1085 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
1086 Evaluation rhoOilEff = 0.0;
1087 if (std::abs(muOilPow.value() - muSolventPow.value()) < cutOff) {
1088 rhoOilEff = ((1.0 - tlMixParamRho) * rhoOil) + (tlMixParamRho * rhoMixSolventGasOil);
1089 }
1090 else {
1091 const Evaluation solventOilEffFraction = (muOilPow * (muOilEffPow - muSolventPow)) /
1092 (muOilEffPow * (muOilPow - muSolventPow));
1093 rhoOilEff = (rhoOil * solventOilEffFraction) + (rhoSolvent * (1.0 - solventOilEffFraction));
1094 }
1095 const Evaluation bOilEff =
1096 rhoOilEff / (FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) +
1097 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) * fs.Rs());
1098 const Evaluation bo = fs.invB(oilPhaseIdx);
1099 const Evaluation bo_eff = pmisc * bOilEff + (1.0 - pmisc) * bo;
1100 fs.setDensity(oilPhaseIdx,
1101 bo_eff * (FluidSystem::referenceDensity(oilPhaseIdx, pvtRegionIdx) +
1102 FluidSystem::referenceDensity(gasPhaseIdx, pvtRegionIdx) * fs.Rs()));
1103
1104 // keep the mu*b interpolation
1105 Evaluation& mobo = asImp_().mobility_[oilPhaseIdx];
1106 muOilEff = bo_eff / (pmisc * bOilEff / muOilEff + (1.0 - pmisc) * bo / muOil);
1107 mobo *= muOil / muOilEff;
1108 }
1109 }
1110
1111protected:
1112 Implementation& asImp_()
1113 { return *static_cast<Implementation*>(this); }
1114
1115 const Implementation& asImp_() const
1116 { return *static_cast<const Implementation*>(this); }
1117
1121
1123};
1124
1132template <class TypeTag>
1134{
1136
1144
1145 using Toolbox = MathToolbox<Evaluation>;
1146
1147 static constexpr unsigned gasPhaseIdx = FluidSystem::gasPhaseIdx;
1148 static constexpr int dimWorld = GridView::dimensionworld;
1149
1150 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
1151 using DimEvalVector = Dune::FieldVector<Evaluation, dimWorld>;
1152
1153public:
1158 template <class Dummy = bool> // we need to make this method a template to avoid
1159 // compiler errors if it is not instantiated!
1160 void updateVolumeFluxPerm(const ElementContext& elemCtx,
1161 unsigned scvfIdx,
1162 unsigned timeIdx)
1163 {
1164 const auto& gradCalc = elemCtx.gradientCalculator();
1165 PressureCallback<TypeTag> pressureCallback(elemCtx);
1166
1167 const auto& scvf = elemCtx.stencil(timeIdx).interiorFace(scvfIdx);
1168 const auto& faceNormal = scvf.normal();
1169
1170 const unsigned i = scvf.interiorIndex();
1171 const unsigned j = scvf.exteriorIndex();
1172
1173 // calculate the "raw" pressure gradient
1174 DimEvalVector solventPGrad;
1175 pressureCallback.setPhaseIndex(gasPhaseIdx);
1176 gradCalc.calculateGradient(solventPGrad,
1177 elemCtx,
1178 scvfIdx,
1179 pressureCallback);
1180 Valgrind::CheckDefined(solventPGrad);
1181
1182 // correct the pressure gradients by the gravitational acceleration
1183 if (Parameters::Get<Parameters::EnableGravity>()) {
1184 // estimate the gravitational acceleration at a given SCV face
1185 // using the arithmetic mean
1186 const auto& gIn = elemCtx.problem().gravity(elemCtx, i, timeIdx);
1187 const auto& gEx = elemCtx.problem().gravity(elemCtx, j, timeIdx);
1188
1189 const auto& intQuantsIn = elemCtx.intensiveQuantities(i, timeIdx);
1190 const auto& intQuantsEx = elemCtx.intensiveQuantities(j, timeIdx);
1191
1192 const auto& posIn = elemCtx.pos(i, timeIdx);
1193 const auto& posEx = elemCtx.pos(j, timeIdx);
1194 const auto& posFace = scvf.integrationPos();
1195
1196 // the distance between the centers of the control volumes
1197 DimVector distVecIn(posIn);
1198 DimVector distVecEx(posEx);
1199 DimVector distVecTotal(posEx);
1200
1201 distVecIn -= posFace;
1202 distVecEx -= posFace;
1203 distVecTotal -= posIn;
1204 const Scalar absDistTotalSquared = distVecTotal.two_norm2();
1205
1206 // calculate the hydrostatic pressure at the integration point of the face
1207 auto rhoIn = intQuantsIn.solventDensity();
1208 auto pStatIn = - rhoIn * (gIn * distVecIn);
1209
1210 // the quantities on the exterior side of the face do not influence the
1211 // result for the TPFA scheme, so they can be treated as scalar values.
1212 Scalar rhoEx = Toolbox::value(intQuantsEx.solventDensity());
1213 Scalar pStatEx = - rhoEx * (gEx * distVecEx);
1214
1215 // compute the hydrostatic gradient between the two control volumes (this
1216 // gradient exhibitis the same direction as the vector between the two
1217 // control volume centers and the length (pStaticExterior -
1218 // pStaticInterior)/distanceInteriorToExterior
1219 DimEvalVector f(distVecTotal);
1220 f *= (pStatEx - pStatIn) / absDistTotalSquared;
1221
1222 // calculate the final potential gradient
1223 for (unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx) {
1224 solventPGrad[dimIdx] += f[dimIdx];
1225
1226 if (!isfinite(solventPGrad[dimIdx])) {
1227 throw NumericalProblem("Non-finite potential gradient for solvent 'phase'");
1228 }
1229 }
1230 }
1231
1232 // determine the upstream and downstream DOFs
1233 Evaluation solventPGradNormal = 0.0;
1234 for (unsigned dimIdx = 0; dimIdx < faceNormal.size(); ++dimIdx) {
1235 solventPGradNormal += solventPGrad[dimIdx]*faceNormal[dimIdx];
1236 }
1237
1238 if (solventPGradNormal > 0) {
1239 solventUpstreamDofIdx_ = j;
1240 solventDownstreamDofIdx_ = i;
1241 }
1242 else {
1243 solventUpstreamDofIdx_ = i;
1244 solventDownstreamDofIdx_ = j;
1245 }
1246
1247 const auto& up = elemCtx.intensiveQuantities(solventUpstreamDofIdx_, timeIdx);
1248
1249 // this is also slightly hacky because it assumes that the derivative of the
1250 // flux between two DOFs only depends on the primary variables in the
1251 // upstream direction. For non-TPFA flux approximation schemes, this is not
1252 // true...
1253 if (solventUpstreamDofIdx_ == i) {
1254 solventVolumeFlux_ = solventPGradNormal * up.solventMobility();
1255 }
1256 else {
1257 solventVolumeFlux_ = solventPGradNormal * scalarValue(up.solventMobility());
1258 }
1259 }
1260
1265 template <class Dummy = bool> // we need to make this method a template to avoid
1266 // compiler errors if it is not instantiated!
1267 void updateVolumeFluxTrans(const ElementContext& elemCtx,
1268 unsigned scvfIdx,
1269 unsigned timeIdx)
1270 {
1271 const ExtensiveQuantities& extQuants = asImp_();
1272
1273 const unsigned interiorDofIdx = extQuants.interiorIndex();
1274 const unsigned exteriorDofIdx = extQuants.exteriorIndex();
1275 assert(interiorDofIdx != exteriorDofIdx);
1276
1277 const auto& intQuantsIn = elemCtx.intensiveQuantities(interiorDofIdx, timeIdx);
1278 const auto& intQuantsEx = elemCtx.intensiveQuantities(exteriorDofIdx, timeIdx);
1279
1280 const unsigned I = elemCtx.globalSpaceIndex(interiorDofIdx, timeIdx);
1281 const unsigned J = elemCtx.globalSpaceIndex(exteriorDofIdx, timeIdx);
1282
1283 const Scalar thpresInToEx = elemCtx.problem().thresholdPressure(I, J);
1284 const Scalar thpresExToIn = elemCtx.problem().thresholdPressure(J, I);
1285 const Scalar trans = elemCtx.problem().transmissibility(elemCtx, interiorDofIdx, exteriorDofIdx);
1286 const Scalar g = elemCtx.problem().gravity()[dimWorld - 1];
1287
1288 const Scalar zIn = elemCtx.problem().dofCenterDepth(elemCtx, interiorDofIdx, timeIdx);
1289 const Scalar zEx = elemCtx.problem().dofCenterDepth(elemCtx, exteriorDofIdx, timeIdx);
1290 const Scalar distZ = zIn - zEx;
1291
1292 const Scalar faceArea = elemCtx.stencil(timeIdx).interiorFace(scvfIdx).area();
1293
1294 updateSolventVolumeFlux(solventVolumeFlux_,
1295 solventUpstreamDofIdx_,
1296 solventDownstreamDofIdx_,
1297 interiorDofIdx,
1298 exteriorDofIdx,
1299 intQuantsIn,
1300 intQuantsEx,
1301 thpresInToEx,
1302 thpresExToIn,
1303 trans,
1304 faceArea,
1305 distZ * g);
1306 }
1307
1324 static void updateSolventVolumeFlux(Evaluation& volumeFlux,
1325 unsigned& upIdx,
1326 unsigned& dnIdx,
1327 const unsigned interiorDofIdx,
1328 const unsigned exteriorDofIdx,
1329 const IntensiveQuantities& intQuantsIn,
1330 const IntensiveQuantities& intQuantsEx,
1331 const Scalar thpresInToEx,
1332 const Scalar thpresExToIn,
1333 const Scalar trans,
1334 const Scalar faceArea,
1335 const Scalar distZg)
1336 {
1337 const Evaluation rhoIn = intQuantsIn.solventDensity();
1338 const Scalar rhoEx = Toolbox::value(intQuantsEx.solventDensity());
1339 const Evaluation rhoAvg = rhoIn * 0.5 + rhoEx * 0.5;
1340
1341 const Evaluation& pressureInterior = intQuantsIn.fluidState().pressure(gasPhaseIdx);
1342 Evaluation pressureExterior = Toolbox::value(intQuantsEx.fluidState().pressure(gasPhaseIdx));
1343 pressureExterior += distZg * rhoAvg;
1344
1345 Evaluation pressureDiffSolvent = pressureExterior - pressureInterior;
1346 const Scalar thpres = pressureDiffSolvent < 0.0 ? thpresInToEx : thpresExToIn;
1347 if (thpres > 0.0) {
1348 if (std::abs(scalarValue(pressureDiffSolvent)) > thpres) {
1349 if (pressureDiffSolvent < 0.0) {
1350 pressureDiffSolvent += thpres;
1351 }
1352 else {
1353 pressureDiffSolvent -= thpres;
1354 }
1355 }
1356 else {
1357 pressureDiffSolvent = 0.0;
1358 }
1359 }
1360
1361 if (pressureDiffSolvent > 0.0) {
1362 upIdx = exteriorDofIdx;
1363 dnIdx = interiorDofIdx;
1364 }
1365 else if (pressureDiffSolvent < 0.0) {
1366 upIdx = interiorDofIdx;
1367 dnIdx = exteriorDofIdx;
1368 }
1369 else {
1370 // pressure potential gradient is zero; force consistent upstream and
1371 // downstream indices over the intersection regardless of the side which it
1372 // is looked at.
1373 upIdx = std::min(interiorDofIdx, exteriorDofIdx);
1374 dnIdx = std::max(interiorDofIdx, exteriorDofIdx);
1375 volumeFlux = 0.0;
1376 return;
1377 }
1378
1379 const IntensiveQuantities& up = (upIdx == interiorDofIdx) ? intQuantsIn : intQuantsEx;
1380 if (upIdx == interiorDofIdx) {
1381 volumeFlux = up.solventMobility() * (-trans / faceArea) * pressureDiffSolvent;
1382 } else {
1383 volumeFlux
1384 = scalarValue(up.solventMobility()) * (-trans / faceArea) * pressureDiffSolvent;
1385 }
1386 }
1387
1388 unsigned solventUpstreamIndex() const
1389 { return solventUpstreamDofIdx_; }
1390
1391 unsigned solventDownstreamIndex() const
1392 { return solventDownstreamDofIdx_; }
1393
1394 const Evaluation& solventVolumeFlux() const
1395 { return solventVolumeFlux_; }
1396
1397 void setSolventVolumeFlux(const Evaluation& solventVolumeFlux)
1398 { solventVolumeFlux_ = solventVolumeFlux; }
1399
1400private:
1401 Implementation& asImp_()
1402 { return *static_cast<Implementation*>(this); }
1403
1404 Evaluation solventVolumeFlux_;
1405 unsigned solventUpstreamDofIdx_;
1406 unsigned solventDownstreamDofIdx_;
1407};
1408
1409} // namespace Opm
1410
1411#endif
Contains classes extending the black-oil model. \detail This file holds dummy definitions,...
Declares the properties required by the black oil model.
Contains the parameters required to extend the black-oil model by solvents.
const Evaluation & solventVolumeFlux() const
Definition: blackoilsolventmodules.hh:1394
void updateVolumeFluxPerm(const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Method which calculates the volume flux of the polymer "phase" using the pressure potential gradient ...
Definition: blackoilsolventmodules.hh:1160
static void updateSolventVolumeFlux(Evaluation &volumeFlux, unsigned &upIdx, unsigned &dnIdx, const unsigned interiorDofIdx, const unsigned exteriorDofIdx, const IntensiveQuantities &intQuantsIn, const IntensiveQuantities &intQuantsEx, const Scalar thpresInToEx, const Scalar thpresExToIn, const Scalar trans, const Scalar faceArea, const Scalar distZg)
Solvent volume flux over a face from gas pressure difference and transmissibility.
Definition: blackoilsolventmodules.hh:1324
unsigned solventDownstreamIndex() const
Definition: blackoilsolventmodules.hh:1391
void updateVolumeFluxTrans(const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Method which calculates the volume flux of the polymer "phase" using the gas pressure potential diffe...
Definition: blackoilsolventmodules.hh:1267
void setSolventVolumeFlux(const Evaluation &solventVolumeFlux)
Definition: blackoilsolventmodules.hh:1397
unsigned solventUpstreamIndex() const
Definition: blackoilsolventmodules.hh:1388
Provides the solvent specific extensive quantities to the generic black-oil module's extensive quanti...
void solventPreSatFuncUpdate_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Called before the saturation functions are doing their magic.
Definition: blackoilsolventmodules.hh:555
Implementation & asImp_()
Definition: blackoilsolventmodules.hh:1112
Evaluation solventViscosity_
Definition: blackoilsolventmodules.hh:1119
const Evaluation & solventViscosity() const
Definition: blackoilsolventmodules.hh:864
const Implementation & asImp_() const
Definition: blackoilsolventmodules.hh:1115
void solventPostSatFuncUpdate_(const Problem &problem, const PrimaryVariables &priVars, const unsigned globalSpaceIdx, const unsigned timeIdx, const LinearizationType linearizationType)
Definition: blackoilsolventmodules.hh:622
Evaluation solventDensity() const
Definition: blackoilsolventmodules.hh:861
void solventPvtUpdate_(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Update the intensive PVT properties needed to handle solvents from the primary variables.
Definition: blackoilsolventmodules.hh:778
const Evaluation & solventMobility() const
Definition: blackoilsolventmodules.hh:867
Evaluation hydrocarbonSaturation_
Definition: blackoilsolventmodules.hh:1118
void solventPreSatFuncUpdate_(const PrimaryVariables &priVars, const unsigned timeIdx, const LinearizationType linearizationType)
Definition: blackoilsolventmodules.hh:563
void solventPostSatFuncUpdate_(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Called after the saturation functions have been doing their magic.
Definition: blackoilsolventmodules.hh:594
void solventPvtUpdate_(const Problem &problem, const unsigned globalSpaceIdx, const unsigned timeIdx)
Definition: blackoilsolventmodules.hh:845
Evaluation solventSaturation() const
Definition: blackoilsolventmodules.hh:855
Scalar solventRefDensity_
Definition: blackoilsolventmodules.hh:1122
Scalar solventRefDensity() const
Definition: blackoilsolventmodules.hh:874
Evaluation rsSolw() const
Definition: blackoilsolventmodules.hh:858
Evaluation solventMobility_
Definition: blackoilsolventmodules.hh:1120
Evaluation solventInverseFormationVolumeFactor() const
Definition: blackoilsolventmodules.hh:870
Provides the volumetric quantities required for the equations needed by the solvents extension of the...
Contains the high level supplements required to extend the black oil model by solvents.
Definition: blackoilsolventmodules.hh:69
static void deserializeEntity(Model &model, std::istream &instream, const DofEntity &dof)
Definition: blackoilsolventmodules.hh:319
static Scalar tlMixParamDensity(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:469
static void setSolventPvt(const SolventPvt &value)
Specify the solvent PVT of a all PVT regions.
Definition: blackoilsolventmodules.hh:107
static bool isCO2Sol()
Definition: blackoilsolventmodules.hh:503
static const TabulatedFunction & misc(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:388
static const TabulatedFunction & msfnKrsg(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:408
static bool isH2Sol()
Definition: blackoilsolventmodules.hh:506
static const TabulatedFunction & sorwmis(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:428
static void computeFlux(RateVector &flux, const ElementContext &elemCtx, unsigned scvfIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:204
static Scalar tlMixParamViscosity(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:458
static const TabulatedFunction & sgcwmis(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:438
static bool eqApplies(unsigned eqIdx)
Definition: blackoilsolventmodules.hh:150
static const TabulatedFunction & pmisc(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:398
static bool primaryVarApplies(unsigned pvIdx)
Definition: blackoilsolventmodules.hh:130
static const TabulatedFunction & ssfnKrs(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:358
static void setIsMiscible(const bool isMiscible)
Definition: blackoilsolventmodules.hh:110
static Scalar computeResidualError(const EqVector &resid)
Return how much a residual is considered an error.
Definition: blackoilsolventmodules.hh:303
static const BrineH2Pvt & brineH2Pvt()
Definition: blackoilsolventmodules.hh:344
static void assignPrimaryVars(PrimaryVariables &priVars, Scalar solventSaturation, Scalar solventRsw)
Assign the solvent specific primary variables to a PrimaryVariables object.
Definition: blackoilsolventmodules.hh:263
static std::string primaryVarName(unsigned pvIdx)
Definition: blackoilsolventmodules.hh:135
static const SolventPvt & solventPvt()
Definition: blackoilsolventmodules.hh:332
static Scalar computeUpdateError(const PrimaryVariables &, const EqVector &)
Return how much a Newton-Raphson update is considered an error.
Definition: blackoilsolventmodules.hh:291
static const H2GasPvt & h2GasPvt()
Definition: blackoilsolventmodules.hh:338
static void updatePrimaryVars(PrimaryVariables &newPv, const PrimaryVariables &oldPv, const EqVector &delta)
Do a Newton-Raphson update the primary variables of the solvents.
Definition: blackoilsolventmodules.hh:280
static bool isSolubleInWater()
Definition: blackoilsolventmodules.hh:500
static std::string eqName(unsigned eqIdx)
Definition: blackoilsolventmodules.hh:155
static const TabulatedFunction & ssfnKrs(const unsigned satnumRegionIdx)
Definition: blackoilsolventmodules.hh:372
static void addSolventFluxes_(RateVector &flux, const Evaluation &solventVolumeFlux, const Evaluation &waterVolumeFlux, const IntensiveQuantities &up)
Add the solvent component flux over a face to rate vector.
Definition: blackoilsolventmodules.hh:235
static void setParams(BlackOilSolventParams< Scalar > &&params)
Set parameters.
Definition: blackoilsolventmodules.hh:101
static const TabulatedFunction & sof2Krn(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:378
static void registerParameters()
Register all run-time parameters for the black-oil solvent module.
Definition: blackoilsolventmodules.hh:116
static Value solubilityLimit(unsigned pvtIdx, const Value &temperature, const Value &pressure, const Value &saltConcentration)
Definition: blackoilsolventmodules.hh:482
static Scalar primaryVarWeight(unsigned pvIdx)
Definition: blackoilsolventmodules.hh:142
static const BrineCo2Pvt & brineCo2Pvt()
Definition: blackoilsolventmodules.hh:341
static void serializeEntity(const Model &model, std::ostream &outstream, const DofEntity &dof)
Definition: blackoilsolventmodules.hh:310
static bool isMiscible()
Definition: blackoilsolventmodules.hh:478
static const TabulatedFunction & tlPMixTable(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:448
static OPM_HOST_DEVICE void addStorage(StorageType &storage, const IntensiveQuantities &intQuants)
Definition: blackoilsolventmodules.hh:171
static Scalar eqWeight(unsigned eqIdx)
Definition: blackoilsolventmodules.hh:162
static const Co2GasPvt & co2GasPvt()
Definition: blackoilsolventmodules.hh:335
static void registerOutputModules(Model &model, Simulator &simulator)
Register all solvent specific VTK and ECL output modules.
Definition: blackoilsolventmodules.hh:124
static const TabulatedFunction & msfnKro(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:418
static const TabulatedFunction & ssfnKrg(const ElemContext &elemCtx, unsigned scvIdx, unsigned timeIdx)
Definition: blackoilsolventmodules.hh:348
static const TabulatedFunction & ssfnKrg(const unsigned satnumRegionIdx)
Definition: blackoilsolventmodules.hh:367
Callback class for a phase pressure.
Definition: quantitycallbacks.hh:85
void setPhaseIndex(unsigned phaseIdx)
Set the index of the fluid phase for which the pressure should be returned.
Definition: quantitycallbacks.hh:109
VTK output module for the black oil model's solvent related quantities.
Definition: vtkblackoilsolventmodule.hpp:54
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilsolventmodule.hpp:84
Defines the common parameters for the porous medium multi-phase models.
Definition: blackoilbioeffectsmodules.hh:45
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
This method contains all callback classes for quantities that are required by some extensive quantiti...
Struct holding the parameters for the BlackOilSolventModule class.
Definition: blackoilsolventparams.hpp:47
::Opm::SolventPvt< Scalar > SolventPvt
Definition: blackoilsolventparams.hpp:52
::Opm::H2GasPvt< Scalar > H2GasPvt
Definition: blackoilsolventparams.hpp:51
::Opm::BrineCo2Pvt< Scalar > BrineCo2Pvt
Definition: blackoilsolventparams.hpp:48
::Opm::Co2GasPvt< Scalar > Co2GasPvt
Definition: blackoilsolventparams.hpp:50
Tabulated1DFunction< Scalar > TabulatedFunction
Definition: blackoilsolventparams.hpp:53
::Opm::BrineH2Pvt< Scalar > BrineH2Pvt
Definition: blackoilsolventparams.hpp:49
Definition: linearizationtype.hh:34