31#ifndef OPM_FLOW_PROBLEM_BLACK_HPP
32#define OPM_FLOW_PROBLEM_BLACK_HPP
34#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
35#include <opm/material/fluidsystems/blackoilpvt/DryGasPvt.hpp>
36#include <opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp>
37#include <opm/material/fluidsystems/blackoilpvt/LiveOilPvt.hpp>
38#include <opm/material/fluidsystems/blackoilpvt/DeadOilPvt.hpp>
39#include <opm/material/fluidsystems/blackoilpvt/ConstantCompressibilityOilPvt.hpp>
40#include <opm/material/fluidsystems/blackoilpvt/ConstantCompressibilityWaterPvt.hpp>
41#include <opm/material/fluidsystems/blackoilpvt/ConstantRsDeadOilPvt.hpp>
47#include <opm/output/eclipse/EclipseIO.hpp>
49#include <opm/input/eclipse/Units/Units.hpp>
85template <
class TypeTag>
141 static constexpr bool enableDissolvedGas =
142 Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
143 enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
144 enum { enableDisgasInWater = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
145 enum { enableGeochemistry = getPropValue<TypeTag, Properties::EnableGeochemistry>() };
146 enum { enableMech = getPropValue<TypeTag, Properties::EnableMech>() };
148 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, enableBioeffects>;
149 using BrineModule = BlackOilBrineModule<TypeTag, enableBrine>;
150 using ConvectiveMixingModule = BlackOilConvectiveMixingModule<TypeTag, enableConvectiveMixing>;
153 using ExtboModule = BlackOilExtboModule<TypeTag, enableExtbo>;
154 using FoamModule = BlackOilFoamModule<TypeTag, enableFoam>;
155 using PolymerModule = BlackOilPolymerModule<TypeTag, enablePolymer>;
156 using SolventModule = BlackOilSolventModule<TypeTag, enableSolvent>;
158 using EclWriterType = EclWriter<TypeTag, OutputBlackOilModule<TypeTag> >;
159 using IndexTraits =
typename FluidSystem::IndexTraitsType;
161 using HybridNewton = BlackOilHybridNewton<TypeTag>;
162 using ModuleParams = BlackoilModuleParams<ConvectiveMixingModuleParam<Scalar>>;
165 using DamarisWriterType = DamarisWriter<TypeTag>;
181 DamarisWriterType::registerParameters();
194 simulator.vanguard().schedule(),
195 simulator.vanguard().actionState(),
196 simulator.vanguard().summaryState(),
198 simulator.vanguard().grid().comm())
204 const auto& vanguard = simulator.vanguard();
206 if constexpr (enableBrine) {
208 brineParams.template initFromState<enableBrine,
209 enableSaltPrecipitation>(vanguard.eclState());
210 BrineModule::setParams(std::move(brineParams));
213 if constexpr (enableDiffusion) {
214 DiffusionModule::initFromState(vanguard.eclState());
217 if constexpr (enableDispersion) {
218 DispersionModule::initFromState(vanguard.eclState());
221 if constexpr (enableExtbo) {
223 extboParams.template initFromState<enableExtbo>(vanguard.eclState());
224 ExtboModule::setParams(std::move(extboParams));
227 if constexpr (enableFoam) {
229 foamParams.template initFromState<enableFoam>(vanguard.eclState());
230 FoamModule::setParams(std::move(foamParams));
233 if constexpr (enableBioeffects) {
235 bioeffectsParams.template initFromState<enableBioeffects, enableMICP>(vanguard.eclState());
236 BioeffectsModule::setParams(std::move(bioeffectsParams));
239 if constexpr (enablePolymer) {
241 polymerParams.template initFromState<enablePolymer, enablePolymerMolarWeight>(vanguard.eclState());
242 PolymerModule::setParams(std::move(polymerParams));
245 if constexpr (enableSolvent) {
247 solventParams.template initFromState<enableSolvent>(vanguard.eclState(), vanguard.schedule());
248 SolventModule::setParams(std::move(solventParams));
252 eclWriter_ = std::make_unique<EclWriterType>(simulator);
256 if constexpr (!enableGeochemistry) {
257 if (vanguard.eclState().runspec().geochem().enabled()) {
258 throw std::runtime_error(
"GEOCHEM keyword in the deck but geochemistry module "
259 "was disabled at compile time!");
264 if constexpr (!enableMech) {
265 const auto& rspec = vanguard.eclState().runspec();
266 if (rspec.mech() && rspec.mechSolver().tpsa()) {
267 throw std::runtime_error(
"TPSA solver enabled in the deck, but geomechanics "
268 "module was disabled at compile time!");
274 damarisWriter_ = std::make_unique<DamarisWriterType>(simulator);
275 enableDamarisOutput_ = Parameters::Get<Parameters::EnableDamarisOutput>();
286 auto& simulator = this->simulator();
288 const int episodeIdx = simulator.episodeIndex();
289 const auto& schedule = simulator.vanguard().schedule();
294 .evalUDQAssignments(episodeIdx, simulator.vanguard().udqState());
296 if (episodeIdx >= 0) {
297 const auto& oilVap = schedule[episodeIdx].oilvap();
298 if (oilVap.getType() == OilVaporizationProperties::OilVaporization::VAPPARS) {
299 FluidSystem::setVapPars(oilVap.vap1(), oilVap.vap2());
302 FluidSystem::setVapPars(0.0, 0.0);
305 if constexpr (enableConvectiveMixing) {
306 ConvectiveMixingModule::beginEpisode(simulator.vanguard().eclState(), schedule, episodeIdx,
307 this->moduleParams_.convectiveMixingModuleParam);
329 FlowProblemType::finishInit();
331 auto& simulator = this->simulator();
333 auto finishTransmissibilities = [updated =
false,
this]()
mutable
335 if (updated) {
return; }
337 this->
transmissibilities_.finishInit([&vg = this->simulator().vanguard()](
const unsigned int it) {
338 return vg.gridIdxToEquilGridIdx(it);
349 if (simulator.vanguard().grid().comm().size() > 1) {
350 if (simulator.vanguard().grid().comm().rank() == 0)
351 eclWriter_->setTransmissibilities(&simulator.vanguard().globalTransmissibility());
353 finishTransmissibilities();
354 eclWriter_->setTransmissibilities(&simulator.problem().eclTransmissibilities());
357 std::function<
unsigned int(
unsigned int)> equilGridToGrid = [&simulator](
unsigned int i) {
358 return simulator.vanguard().gridEquilIdxToGridIdx(i);
361 this->
eclWriter_->extractOutputTransAndNNC(equilGridToGrid);
363 simulator.vanguard().releaseGlobalTransmissibilities();
365 const auto& eclState = simulator.vanguard().eclState();
366 const auto& schedule = simulator.vanguard().schedule();
369 simulator.setStartTime(schedule.getStartTime());
370 simulator.setEndTime(schedule.simTime(schedule.size() - 1));
376 simulator.setEpisodeIndex(-1);
377 simulator.setEpisodeLength(0.0);
384 const auto& tuning = schedule[0].tuning();
391 bool isThermal = eclState.getSimulationConfig().isThermal();
392 bool isTemp = eclState.getSimulationConfig().isTemp();
393 bool conserveInnerEnergy = isTemp || (isThermal && Parameters::Get<Parameters::ConserveInnerEnergyThermal>());
394 FluidSystem::setEnergyEqualEnthalpy(conserveInnerEnergy);
396 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
397 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
402 [&simulator](
const unsigned idx)
404 std::array<int,dim> coords;
405 simulator.vanguard().cartesianCoordinate(idx, coords);
406 std::ranges::transform(coords, coords.begin(),
407 [](const auto c) { return c + 1; });
419 finishTransmissibilities();
421 const auto& initconfig = eclState.getInitConfig();
423 if (initconfig.restartRequested()) {
434 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
435 const auto& vanguard = this->simulator().vanguard();
436 const auto& gridView = vanguard.gridView();
437 const int numElements = gridView.size(0);
438 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
447 this->
drift_.resize(this->model().numGridDof());
454 if (!initconfig.restartRequested() && !eclState.getIOConfig().initOnly()) {
455 simulator.startNextEpisode(schedule.seconds(1));
456 simulator.setEpisodeIndex(0);
457 simulator.setTimeStepIndex(0);
460 if (Parameters::Get<Parameters::CheckSatfuncConsistency>() &&
470 this->simulator().vanguard().grid().comm().barrier();
472 throw std::domain_error {
473 "Saturation function end-points do not "
474 "meet requisite consistency conditions"
483 eclState.runspec().tabdims().getNumPVTTables());
485 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
486 simulator.setTimeStepSize(0.0);
487 simulator.model().applyInitialSolution();
491 if (!eclState.getIOConfig().initOnly()) {
492 if (!this->
enableTuning_ && eclState.getSimulationConfig().anyTUNING()) {
493 OpmLog::info(
"\nThe deck has TUNING in the SCHEDULE section, but "
494 "it is ignored due\nto the flag --enable-tuning=false. "
495 "Set this flag to true to activate it.\n"
496 "Manually tuning the simulator with the TUNING keyword may "
497 "increase run time.\nIt is recommended using the simulator's "
498 "default tuning (--enable-tuning=false).");
508 FlowProblemType::endTimeStep();
509 this->endStepApplyAction();
516 this->eclWriter().mutableOutputModule().invalidateLocalData();
519 const auto& grid = this->simulator().vanguard().gridView().grid();
521 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
522 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
523 if (!isCpGrid || (grid.maxLevel() == 0)) {
524 this->eclWriter_->evalSummaryState(!this->episodeWillBeOver());
528 OPM_TIMEBLOCK(applyActions);
530 const int episodeIdx = this->episodeIndex();
531 auto& simulator = this->simulator();
535 this->simulator().vanguard().schedule().clearEvents(episodeIdx);
539 .applyActions(episodeIdx, simulator.time() + simulator.timeStepSize(),
540 [
this](
const bool global)
542 using TransUpdateQuantities = typename
543 Vanguard::TransmissibilityType::TransUpdateQuantities;
545 this->transmissibilities_
546 .update(global, TransUpdateQuantities::All,
547 [&vg = this->simulator().vanguard()]
548 (const unsigned int i)
550 return vg.gridIdxToEquilGridIdx(i);
561 OPM_TIMEBLOCK(endEpisode);
574 .evalUDQAssignments(this->episodeIndex(), this->simulator().vanguard().udqState());
576 FlowProblemType::endEpisode();
581 if (this->enableEclOutput_) {
582 this->eclWriter_->writeReports(timer);
593 FlowProblemType::writeOutput(verbose);
595 const auto isSubStep = !this->episodeWillBeOver();
597 auto localCellData = data::Solution {};
602 if (this->enableDamarisOutput_ && (this->damarisWriter_ !=
nullptr)) {
603 this->damarisWriter_->writeOutput(localCellData, isSubStep);
607 if (this->enableEclOutput_ && (this->eclWriter_ !=
nullptr)) {
608 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
609 this->simulator().vanguard().schedule()
610 .exitStatus().has_value());
616 OPM_TIMEBLOCK(finalizeOutput);
628 FlowProblemType::initialSolutionApplied();
633 this->thresholdPressures_.finishInit();
636 const auto& grid = this->simulator().vanguard().gridView().grid();
638 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
639 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
641 if (!isCpGrid || (grid.maxLevel() == 0)) {
642 if (this->simulator().episodeIndex() == 0) {
643 eclWriter_->writeInitialFIPReport();
649 unsigned globalDofIdx,
650 unsigned timeIdx)
const override
652 this->aquiferModel_.addToSource(rate, globalDofIdx, timeIdx);
655 const auto& source = this->simulator().vanguard().schedule()[this->episodeIndex()].source();
656 std::array<int,3> ijk;
657 this->simulator().vanguard().cartesianCoordinate(globalDofIdx, ijk);
659 if (source.hasSource(ijk)) {
660 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
661 static std::array<SourceComponent, 3> sc_map = {SourceComponent::WATER, SourceComponent::OIL, SourceComponent::GAS};
662 static std::array<int, 3> phidx_map = {FluidSystem::waterPhaseIdx, FluidSystem::oilPhaseIdx, FluidSystem::gasPhaseIdx};
663 static std::array<int, 3> cidx_map = {waterCompIdx, oilCompIdx, gasCompIdx};
665 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
666 const auto phaseIdx = phidx_map[i];
667 const auto sourceComp = sc_map[i];
668 const auto compIdx = cidx_map[i];
669 if (!FluidSystem::phaseIsActive(phaseIdx)) {
672 Scalar mass_rate = source.rate(ijk, sourceComp) / this->model().dofTotalVolume(globalDofIdx);
673 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
674 mass_rate /= FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
676 rate[FluidSystem::canonicalToActiveCompIdx(compIdx)] += mass_rate;
679 if constexpr (enableSolvent) {
680 Scalar mass_rate = source.rate(ijk, SourceComponent::SOLVENT) / this->model().dofTotalVolume(globalDofIdx);
681 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
682 const auto& solventPvt = SolventModule::solventPvt();
683 mass_rate /= solventPvt.referenceDensity(pvtRegionIdx);
685 rate[Indices::contiSolventEqIdx] += mass_rate;
687 if constexpr (enablePolymer) {
688 rate[Indices::polymerConcentrationIdx] += source.rate(ijk, SourceComponent::POLYMER) / this->model().dofTotalVolume(globalDofIdx);
690 if constexpr (enableMICP) {
691 rate[Indices::microbialConcentrationIdx] += source.rate(ijk, SourceComponent::MICR) / this->model().dofTotalVolume(globalDofIdx);
692 rate[Indices::oxygenConcentrationIdx] += source.rate(ijk, SourceComponent::OXYG) / this->model().dofTotalVolume(globalDofIdx);
693 rate[Indices::ureaConcentrationIdx] += source.rate(ijk, SourceComponent::UREA) / (this->model().dofTotalVolume(globalDofIdx));
695 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
696 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
697 const auto phaseIdx = phidx_map[i];
698 if (!FluidSystem::phaseIsActive(phaseIdx)) {
701 const auto sourceComp = sc_map[i];
702 const auto source_hrate = source.hrate(ijk, sourceComp);
704 rate[Indices::contiEnergyEqIdx] += source_hrate.value() / this->model().dofTotalVolume(globalDofIdx);
706 const auto& intQuants = this->simulator().model().intensiveQuantities(globalDofIdx, 0);
707 auto fs = intQuants.fluidState();
709 const auto source_temp = source.temperature(ijk, sourceComp);
711 Scalar temperature = source_temp.value();
712 fs.setTemperature(temperature);
714 const auto& h = FluidSystem::enthalpy(fs, phaseIdx, pvtRegionIdx);
715 Scalar mass_rate = source.rate(ijk, sourceComp)/ this->model().dofTotalVolume(globalDofIdx);
716 Scalar energy_rate = getValue(h)*mass_rate;
717 rate[Indices::contiEnergyEqIdx] += energy_rate;
725 if (this->enableDriftCompensation_) {
726 const auto& simulator = this->simulator();
727 const auto& model = this->model();
732 Scalar maxCompensation = model.newtonMethod().tolerance()/10;
733 Scalar poro = this->porosity(globalDofIdx, timeIdx);
734 Scalar dt = simulator.timeStepSize();
735 EqVector dofDriftRate = this->drift_[globalDofIdx];
736 dofDriftRate /= dt*model.dofTotalVolume(globalDofIdx);
739 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
740 Scalar cnv = std::abs(dofDriftRate[eqIdx])*dt*model.eqWeight(globalDofIdx, eqIdx)/poro;
741 if (cnv > maxCompensation) {
742 dofDriftRate[eqIdx] *= maxCompensation/cnv;
746 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx)
747 rate[eqIdx] -= dofDriftRate[eqIdx];
754 template <
class LhsEval,
class Callback>
757 OPM_TIMEBLOCK_LOCAL(permFactTransMultiplier, Subsystem::PvtProps);
758 if constexpr (enableSaltPrecipitation) {
759 const auto& fs = intQuants.fluidState();
760 unsigned tableIdx = this->simulator().problem().satnumRegionIndex(elementIdx);
761 LhsEval porosityFactor = obtain(1. - fs.saltSaturation());
762 porosityFactor = min(porosityFactor, 1.0);
763 const auto& permfactTable = BrineModule::permfactTable(tableIdx);
764 return permfactTable.eval(porosityFactor,
true);
766 else if constexpr (enableBioeffects) {
767 return obtain(intQuants.permFactor());
776 {
return initialFluidStates_[globalDofIdx]; }
779 {
return initialFluidStates_; }
782 {
return initialFluidStates_; }
785 {
return eclWriter_->eclIO(); }
788 {
return eclWriter_->setSubStepReport(report); }
791 {
return eclWriter_->setSimulationReport(report); }
795 OPM_TIMEBLOCK_LOCAL(boundaryFluidState, Subsystem::Assembly);
796 const auto& bcprop = this->simulator().vanguard().schedule()[this->episodeIndex()].bcprop;
797 if (bcprop.size() > 0) {
798 FaceDir::DirEnum dir = FaceDir::FromIntersectionIndex(directionId);
802 if (this->bcindex_(dir)[globalDofIdx] == 0)
803 return initialFluidStates_[globalDofIdx];
805 const auto& bc = bcprop[this->bcindex_(dir)[globalDofIdx]];
806 if (bc.bctype == BCType::DIRICHLET )
808 InitialFluidState fluidState;
809 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
810 fluidState.setPvtRegionIndex(pvtRegionIdx);
812 switch (bc.component) {
813 case BCComponent::OIL:
814 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx))
815 throw std::logic_error(
"oil is not active and you're trying to add oil BC");
817 fluidState.setSaturation(FluidSystem::oilPhaseIdx, 1.0);
819 case BCComponent::GAS:
820 if (!FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
821 throw std::logic_error(
"gas is not active and you're trying to add gas BC");
823 fluidState.setSaturation(FluidSystem::gasPhaseIdx, 1.0);
825 case BCComponent::WATER:
826 if (!FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
827 throw std::logic_error(
"water is not active and you're trying to add water BC");
829 fluidState.setSaturation(FluidSystem::waterPhaseIdx, 1.0);
831 case BCComponent::SOLVENT:
832 case BCComponent::POLYMER:
833 case BCComponent::MICR:
834 case BCComponent::OXYG:
835 case BCComponent::UREA:
837 throw std::logic_error(
"you need to specify a valid component (OIL, WATER or GAS) when DIRICHLET type is set in BC");
839 fluidState.setTotalSaturation(1.0);
840 double pressure = initialFluidStates_[globalDofIdx].pressure(this->refPressurePhaseIdx_());
841 const auto pressure_input = bc.pressure;
842 if (pressure_input) {
843 pressure = *pressure_input;
846 std::array<Scalar, numPhases> pc = {0};
847 const auto& matParams = this->materialLawParams(globalDofIdx);
848 MaterialLaw::capillaryPressures(pc, matParams, fluidState);
849 Valgrind::CheckDefined(pressure);
850 Valgrind::CheckDefined(pc);
851 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
852 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
853 if (Indices::oilEnabled)
854 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
855 else if (Indices::gasEnabled)
856 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
857 else if (Indices::waterEnabled)
859 fluidState.setPressure(phaseIdx, pressure);
861 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
862 double temperature = initialFluidStates_[globalDofIdx].temperature(0);
863 const auto temperature_input = bc.temperature;
864 if(temperature_input)
865 temperature = *temperature_input;
866 fluidState.setTemperature(temperature);
869 if constexpr (enableDissolvedGas) {
870 if (FluidSystem::enableDissolvedGas()) {
871 fluidState.setRs(0.0);
872 fluidState.setRv(0.0);
875 if constexpr (enableDisgasInWater) {
876 if (FluidSystem::enableDissolvedGasInWater()) {
877 fluidState.setRsw(0.0);
880 if constexpr (enableVapwat) {
881 if (FluidSystem::enableVaporizedWater()) {
882 fluidState.setRvw(0.0);
886 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
887 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
889 const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, pvtRegionIdx);
890 fluidState.setInvB(phaseIdx, b);
892 const auto& rho = FluidSystem::density(fluidState, phaseIdx, pvtRegionIdx);
893 fluidState.setDensity(phaseIdx, rho);
894 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
895 const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, pvtRegionIdx);
896 fluidState.setEnthalpy(phaseIdx, h);
899 fluidState.checkDefined();
903 return initialFluidStates_[globalDofIdx];
908 {
return *eclWriter_; }
911 {
return *eclWriter_; }
919 return this->mixControls_.maxGasDissolutionFactor(timeIdx, globalDofIdx,
920 this->episodeIndex(),
921 this->pvtRegionIndex(globalDofIdx));
930 return this->mixControls_.maxOilVaporizationFactor(timeIdx, globalDofIdx,
931 this->episodeIndex(),
932 this->pvtRegionIndex(globalDofIdx));
948 const auto& rspec = this->simulator().vanguard().eclState().runspec();
949 const bool tpsaActive = rspec.mech() && rspec.mechSolver().tpsa();
954 int episodeIdx = this->episodeIndex();
955 return !this->mixControls_.drsdtActive(episodeIdx) &&
956 !this->mixControls_.drvdtActive(episodeIdx) &&
957 this->rockCompPoroMultWc_.empty() &&
958 this->rockCompPoroMult_.empty();
967 template <
class Context>
970 unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
972 values.setPvtRegionIndex(pvtRegionIndex(context, spaceIdx, timeIdx));
973 values.assignNaive(initialFluidStates_[globalDofIdx]);
975 if constexpr (enableSolvent) {
976 SolventModule::assignPrimaryVars(values,
977 this->solventSaturation_[globalDofIdx],
978 this->solventRsw_[globalDofIdx]);
981 if constexpr (enablePolymer) {
982 values[Indices::polymerConcentrationIdx] = this->polymer_.concentration[globalDofIdx];
985 if constexpr (enablePolymerMolarWeight) {
986 values[Indices::polymerMoleWeightIdx]= this->polymer_.moleWeight[globalDofIdx];
989 if constexpr (enableBrine) {
990 if (enableSaltPrecipitation && values.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp) {
991 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltSaturation();
994 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltConcentration();
998 if constexpr (enableBioeffects) {
999 values[Indices::microbialConcentrationIdx] = this->bioeffects_.microbialConcentration[globalDofIdx];
1000 values[Indices::biofilmVolumeFractionIdx] = this->bioeffects_.biofilmVolumeFraction[globalDofIdx];
1001 if constexpr (enableMICP) {
1002 values[Indices::oxygenConcentrationIdx] = this->bioeffects_.oxygenConcentration[globalDofIdx];
1003 values[Indices::ureaConcentrationIdx] = this->bioeffects_.ureaConcentration[globalDofIdx];
1004 values[Indices::calciteVolumeFractionIdx] = this->bioeffects_.calciteVolumeFraction[globalDofIdx];
1008 values.checkDefined();
1014 return this->mixControls_.drsdtcon(elemIdx, episodeIdx,
1015 this->pvtRegionIndex(elemIdx));
1020 return this->mixControls_.drsdtConvective(episodeIdx, this->pvtRegionIndex(elemIdx));
1028 template <
class Context>
1030 const Context& context,
1032 unsigned timeIdx)
const
1034 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
1035 if (!context.intersection(spaceIdx).boundary())
1038 if constexpr (energyModuleType != EnergyModules::FullyImplicitThermal || !enableThermalFluxBoundaries)
1046 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
1047 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
1048 values.setThermalFlow(context, spaceIdx, timeIdx, this->initialFluidStates_[globalDofIdx] );
1051 if (this->nonTrivialBoundaryConditions()) {
1052 unsigned indexInInside = context.intersection(spaceIdx).indexInInside();
1053 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
1054 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
1055 unsigned pvtRegionIdx = pvtRegionIndex(context, spaceIdx, timeIdx);
1056 const auto [type, massrate] = this->boundaryCondition(globalDofIdx, indexInInside);
1057 if (type == BCType::THERMAL)
1058 values.setThermalFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1059 else if (type == BCType::FREE || type == BCType::DIRICHLET)
1060 values.setFreeFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1061 else if (type == BCType::RATE)
1062 values.setMassRate(massrate, pvtRegionIdx);
1072 auto& simulator = this->simulator();
1073 const auto& eclState = simulator.vanguard().eclState();
1075 std::size_t numElems = this->model().numGridDof();
1076 this->initialFluidStates_.resize(numElems);
1077 if constexpr (enableSolvent) {
1078 this->solventSaturation_.resize(numElems, 0.0);
1079 this->solventRsw_.resize(numElems, 0.0);
1082 if constexpr (enablePolymer)
1083 this->polymer_.concentration.resize(numElems, 0.0);
1085 if constexpr (enablePolymerMolarWeight) {
1086 const std::string msg {
"Support of the RESTART for polymer molecular weight "
1087 "is not implemented yet. The polymer weight value will be "
1088 "zero when RESTART begins"};
1089 OpmLog::warning(
"NO_POLYMW_RESTART", msg);
1090 this->polymer_.moleWeight.resize(numElems, 0.0);
1093 if constexpr (enableBioeffects) {
1094 this->bioeffects_.resize(numElems);
1098 this->mixControls_.init(numElems, restart_step, eclState.runspec().tabdims().getNumPVTTables());
1100 if constexpr (enableBioeffects) {
1101 this->bioeffects_ = this->eclWriter_->outputModule().getBioeffects().getSolution();
1104 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1105 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1106 elemFluidState.setPvtRegionIndex(pvtRegionIndex(elemIdx));
1107 this->eclWriter_->outputModule().initHysteresisParams(simulator, elemIdx);
1108 this->eclWriter_->outputModule().assignToFluidState(elemFluidState, elemIdx);
1117 auto ssol = enableSolvent
1118 ? this->eclWriter_->outputModule().getSolventSaturation(elemIdx)
1121 this->processRestartSaturations_(elemFluidState, ssol);
1123 if constexpr (enableSolvent) {
1124 this->solventSaturation_[elemIdx] = ssol;
1125 this->solventRsw_[elemIdx] = this->eclWriter_->outputModule().getSolventRsw(elemIdx);
1130 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1131 bool needTemperature = (eclState.runspec().co2Storage() || eclState.runspec().h2Storage());
1132 if (needTemperature) {
1133 const auto& fp = simulator.vanguard().eclState().fieldProps();
1134 elemFluidState.setTemperature(fp.get_double(
"TEMPI")[elemIdx]);
1138 this->mixControls_.updateLastValues(elemIdx, elemFluidState.Rs(), elemFluidState.Rv());
1140 if constexpr (enablePolymer)
1141 this->polymer_.concentration[elemIdx] = this->eclWriter_->outputModule().getPolymerConcentration(elemIdx);
1145 const int episodeIdx = this->episodeIndex();
1146 this->mixControls_.updateMaxValues(episodeIdx, simulator.timeStepSize());
1151 auto& sol = this->model().solution(0);
1152 const auto& gridView = this->gridView();
1154 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
1155 elemCtx.updatePrimaryStencil(elem);
1156 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1157 this->initial(sol[elemIdx], elemCtx, 0, 0);
1165 this->model().syncOverlap();
1168 this->updateReferencePorosity_();
1169 this->mixControls_.init(this->model().numGridDof(),
1170 this->episodeIndex(),
1171 eclState.runspec().tabdims().getNumPVTTables());
1179 {
return thresholdPressures_.thresholdPressure(elem1Idx, elem2Idx); }
1182 {
return thresholdPressures_; }
1185 {
return thresholdPressures_; }
1189 return moduleParams_;
1192 template<
class Serializer>
1196 serializer(mixControls_);
1197 serializer(*eclWriter_);
1203 this->updateExplicitQuantities_(first_step_after_restart);
1205 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>())
1206 updateMaxPolymerAdsorption_();
1208 mixControls_.updateExplicitQuantities(episodeIdx, timeStepSize);
1214 this->updateProperty_(
"FlowProblemBlackoil::updateMaxPolymerAdsorption_() failed:",
1217 this->updateMaxPolymerAdsorption_(compressedDofIdx,iq);
1223 const Scalar pa = scalarValue(iq.polymerAdsorption());
1224 auto& mpa = this->polymer_.maxAdsorption;
1225 if (mpa[compressedDofIdx] < pa) {
1226 mpa[compressedDofIdx] = pa;
1235 std::vector<Scalar> sumInvB(numPhases, 0.0);
1236 const auto& gridView = this->gridView();
1238 for(
const auto& elem: elements(gridView, Dune::Partitions::interior)) {
1239 elemCtx.updatePrimaryStencil(elem);
1240 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1241 const auto& dofFluidState = this->initialFluidStates_[elemIdx];
1242 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1243 if (!FluidSystem::phaseIsActive(phaseIdx))
1246 sumInvB[phaseIdx] += dofFluidState.invB(phaseIdx);
1250 std::size_t numDof = this->model().numGridDof();
1251 const auto& comm = this->simulator().vanguard().grid().comm();
1252 comm.sum(sumInvB.data(),sumInvB.size());
1253 Scalar numTotalDof = comm.sum(numDof);
1255 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1256 if (!FluidSystem::phaseIsActive(phaseIdx))
1259 Scalar avgB = numTotalDof / sumInvB[phaseIdx];
1260 const unsigned solventCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
1261 const unsigned activeSolventCompIdx = FluidSystem::canonicalToActiveCompIdx(solventCompIdx);
1262 this->model().setEqWeight(activeSolventCompIdx, avgB);
1269 OPM_TIMEBLOCK(updateCompositionChangeLimits);
1272 int episodeIdx = this->episodeIndex();
1273 std::array<bool,3> active{this->mixControls_.drsdtConvective(episodeIdx),
1274 this->mixControls_.drsdtActive(episodeIdx),
1275 this->mixControls_.drvdtActive(episodeIdx)};
1276 if (!active[0] && !active[1] && !active[2]) {
1280 this->updateProperty_(
"FlowProblemBlackoil::updateCompositionChangeLimits_()) failed:",
1281 [
this,episodeIdx,active](
unsigned compressedDofIdx,
1284 const DimMatrix& perm = this->intrinsicPermeability(compressedDofIdx);
1285 const Scalar distZ = active[0] ? this->simulator().vanguard().cellThickness(compressedDofIdx) : 0.0;
1286 const int pvtRegionIdx = this->pvtRegionIndex(compressedDofIdx);
1287 this->mixControls_.update(compressedDofIdx,
1290 this->gravity_[
dim - 1],
1303 if(this->simulator().vanguard().grid().maxLevel() > 0) {
1304 throw std::invalid_argument(
"Refined grids are not yet supported for restart ");
1308 auto& simulator = this->simulator();
1309 const auto& schedule = simulator.vanguard().schedule();
1310 const auto& eclState = simulator.vanguard().eclState();
1311 const auto& initconfig = eclState.getInitConfig();
1312 const int restart_step = initconfig.getRestartStep();
1314 simulator.setTime(schedule.seconds(restart_step));
1316 simulator.startNextEpisode(simulator.startTime() + simulator.time(),
1317 schedule.stepLength(restart_step));
1318 simulator.setEpisodeIndex(restart_step);
1320 this->eclWriter_->beginRestart();
1322 Scalar dt = std::min(this->eclWriter_->restartTimeStepSize(), simulator.episodeLength());
1323 simulator.setTimeStepSize(dt);
1325 this->readSolutionFromOutputModule(restart_step,
false);
1327 this->eclWriter_->endRestart();
1332 const auto& simulator = this->simulator();
1337 std::size_t numElems = this->model().numGridDof();
1338 this->initialFluidStates_.resize(numElems);
1339 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1340 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1347 const auto& simulator = this->simulator();
1348 const auto& vanguard = simulator.vanguard();
1349 const auto& eclState = vanguard.eclState();
1350 const auto& fp = eclState.fieldProps();
1351 bool has_swat = fp.has_double(
"SWAT");
1352 bool has_sgas = fp.has_double(
"SGAS");
1353 bool has_rs = fp.has_double(
"RS");
1354 bool has_rsw = fp.has_double(
"RSW");
1355 bool has_rv = fp.has_double(
"RV");
1356 bool has_rvw = fp.has_double(
"RVW");
1357 bool has_pressure = fp.has_double(
"PRESSURE");
1358 bool has_salt = fp.has_double(
"SALT");
1359 bool has_saltp = fp.has_double(
"SALTP");
1362 if (Indices::numPhases > 1) {
1363 if (FluidSystem::phaseIsActive(waterPhaseIdx) && !has_swat)
1364 throw std::runtime_error(
"The ECL input file requires the presence of the SWAT keyword if "
1365 "the water phase is active");
1366 if (FluidSystem::phaseIsActive(gasPhaseIdx) && !has_sgas && FluidSystem::phaseIsActive(oilPhaseIdx))
1367 throw std::runtime_error(
"The ECL input file requires the presence of the SGAS keyword if "
1368 "the gas phase is active");
1371 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
1372 "keyword if the model is initialized explicitly");
1373 if (FluidSystem::enableDissolvedGas() && !has_rs)
1374 throw std::runtime_error(
"The ECL input file requires the RS keyword to be present if"
1375 " dissolved gas is enabled and the model is initialized explicitly");
1376 if (FluidSystem::enableDissolvedGasInWater() && !has_rsw)
1377 OpmLog::warning(
"The model is initialized explicitly and the RSW keyword is not present in the"
1378 " ECL input file. The RSW values are set equal to 0");
1379 if (FluidSystem::enableVaporizedOil() && !has_rv)
1380 throw std::runtime_error(
"The ECL input file requires the RV keyword to be present if"
1381 " vaporized oil is enabled and the model is initialized explicitly");
1382 if (FluidSystem::enableVaporizedWater() && !has_rvw)
1383 throw std::runtime_error(
"The ECL input file requires the RVW keyword to be present if"
1384 " vaporized water is enabled and the model is initialized explicitly");
1385 if (enableBrine && !has_salt)
1386 throw std::runtime_error(
"The ECL input file requires the SALT keyword to be present if"
1387 " brine is enabled and the model is initialized explicitly");
1388 if (enableSaltPrecipitation && !has_saltp)
1389 throw std::runtime_error(
"The ECL input file requires the SALTP keyword to be present if"
1390 " salt precipitation is enabled and the model is initialized explicitly");
1392 std::size_t numDof = this->model().numGridDof();
1394 initialFluidStates_.resize(numDof);
1396 std::vector<double> waterSaturationData;
1397 std::vector<double> gasSaturationData;
1398 std::vector<double> pressureData;
1399 std::vector<double> rsData;
1400 std::vector<double> rswData;
1401 std::vector<double> rvData;
1402 std::vector<double> rvwData;
1403 std::vector<double> tempiData;
1404 std::vector<double> saltData;
1405 std::vector<double> saltpData;
1407 if (FluidSystem::phaseIsActive(waterPhaseIdx) && Indices::numPhases > 1)
1408 waterSaturationData = fp.get_double(
"SWAT");
1410 waterSaturationData.resize(numDof);
1412 if (FluidSystem::phaseIsActive(gasPhaseIdx) && FluidSystem::phaseIsActive(oilPhaseIdx))
1413 gasSaturationData = fp.get_double(
"SGAS");
1415 gasSaturationData.resize(numDof);
1417 pressureData = fp.get_double(
"PRESSURE");
1418 if (FluidSystem::enableDissolvedGas())
1419 rsData = fp.get_double(
"RS");
1421 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1422 rswData = fp.get_double(
"RSW");
1424 if (FluidSystem::enableVaporizedOil())
1425 rvData = fp.get_double(
"RV");
1427 if (FluidSystem::enableVaporizedWater())
1428 rvwData = fp.get_double(
"RVW");
1431 tempiData = fp.get_double(
"TEMPI");
1434 if constexpr (enableBrine)
1435 saltData = fp.get_double(
"SALT");
1438 if constexpr (enableSaltPrecipitation)
1439 saltpData = fp.get_double(
"SALTP");
1442 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1443 auto& dofFluidState = initialFluidStates_[dofIdx];
1445 dofFluidState.setPvtRegionIndex(pvtRegionIndex(dofIdx));
1450 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1451 Scalar temperatureLoc = tempiData[dofIdx];
1452 if (!std::isfinite(temperatureLoc) || temperatureLoc <= 0)
1453 temperatureLoc = FluidSystem::surfaceTemperature;
1454 dofFluidState.setTemperature(temperatureLoc);
1460 if constexpr (enableBrine)
1461 dofFluidState.setSaltConcentration(saltData[dofIdx]);
1466 if constexpr (enableSaltPrecipitation)
1467 dofFluidState.setSaltSaturation(saltpData[dofIdx]);
1472 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
1473 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
1474 waterSaturationData[dofIdx]);
1476 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)){
1477 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)){
1478 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1480 - waterSaturationData[dofIdx]);
1483 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1484 gasSaturationData[dofIdx]);
1486 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1487 const Scalar soil = 1.0 - waterSaturationData[dofIdx] - gasSaturationData[dofIdx];
1488 if (soil < smallSaturationTolerance_) {
1489 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, 0.0);
1492 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, soil);
1499 Scalar pressure = pressureData[dofIdx];
1503 std::array<Scalar, numPhases> pc = {0};
1504 const auto& matParams = this->materialLawParams(dofIdx);
1505 MaterialLaw::capillaryPressures(pc, matParams, dofFluidState);
1506 Valgrind::CheckDefined(pressure);
1507 Valgrind::CheckDefined(pc);
1508 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1509 if (!FluidSystem::phaseIsActive(phaseIdx))
1512 if (Indices::oilEnabled)
1513 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
1514 else if (Indices::gasEnabled)
1515 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
1516 else if (Indices::waterEnabled)
1518 dofFluidState.setPressure(phaseIdx, pressure);
1521 if constexpr (enableDissolvedGas) {
1522 if (FluidSystem::enableDissolvedGas())
1523 dofFluidState.setRs(rsData[dofIdx]);
1524 else if (Indices::gasEnabled && Indices::oilEnabled)
1525 dofFluidState.setRs(0.0);
1526 if (FluidSystem::enableVaporizedOil())
1527 dofFluidState.setRv(rvData[dofIdx]);
1528 else if (Indices::gasEnabled && Indices::oilEnabled)
1529 dofFluidState.setRv(0.0);
1532 if constexpr (enableDisgasInWater) {
1533 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1534 dofFluidState.setRsw(rswData[dofIdx]);
1537 if constexpr (enableVapwat) {
1538 if (FluidSystem::enableVaporizedWater())
1539 dofFluidState.setRvw(rvwData[dofIdx]);
1545 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1546 if (!FluidSystem::phaseIsActive(phaseIdx))
1549 const auto& b = FluidSystem::inverseFormationVolumeFactor(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1550 dofFluidState.setInvB(phaseIdx, b);
1552 const auto& rho = FluidSystem::density(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1553 dofFluidState.setDensity(phaseIdx, rho);
1564 Scalar sumSaturation = 0.0;
1565 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1566 if (FluidSystem::phaseIsActive(phaseIdx)) {
1567 if (elemFluidState.saturation(phaseIdx) < smallSaturationTolerance_)
1568 elemFluidState.setSaturation(phaseIdx, 0.0);
1570 sumSaturation += elemFluidState.saturation(phaseIdx);
1574 if constexpr (enableSolvent) {
1575 if (solventSaturation < smallSaturationTolerance_)
1576 solventSaturation = 0.0;
1578 sumSaturation += solventSaturation;
1581 assert(sumSaturation > 0.0);
1583 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1584 if (FluidSystem::phaseIsActive(phaseIdx)) {
1585 const Scalar saturation = elemFluidState.saturation(phaseIdx) / sumSaturation;
1586 elemFluidState.setSaturation(phaseIdx, saturation);
1589 if constexpr (enableSolvent) {
1590 solventSaturation = solventSaturation / sumSaturation;
1596 FlowProblemType::readInitialCondition_();
1598 if constexpr (enableSolvent || enablePolymer || enablePolymerMolarWeight || enableBioeffects)
1599 this->readBlackoilExtentionsInitialConditions_(this->model().numGridDof(),
1602 enablePolymerMolarWeight,
1610 if constexpr (!enableSolvent)
1611 throw std::logic_error(
"solvent is disabled and you're trying to add solvent to BC");
1613 rate[Indices::solventSaturationIdx] = bc.rate;
1618 if constexpr (!enablePolymer)
1619 throw std::logic_error(
"polymer is disabled and you're trying to add polymer to BC");
1621 rate[Indices::polymerConcentrationIdx] = bc.rate;
1626 if constexpr (!enableMICP)
1627 throw std::logic_error(
"MICP is disabled and you're trying to add microbes to BC");
1629 rate[Indices::microbialConcentrationIdx] = bc.rate;
1634 if constexpr (!enableMICP)
1635 throw std::logic_error(
"MICP is disabled and you're trying to add oxygen to BC");
1637 rate[Indices::oxygenConcentrationIdx] = bc.rate;
1642 if constexpr (!enableMICP)
1643 throw std::logic_error(
"MICP is disabled and you're trying to add urea to BC");
1645 rate[Indices::ureaConcentrationIdx] = bc.rate;
1647 rate[Indices::ureaConcentrationIdx] *= getPropValue<TypeTag, Properties::BlackOilUreaScalingFactor>();
1652 OPM_TIMEBLOCK(updateExplicitQuantities);
1653 const bool invalidateFromMaxWaterSat = this->updateMaxWaterSaturation_();
1654 const bool invalidateFromMinPressure = this->updateMinPressure_();
1657 const bool invalidateFromHyst = this->updateHysteresis_();
1658 const bool invalidateFromMaxOilSat = this->updateMaxOilSaturation_();
1661 const bool invalidateDRDT = !first_step_after_restart && this->updateCompositionChangeLimits_();
1664 const bool invalidateIntensiveQuantities
1665 = invalidateFromMaxWaterSat || invalidateFromMinPressure || invalidateFromHyst || invalidateFromMaxOilSat || invalidateDRDT;
1666 if (invalidateIntensiveQuantities) {
1667 OPM_TIMEBLOCK(beginTimeStepInvalidateIntensiveQuantities);
1668 this->model().invalidateAndUpdateIntensiveQuantities(0);
1671 this->updateRockCompTransMultVal_();
1676 if (
const auto nph = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
1677 + FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)
1678 + FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
1687 const auto numSamplePoints =
static_cast<std::size_t
>
1688 (Parameters::Get<Parameters::NumSatfuncConsistencySamplePoints>());
1690 auto sfuncConsistencyChecks =
1692 numSamplePoints, this->simulator().vanguard().eclState(),
1693 [&cmap = this->simulator().vanguard().cartesianIndexMapper()](
const int elemIdx)
1694 {
return cmap.cartesianIndex(elemIdx); }
1697 const auto ioRank = 0;
1698 const auto isIoRank = this->simulator().vanguard()
1699 .grid().comm().rank() == ioRank;
1705 .
run(this->simulator().vanguard().grid().levelGridView(0),
1706 [&vg = this->simulator().vanguard(),
1707 &emap = this->simulator().model().elementMapper()]
1709 {
return vg.gridIdxToEquilGridIdx(emap.index(elem)); });
1711 using ViolationLevel =
typename Satfunc::PhaseChecks::
1712 SatfuncConsistencyCheckManager<Scalar>::ViolationLevel;
1714 auto reportFailures = [&sfuncConsistencyChecks]
1715 (
const ViolationLevel level)
1717 sfuncConsistencyChecks.reportFailures
1718 (level, [](std::string_view record)
1719 { OpmLog::info(std::string { record }); });
1722 if (sfuncConsistencyChecks.anyFailedStandardChecks()) {
1724 OpmLog::warning(
"Saturation Function "
1725 "End-point Consistency Problems");
1727 reportFailures(ViolationLevel::Standard);
1731 if (sfuncConsistencyChecks.anyFailedCriticalChecks()) {
1733 OpmLog::error(
"Saturation Function "
1734 "End-point Consistency Failures");
1736 reportFailures(ViolationLevel::Critical);
1756 const Scalar smallSaturationTolerance_ = 1.e-6;
1758 bool enableDamarisOutput_ = false ;
1759 std::unique_ptr<DamarisWriterType> damarisWriter_;
1780 bool episodeWillBeOver()
const override
1782 const auto currTime = this->simulator().time()
1783 + this->simulator().timeStepSize();
1785 const auto nextReportStep =
1786 this->simulator().vanguard().schedule()
1787 .seconds(this->simulator().episodeIndex() + 1);
1789 const auto isSubStep = (nextReportStep - currTime)
1790 > (2 * std::numeric_limits<float>::epsilon()) * nextReportStep;
Classes required for dynamic convective mixing.
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:123
static void registerParameters()
Definition: EclWriter.hpp:151
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:202
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:353
Scalar initialTimeStepSize_
Definition: FlowGenericProblem.hpp:365
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:371
bool enableDriftCompensationTemp_
Definition: FlowGenericProblem.hpp:372
bool enableTuning_
Definition: FlowGenericProblem.hpp:364
void readRockParameters_(const std::vector< Scalar > &cellCenterDepths, std::function< std::array< int, 3 >(const unsigned)> ijkIndex)
Definition: FlowGenericProblem_impl.hpp:153
std::vector< Scalar > maxOilSaturation_
Definition: FlowGenericProblem.hpp:354
Scalar maxTimeStepAfterWellEvent_
Definition: FlowGenericProblem.hpp:366
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemBlackoil.hpp:87
HybridNewton hybridNewton_
Definition: FlowProblemBlackoil.hpp:1767
void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart) override
Definition: FlowProblemBlackoil.hpp:1201
bool updateMaxPolymerAdsorption_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblemBlackoil.hpp:1221
void handlePolymerBC(const BCProp::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1616
void writeOutput(const bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemBlackoil.hpp:591
void readInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1594
void handleOxygBC(const BCProp::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1632
void readEquilInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1330
void handleSolventBC(const BCProp::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1608
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:917
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemBlackoil.hpp:781
void processRestartSaturations_(InitialFluidState &elemFluidState, Scalar &solventSaturation)
Definition: FlowProblemBlackoil.hpp:1560
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemBlackoil.hpp:778
FlowProblemBlackoil(Simulator &simulator)
Definition: FlowProblemBlackoil.hpp:189
bool enableEclOutput_
Definition: FlowProblemBlackoil.hpp:1753
Scalar drsdtcon(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:1012
void endStepApplyAction()
Definition: FlowProblemBlackoil.hpp:512
bool drsdtconIsActive(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:1018
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:928
std::vector< InitialFluidState > initialFluidStates_
Definition: FlowProblemBlackoil.hpp:1751
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemBlackoil.hpp:506
void updateMaxPolymerAdsorption_()
Definition: FlowProblemBlackoil.hpp:1211
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemBlackoil.hpp:775
void endEpisode() override
Called by the simulator after the end of an episode.
Definition: FlowProblemBlackoil.hpp:559
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemBlackoil.hpp:787
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemBlackoil.hpp:968
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemBlackoil.hpp:324
void handleMicrBC(const BCProp::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1624
const FlowThresholdPressure< TypeTag > & thresholdPressure() const
Definition: FlowProblemBlackoil.hpp:1181
void finalizeOutput()
Definition: FlowProblemBlackoil.hpp:614
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemBlackoil.hpp:1029
InitialFluidState boundaryFluidState(unsigned globalDofIdx, const int directionId) const
Definition: FlowProblemBlackoil.hpp:793
std::unique_ptr< EclWriterType > eclWriter_
Definition: FlowProblemBlackoil.hpp:1754
void initialSolutionApplied() override
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblemBlackoil.hpp:626
const ModuleParams & moduleParams() const
Definition: FlowProblemBlackoil.hpp:1187
void readEclRestartSolution_()
Definition: FlowProblemBlackoil.hpp:1300
FlowThresholdPressure< TypeTag > & thresholdPressure()
Definition: FlowProblemBlackoil.hpp:1184
FlowThresholdPressure< TypeTag > thresholdPressures_
Definition: FlowProblemBlackoil.hpp:1749
void readExplicitInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1345
void beginEpisode() override
Called by the simulator before an episode begins.
Definition: FlowProblemBlackoil.hpp:282
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:946
LhsEval permFactTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Calculate the transmissibility multiplier due to porosity reduction.
Definition: FlowProblemBlackoil.hpp:755
void serializeOp(Serializer &serializer)
Definition: FlowProblemBlackoil.hpp:1193
MixingRateControls< FluidSystem > mixControls_
Definition: FlowProblemBlackoil.hpp:1761
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemBlackoil.hpp:579
ModuleParams moduleParams_
Definition: FlowProblemBlackoil.hpp:1765
const EclWriterType & eclWriter() const
Definition: FlowProblemBlackoil.hpp:907
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemBlackoil.hpp:790
void addToSourceDense(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const override
Definition: FlowProblemBlackoil.hpp:648
void computeAndSetEqWeights_()
Definition: FlowProblemBlackoil.hpp:1233
void beginTimeStep() override
Called by the simulator before each time integration.
Definition: FlowProblemBlackoil.hpp:315
void updateExplicitQuantities_(const bool first_step_after_restart)
Definition: FlowProblemBlackoil.hpp:1650
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemBlackoil.hpp:175
ActionHandler< Scalar, IndexTraits > actionHandler_
Definition: FlowProblemBlackoil.hpp:1763
void readSolutionFromOutputModule(const int restart_step, bool fip_init)
Read simulator solution state from the outputmodule (used with restart)
Definition: FlowProblemBlackoil.hpp:1070
const EclipseIO & eclIO() const
Definition: FlowProblemBlackoil.hpp:784
Scalar thresholdPressure(unsigned elem1Idx, unsigned elem2Idx) const
Definition: FlowProblemBlackoil.hpp:1178
void handleUreaBC(const BCProp::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1640
EclWriterType & eclWriter()
Definition: FlowProblemBlackoil.hpp:910
bool satfuncConsistencyRequirementsMet() const
Definition: FlowProblemBlackoil.hpp:1674
bool updateCompositionChangeLimits_()
Definition: FlowProblemBlackoil.hpp:1267
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:95
static constexpr bool enableFoam
Definition: FlowProblem.hpp:126
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:523
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:906
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:706
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:108
@ numComponents
Definition: FlowProblem.hpp:118
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:102
void initGravity_(const EclipseState &eclState)
Set the gravity vector from the run's configuration.
Definition: FlowProblem.hpp:1627
GetPropType< TypeTag, Properties::EqVector > EqVector
Definition: FlowProblem.hpp:107
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: FlowProblem.hpp:152
GlobalEqVector drift_
Definition: FlowProblem.hpp:1856
@ gasCompIdx
Definition: FlowProblem.hpp:144
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:149
Dune::FieldMatrix< Scalar, dimWorld, dimWorld > DimMatrix
Definition: FlowProblem.hpp:166
@ waterPhaseIdx
Definition: FlowProblem.hpp:140
int episodeIndex() const
Definition: FlowProblem.hpp:304
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:109
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: FlowProblem.hpp:106
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:150
@ enableExperiments
Definition: FlowProblem.hpp:133
static constexpr bool enableDiffusion
Definition: FlowProblem.hpp:123
@ dimWorld
Definition: FlowProblem.hpp:113
TracerModel tracerModel_
Definition: FlowProblem.hpp:1862
@ enableThermalFluxBoundaries
Definition: FlowProblem.hpp:136
WellModel wellModel_
Definition: FlowProblem.hpp:1858
virtual void beginEpisode()
Called by the simulator before an episode begins.
Definition: FlowProblem.hpp:312
static constexpr bool enablePolymerMolarWeight
Definition: FlowProblem.hpp:128
virtual void beginTimeStep()
Called by the simulator before each time integration.
Definition: FlowProblem.hpp:371
@ gasPhaseIdx
Definition: FlowProblem.hpp:138
static constexpr bool enableSolvent
Definition: FlowProblem.hpp:129
@ numPhases
Definition: FlowProblem.hpp:117
static constexpr bool enablePolymer
Definition: FlowProblem.hpp:127
@ numEq
Definition: FlowProblem.hpp:116
void readThermalParameters_()
Definition: FlowProblem.hpp:1481
@ dim
Definition: FlowProblem.hpp:112
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: FlowProblem.hpp:161
@ enableSaltPrecipitation
Definition: FlowProblem.hpp:135
TemperatureModel temperatureModel_
Definition: FlowProblem.hpp:1863
static constexpr bool enableExtbo
Definition: FlowProblem.hpp:125
static constexpr bool enableConvectiveMixing
Definition: FlowProblem.hpp:122
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:103
@ oilCompIdx
Definition: FlowProblem.hpp:145
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:191
void updatePffDofData_()
Definition: FlowProblem.hpp:1649
static constexpr bool enableDispersion
Definition: FlowProblem.hpp:124
@ oilPhaseIdx
Definition: FlowProblem.hpp:139
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:148
void readBoundaryConditions_()
Definition: FlowProblem.hpp:1680
Vanguard::TransmissibilityType transmissibilities_
Definition: FlowProblem.hpp:1851
static constexpr EnergyModules energyModuleType
Definition: FlowProblem.hpp:131
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:105
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:158
static constexpr bool enableBioeffects
Definition: FlowProblem.hpp:120
void readMaterialParameters_()
Definition: FlowProblem.hpp:1441
static constexpr bool enableBrine
Definition: FlowProblem.hpp:121
@ waterCompIdx
Definition: FlowProblem.hpp:146
@ enableMICP
Definition: FlowProblem.hpp:134
This class calculates the threshold pressure for grid faces according to the Eclipse Reference Manual...
Definition: FlowThresholdPressure.hpp:59
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
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
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:47
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
Definition: SimulatorReport.hpp:125
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34