31#ifndef OPM_FLOW_PROBLEM_BLACK_HPP
32#define OPM_FLOW_PROBLEM_BLACK_HPP
36#include <opm/input/eclipse/EclipseState/Aquifer/AquiferConfig.hpp>
37#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquiferCell.hpp>
38#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
39#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
41#include <opm/output/eclipse/EclipseIO.hpp>
68#include <unordered_map>
79template <
class TypeTag>
135 static constexpr bool enableDissolvedGas =
136 Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
137 enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
138 enum { enableDisgasInWater = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
139 enum { enableGeochemistry = getPropValue<TypeTag, Properties::EnableGeochemistry>() };
140 enum { enableMech = getPropValue<TypeTag, Properties::EnableMech>() };
142 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, enableBioeffects>;
143 using BrineModule = BlackOilBrineModule<TypeTag, enableBrine>;
144 using ConvectiveMixingModule = BlackOilConvectiveMixingModule<TypeTag, enableConvectiveMixing>;
147 using ExtboModule = BlackOilExtboModule<TypeTag, enableExtbo>;
148 using FoamModule = BlackOilFoamModule<TypeTag, enableFoam>;
149 using PolymerModule = BlackOilPolymerModule<TypeTag, enablePolymer>;
150 using SolventModule = BlackOilSolventModule<TypeTag, enableSolvent>;
152 using EclWriterType = EclWriter<TypeTag, OutputBlackOilModule<TypeTag> >;
153 using IndexTraits =
typename FluidSystem::IndexTraitsType;
155 using HybridNewton = BlackOilHybridNewton<TypeTag>;
158 using DamarisWriterType = DamarisWriter<TypeTag>;
174 DamarisWriterType::registerParameters();
187 simulator.vanguard().schedule(),
188 simulator.vanguard().actionState(),
189 simulator.vanguard().summaryState(),
191 simulator.vanguard().grid().comm())
197 const auto& vanguard = simulator.vanguard();
199 if constexpr (enableBrine) {
201 brineParams.template initFromState<enableBrine,
202 enableSaltPrecipitation>(vanguard.eclState());
203 BrineModule::setParams(std::move(brineParams));
206 if constexpr (enableDiffusion) {
207 DiffusionModule::initFromState(vanguard.eclState());
210 if constexpr (enableDispersion) {
211 DispersionModule::initFromState(vanguard.eclState());
214 if constexpr (enableExtbo) {
216 extboParams.template initFromState<enableExtbo>(vanguard.eclState());
217 ExtboModule::setParams(std::move(extboParams));
220 if constexpr (enableFoam) {
222 foamParams.template initFromState<enableFoam>(vanguard.eclState());
223 FoamModule::setParams(std::move(foamParams));
226 if constexpr (enableBioeffects) {
228 bioeffectsParams.template initFromState<enableBioeffects, enableMICP>(vanguard.eclState());
229 BioeffectsModule::setParams(std::move(bioeffectsParams));
232 if constexpr (enablePolymer) {
234 polymerParams.template initFromState<enablePolymer, enablePolymerMolarWeight>(vanguard.eclState());
235 PolymerModule::setParams(std::move(polymerParams));
238 if constexpr (enableSolvent) {
240 solventParams.template initFromState<enableSolvent>(vanguard.eclState(), vanguard.schedule());
241 SolventModule::setParams(std::move(solventParams));
245 eclWriter_ = std::make_unique<EclWriterType>(simulator);
249 if constexpr (!enableGeochemistry) {
250 if (vanguard.eclState().runspec().geochem().enabled()) {
251 throw std::runtime_error(
"GEOCHEM keyword in the deck but geochemistry module "
252 "was disabled at compile time!");
257 if constexpr (!enableMech) {
258 const auto& rspec = vanguard.eclState().runspec();
259 if (rspec.mech() && rspec.mechSolver().tpsa()) {
260 throw std::runtime_error(
"TPSA solver enabled in the deck, but geomechanics "
261 "module was disabled at compile time!");
267 damarisWriter_ = std::make_unique<DamarisWriterType>(simulator);
268 enableDamarisOutput_ = Parameters::Get<Parameters::EnableDamarisOutput>();
279 auto& simulator = this->simulator();
281 const int episodeIdx = simulator.episodeIndex();
282 const auto& schedule = simulator.vanguard().schedule();
287 .evalUDQAssignments(episodeIdx, simulator.vanguard().udqState());
289 if (episodeIdx >= 0) {
290 const auto& oilVap = schedule[episodeIdx].oilvap();
291 if (oilVap.getType() == OilVaporizationProperties::OilVaporization::VAPPARS) {
292 FluidSystem::setVapPars(oilVap.vap1(), oilVap.vap2());
295 FluidSystem::setVapPars(0.0, 0.0);
298 if constexpr (enableConvectiveMixing) {
299 ConvectiveMixingModule::beginEpisode(simulator.vanguard().eclState(), schedule, episodeIdx,
300 this->moduleParams_.convectiveMixingModuleParam);
319 FlowProblemType::finishInit();
321 auto& simulator = this->simulator();
322 const bool transmissibilitiesFinished =
325 const auto& eclState = simulator.vanguard().eclState();
326 const auto& schedule = simulator.vanguard().schedule();
331 bool isThermal = eclState.getSimulationConfig().isThermal();
332 bool isTemp = eclState.getSimulationConfig().isTemp();
333 bool conserveInnerEnergy = isTemp || (isThermal && Parameters::Get<Parameters::ConserveInnerEnergyThermal>());
334 FluidSystem::setEnergyEqualEnthalpy(conserveInnerEnergy);
343 if (!transmissibilitiesFinished) {
347 const auto& initconfig = eclState.getInitConfig();
349 if (initconfig.restartRequested()) {
360 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
361 const auto& vanguard = this->simulator().vanguard();
362 const auto& gridView = vanguard.gridView();
363 const int numElements = gridView.size(0);
364 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
373 this->
drift_.resize(this->model().numGridDof());
380 if (!initconfig.restartRequested() && !eclState.getIOConfig().initOnly()) {
381 simulator.startNextEpisode(schedule.seconds(1));
382 simulator.setEpisodeIndex(0);
383 simulator.setTimeStepIndex(0);
386 if (Parameters::Get<Parameters::CheckSatfuncConsistency>() &&
396 this->simulator().vanguard().grid().comm().barrier();
398 throw std::domain_error {
399 "Saturation function end-points do not "
400 "meet requisite consistency conditions"
412 eclState.runspec().tabdims().getNumPVTTables());
418 if (!initconfig.restartRequested()) {
421 this->
mixControls_.updateLastValues(elemIdx, fs.Rs(), fs.Rv());
425 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
426 simulator.setTimeStepSize(0.0);
427 simulator.model().applyInitialSolution();
431 if (!eclState.getIOConfig().initOnly()) {
432 if (!this->
enableTuning_ && eclState.getSimulationConfig().anyTUNING()) {
433 OpmLog::info(
"\nThe deck has TUNING in the SCHEDULE section, but "
434 "it is ignored due\nto the flag --enable-tuning=false. "
435 "Set this flag to true to activate it.\n"
436 "Manually tuning the simulator with the TUNING keyword may "
437 "increase run time.\nIt is recommended using the simulator's "
438 "default tuning (--enable-tuning=false).");
459 const auto& grid = this->simulator().vanguard().gridView().grid();
461 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
462 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
463 if (!isCpGrid || (grid.maxLevel() == 0)) {
464 this->
eclWriter_->evalSummaryState(!this->episodeWillBeOver());
468 OPM_TIMEBLOCK(applyActions);
471 auto& simulator = this->simulator();
475 this->simulator().vanguard().schedule().clearEvents(episodeIdx);
479 .applyActions(episodeIdx, simulator.time() + simulator.timeStepSize(),
480 [
this](
const bool global)
482 using TransUpdateQuantities = typename
483 Vanguard::TransmissibilityType::TransUpdateQuantities;
485 this->transmissibilities_
486 .update(global, TransUpdateQuantities::All,
487 [&vg = this->simulator().vanguard()]
488 (const unsigned int i)
490 return vg.gridIdxToEquilGridIdx(i);
501 OPM_TIMEBLOCK(endEpisode);
514 .evalUDQAssignments(this->episodeIndex(), this->simulator().vanguard().udqState());
516 FlowProblemType::endEpisode();
521 if (this->enableEclOutput_) {
522 this->eclWriter_->writeReports(timer);
533 FlowProblemType::writeOutput(verbose);
535 const auto isSubStep = !this->episodeWillBeOver();
537 auto localCellData = data::Solution {};
542 if (this->enableDamarisOutput_ && (this->damarisWriter_ !=
nullptr)) {
543 this->damarisWriter_->writeOutput(localCellData, isSubStep);
547 if (this->enableEclOutput_ && (this->eclWriter_ !=
nullptr)) {
548 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
549 this->simulator().vanguard().schedule()
550 .exitStatus().has_value());
556 OPM_TIMEBLOCK(finalizeOutput);
568 FlowProblemType::initialSolutionApplied();
573 this->thresholdPressures_.finishInit();
575 if (this->checkAquiferEquilibration_) {
576 this->checkAquiferEquilibration_ =
false;
577 this->checkNumericalAquiferEquilibration_();
581 const auto& grid = this->simulator().vanguard().gridView().grid();
583 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
584 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
586 if (!isCpGrid || (grid.maxLevel() == 0)) {
587 if (this->simulator().episodeIndex() == 0) {
588 eclWriter_->writeInitialFIPReport();
594 unsigned globalDofIdx,
595 unsigned timeIdx)
const override
597 this->aquiferModel_.addToSource(rate, globalDofIdx, timeIdx);
600 const auto& source = this->simulator().vanguard().schedule()[this->episodeIndex()].source();
601 std::array<int,3> ijk;
602 this->simulator().vanguard().cartesianCoordinate(globalDofIdx, ijk);
604 if (source.hasSource(ijk)) {
605 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
606 static std::array<SourceComponent, 3> sc_map = {SourceComponent::WATER, SourceComponent::OIL, SourceComponent::GAS};
607 static std::array<int, 3> phidx_map = {FluidSystem::waterPhaseIdx, FluidSystem::oilPhaseIdx, FluidSystem::gasPhaseIdx};
608 static std::array<int, 3> cidx_map = {waterCompIdx, oilCompIdx, gasCompIdx};
610 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
611 const auto phaseIdx = phidx_map[i];
612 const auto sourceComp = sc_map[i];
613 const auto compIdx = cidx_map[i];
614 if (!FluidSystem::phaseIsActive(phaseIdx)) {
617 Scalar mass_rate = source.rate(ijk, sourceComp) / this->model().dofTotalVolume(globalDofIdx);
618 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
619 mass_rate /= FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
621 rate[FluidSystem::canonicalToActiveCompIdx(compIdx)] += mass_rate;
624 if constexpr (enableSolvent) {
625 Scalar mass_rate = source.rate(ijk, SourceComponent::SOLVENT) / this->model().dofTotalVolume(globalDofIdx);
626 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
627 const auto& solventPvt = SolventModule::solventPvt();
628 mass_rate /= solventPvt.referenceDensity(pvtRegionIdx);
630 rate[Indices::contiSolventEqIdx] += mass_rate;
632 if constexpr (enablePolymer) {
633 rate[Indices::polymerConcentrationIdx] += source.rate(ijk, SourceComponent::POLYMER) / this->model().dofTotalVolume(globalDofIdx);
635 if constexpr (enableMICP) {
636 rate[Indices::microbialConcentrationIdx] += source.rate(ijk, SourceComponent::MICR) / this->model().dofTotalVolume(globalDofIdx);
637 rate[Indices::oxygenConcentrationIdx] += source.rate(ijk, SourceComponent::OXYG) / this->model().dofTotalVolume(globalDofIdx);
638 rate[Indices::ureaConcentrationIdx] += source.rate(ijk, SourceComponent::UREA) / (this->model().dofTotalVolume(globalDofIdx));
640 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
641 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
642 const auto phaseIdx = phidx_map[i];
643 if (!FluidSystem::phaseIsActive(phaseIdx)) {
646 const auto sourceComp = sc_map[i];
647 const auto source_hrate = source.hrate(ijk, sourceComp);
649 rate[Indices::contiEnergyEqIdx] += source_hrate.value() / this->model().dofTotalVolume(globalDofIdx);
651 const auto& intQuants = this->simulator().model().intensiveQuantities(globalDofIdx, 0);
652 auto fs = intQuants.fluidState();
654 const auto source_temp = source.temperature(ijk, sourceComp);
656 Scalar temperature = source_temp.value();
657 fs.setTemperature(temperature);
659 const auto& h = FluidSystem::enthalpy(fs, phaseIdx, pvtRegionIdx);
660 Scalar mass_rate = source.rate(ijk, sourceComp)/ this->model().dofTotalVolume(globalDofIdx);
661 Scalar energy_rate = getValue(h)*mass_rate;
662 rate[Indices::contiEnergyEqIdx] += energy_rate;
670 if (this->enableDriftCompensation_) {
671 const auto& simulator = this->simulator();
672 const auto& model = this->model();
677 Scalar maxCompensation = model.newtonMethod().tolerance()/10;
678 Scalar poro = this->porosity(globalDofIdx, timeIdx);
679 Scalar dt = simulator.timeStepSize();
680 EqVector dofDriftRate = this->drift_[globalDofIdx];
681 dofDriftRate /= dt*model.dofTotalVolume(globalDofIdx);
684 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
685 Scalar cnv = std::abs(dofDriftRate[eqIdx])*dt*model.eqWeight(globalDofIdx, eqIdx)/poro;
686 if (cnv > maxCompensation) {
687 dofDriftRate[eqIdx] *= maxCompensation/cnv;
691 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx)
692 rate[eqIdx] -= dofDriftRate[eqIdx];
699 template <
class LhsEval,
class Callback>
702 OPM_TIMEBLOCK_LOCAL(permFactTransMultiplier, Subsystem::PvtProps);
703 if constexpr (enableSaltPrecipitation) {
704 const auto& fs = intQuants.fluidState();
705 unsigned tableIdx = this->simulator().problem().satnumRegionIndex(elementIdx);
706 LhsEval porosityFactor = obtain(1. - fs.saltSaturation());
707 porosityFactor = min(porosityFactor, 1.0);
708 const auto& permfactTable = BrineModule::permfactTable(tableIdx);
709 return permfactTable.eval(porosityFactor,
true);
711 else if constexpr (enableBioeffects) {
712 return obtain(intQuants.permFactor());
721 {
return initialFluidStates_[globalDofIdx]; }
724 {
return initialFluidStates_; }
727 {
return initialFluidStates_; }
730 {
return eclWriter_->eclIO(); }
733 {
return eclWriter_->setSubStepReport(report); }
736 {
return eclWriter_->setSimulationReport(report); }
740 OPM_TIMEBLOCK_LOCAL(boundaryFluidState, Subsystem::Assembly);
741 const auto& bcstate = this->simulator().vanguard().schedule()[this->episodeIndex()].bcstate;
742 if (bcstate.size() > 0) {
743 FaceDir::DirEnum dir = FaceDir::FromIntersectionIndex(directionId);
747 if (this->bcindex_(dir)[globalDofIdx] == 0)
748 return initialFluidStates_[globalDofIdx];
750 const auto& bc = bcstate[this->bcindex_(dir)[globalDofIdx]];
751 if (bc.bctype == BCType::DIRICHLET )
753 InitialFluidState fluidState;
754 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
755 fluidState.setPvtRegionIndex(pvtRegionIdx);
757 switch (bc.component) {
758 case BCComponent::OIL:
759 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx))
760 throw std::logic_error(
"oil is not active and you're trying to add oil BC");
762 fluidState.setSaturation(FluidSystem::oilPhaseIdx, 1.0);
764 case BCComponent::GAS:
765 if (!FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
766 throw std::logic_error(
"gas is not active and you're trying to add gas BC");
768 fluidState.setSaturation(FluidSystem::gasPhaseIdx, 1.0);
770 case BCComponent::WATER:
771 if (!FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
772 throw std::logic_error(
"water is not active and you're trying to add water BC");
774 fluidState.setSaturation(FluidSystem::waterPhaseIdx, 1.0);
776 case BCComponent::SOLVENT:
777 case BCComponent::POLYMER:
778 case BCComponent::MICR:
779 case BCComponent::OXYG:
780 case BCComponent::UREA:
782 throw std::logic_error(
"you need to specify a valid component (OIL, WATER or GAS) when DIRICHLET type is set in BC");
784 fluidState.setTotalSaturation(1.0);
785 double pressure = initialFluidStates_[globalDofIdx].pressure(this->refPressurePhaseIdx_());
786 const auto pressure_input = bc.pressure;
787 if (pressure_input) {
788 pressure = *pressure_input;
791 std::array<Scalar, numPhases> pc = {0};
792 const auto& matParams = this->materialLawParams(globalDofIdx);
793 MaterialLaw::capillaryPressures(pc, matParams, fluidState);
794 Valgrind::CheckDefined(pressure);
795 Valgrind::CheckDefined(pc);
796 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
797 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
798 if (Indices::oilEnabled)
799 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
800 else if (Indices::gasEnabled)
801 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
802 else if (Indices::waterEnabled)
804 fluidState.setPressure(phaseIdx, pressure);
806 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
807 double temperature = initialFluidStates_[globalDofIdx].temperature(0);
808 const auto temperature_input = bc.temperature;
809 if(temperature_input)
810 temperature = *temperature_input;
811 fluidState.setTemperature(temperature);
814 if constexpr (enableDissolvedGas) {
815 if (FluidSystem::enableDissolvedGas()) {
816 fluidState.setRs(0.0);
817 fluidState.setRv(0.0);
820 if constexpr (enableDisgasInWater) {
821 if (FluidSystem::enableDissolvedGasInWater()) {
822 fluidState.setRsw(0.0);
825 if constexpr (enableVapwat) {
826 if (FluidSystem::enableVaporizedWater()) {
827 fluidState.setRvw(0.0);
831 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
832 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
834 const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, pvtRegionIdx);
835 fluidState.setInvB(phaseIdx, b);
837 const auto& rho = FluidSystem::density(fluidState, phaseIdx, pvtRegionIdx);
838 fluidState.setDensity(phaseIdx, rho);
839 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
840 const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, pvtRegionIdx);
841 fluidState.setEnthalpy(phaseIdx, h);
844 fluidState.checkDefined();
848 return initialFluidStates_[globalDofIdx];
853 {
return *eclWriter_; }
856 {
return *eclWriter_; }
864 return this->mixControls_.maxGasDissolutionFactor(timeIdx, globalDofIdx,
865 this->episodeIndex(),
866 this->pvtRegionIndex(globalDofIdx));
875 return this->mixControls_.maxOilVaporizationFactor(timeIdx, globalDofIdx,
876 this->episodeIndex(),
877 this->pvtRegionIndex(globalDofIdx));
893 const auto& rspec = this->simulator().vanguard().eclState().runspec();
894 const bool tpsaActive = rspec.mech() && rspec.mechSolver().tpsa();
899 int episodeIdx = this->episodeIndex();
900 return !this->mixControls_.drsdtActive(episodeIdx) &&
901 !this->mixControls_.drvdtActive(episodeIdx) &&
902 this->rockCompPoroMultWc_.empty() &&
903 this->rockCompPoroMult_.empty();
912 template <
class Context>
915 unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
917 values.setPvtRegionIndex(pvtRegionIndex(context, spaceIdx, timeIdx));
918 values.assignNaive(initialFluidStates_[globalDofIdx]);
920 if constexpr (enableSolvent) {
921 SolventModule::assignPrimaryVars(values,
922 this->solventSaturation_[globalDofIdx],
923 this->solventRsw_[globalDofIdx]);
926 if constexpr (enablePolymer) {
927 values[Indices::polymerConcentrationIdx] = this->polymer_.concentration[globalDofIdx];
930 if constexpr (enablePolymerMolarWeight) {
931 values[Indices::polymerMoleWeightIdx]= this->polymer_.moleWeight[globalDofIdx];
934 if constexpr (enableBrine) {
935 if (enableSaltPrecipitation && values.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp) {
936 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltSaturation();
939 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltConcentration();
943 if constexpr (enableBioeffects) {
944 values[Indices::microbialConcentrationIdx] = this->bioeffects_.microbialConcentration[globalDofIdx];
945 values[Indices::biofilmVolumeFractionIdx] = this->bioeffects_.biofilmVolumeFraction[globalDofIdx];
946 if constexpr (enableMICP) {
947 values[Indices::oxygenConcentrationIdx] = this->bioeffects_.oxygenConcentration[globalDofIdx];
948 values[Indices::ureaConcentrationIdx] = this->bioeffects_.ureaConcentration[globalDofIdx];
949 values[Indices::calciteVolumeFractionIdx] = this->bioeffects_.calciteVolumeFraction[globalDofIdx];
953 values.checkDefined();
959 return this->mixControls_.drsdtcon(elemIdx, episodeIdx,
960 this->pvtRegionIndex(elemIdx));
965 return this->mixControls_.drsdtConvective(episodeIdx, this->pvtRegionIndex(elemIdx));
973 template <
class Context>
975 const Context& context,
977 unsigned timeIdx)
const
979 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
980 if (!context.intersection(spaceIdx).boundary())
983 if constexpr (energyModuleType != EnergyModules::FullyImplicitThermal || !enableThermalFluxBoundaries)
991 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
992 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
993 values.setThermalFlow(context, spaceIdx, timeIdx, this->initialFluidStates_[globalDofIdx] );
996 if (this->nonTrivialBoundaryConditions()) {
997 unsigned indexInInside = context.intersection(spaceIdx).indexInInside();
998 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
999 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
1000 unsigned pvtRegionIdx = pvtRegionIndex(context, spaceIdx, timeIdx);
1001 const auto [type, massrate] = this->boundaryCondition(globalDofIdx, indexInInside);
1002 if (type == BCType::THERMAL)
1003 values.setThermalFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1004 else if (type == BCType::FREE || type == BCType::DIRICHLET)
1005 values.setFreeFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1006 else if (type == BCType::RATE)
1007 values.setMassRate(massrate, pvtRegionIdx);
1017 auto& simulator = this->simulator();
1018 const auto& eclState = simulator.vanguard().eclState();
1020 std::size_t numElems = this->model().numGridDof();
1021 this->initialFluidStates_.resize(numElems);
1022 if constexpr (enableSolvent) {
1023 this->solventSaturation_.resize(numElems, 0.0);
1024 this->solventRsw_.resize(numElems, 0.0);
1027 if constexpr (enablePolymer)
1028 this->polymer_.concentration.resize(numElems, 0.0);
1030 if constexpr (enablePolymerMolarWeight) {
1031 const std::string msg {
"Support of the RESTART for polymer molecular weight "
1032 "is not implemented yet. The polymer weight value will be "
1033 "zero when RESTART begins"};
1034 OpmLog::warning(
"NO_POLYMW_RESTART", msg);
1035 this->polymer_.moleWeight.resize(numElems, 0.0);
1038 if constexpr (enableBioeffects) {
1039 this->bioeffects_.resize(numElems);
1043 this->mixControls_.init(numElems, restart_step, eclState.runspec().tabdims().getNumPVTTables());
1045 if constexpr (enableBioeffects) {
1046 this->bioeffects_ = this->eclWriter_->outputModule().getBioeffects().getSolution();
1049 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1050 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1051 elemFluidState.setPvtRegionIndex(pvtRegionIndex(elemIdx));
1052 this->eclWriter_->outputModule().initHysteresisParams(simulator, elemIdx);
1053 this->eclWriter_->outputModule().assignToFluidState(elemFluidState, elemIdx);
1062 auto ssol = enableSolvent
1063 ? this->eclWriter_->outputModule().getSolventSaturation(elemIdx)
1066 this->processRestartSaturations_(elemFluidState, ssol);
1068 if constexpr (enableSolvent) {
1069 this->solventSaturation_[elemIdx] = ssol;
1070 this->solventRsw_[elemIdx] = this->eclWriter_->outputModule().getSolventRsw(elemIdx);
1076 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1077 const auto& rspec = eclState.runspec();
1078 bool needTemperature = rspec.co2Storage() || rspec.h2Storage()
1079 || rspec.co2Sol() || rspec.h2Sol();
1080 if (needTemperature) {
1081 const auto& fp = simulator.vanguard().eclState().fieldProps();
1082 elemFluidState.setTemperature(fp.get_double(
"TEMPI")[elemIdx]);
1086 this->mixControls_.updateLastValues(elemIdx, elemFluidState.Rs(), elemFluidState.Rv());
1088 if constexpr (enablePolymer)
1089 this->polymer_.concentration[elemIdx] = this->eclWriter_->outputModule().getPolymerConcentration(elemIdx);
1093 const int episodeIdx = this->episodeIndex();
1094 this->mixControls_.updateMaxValues(episodeIdx, simulator.timeStepSize());
1099 auto& sol = this->model().solution(0);
1100 const auto& gridView = this->gridView();
1102 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
1103 elemCtx.updatePrimaryStencil(elem);
1104 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1105 this->initial(sol[elemIdx], elemCtx, 0, 0);
1113 this->model().syncOverlap();
1116 this->updateReferencePorosity_();
1117 this->mixControls_.init(this->model().numGridDof(),
1118 this->episodeIndex(),
1119 eclState.runspec().tabdims().getNumPVTTables());
1123 template<
class Serializer>
1127 serializer(mixControls_);
1128 serializer(*eclWriter_);
1135 FlowProblemType::captureBeginTimeStepState_();
1136 prev_timestep_state_.mixControls = mixControls_;
1142 FlowProblemType::restoreBeginTimeStepState_();
1143 mixControls_ = prev_timestep_state_.mixControls;
1148 this->updateExplicitQuantities_(first_step_after_restart);
1150 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>())
1151 updateMaxPolymerAdsorption_();
1153 mixControls_.updateExplicitQuantities(episodeIdx, timeStepSize);
1159 this->updateProperty_(
"FlowProblemBlackoil::updateMaxPolymerAdsorption_() failed:",
1162 this->updateMaxPolymerAdsorption_(compressedDofIdx,iq);
1168 const Scalar pa = scalarValue(iq.polymerAdsorption());
1169 auto& mpa = this->polymer_.maxAdsorption;
1170 if (mpa[compressedDofIdx] < pa) {
1171 mpa[compressedDofIdx] = pa;
1180 std::vector<Scalar> sumInvB(numPhases, 0.0);
1181 const auto& gridView = this->gridView();
1183 for(
const auto& elem: elements(gridView, Dune::Partitions::interior)) {
1184 elemCtx.updatePrimaryStencil(elem);
1185 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1186 const auto& dofFluidState = this->initialFluidStates_[elemIdx];
1187 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1188 if (!FluidSystem::phaseIsActive(phaseIdx))
1191 sumInvB[phaseIdx] += dofFluidState.invB(phaseIdx);
1195 std::size_t numDof = this->model().numGridDof();
1196 const auto& comm = this->simulator().vanguard().grid().comm();
1197 comm.sum(sumInvB.data(),sumInvB.size());
1198 Scalar numTotalDof = comm.sum(numDof);
1200 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1201 if (!FluidSystem::phaseIsActive(phaseIdx))
1204 Scalar avgB = numTotalDof / sumInvB[phaseIdx];
1205 const unsigned solventCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
1206 const unsigned activeSolventCompIdx = FluidSystem::canonicalToActiveCompIdx(solventCompIdx);
1207 this->model().setEqWeight(activeSolventCompIdx, avgB);
1214 OPM_TIMEBLOCK(updateCompositionChangeLimits);
1217 int episodeIdx = this->episodeIndex();
1218 std::array<bool,3> active{this->mixControls_.drsdtConvective(episodeIdx),
1219 this->mixControls_.drsdtActive(episodeIdx),
1220 this->mixControls_.drvdtActive(episodeIdx)};
1221 if (!active[0] && !active[1] && !active[2]) {
1225 this->updateProperty_(
"FlowProblemBlackoil::updateCompositionChangeLimits_()) failed:",
1226 [
this,episodeIdx,active](
unsigned compressedDofIdx,
1229 const DimMatrix& perm = this->intrinsicPermeability(compressedDofIdx);
1230 const Scalar distZ = active[0] ? this->simulator().vanguard().cellThickness(compressedDofIdx) : 0.0;
1231 const int pvtRegionIdx = this->pvtRegionIndex(compressedDofIdx);
1232 this->mixControls_.update(compressedDofIdx,
1235 this->gravity_[
dim - 1],
1248 if(this->simulator().vanguard().grid().maxLevel() > 0) {
1249 throw std::invalid_argument(
"Refined grids are not yet supported for restart ");
1253 auto& simulator = this->simulator();
1254 const auto& schedule = simulator.vanguard().schedule();
1255 const auto& eclState = simulator.vanguard().eclState();
1256 const auto& initconfig = eclState.getInitConfig();
1257 const int restart_step = initconfig.getRestartStep();
1259 simulator.setTime(schedule.seconds(restart_step));
1261 simulator.startNextEpisode(simulator.startTime() + simulator.time(),
1262 schedule.stepLength(restart_step));
1263 simulator.setEpisodeIndex(restart_step);
1265 this->eclWriter_->beginRestart();
1267 Scalar dt = std::min(this->eclWriter_->restartTimeStepSize(), simulator.episodeLength());
1268 simulator.setTimeStepSize(dt);
1270 this->readSolutionFromOutputModule(restart_step,
false);
1272 this->eclWriter_->endRestart();
1277 const auto& simulator = this->simulator();
1282 std::size_t numElems = this->model().numGridDof();
1283 this->initialFluidStates_.resize(numElems);
1284 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1285 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1292 const auto& simulator = this->simulator();
1293 const auto& vanguard = simulator.vanguard();
1294 const auto& eclState = vanguard.eclState();
1295 const auto& fp = eclState.fieldProps();
1296 bool has_swat = fp.has_double(
"SWAT");
1297 bool has_sgas = fp.has_double(
"SGAS");
1298 bool has_rs = fp.has_double(
"RS");
1299 bool has_rsw = fp.has_double(
"RSW");
1300 bool has_rv = fp.has_double(
"RV");
1301 bool has_rvw = fp.has_double(
"RVW");
1302 bool has_pressure = fp.has_double(
"PRESSURE");
1303 bool has_salt = fp.has_double(
"SALT");
1304 bool has_saltp = fp.has_double(
"SALTP");
1307 if (Indices::numPhases > 1) {
1308 if (FluidSystem::phaseIsActive(waterPhaseIdx) && !has_swat)
1309 throw std::runtime_error(
"The ECL input file requires the presence of the SWAT keyword if "
1310 "the water phase is active");
1311 if (FluidSystem::phaseIsActive(gasPhaseIdx) && !has_sgas && FluidSystem::phaseIsActive(oilPhaseIdx))
1312 throw std::runtime_error(
"The ECL input file requires the presence of the SGAS keyword if "
1313 "the gas phase is active");
1316 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
1317 "keyword if the model is initialized explicitly");
1318 if (FluidSystem::enableDissolvedGas() && !has_rs)
1319 throw std::runtime_error(
"The ECL input file requires the RS keyword to be present if"
1320 " dissolved gas is enabled and the model is initialized explicitly");
1321 if (FluidSystem::enableDissolvedGasInWater() && !has_rsw)
1322 OpmLog::warning(
"The model is initialized explicitly and the RSW keyword is not present in the"
1323 " ECL input file. The RSW values are set equal to 0");
1324 if (FluidSystem::enableVaporizedOil() && !has_rv)
1325 throw std::runtime_error(
"The ECL input file requires the RV keyword to be present if"
1326 " vaporized oil is enabled and the model is initialized explicitly");
1327 if (FluidSystem::enableVaporizedWater() && !has_rvw)
1328 throw std::runtime_error(
"The ECL input file requires the RVW keyword to be present if"
1329 " vaporized water is enabled and the model is initialized explicitly");
1330 if (enableBrine && !has_salt)
1331 throw std::runtime_error(
"The ECL input file requires the SALT keyword to be present if"
1332 " brine is enabled and the model is initialized explicitly");
1333 if (enableSaltPrecipitation && !has_saltp)
1334 throw std::runtime_error(
"The ECL input file requires the SALTP keyword to be present if"
1335 " salt precipitation is enabled and the model is initialized explicitly");
1337 std::size_t numDof = this->model().numGridDof();
1339 initialFluidStates_.resize(numDof);
1341 std::vector<double> waterSaturationData;
1342 std::vector<double> gasSaturationData;
1343 std::vector<double> pressureData;
1344 std::vector<double> rsData;
1345 std::vector<double> rswData;
1346 std::vector<double> rvData;
1347 std::vector<double> rvwData;
1348 std::vector<double> tempiData;
1349 std::vector<double> saltData;
1350 std::vector<double> saltpData;
1352 if (FluidSystem::phaseIsActive(waterPhaseIdx) && Indices::numPhases > 1)
1353 waterSaturationData = fp.get_double(
"SWAT");
1355 waterSaturationData.resize(numDof);
1357 if (FluidSystem::phaseIsActive(gasPhaseIdx) && FluidSystem::phaseIsActive(oilPhaseIdx))
1358 gasSaturationData = fp.get_double(
"SGAS");
1360 gasSaturationData.resize(numDof);
1362 pressureData = fp.get_double(
"PRESSURE");
1363 if (FluidSystem::enableDissolvedGas())
1364 rsData = fp.get_double(
"RS");
1366 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1367 rswData = fp.get_double(
"RSW");
1369 if (FluidSystem::enableVaporizedOil())
1370 rvData = fp.get_double(
"RV");
1372 if (FluidSystem::enableVaporizedWater())
1373 rvwData = fp.get_double(
"RVW");
1376 tempiData = fp.get_double(
"TEMPI");
1379 if constexpr (enableBrine)
1380 saltData = fp.get_double(
"SALT");
1383 if constexpr (enableSaltPrecipitation)
1384 saltpData = fp.get_double(
"SALTP");
1387 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1388 auto& dofFluidState = initialFluidStates_[dofIdx];
1390 dofFluidState.setPvtRegionIndex(pvtRegionIndex(dofIdx));
1395 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1396 Scalar temperatureLoc = tempiData[dofIdx];
1397 if (!std::isfinite(temperatureLoc) || temperatureLoc <= 0)
1398 temperatureLoc = FluidSystem::surfaceTemperature;
1399 dofFluidState.setTemperature(temperatureLoc);
1405 if constexpr (enableBrine)
1406 dofFluidState.setSaltConcentration(saltData[dofIdx]);
1411 if constexpr (enableSaltPrecipitation)
1412 dofFluidState.setSaltSaturation(saltpData[dofIdx]);
1417 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
1418 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
1419 waterSaturationData[dofIdx]);
1421 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)){
1422 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)){
1423 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1425 - waterSaturationData[dofIdx]);
1428 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1429 gasSaturationData[dofIdx]);
1431 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1432 const Scalar soil = 1.0 - waterSaturationData[dofIdx] - gasSaturationData[dofIdx];
1433 if (soil < smallSaturationTolerance_) {
1434 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, 0.0);
1437 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, soil);
1444 Scalar pressure = pressureData[dofIdx];
1448 std::array<Scalar, numPhases> pc = {0};
1449 const auto& matParams = this->materialLawParams(dofIdx);
1450 MaterialLaw::capillaryPressures(pc, matParams, dofFluidState);
1451 Valgrind::CheckDefined(pressure);
1452 Valgrind::CheckDefined(pc);
1453 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1454 if (!FluidSystem::phaseIsActive(phaseIdx))
1457 if (Indices::oilEnabled)
1458 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
1459 else if (Indices::gasEnabled)
1460 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
1461 else if (Indices::waterEnabled)
1463 dofFluidState.setPressure(phaseIdx, pressure);
1466 if constexpr (enableDissolvedGas) {
1467 if (FluidSystem::enableDissolvedGas())
1468 dofFluidState.setRs(rsData[dofIdx]);
1469 else if (Indices::gasEnabled && Indices::oilEnabled)
1470 dofFluidState.setRs(0.0);
1471 if (FluidSystem::enableVaporizedOil())
1472 dofFluidState.setRv(rvData[dofIdx]);
1473 else if (Indices::gasEnabled && Indices::oilEnabled)
1474 dofFluidState.setRv(0.0);
1477 if constexpr (enableDisgasInWater) {
1478 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1479 dofFluidState.setRsw(rswData[dofIdx]);
1482 if constexpr (enableVapwat) {
1483 if (FluidSystem::enableVaporizedWater())
1484 dofFluidState.setRvw(rvwData[dofIdx]);
1490 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1491 if (!FluidSystem::phaseIsActive(phaseIdx))
1494 const auto& b = FluidSystem::inverseFormationVolumeFactor(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1495 dofFluidState.setInvB(phaseIdx, b);
1497 const auto& rho = FluidSystem::density(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1498 dofFluidState.setDensity(phaseIdx, rho);
1509 Scalar sumSaturation = 0.0;
1510 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1511 if (FluidSystem::phaseIsActive(phaseIdx)) {
1512 if (elemFluidState.saturation(phaseIdx) < smallSaturationTolerance_)
1513 elemFluidState.setSaturation(phaseIdx, 0.0);
1515 sumSaturation += elemFluidState.saturation(phaseIdx);
1519 if constexpr (enableSolvent) {
1520 if (solventSaturation < smallSaturationTolerance_)
1521 solventSaturation = 0.0;
1523 sumSaturation += solventSaturation;
1526 assert(sumSaturation > 0.0);
1528 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1529 if (FluidSystem::phaseIsActive(phaseIdx)) {
1530 const Scalar saturation = elemFluidState.saturation(phaseIdx) / sumSaturation;
1531 elemFluidState.setSaturation(phaseIdx, saturation);
1534 if constexpr (enableSolvent) {
1535 solventSaturation = solventSaturation / sumSaturation;
1541 FlowProblemType::readInitialCondition_();
1543 if constexpr (enableSolvent || enablePolymer || enablePolymerMolarWeight || enableBioeffects)
1544 this->readBlackoilExtentionsInitialConditions_(this->model().numGridDof(),
1547 enablePolymerMolarWeight,
1555 if constexpr (!enableSolvent)
1556 throw std::logic_error(
"solvent is disabled and you're trying to add solvent to BC");
1558 rate[Indices::solventSaturationIdx] = bc.rate;
1563 if constexpr (!enablePolymer)
1564 throw std::logic_error(
"polymer is disabled and you're trying to add polymer to BC");
1566 rate[Indices::polymerConcentrationIdx] = bc.rate;
1571 if constexpr (!enableMICP)
1572 throw std::logic_error(
"MICP is disabled and you're trying to add microbes to BC");
1574 rate[Indices::microbialConcentrationIdx] = bc.rate;
1579 if constexpr (!enableMICP)
1580 throw std::logic_error(
"MICP is disabled and you're trying to add oxygen to BC");
1582 rate[Indices::oxygenConcentrationIdx] = bc.rate;
1587 if constexpr (!enableMICP)
1588 throw std::logic_error(
"MICP is disabled and you're trying to add urea to BC");
1590 rate[Indices::ureaConcentrationIdx] = bc.rate;
1592 rate[Indices::ureaConcentrationIdx] *= getPropValue<TypeTag, Properties::BlackOilUreaScalingFactor>();
1597 OPM_TIMEBLOCK(updateExplicitQuantities);
1598 const bool invalidateFromMaxWaterSat = this->updateMaxWaterSaturation_();
1599 const bool invalidateFromMinPressure = this->updateMinPressure_();
1602 const bool invalidateFromHyst = this->updateHysteresis_();
1603 const bool invalidateFromMaxOilSat = this->updateMaxOilSaturation_();
1606 const bool invalidateDRDT = !first_step_after_restart && this->updateCompositionChangeLimits_();
1609 const bool invalidateIntensiveQuantities
1610 = invalidateFromMaxWaterSat || invalidateFromMinPressure || invalidateFromHyst || invalidateFromMaxOilSat || invalidateDRDT;
1611 if (invalidateIntensiveQuantities) {
1612 OPM_TIMEBLOCK(beginTimeStepInvalidateIntensiveQuantities);
1613 this->model().invalidateAndUpdateIntensiveQuantities(0);
1616 this->updateRockCompTransMultVal_();
1627 const unsigned aquIdx,
1628 const FaceDir::DirEnum faceDir)
const
1633 const auto& model = this->model();
1634 const auto& iqCell = model.intensiveQuantities(cellIdx, 0);
1635 const auto& iqAqu = model.intensiveQuantities(aquIdx, 0);
1637 const Scalar distZg = (this->dofCenterDepth(cellIdx) - this->dofCenterDepth(aquIdx))
1638 * this->gravity_[
dim - 1];
1639 const Scalar thpresCellToAqu = this->thresholdPressure(cellIdx, aquIdx);
1640 const Scalar thpresAquToCell = this->thresholdPressure(aquIdx, cellIdx);
1643 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1644 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1648 constexpr unsigned cellLocalIdx = 0;
1649 constexpr unsigned aquLocalIdx = 1;
1650 short upIdx = cellLocalIdx;
1651 short dnIdx = aquLocalIdx;
1653 ExtensiveQuantities::calculatePhasePressureDiff_(upIdx, dnIdx, pressureDifference,
1654 iqCell, iqAqu, phaseIdx,
1655 cellLocalIdx, aquLocalIdx,
1656 model.dofTotalVolume(cellIdx),
1657 model.dofTotalVolume(aquIdx),
1658 cellIdx, aquIdx, distZg,
1659 thpresCellToAqu, thpresAquToCell,
1660 this->moduleParams());
1663 const Scalar dp = getValue(pressureDifference);
1664 const auto& up = (upIdx ==
static_cast<short>(cellLocalIdx)) ? iqCell : iqAqu;
1666 getValue(up.fluidState().saturation(phaseIdx)) > 0.0 &&
1667 getValue(up.mobility(phaseIdx, faceDir)) > 0.0 &&
1668 std::abs(dp) > std::abs(largest))
1681 const auto& vanguard = this->simulator().vanguard();
1682 const auto& eclState = vanguard.eclState();
1683 if (!eclState.aquifer().hasNumericalAquifer() ||
1684 !eclState.fieldProps().has_int(
"EQLNUM"))
1689 std::unordered_map<std::size_t, std::size_t> aquiferOfCell;
1690 for (
const auto& [cartIdx, cell] : eclState.aquifer().numericalAquifers().allAquiferCells()) {
1691 aquiferOfCell.emplace(cartIdx, cell->aquifer_id);
1694 const auto eqlnum = this->lookUpData_.template
1695 assignFieldPropsIntOnLeaf<int>(eclState.fieldProps(),
"EQLNUM",
false);
1700 std::vector<NumericalAquiferEquilibrationMismatch> mismatches;
1701 const auto& gridView = this->gridView();
1702 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
1703 const unsigned cellIdx = this->elementMapper().index(elem);
1704 const auto cellCart = vanguard.cartesianIndex(cellIdx);
1705 const bool cellIsAquifer = aquiferOfCell.contains(cellCart);
1706 for (
const auto& intersection : intersections(gridView, elem)) {
1707 if (!intersection.neighbor()) {
1710 const unsigned aquIdx = this->elementMapper().index(intersection.outside());
1711 const auto aquCart = vanguard.cartesianIndex(aquIdx);
1712 const auto aquifer = aquiferOfCell.find(aquCart);
1713 if (aquifer == aquiferOfCell.end() ||
1714 (cellIsAquifer && cellCart > aquCart) ||
1715 eqlnum[aquIdx] == eqlnum[cellIdx] ||
1716 !(this->transmissibility(cellIdx, aquIdx) > 0.0))
1722 const int dirId = intersection.indexInInside();
1723 const auto faceDir = (dirId < 0) ? FaceDir::DirEnum::Unknown
1724 : FaceDir::FromIntersectionIndex(dirId);
1726 const Scalar dp = this->initialFlowPressureDifference_(cellIdx, aquIdx, faceDir);
1728 mismatches.push_back({aquifer->second, eqlnum[aquIdx], eqlnum[cellIdx], dp});
1734 Parameters::Get<Parameters::AllowInconsistentAquiferEquilibration>());
1739 if (
const auto nph = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
1740 + FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)
1741 + FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
1750 const auto numSamplePoints =
static_cast<std::size_t
>
1751 (Parameters::Get<Parameters::NumSatfuncConsistencySamplePoints>());
1753 auto sfuncConsistencyChecks =
1755 numSamplePoints, this->simulator().vanguard().eclState(),
1756 [&cmap = this->simulator().vanguard().cartesianIndexMapper()](
const int elemIdx)
1757 {
return cmap.cartesianIndex(elemIdx); }
1760 const auto ioRank = 0;
1761 const auto isIoRank = this->simulator().vanguard()
1762 .grid().comm().rank() == ioRank;
1768 .
run(this->simulator().vanguard().grid().levelGridView(0),
1769 [&vg = this->simulator().vanguard(),
1770 &emap = this->simulator().model().elementMapper()]
1772 {
return vg.gridIdxToEquilGridIdx(emap.index(elem)); });
1777 auto reportFailures = [&sfuncConsistencyChecks]
1778 (
const ViolationLevel level)
1780 sfuncConsistencyChecks.reportFailures
1781 (level, [](std::string_view record)
1782 { OpmLog::info(std::string { record }); });
1785 if (sfuncConsistencyChecks.anyFailedStandardChecks()) {
1787 OpmLog::warning(
"Saturation Function "
1788 "End-point Consistency Problems");
1790 reportFailures(ViolationLevel::Standard);
1794 if (sfuncConsistencyChecks.anyFailedCriticalChecks()) {
1796 OpmLog::error(
"Saturation Function "
1797 "End-point Consistency Failures");
1799 reportFailures(ViolationLevel::Critical);
1817 const Scalar smallSaturationTolerance_ = 1.e-6;
1819 bool enableDamarisOutput_ = false ;
1820 std::unique_ptr<DamarisWriterType> damarisWriter_;
1826 bool checkAquiferEquilibration_{
false};
1833 : mixControls(schedule)
1856 bool episodeWillBeOver()
const override
1858 const auto currTime = this->simulator().time()
1859 + this->simulator().timeStepSize();
1861 const auto nextReportStep =
1862 this->simulator().vanguard().schedule()
1863 .seconds(this->simulator().episodeIndex() + 1);
1865 const auto isSubStep = (nextReportStep - currTime)
1866 > (2 * std::numeric_limits<float>::epsilon()) * nextReportStep;
Contains classes extending the black-oil model. \detail This file holds dummy definitions,...
Class handling Action support in simulator.
Definition: ActionHandler.hpp:52
Provides the auxiliary methods required for consideration of the diffusion equation.
Provides the auxiliary methods required for consideration of the dispersion equation.
Hybrid Newton solver extension for the black-oil model.
Definition: HybridNewton.hpp:60
void tryApplyHybridNewton()
Attempt to apply the Hybrid Newton correction at the current timestep.
Definition: HybridNewton.hpp:101
Collects necessary output values and pass it to opm-common's ECL output.
Definition: EclWriter.hpp:124
OutputModule & mutableOutputModule() const
Definition: EclWriter.hpp:775
static void registerParameters()
Definition: EclWriter.hpp:152
Computes the initial condition based on the EQUIL keyword from ECL.
Definition: EquilInitializer.hpp:59
const ScalarFluidState & initialFluidState(unsigned elemIdx) const
Return the initial thermodynamic state which should be used as the initial condition.
Definition: EquilInitializer.hpp:207
BlackOilFluidState< Scalar, FluidSystem, energyModuleType !=EnergyModules::NoTemperature, energyModuleType==EnergyModules::FullyImplicitThermal, enableDissolution, enableVapwat, enableBrine, enableSaltPrecipitation, enableDisgasInWater, enableSolvent, Indices::numPhases > ScalarFluidState
Definition: EquilInitializer.hpp:102
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:385
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:403
bool enableDriftCompensationTemp_
Definition: FlowGenericProblem.hpp:404
bool enableTuning_
Definition: FlowGenericProblem.hpp:396
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemBlackoil.hpp:81
HybridNewton hybridNewton_
Definition: FlowProblemBlackoil.hpp:1843
void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart) override
Definition: FlowProblemBlackoil.hpp:1146
bool updateMaxPolymerAdsorption_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblemBlackoil.hpp:1166
void writeOutput(const bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemBlackoil.hpp:531
void readInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1539
void readEquilInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1275
void handleSolventBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1553
bool checkAquiferEquilibration_
Definition: FlowProblemBlackoil.hpp:1826
Scalar maxGasDissolutionFactor(unsigned timeIdx, unsigned globalDofIdx) const
Returns the maximum value of the gas dissolution factor at the current time for a given degree of fre...
Definition: FlowProblemBlackoil.hpp:862
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemBlackoil.hpp:726
void processRestartSaturations_(InitialFluidState &elemFluidState, Scalar &solventSaturation)
Definition: FlowProblemBlackoil.hpp:1505
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemBlackoil.hpp:723
FlowProblemBlackoil(Simulator &simulator)
Definition: FlowProblemBlackoil.hpp:182
bool enableEclOutput_
Definition: FlowProblemBlackoil.hpp:1814
PrevTimestepState prev_timestep_state_
Definition: FlowProblemBlackoil.hpp:1839
Scalar drsdtcon(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:957
void endStepApplyAction()
Definition: FlowProblemBlackoil.hpp:452
bool drsdtconIsActive(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:963
void handleMicrBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1569
Scalar maxOilVaporizationFactor(unsigned timeIdx, unsigned globalDofIdx) const
Returns the maximum value of the oil vaporization factor at the current time for a given degree of fr...
Definition: FlowProblemBlackoil.hpp:873
std::vector< InitialFluidState > initialFluidStates_
Definition: FlowProblemBlackoil.hpp:1812
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemBlackoil.hpp:446
void updateMaxPolymerAdsorption_()
Definition: FlowProblemBlackoil.hpp:1156
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemBlackoil.hpp:720
void endEpisode() override
Called by the simulator after the end of an episode.
Definition: FlowProblemBlackoil.hpp:499
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemBlackoil.hpp:732
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemBlackoil.hpp:913
void checkNumericalAquiferEquilibration_() const
Definition: FlowProblemBlackoil.hpp:1679
Scalar initialFlowPressureDifference_(const unsigned cellIdx, const unsigned aquIdx, const FaceDir::DirEnum faceDir) const
Definition: FlowProblemBlackoil.hpp:1626
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemBlackoil.hpp:317
void finalizeOutput()
Definition: FlowProblemBlackoil.hpp:554
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemBlackoil.hpp:974
void handleOxygBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1577
InitialFluidState boundaryFluidState(unsigned globalDofIdx, const int directionId) const
Definition: FlowProblemBlackoil.hpp:738
std::unique_ptr< EclWriterType > eclWriter_
Definition: FlowProblemBlackoil.hpp:1815
void initialSolutionApplied() override
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblemBlackoil.hpp:566
void captureBeginTimeStepState_() override
Snapshot the mixing rate controls before the timestep runs.
Definition: FlowProblemBlackoil.hpp:1133
void readEclRestartSolution_()
Definition: FlowProblemBlackoil.hpp:1245
void readExplicitInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1290
void beginEpisode() override
Called by the simulator before an episode begins.
Definition: FlowProblemBlackoil.hpp:275
bool recycleFirstIterationStorage() const
Return if the storage term of the first iteration is identical to the storage term for the solution o...
Definition: FlowProblemBlackoil.hpp:891
void handleUreaBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1585
LhsEval permFactTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Calculate the transmissibility multiplier due to porosity reduction.
Definition: FlowProblemBlackoil.hpp:700
void serializeOp(Serializer &serializer)
Definition: FlowProblemBlackoil.hpp:1124
MixingRateControls< FluidSystem > mixControls_
Definition: FlowProblemBlackoil.hpp:1822
void handlePolymerBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1561
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemBlackoil.hpp:519
const EclWriterType & eclWriter() const
Definition: FlowProblemBlackoil.hpp:852
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemBlackoil.hpp:735
void addToSourceDense(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const override
Definition: FlowProblemBlackoil.hpp:593
void computeAndSetEqWeights_()
Definition: FlowProblemBlackoil.hpp:1178
void beginTimeStep() override
Called by the simulator before each time integration.
Definition: FlowProblemBlackoil.hpp:308
void updateExplicitQuantities_(const bool first_step_after_restart)
Definition: FlowProblemBlackoil.hpp:1595
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemBlackoil.hpp:168
ActionHandler< Scalar, IndexTraits > actionHandler_
Definition: FlowProblemBlackoil.hpp:1841
void readSolutionFromOutputModule(const int restart_step, bool fip_init)
Read simulator solution state from the outputmodule (used with restart)
Definition: FlowProblemBlackoil.hpp:1015
const EclipseIO & eclIO() const
Definition: FlowProblemBlackoil.hpp:729
void restoreBeginTimeStepState_() override
Restore mixing rate controls after a failed timestep.
Definition: FlowProblemBlackoil.hpp:1140
EclWriterType & eclWriter()
Definition: FlowProblemBlackoil.hpp:855
bool satfuncConsistencyRequirementsMet() const
Definition: FlowProblemBlackoil.hpp:1737
bool updateCompositionChangeLimits_()
Definition: FlowProblemBlackoil.hpp:1212
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:101
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:166
static constexpr bool enableFoam
Definition: FlowProblem.hpp:132
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:544
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:962
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:742
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:114
@ numComponents
Definition: FlowProblem.hpp:124
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:108
GetPropType< TypeTag, Properties::EqVector > EqVector
Definition: FlowProblem.hpp:113
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: FlowProblem.hpp:158
GlobalEqVector drift_
Definition: FlowProblem.hpp:2120
@ gasCompIdx
Definition: FlowProblem.hpp:150
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:155
Dune::FieldMatrix< Scalar, dimWorld, dimWorld > DimMatrix
Definition: FlowProblem.hpp:172
@ waterPhaseIdx
Definition: FlowProblem.hpp:146
int episodeIndex() const
Definition: FlowProblem.hpp:315
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:115
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: FlowProblem.hpp:112
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:156
@ enableExperiments
Definition: FlowProblem.hpp:139
static constexpr bool enableDiffusion
Definition: FlowProblem.hpp:129
@ dimWorld
Definition: FlowProblem.hpp:119
TracerModel tracerModel_
Definition: FlowProblem.hpp:2126
@ enableThermalFluxBoundaries
Definition: FlowProblem.hpp:142
WellModel wellModel_
Definition: FlowProblem.hpp:2122
virtual void beginEpisode()
Called by the simulator before an episode begins.
Definition: FlowProblem.hpp:323
static constexpr bool enablePolymerMolarWeight
Definition: FlowProblem.hpp:134
virtual void beginTimeStep()
Called by the simulator before each time integration.
Definition: FlowProblem.hpp:382
@ gasPhaseIdx
Definition: FlowProblem.hpp:144
static constexpr bool enableSolvent
Definition: FlowProblem.hpp:135
@ numPhases
Definition: FlowProblem.hpp:123
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1428
static constexpr bool enablePolymer
Definition: FlowProblem.hpp:133
@ numEq
Definition: FlowProblem.hpp:122
@ dim
Definition: FlowProblem.hpp:118
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: FlowProblem.hpp:167
@ enableSaltPrecipitation
Definition: FlowProblem.hpp:141
TemperatureModel temperatureModel_
Definition: FlowProblem.hpp:2127
static constexpr bool enableExtbo
Definition: FlowProblem.hpp:131
static constexpr bool enableConvectiveMixing
Definition: FlowProblem.hpp:128
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:109
bool prepareTransmissibilityOutput_(EclWriterType &eclWriter, const bool enableEclOutput)
Definition: FlowProblem.hpp:1437
@ oilCompIdx
Definition: FlowProblem.hpp:151
void initializeSimulatorTime_()
Definition: FlowProblem.hpp:1496
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:200
void updatePffDofData_()
Definition: FlowProblem.hpp:1890
static constexpr bool enableDispersion
Definition: FlowProblem.hpp:130
@ oilPhaseIdx
Definition: FlowProblem.hpp:145
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:154
void readBoundaryConditions_()
Definition: FlowProblem.hpp:1921
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:462
static constexpr EnergyModules energyModuleType
Definition: FlowProblem.hpp:137
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:111
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:164
void initializeModelProperties_()
Definition: FlowProblem.hpp:1520
static constexpr bool enableBioeffects
Definition: FlowProblem.hpp:126
static constexpr bool enableBrine
Definition: FlowProblem.hpp:127
@ waterCompIdx
Definition: FlowProblem.hpp:152
@ enableMICP
Definition: FlowProblem.hpp:140
Class handling mixing rate controls for a FlowProblemBlackoil.
Definition: MixingRateControls.hpp:46
Definition: SatfuncConsistencyCheckManager.hpp:58
SatfuncConsistencyCheckManager & collectFailuresTo(const int root)
Definition: SatfuncConsistencyCheckManager.hpp:99
void run(const GridView &gv, GetCellIndex &&getCellIndex)
Definition: SatfuncConsistencyCheckManager.hpp:128
typename SatfuncConsistencyChecks< Scalar >::ViolationLevel ViolationLevel
Severity level for consistency condition violation.
Definition: SatfuncConsistencyCheckManager.hpp:71
Definition: SimulatorTimer.hpp:38
VTK output module for the tracer model's parameters.
Definition: VtkTracerModule.hpp:58
static void registerParameters()
Register all run-time parameters for the tracer VTK output module.
Definition: VtkTracerModule.hpp:84
@ NONE
Definition: DeferredLogger.hpp:46
static constexpr int dim
Definition: structuredgridvanguard.hh:68
Definition: blackoilbioeffectsmodules.hh:45
constexpr double numericalAquiferEquilibrationTolerance
Definition: NumericalAquiferEquilibrationCheck.hpp:45
std::size_t checkNumericalAquiferEquilibration(const std::vector< NumericalAquiferEquilibrationMismatch > &localMismatches, const EclipseState &eclState, const Parallel::Communication &comm, bool allowMismatch)
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
Struct holding the parameters for the BlackOilBioeffectsModule class.
Definition: blackoilbioeffectsparams.hpp:42
Struct holding the parameters for the BlackoilBrineModule class.
Definition: blackoilbrineparams.hpp:42
Struct holding the parameters for the BlackoilExtboModule class.
Definition: blackoilextboparams.hpp:48
Struct holding the parameters for the BlackoilFoamModule class.
Definition: blackoilfoamparams.hpp:44
Struct holding the parameters for the BlackOilPolymerModule class.
Definition: blackoilpolymerparams.hpp:43
Struct holding the parameters for the BlackOilSolventModule class.
Definition: blackoilsolventparams.hpp:47
Blackoil part of the begin-of-timestep snapshot; see FlowProblem::PrevTimestepState.
Definition: FlowProblemBlackoil.hpp:1831
MixingRateControls< FluidSystem > mixControls
DRSDT / DRVDT.
Definition: FlowProblemBlackoil.hpp:1836
PrevTimestepState(const Schedule &schedule)
Definition: FlowProblemBlackoil.hpp:1832
Definition: SimulatorReport.hpp:202
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34