31#ifndef OPM_FLOW_PROBLEM_BLACK_HPP
32#define OPM_FLOW_PROBLEM_BLACK_HPP
34#include <opm/input/eclipse/Schedule/Events.hpp>
35#include <opm/input/eclipse/Schedule/OilVaporizationProperties.hpp>
39#include <opm/input/eclipse/EclipseState/Aquifer/AquiferConfig.hpp>
40#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquiferCell.hpp>
41#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
42#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
44#include <opm/output/eclipse/EclipseIO.hpp>
71#include <unordered_map>
82template <
class TypeTag>
138 static constexpr bool enableDissolvedGas =
139 Indices::compositionSwitchIdx != std::numeric_limits<unsigned>::max();
140 enum { enableVapwat = getPropValue<TypeTag, Properties::EnableVapwat>() };
141 enum { enableDisgasInWater = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
142 enum { enableGeochemistry = getPropValue<TypeTag, Properties::EnableGeochemistry>() };
143 enum { enableMech = getPropValue<TypeTag, Properties::EnableMech>() };
145 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, enableBioeffects>;
146 using BrineModule = BlackOilBrineModule<TypeTag, enableBrine>;
147 using ConvectiveMixingModule = BlackOilConvectiveMixingModule<TypeTag, enableConvectiveMixing>;
150 using ExtboModule = BlackOilExtboModule<TypeTag, enableExtbo>;
151 using FoamModule = BlackOilFoamModule<TypeTag, enableFoam>;
152 using PolymerModule = BlackOilPolymerModule<TypeTag, enablePolymer>;
153 using SolventModule = BlackOilSolventModule<TypeTag, enableSolvent>;
155 using EclWriterType = EclWriter<TypeTag, OutputBlackOilModule<TypeTag> >;
156 using IndexTraits =
typename FluidSystem::IndexTraitsType;
158 using HybridNewton = BlackOilHybridNewton<TypeTag>;
161 using DamarisWriterType = DamarisWriter<TypeTag>;
177 DamarisWriterType::registerParameters();
190 simulator.vanguard().schedule(),
191 simulator.vanguard().actionState(),
192 simulator.vanguard().summaryState(),
194 simulator.vanguard().grid().comm())
200 const auto& vanguard = simulator.vanguard();
202 if constexpr (enableBrine) {
204 brineParams.template initFromState<enableBrine,
205 enableSaltPrecipitation>(vanguard.eclState());
206 BrineModule::setParams(std::move(brineParams));
209 if constexpr (enableDiffusion) {
210 DiffusionModule::initFromState(vanguard.eclState());
213 if constexpr (enableDispersion) {
214 DispersionModule::initFromState(vanguard.eclState());
217 if constexpr (enableExtbo) {
219 extboParams.template initFromState<enableExtbo>(vanguard.eclState());
220 ExtboModule::setParams(std::move(extboParams));
223 if constexpr (enableFoam) {
225 foamParams.template initFromState<enableFoam>(vanguard.eclState());
226 FoamModule::setParams(std::move(foamParams));
229 if constexpr (enableBioeffects) {
231 bioeffectsParams.template initFromState<enableBioeffects, enableMICP>(vanguard.eclState());
232 BioeffectsModule::setParams(std::move(bioeffectsParams));
235 if constexpr (enablePolymer) {
237 polymerParams.template initFromState<enablePolymer, enablePolymerMolarWeight>(vanguard.eclState());
238 PolymerModule::setParams(std::move(polymerParams));
241 if constexpr (enableSolvent) {
243 solventParams.template initFromState<enableSolvent>(vanguard.eclState(), vanguard.schedule());
244 SolventModule::setParams(std::move(solventParams));
248 eclWriter_ = std::make_unique<EclWriterType>(simulator);
252 if constexpr (!enableGeochemistry) {
253 if (vanguard.eclState().runspec().geochem().enabled()) {
254 throw std::runtime_error(
"GEOCHEM keyword in the deck but geochemistry module "
255 "was disabled at compile time!");
260 if constexpr (!enableMech) {
261 const auto& rspec = vanguard.eclState().runspec();
262 if (rspec.mech() && rspec.mechSolver().tpsa()) {
263 throw std::runtime_error(
"TPSA solver enabled in the deck, but geomechanics "
264 "module was disabled at compile time!");
270 damarisWriter_ = std::make_unique<DamarisWriterType>(simulator);
271 enableDamarisOutput_ = Parameters::Get<Parameters::EnableDamarisOutput>();
280 checkGpuAssemblySchedule_();
283 auto& simulator = this->simulator();
285 const int episodeIdx = simulator.episodeIndex();
286 const auto& schedule = simulator.vanguard().schedule();
291 .evalUDQAssignments(episodeIdx, simulator.vanguard().udqState());
293 if (episodeIdx >= 0) {
294 const auto& oilVap = schedule[episodeIdx].oilvap();
295 if (oilVap.getType() == OilVaporizationProperties::OilVaporization::VAPPARS) {
296 FluidSystem::setVapPars(oilVap.vap1(), oilVap.vap2());
299 FluidSystem::setVapPars(0.0, 0.0);
302 if constexpr (enableConvectiveMixing) {
303 ConvectiveMixingModule::beginEpisode(simulator.vanguard().eclState(), schedule, episodeIdx,
304 this->moduleParams_.convectiveMixingModuleParam);
323 FlowProblemType::finishInit();
325 auto& simulator = this->simulator();
326 const bool transmissibilitiesFinished =
329 const auto& eclState = simulator.vanguard().eclState();
330 const auto& schedule = simulator.vanguard().schedule();
335 bool isThermal = eclState.getSimulationConfig().isThermal();
336 bool isTemp = eclState.getSimulationConfig().isTemp();
337 bool conserveInnerEnergy = isTemp || (isThermal && Parameters::Get<Parameters::ConserveInnerEnergyThermal>());
338 FluidSystem::setEnergyEqualEnthalpy(conserveInnerEnergy);
347 if (!transmissibilitiesFinished) {
351 const auto& initconfig = eclState.getInitConfig();
353 if (initconfig.restartRequested()) {
364 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
365 const auto& vanguard = this->simulator().vanguard();
366 const auto& gridView = vanguard.gridView();
367 const int numElements = gridView.size(0);
368 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
377 this->
drift_.resize(this->model().numGridDof());
384 if (!initconfig.restartRequested() && !eclState.getIOConfig().initOnly()) {
385 simulator.startNextEpisode(schedule.seconds(1));
386 simulator.setEpisodeIndex(0);
387 simulator.setTimeStepIndex(0);
390 if (Parameters::Get<Parameters::CheckSatfuncConsistency>() &&
400 this->simulator().vanguard().grid().comm().barrier();
402 throw std::domain_error {
403 "Saturation function end-points do not "
404 "meet requisite consistency conditions"
416 eclState.runspec().tabdims().getNumPVTTables());
422 if (!initconfig.restartRequested()) {
425 this->
mixControls_.updateLastValues(elemIdx, fs.Rs(), fs.Rv());
429 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
430 simulator.setTimeStepSize(0.0);
431 simulator.model().applyInitialSolution();
435 if (!eclState.getIOConfig().initOnly()) {
436 if (!this->
enableTuning_ && eclState.getSimulationConfig().anyTUNING()) {
437 OpmLog::info(
"\nThe deck has TUNING in the SCHEDULE section, but "
438 "it is ignored due\nto the flag --enable-tuning=false. "
439 "Set this flag to true to activate it.\n"
440 "Manually tuning the simulator with the TUNING keyword may "
441 "increase run time.\nIt is recommended using the simulator's "
442 "default tuning (--enable-tuning=false).");
463 const auto& grid = this->simulator().vanguard().gridView().grid();
465 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
466 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
467 if (!isCpGrid || (grid.maxLevel() == 0)) {
468 this->
eclWriter_->evalSummaryState(!this->episodeWillBeOver());
472 OPM_TIMEBLOCK(applyActions);
475 auto& simulator = this->simulator();
479 this->simulator().vanguard().schedule().clearEvents(episodeIdx);
483 .applyActions(episodeIdx, simulator.time() + simulator.timeStepSize(),
484 [
this](
const bool global)
486 using TransUpdateQuantities = typename
487 Vanguard::TransmissibilityType::TransUpdateQuantities;
489 this->transmissibilities_
490 .update(global, TransUpdateQuantities::All,
491 [&vg = this->simulator().vanguard()]
492 (const unsigned int i)
494 return vg.gridIdxToEquilGridIdx(i);
499 checkGpuAssemblySchedule_();
508 OPM_TIMEBLOCK(endEpisode);
521 .evalUDQAssignments(this->episodeIndex(), this->simulator().vanguard().udqState());
523 FlowProblemType::endEpisode();
528 if (this->enableEclOutput_) {
529 this->eclWriter_->writeReports(timer);
540 FlowProblemType::writeOutput(verbose);
542 const auto isSubStep = !this->episodeWillBeOver();
544 auto localCellData = data::Solution {};
549 if (this->enableDamarisOutput_ && (this->damarisWriter_ !=
nullptr)) {
550 this->damarisWriter_->writeOutput(localCellData, isSubStep);
554 if (this->enableEclOutput_ && (this->eclWriter_ !=
nullptr)) {
555 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
556 this->simulator().vanguard().schedule()
557 .exitStatus().has_value());
563 OPM_TIMEBLOCK(finalizeOutput);
575 FlowProblemType::initialSolutionApplied();
580 this->thresholdPressures_.finishInit();
582 if (this->checkAquiferEquilibration_) {
583 this->checkAquiferEquilibration_ =
false;
584 this->checkNumericalAquiferEquilibration_();
588 const auto& grid = this->simulator().vanguard().gridView().grid();
590 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
591 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
593 if (!isCpGrid || (grid.maxLevel() == 0)) {
594 if (this->simulator().episodeIndex() == 0) {
595 eclWriter_->writeInitialFIPReport();
601 unsigned globalDofIdx,
602 unsigned timeIdx)
const override
604 this->aquiferModel_.addToSource(rate, globalDofIdx, timeIdx);
607 const auto& source = this->simulator().vanguard().schedule()[this->episodeIndex()].source();
608 std::array<int,3> ijk;
609 this->simulator().vanguard().cartesianCoordinate(globalDofIdx, ijk);
611 if (source.hasSource(ijk)) {
612 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
613 static std::array<SourceComponent, 3> sc_map = {SourceComponent::WATER, SourceComponent::OIL, SourceComponent::GAS};
614 static std::array<int, 3> phidx_map = {FluidSystem::waterPhaseIdx, FluidSystem::oilPhaseIdx, FluidSystem::gasPhaseIdx};
615 static std::array<int, 3> cidx_map = {waterCompIdx, oilCompIdx, gasCompIdx};
617 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
618 const auto phaseIdx = phidx_map[i];
619 const auto sourceComp = sc_map[i];
620 const auto compIdx = cidx_map[i];
621 if (!FluidSystem::phaseIsActive(phaseIdx)) {
624 Scalar mass_rate = source.rate(ijk, sourceComp) / this->model().dofTotalVolume(globalDofIdx);
625 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
626 mass_rate /= FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
628 rate[FluidSystem::canonicalToActiveCompIdx(compIdx)] += mass_rate;
631 if constexpr (enableSolvent) {
632 Scalar mass_rate = source.rate(ijk, SourceComponent::SOLVENT) / this->model().dofTotalVolume(globalDofIdx);
633 if constexpr (getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
634 const auto& solventPvt = SolventModule::solventPvt();
635 mass_rate /= solventPvt.referenceDensity(pvtRegionIdx);
637 rate[Indices::contiSolventEqIdx] += mass_rate;
639 if constexpr (enablePolymer) {
640 rate[Indices::polymerConcentrationIdx] += source.rate(ijk, SourceComponent::POLYMER) / this->model().dofTotalVolume(globalDofIdx);
642 if constexpr (enableMICP) {
643 rate[Indices::microbialConcentrationIdx] += source.rate(ijk, SourceComponent::MICR) / this->model().dofTotalVolume(globalDofIdx);
644 rate[Indices::oxygenConcentrationIdx] += source.rate(ijk, SourceComponent::OXYG) / this->model().dofTotalVolume(globalDofIdx);
645 rate[Indices::ureaConcentrationIdx] += source.rate(ijk, SourceComponent::UREA) / (this->model().dofTotalVolume(globalDofIdx));
647 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
648 for (
unsigned i = 0; i < phidx_map.size(); ++i) {
649 const auto phaseIdx = phidx_map[i];
650 if (!FluidSystem::phaseIsActive(phaseIdx)) {
653 const auto sourceComp = sc_map[i];
654 const auto source_hrate = source.hrate(ijk, sourceComp);
656 rate[Indices::contiEnergyEqIdx] += source_hrate.value() / this->model().dofTotalVolume(globalDofIdx);
658 const auto& intQuants = this->simulator().model().intensiveQuantities(globalDofIdx, 0);
659 auto fs = intQuants.fluidState();
661 const auto source_temp = source.temperature(ijk, sourceComp);
663 Scalar temperature = source_temp.value();
664 fs.setTemperature(temperature);
666 const auto& h = FluidSystem::enthalpy(fs, phaseIdx, pvtRegionIdx);
667 Scalar mass_rate = source.rate(ijk, sourceComp)/ this->model().dofTotalVolume(globalDofIdx);
668 Scalar energy_rate = getValue(h)*mass_rate;
669 rate[Indices::contiEnergyEqIdx] += energy_rate;
677 if (this->enableDriftCompensation_) {
678 const auto& simulator = this->simulator();
679 const auto& model = this->model();
684 Scalar maxCompensation = model.newtonMethod().tolerance()/10;
685 Scalar poro = this->porosity(globalDofIdx, timeIdx);
686 Scalar dt = simulator.timeStepSize();
687 EqVector dofDriftRate = this->drift_[globalDofIdx];
688 dofDriftRate /= dt*model.dofTotalVolume(globalDofIdx);
691 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
692 Scalar cnv = std::abs(dofDriftRate[eqIdx])*dt*model.eqWeight(globalDofIdx, eqIdx)/poro;
693 if (cnv > maxCompensation) {
694 dofDriftRate[eqIdx] *= maxCompensation/cnv;
698 for (
unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx)
699 rate[eqIdx] -= dofDriftRate[eqIdx];
706 template <
class LhsEval,
class Callback>
709 OPM_TIMEBLOCK_LOCAL(permFactTransMultiplier, Subsystem::PvtProps);
710 if constexpr (enableSaltPrecipitation) {
711 const auto& fs = intQuants.fluidState();
712 unsigned tableIdx = this->simulator().problem().satnumRegionIndex(elementIdx);
713 LhsEval porosityFactor = obtain(1. - fs.saltSaturation());
714 porosityFactor = min(porosityFactor, 1.0);
715 const auto& permfactTable = BrineModule::permfactTable(tableIdx);
716 return permfactTable.eval(porosityFactor,
true);
718 else if constexpr (enableBioeffects) {
719 return obtain(intQuants.permFactor());
728 {
return initialFluidStates_[globalDofIdx]; }
731 {
return initialFluidStates_; }
734 {
return initialFluidStates_; }
737 {
return eclWriter_->eclIO(); }
740 {
return eclWriter_->setSubStepReport(report); }
743 {
return eclWriter_->setSimulationReport(report); }
747 OPM_TIMEBLOCK_LOCAL(boundaryFluidState, Subsystem::Assembly);
748 const auto& bcstate = this->simulator().vanguard().schedule()[this->episodeIndex()].bcstate;
749 if (bcstate.size() > 0) {
750 FaceDir::DirEnum dir = FaceDir::FromIntersectionIndex(directionId);
754 if (this->bcindex_(dir)[globalDofIdx] == 0)
755 return initialFluidStates_[globalDofIdx];
757 const auto& bc = bcstate[this->bcindex_(dir)[globalDofIdx]];
758 if (bc.bctype == BCType::DIRICHLET )
760 InitialFluidState fluidState;
761 const int pvtRegionIdx = this->pvtRegionIndex(globalDofIdx);
762 fluidState.setPvtRegionIndex(pvtRegionIdx);
764 switch (bc.component) {
765 case BCComponent::OIL:
766 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx))
767 throw std::logic_error(
"oil is not active and you're trying to add oil BC");
769 fluidState.setSaturation(FluidSystem::oilPhaseIdx, 1.0);
771 case BCComponent::GAS:
772 if (!FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx))
773 throw std::logic_error(
"gas is not active and you're trying to add gas BC");
775 fluidState.setSaturation(FluidSystem::gasPhaseIdx, 1.0);
777 case BCComponent::WATER:
778 if (!FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
779 throw std::logic_error(
"water is not active and you're trying to add water BC");
781 fluidState.setSaturation(FluidSystem::waterPhaseIdx, 1.0);
783 case BCComponent::SOLVENT:
784 case BCComponent::POLYMER:
785 case BCComponent::MICR:
786 case BCComponent::OXYG:
787 case BCComponent::UREA:
789 throw std::logic_error(
"you need to specify a valid component (OIL, WATER or GAS) when DIRICHLET type is set in BC");
791 fluidState.setTotalSaturation(1.0);
792 double pressure = initialFluidStates_[globalDofIdx].pressure(this->refPressurePhaseIdx_());
793 const auto pressure_input = bc.pressure;
794 if (pressure_input) {
795 pressure = *pressure_input;
798 std::array<Scalar, numPhases> pc = {0};
799 const auto& matParams = this->materialLawParams(globalDofIdx);
800 MaterialLaw::capillaryPressures(pc, matParams, fluidState);
801 Valgrind::CheckDefined(pressure);
802 Valgrind::CheckDefined(pc);
803 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
804 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
805 if (Indices::oilEnabled)
806 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
807 else if (Indices::gasEnabled)
808 fluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
809 else if (Indices::waterEnabled)
811 fluidState.setPressure(phaseIdx, pressure);
813 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
814 double temperature = initialFluidStates_[globalDofIdx].temperature(0);
815 const auto temperature_input = bc.temperature;
816 if(temperature_input)
817 temperature = *temperature_input;
818 fluidState.setTemperature(temperature);
821 if constexpr (enableDissolvedGas) {
822 if (FluidSystem::enableDissolvedGas()) {
823 fluidState.setRs(0.0);
824 fluidState.setRv(0.0);
827 if constexpr (enableDisgasInWater) {
828 if (FluidSystem::enableDissolvedGasInWater()) {
829 fluidState.setRsw(0.0);
832 if constexpr (enableVapwat) {
833 if (FluidSystem::enableVaporizedWater()) {
834 fluidState.setRvw(0.0);
838 for (
unsigned activePhaseIdx = 0; activePhaseIdx < FluidSystem::numActivePhases(); ++activePhaseIdx) {
839 const auto phaseIdx = FluidSystem::activeToCanonicalPhaseIdx(activePhaseIdx);
841 const auto& b = FluidSystem::inverseFormationVolumeFactor(fluidState, phaseIdx, pvtRegionIdx);
842 fluidState.setInvB(phaseIdx, b);
844 const auto& rho = FluidSystem::density(fluidState, phaseIdx, pvtRegionIdx);
845 fluidState.setDensity(phaseIdx, rho);
846 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal) {
847 const auto& h = FluidSystem::enthalpy(fluidState, phaseIdx, pvtRegionIdx);
848 fluidState.setEnthalpy(phaseIdx, h);
851 fluidState.checkDefined();
855 return initialFluidStates_[globalDofIdx];
860 {
return *eclWriter_; }
863 {
return *eclWriter_; }
871 return this->mixControls_.maxGasDissolutionFactor(timeIdx, globalDofIdx,
872 this->episodeIndex(),
873 this->pvtRegionIndex(globalDofIdx));
882 return this->mixControls_.maxOilVaporizationFactor(timeIdx, globalDofIdx,
883 this->episodeIndex(),
884 this->pvtRegionIndex(globalDofIdx));
900 const auto& rspec = this->simulator().vanguard().eclState().runspec();
901 const bool tpsaActive = rspec.mech() && rspec.mechSolver().tpsa();
906 int episodeIdx = this->episodeIndex();
907 return !this->mixControls_.drsdtActive(episodeIdx) &&
908 !this->mixControls_.drvdtActive(episodeIdx) &&
909 this->rockCompPoroMultWc_.empty() &&
910 this->rockCompPoroMult_.empty();
919 template <
class Context>
922 unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
924 values.setPvtRegionIndex(pvtRegionIndex(context, spaceIdx, timeIdx));
925 values.assignNaive(initialFluidStates_[globalDofIdx]);
927 if constexpr (enableSolvent) {
928 SolventModule::assignPrimaryVars(values,
929 this->solventSaturation_[globalDofIdx],
930 this->solventRsw_[globalDofIdx]);
933 if constexpr (enablePolymer) {
934 values[Indices::polymerConcentrationIdx] = this->polymer_.concentration[globalDofIdx];
937 if constexpr (enablePolymerMolarWeight) {
938 values[Indices::polymerMoleWeightIdx]= this->polymer_.moleWeight[globalDofIdx];
941 if constexpr (enableBrine) {
942 if (enableSaltPrecipitation && values.primaryVarsMeaningBrine() == PrimaryVariables::BrineMeaning::Sp) {
943 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltSaturation();
946 values[Indices::saltConcentrationIdx] = initialFluidStates_[globalDofIdx].saltConcentration();
950 if constexpr (enableBioeffects) {
951 values[Indices::microbialConcentrationIdx] = this->bioeffects_.microbialConcentration[globalDofIdx];
952 values[Indices::biofilmVolumeFractionIdx] = this->bioeffects_.biofilmVolumeFraction[globalDofIdx];
953 if constexpr (enableMICP) {
954 values[Indices::oxygenConcentrationIdx] = this->bioeffects_.oxygenConcentration[globalDofIdx];
955 values[Indices::ureaConcentrationIdx] = this->bioeffects_.ureaConcentration[globalDofIdx];
956 values[Indices::calciteVolumeFractionIdx] = this->bioeffects_.calciteVolumeFraction[globalDofIdx];
960 values.checkDefined();
966 return this->mixControls_.drsdtcon(elemIdx, episodeIdx,
967 this->pvtRegionIndex(elemIdx));
972 return this->mixControls_.drsdtConvective(episodeIdx, this->pvtRegionIndex(elemIdx));
980 template <
class Context>
982 const Context& context,
984 unsigned timeIdx)
const
986 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
987 if (!context.intersection(spaceIdx).boundary())
990 if constexpr (energyModuleType != EnergyModules::FullyImplicitThermal || !enableThermalFluxBoundaries)
998 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
999 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
1000 values.setThermalFlow(context, spaceIdx, timeIdx, this->initialFluidStates_[globalDofIdx] );
1003 if (this->nonTrivialBoundaryConditions()) {
1004 unsigned indexInInside = context.intersection(spaceIdx).indexInInside();
1005 unsigned interiorDofIdx = context.interiorScvIndex(spaceIdx, timeIdx);
1006 unsigned globalDofIdx = context.globalSpaceIndex(interiorDofIdx, timeIdx);
1007 unsigned pvtRegionIdx = pvtRegionIndex(context, spaceIdx, timeIdx);
1008 const auto [type, massrate] = this->boundaryCondition(globalDofIdx, indexInInside);
1009 if (type == BCType::THERMAL)
1010 values.setThermalFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1011 else if (type == BCType::FREE || type == BCType::DIRICHLET)
1012 values.setFreeFlow(context, spaceIdx, timeIdx, this->boundaryFluidState(globalDofIdx, indexInInside));
1013 else if (type == BCType::RATE)
1014 values.setMassRate(massrate, pvtRegionIdx);
1024 auto& simulator = this->simulator();
1025 const auto& eclState = simulator.vanguard().eclState();
1027 std::size_t numElems = this->model().numGridDof();
1028 this->initialFluidStates_.resize(numElems);
1029 if constexpr (enableSolvent) {
1030 this->solventSaturation_.resize(numElems, 0.0);
1031 this->solventRsw_.resize(numElems, 0.0);
1034 if constexpr (enablePolymer)
1035 this->polymer_.concentration.resize(numElems, 0.0);
1037 if constexpr (enablePolymerMolarWeight) {
1038 const std::string msg {
"Support of the RESTART for polymer molecular weight "
1039 "is not implemented yet. The polymer weight value will be "
1040 "zero when RESTART begins"};
1041 OpmLog::warning(
"NO_POLYMW_RESTART", msg);
1042 this->polymer_.moleWeight.resize(numElems, 0.0);
1045 if constexpr (enableBioeffects) {
1046 this->bioeffects_.resize(numElems);
1050 this->mixControls_.init(numElems, restart_step, eclState.runspec().tabdims().getNumPVTTables());
1052 if constexpr (enableBioeffects) {
1053 this->bioeffects_ = this->eclWriter_->outputModule().getBioeffects().getSolution();
1056 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1057 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1058 elemFluidState.setPvtRegionIndex(pvtRegionIndex(elemIdx));
1059 this->eclWriter_->outputModule().initHysteresisParams(simulator, elemIdx);
1060 this->eclWriter_->outputModule().assignToFluidState(elemFluidState, elemIdx);
1069 auto ssol = enableSolvent
1070 ? this->eclWriter_->outputModule().getSolventSaturation(elemIdx)
1073 this->processRestartSaturations_(elemFluidState, ssol);
1075 if constexpr (enableSolvent) {
1076 this->solventSaturation_[elemIdx] = ssol;
1077 this->solventRsw_[elemIdx] = this->eclWriter_->outputModule().getSolventRsw(elemIdx);
1083 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1084 const auto& rspec = eclState.runspec();
1085 bool needTemperature = rspec.co2Storage() || rspec.h2Storage()
1086 || rspec.co2Sol() || rspec.h2Sol();
1087 if (needTemperature) {
1088 const auto& fp = simulator.vanguard().eclState().fieldProps();
1089 elemFluidState.setTemperature(fp.get_double(
"TEMPI")[elemIdx]);
1093 this->mixControls_.updateLastValues(elemIdx, elemFluidState.Rs(), elemFluidState.Rv());
1095 if constexpr (enablePolymer)
1096 this->polymer_.concentration[elemIdx] = this->eclWriter_->outputModule().getPolymerConcentration(elemIdx);
1100 const int episodeIdx = this->episodeIndex();
1101 this->mixControls_.updateMaxValues(episodeIdx, simulator.timeStepSize());
1106 auto& sol = this->model().solution(0);
1107 const auto& gridView = this->gridView();
1109 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
1110 elemCtx.updatePrimaryStencil(elem);
1111 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1112 this->initial(sol[elemIdx], elemCtx, 0, 0);
1120 this->model().syncOverlap();
1123 this->updateReferencePorosity_();
1124 this->mixControls_.init(this->model().numGridDof(),
1125 this->episodeIndex(),
1126 eclState.runspec().tabdims().getNumPVTTables());
1130 template<
class Serializer>
1134 serializer(mixControls_);
1135 serializer(*eclWriter_);
1142 FlowProblemType::captureBeginTimeStepState_();
1143 prev_timestep_state_.mixControls = mixControls_;
1149 FlowProblemType::restoreBeginTimeStepState_();
1150 mixControls_ = prev_timestep_state_.mixControls;
1155 this->updateExplicitQuantities_(first_step_after_restart);
1157 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>())
1158 updateMaxPolymerAdsorption_();
1160 mixControls_.updateExplicitQuantities(episodeIdx, timeStepSize);
1166 this->updateProperty_(
"FlowProblemBlackoil::updateMaxPolymerAdsorption_() failed:",
1169 this->updateMaxPolymerAdsorption_(compressedDofIdx,iq);
1175 const Scalar pa = scalarValue(iq.polymerAdsorption());
1176 auto& mpa = this->polymer_.maxAdsorption;
1177 if (mpa[compressedDofIdx] < pa) {
1178 mpa[compressedDofIdx] = pa;
1187 std::vector<Scalar> sumInvB(numPhases, 0.0);
1188 const auto& gridView = this->gridView();
1190 for(
const auto& elem: elements(gridView, Dune::Partitions::interior)) {
1191 elemCtx.updatePrimaryStencil(elem);
1192 int elemIdx = elemCtx.globalSpaceIndex(0, 0);
1193 const auto& dofFluidState = this->initialFluidStates_[elemIdx];
1194 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1195 if (!FluidSystem::phaseIsActive(phaseIdx))
1198 sumInvB[phaseIdx] += dofFluidState.invB(phaseIdx);
1202 std::size_t numDof = this->model().numGridDof();
1203 const auto& comm = this->simulator().vanguard().grid().comm();
1204 comm.sum(sumInvB.data(),sumInvB.size());
1205 Scalar numTotalDof = comm.sum(numDof);
1207 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1208 if (!FluidSystem::phaseIsActive(phaseIdx))
1211 Scalar avgB = numTotalDof / sumInvB[phaseIdx];
1212 const unsigned solventCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
1213 const unsigned activeSolventCompIdx = FluidSystem::canonicalToActiveCompIdx(solventCompIdx);
1214 this->model().setEqWeight(activeSolventCompIdx, avgB);
1221 OPM_TIMEBLOCK(updateCompositionChangeLimits);
1224 int episodeIdx = this->episodeIndex();
1225 std::array<bool,3> active{this->mixControls_.drsdtConvective(episodeIdx),
1226 this->mixControls_.drsdtActive(episodeIdx),
1227 this->mixControls_.drvdtActive(episodeIdx)};
1228 if (!active[0] && !active[1] && !active[2]) {
1232 this->updateProperty_(
"FlowProblemBlackoil::updateCompositionChangeLimits_()) failed:",
1233 [
this,episodeIdx,active](
unsigned compressedDofIdx,
1236 const DimMatrix& perm = this->intrinsicPermeability(compressedDofIdx);
1237 const Scalar distZ = active[0] ? this->simulator().vanguard().cellThickness(compressedDofIdx) : 0.0;
1238 const int pvtRegionIdx = this->pvtRegionIndex(compressedDofIdx);
1239 this->mixControls_.update(compressedDofIdx,
1242 this->gravity_[
dim - 1],
1255 if(this->simulator().vanguard().grid().maxLevel() > 0) {
1256 throw std::invalid_argument(
"Refined grids are not yet supported for restart ");
1260 auto& simulator = this->simulator();
1261 const auto& schedule = simulator.vanguard().schedule();
1262 const auto& eclState = simulator.vanguard().eclState();
1263 const auto& initconfig = eclState.getInitConfig();
1264 const int restart_step = initconfig.getRestartStep();
1266 simulator.setTime(schedule.seconds(restart_step));
1268 simulator.startNextEpisode(simulator.startTime() + simulator.time(),
1269 schedule.stepLength(restart_step));
1270 simulator.setEpisodeIndex(restart_step);
1272 this->eclWriter_->beginRestart();
1274 Scalar dt = std::min(this->eclWriter_->restartTimeStepSize(), simulator.episodeLength());
1275 simulator.setTimeStepSize(dt);
1277 this->readSolutionFromOutputModule(restart_step,
false);
1279 this->eclWriter_->endRestart();
1284 const auto& simulator = this->simulator();
1289 std::size_t numElems = this->model().numGridDof();
1290 this->initialFluidStates_.resize(numElems);
1291 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1292 auto& elemFluidState = this->initialFluidStates_[elemIdx];
1299 const auto& simulator = this->simulator();
1300 const auto& vanguard = simulator.vanguard();
1301 const auto& eclState = vanguard.eclState();
1302 const auto& fp = eclState.fieldProps();
1303 bool has_swat = fp.has_double(
"SWAT");
1304 bool has_sgas = fp.has_double(
"SGAS");
1305 bool has_rs = fp.has_double(
"RS");
1306 bool has_rsw = fp.has_double(
"RSW");
1307 bool has_rv = fp.has_double(
"RV");
1308 bool has_rvw = fp.has_double(
"RVW");
1309 bool has_pressure = fp.has_double(
"PRESSURE");
1310 bool has_salt = fp.has_double(
"SALT");
1311 bool has_saltp = fp.has_double(
"SALTP");
1314 if (Indices::numPhases > 1) {
1315 if (FluidSystem::phaseIsActive(waterPhaseIdx) && !has_swat)
1316 throw std::runtime_error(
"The ECL input file requires the presence of the SWAT keyword if "
1317 "the water phase is active");
1318 if (FluidSystem::phaseIsActive(gasPhaseIdx) && !has_sgas && FluidSystem::phaseIsActive(oilPhaseIdx))
1319 throw std::runtime_error(
"The ECL input file requires the presence of the SGAS keyword if "
1320 "the gas phase is active");
1323 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
1324 "keyword if the model is initialized explicitly");
1325 if (FluidSystem::enableDissolvedGas() && !has_rs)
1326 throw std::runtime_error(
"The ECL input file requires the RS keyword to be present if"
1327 " dissolved gas is enabled and the model is initialized explicitly");
1328 if (FluidSystem::enableDissolvedGasInWater() && !has_rsw)
1329 OpmLog::warning(
"The model is initialized explicitly and the RSW keyword is not present in the"
1330 " ECL input file. The RSW values are set equal to 0");
1331 if (FluidSystem::enableVaporizedOil() && !has_rv)
1332 throw std::runtime_error(
"The ECL input file requires the RV keyword to be present if"
1333 " vaporized oil is enabled and the model is initialized explicitly");
1334 if (FluidSystem::enableVaporizedWater() && !has_rvw)
1335 throw std::runtime_error(
"The ECL input file requires the RVW keyword to be present if"
1336 " vaporized water is enabled and the model is initialized explicitly");
1337 if (enableBrine && !has_salt)
1338 throw std::runtime_error(
"The ECL input file requires the SALT keyword to be present if"
1339 " brine is enabled and the model is initialized explicitly");
1340 if (enableSaltPrecipitation && !has_saltp)
1341 throw std::runtime_error(
"The ECL input file requires the SALTP keyword to be present if"
1342 " salt precipitation is enabled and the model is initialized explicitly");
1344 std::size_t numDof = this->model().numGridDof();
1346 initialFluidStates_.resize(numDof);
1348 std::vector<double> waterSaturationData;
1349 std::vector<double> gasSaturationData;
1350 std::vector<double> pressureData;
1351 std::vector<double> rsData;
1352 std::vector<double> rswData;
1353 std::vector<double> rvData;
1354 std::vector<double> rvwData;
1355 std::vector<double> tempiData;
1356 std::vector<double> saltData;
1357 std::vector<double> saltpData;
1359 if (FluidSystem::phaseIsActive(waterPhaseIdx) && Indices::numPhases > 1)
1360 waterSaturationData = fp.get_double(
"SWAT");
1362 waterSaturationData.resize(numDof);
1364 if (FluidSystem::phaseIsActive(gasPhaseIdx) && FluidSystem::phaseIsActive(oilPhaseIdx))
1365 gasSaturationData = fp.get_double(
"SGAS");
1367 gasSaturationData.resize(numDof);
1369 pressureData = fp.get_double(
"PRESSURE");
1370 if (FluidSystem::enableDissolvedGas())
1371 rsData = fp.get_double(
"RS");
1373 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1374 rswData = fp.get_double(
"RSW");
1376 if (FluidSystem::enableVaporizedOil())
1377 rvData = fp.get_double(
"RV");
1379 if (FluidSystem::enableVaporizedWater())
1380 rvwData = fp.get_double(
"RVW");
1383 tempiData = fp.get_double(
"TEMPI");
1386 if constexpr (enableBrine)
1387 saltData = fp.get_double(
"SALT");
1390 if constexpr (enableSaltPrecipitation)
1391 saltpData = fp.get_double(
"SALTP");
1394 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1395 auto& dofFluidState = initialFluidStates_[dofIdx];
1397 dofFluidState.setPvtRegionIndex(pvtRegionIndex(dofIdx));
1402 if constexpr (energyModuleType != EnergyModules::NoTemperature) {
1403 Scalar temperatureLoc = tempiData[dofIdx];
1404 if (!std::isfinite(temperatureLoc) || temperatureLoc <= 0)
1405 temperatureLoc = FluidSystem::surfaceTemperature;
1406 dofFluidState.setTemperature(temperatureLoc);
1412 if constexpr (enableBrine)
1413 dofFluidState.setSaltConcentration(saltData[dofIdx]);
1418 if constexpr (enableSaltPrecipitation)
1419 dofFluidState.setSaltSaturation(saltpData[dofIdx]);
1424 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx))
1425 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
1426 waterSaturationData[dofIdx]);
1428 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)){
1429 if (!FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)){
1430 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1432 - waterSaturationData[dofIdx]);
1435 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
1436 gasSaturationData[dofIdx]);
1438 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
1439 const Scalar soil = 1.0 - waterSaturationData[dofIdx] - gasSaturationData[dofIdx];
1440 if (soil < smallSaturationTolerance_) {
1441 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, 0.0);
1444 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx, soil);
1451 Scalar pressure = pressureData[dofIdx];
1455 std::array<Scalar, numPhases> pc = {0};
1456 const auto& matParams = this->materialLawParams(dofIdx);
1457 MaterialLaw::capillaryPressures(pc, matParams, dofFluidState);
1458 Valgrind::CheckDefined(pressure);
1459 Valgrind::CheckDefined(pc);
1460 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1461 if (!FluidSystem::phaseIsActive(phaseIdx))
1464 if (Indices::oilEnabled)
1465 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
1466 else if (Indices::gasEnabled)
1467 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
1468 else if (Indices::waterEnabled)
1470 dofFluidState.setPressure(phaseIdx, pressure);
1473 if constexpr (enableDissolvedGas) {
1474 if (FluidSystem::enableDissolvedGas())
1475 dofFluidState.setRs(rsData[dofIdx]);
1476 else if (Indices::gasEnabled && Indices::oilEnabled)
1477 dofFluidState.setRs(0.0);
1478 if (FluidSystem::enableVaporizedOil())
1479 dofFluidState.setRv(rvData[dofIdx]);
1480 else if (Indices::gasEnabled && Indices::oilEnabled)
1481 dofFluidState.setRv(0.0);
1484 if constexpr (enableDisgasInWater) {
1485 if (FluidSystem::enableDissolvedGasInWater() && has_rsw)
1486 dofFluidState.setRsw(rswData[dofIdx]);
1489 if constexpr (enableVapwat) {
1490 if (FluidSystem::enableVaporizedWater())
1491 dofFluidState.setRvw(rvwData[dofIdx]);
1497 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1498 if (!FluidSystem::phaseIsActive(phaseIdx))
1501 const auto& b = FluidSystem::inverseFormationVolumeFactor(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1502 dofFluidState.setInvB(phaseIdx, b);
1504 const auto& rho = FluidSystem::density(dofFluidState, phaseIdx, pvtRegionIndex(dofIdx));
1505 dofFluidState.setDensity(phaseIdx, rho);
1516 Scalar sumSaturation = 0.0;
1517 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1518 if (FluidSystem::phaseIsActive(phaseIdx)) {
1519 if (elemFluidState.saturation(phaseIdx) < smallSaturationTolerance_)
1520 elemFluidState.setSaturation(phaseIdx, 0.0);
1522 sumSaturation += elemFluidState.saturation(phaseIdx);
1526 if constexpr (enableSolvent) {
1527 if (solventSaturation < smallSaturationTolerance_)
1528 solventSaturation = 0.0;
1530 sumSaturation += solventSaturation;
1533 assert(sumSaturation > 0.0);
1535 for (std::size_t phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1536 if (FluidSystem::phaseIsActive(phaseIdx)) {
1537 const Scalar saturation = elemFluidState.saturation(phaseIdx) / sumSaturation;
1538 elemFluidState.setSaturation(phaseIdx, saturation);
1541 if constexpr (enableSolvent) {
1542 solventSaturation = solventSaturation / sumSaturation;
1548 FlowProblemType::readInitialCondition_();
1550 if constexpr (enableSolvent || enablePolymer || enablePolymerMolarWeight || enableBioeffects)
1551 this->readBlackoilExtentionsInitialConditions_(this->model().numGridDof(),
1554 enablePolymerMolarWeight,
1562 if constexpr (!enableSolvent)
1563 throw std::logic_error(
"solvent is disabled and you're trying to add solvent to BC");
1565 rate[Indices::solventSaturationIdx] = bc.rate;
1570 if constexpr (!enablePolymer)
1571 throw std::logic_error(
"polymer is disabled and you're trying to add polymer to BC");
1573 rate[Indices::polymerConcentrationIdx] = bc.rate;
1578 if constexpr (!enableMICP)
1579 throw std::logic_error(
"MICP is disabled and you're trying to add microbes to BC");
1581 rate[Indices::microbialConcentrationIdx] = bc.rate;
1586 if constexpr (!enableMICP)
1587 throw std::logic_error(
"MICP is disabled and you're trying to add oxygen to BC");
1589 rate[Indices::oxygenConcentrationIdx] = bc.rate;
1594 if constexpr (!enableMICP)
1595 throw std::logic_error(
"MICP is disabled and you're trying to add urea to BC");
1597 rate[Indices::ureaConcentrationIdx] = bc.rate;
1599 rate[Indices::ureaConcentrationIdx] *= getPropValue<TypeTag, Properties::BlackOilUreaScalingFactor>();
1604 OPM_TIMEBLOCK(updateExplicitQuantities);
1605 const bool invalidateFromMaxWaterSat = this->updateMaxWaterSaturation_();
1606 const bool invalidateFromMinPressure = this->updateMinPressure_();
1609 const bool invalidateFromHyst = this->updateHysteresis_();
1610 const bool invalidateFromMaxOilSat = this->updateMaxOilSaturation_();
1613 const bool invalidateDRDT = !first_step_after_restart && this->updateCompositionChangeLimits_();
1616 const bool invalidateIntensiveQuantities
1617 = invalidateFromMaxWaterSat || invalidateFromMinPressure || invalidateFromHyst || invalidateFromMaxOilSat || invalidateDRDT;
1618 if (invalidateIntensiveQuantities) {
1619 OPM_TIMEBLOCK(beginTimeStepInvalidateIntensiveQuantities);
1620 this->model().invalidateAndUpdateIntensiveQuantities(0);
1623 this->updateRockCompTransMultVal_();
1634 const unsigned aquIdx,
1635 const FaceDir::DirEnum faceDir)
const
1640 const auto& model = this->model();
1641 const auto& iqCell = model.intensiveQuantities(cellIdx, 0);
1642 const auto& iqAqu = model.intensiveQuantities(aquIdx, 0);
1644 const Scalar distZg = (this->dofCenterDepth(cellIdx) - this->dofCenterDepth(aquIdx))
1645 * this->gravity_[
dim - 1];
1646 const Scalar thpresCellToAqu = this->thresholdPressure(cellIdx, aquIdx);
1647 const Scalar thpresAquToCell = this->thresholdPressure(aquIdx, cellIdx);
1650 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
1651 if (!FluidSystem::phaseIsActive(phaseIdx)) {
1655 constexpr unsigned cellLocalIdx = 0;
1656 constexpr unsigned aquLocalIdx = 1;
1657 short upIdx = cellLocalIdx;
1658 short dnIdx = aquLocalIdx;
1660 ExtensiveQuantities::calculatePhasePressureDiff_(upIdx, dnIdx, pressureDifference,
1661 iqCell, iqAqu, phaseIdx,
1662 cellLocalIdx, aquLocalIdx,
1663 model.dofTotalVolume(cellIdx),
1664 model.dofTotalVolume(aquIdx),
1665 cellIdx, aquIdx, distZg,
1666 thpresCellToAqu, thpresAquToCell,
1667 this->moduleParams());
1670 const Scalar dp = getValue(pressureDifference);
1671 const auto& up = (upIdx ==
static_cast<short>(cellLocalIdx)) ? iqCell : iqAqu;
1673 getValue(up.fluidState().saturation(phaseIdx)) > 0.0 &&
1674 getValue(up.mobility(phaseIdx, faceDir)) > 0.0 &&
1675 std::abs(dp) > std::abs(largest))
1688 const auto& vanguard = this->simulator().vanguard();
1689 const auto& eclState = vanguard.eclState();
1690 if (!eclState.aquifer().hasNumericalAquifer() ||
1691 !eclState.fieldProps().has_int(
"EQLNUM"))
1696 std::unordered_map<std::size_t, std::size_t> aquiferOfCell;
1697 for (
const auto& [cartIdx, cell] : eclState.aquifer().numericalAquifers().allAquiferCells()) {
1698 aquiferOfCell.emplace(cartIdx, cell->aquifer_id);
1701 const auto eqlnum = this->lookUpData_.template
1702 assignFieldPropsIntOnLeaf<int>(eclState.fieldProps(),
"EQLNUM",
false);
1707 std::vector<NumericalAquiferEquilibrationMismatch> mismatches;
1708 const auto& gridView = this->gridView();
1709 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
1710 const unsigned cellIdx = this->elementMapper().index(elem);
1711 const auto cellCart = vanguard.cartesianIndex(cellIdx);
1712 const bool cellIsAquifer = aquiferOfCell.contains(cellCart);
1713 for (
const auto& intersection : intersections(gridView, elem)) {
1714 if (!intersection.neighbor()) {
1717 const unsigned aquIdx = this->elementMapper().index(intersection.outside());
1718 const auto aquCart = vanguard.cartesianIndex(aquIdx);
1719 const auto aquifer = aquiferOfCell.find(aquCart);
1720 if (aquifer == aquiferOfCell.end() ||
1721 (cellIsAquifer && cellCart > aquCart) ||
1722 eqlnum[aquIdx] == eqlnum[cellIdx] ||
1723 !(this->transmissibility(cellIdx, aquIdx) > 0.0))
1729 const int dirId = intersection.indexInInside();
1730 const auto faceDir = (dirId < 0) ? FaceDir::DirEnum::Unknown
1731 : FaceDir::FromIntersectionIndex(dirId);
1733 const Scalar dp = this->initialFlowPressureDifference_(cellIdx, aquIdx, faceDir);
1735 mismatches.push_back({aquifer->second, eqlnum[aquIdx], eqlnum[cellIdx], dp});
1741 Parameters::Get<Parameters::AllowInconsistentAquiferEquilibration>());
1746 if (
const auto nph = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
1747 + FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)
1748 + FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
1757 const auto numSamplePoints =
static_cast<std::size_t
>
1758 (Parameters::Get<Parameters::NumSatfuncConsistencySamplePoints>());
1760 auto sfuncConsistencyChecks =
1762 numSamplePoints, this->simulator().vanguard().eclState(),
1763 [&cmap = this->simulator().vanguard().cartesianIndexMapper()](
const int elemIdx)
1764 {
return cmap.cartesianIndex(elemIdx); }
1767 const auto ioRank = 0;
1768 const auto isIoRank = this->simulator().vanguard()
1769 .grid().comm().rank() == ioRank;
1775 .
run(this->simulator().vanguard().grid().levelGridView(0),
1776 [&vg = this->simulator().vanguard(),
1777 &emap = this->simulator().model().elementMapper()]
1779 {
return vg.gridIdxToEquilGridIdx(emap.index(elem)); });
1784 auto reportFailures = [&sfuncConsistencyChecks]
1785 (
const ViolationLevel level)
1787 sfuncConsistencyChecks.reportFailures
1788 (level, [](std::string_view record)
1789 { OpmLog::info(std::string { record }); });
1792 if (sfuncConsistencyChecks.anyFailedStandardChecks()) {
1794 OpmLog::warning(
"Saturation Function "
1795 "End-point Consistency Problems");
1797 reportFailures(ViolationLevel::Standard);
1801 if (sfuncConsistencyChecks.anyFailedCriticalChecks()) {
1803 OpmLog::error(
"Saturation Function "
1804 "End-point Consistency Failures");
1806 reportFailures(ViolationLevel::Critical);
1824 const Scalar smallSaturationTolerance_ = 1.e-6;
1826 bool enableDamarisOutput_ = false ;
1827 std::unique_ptr<DamarisWriterType> damarisWriter_;
1833 bool checkAquiferEquilibration_{
false};
1840 : mixControls(schedule)
1853 void checkGpuAssemblySchedule_()
const
1855 if constexpr (getPropValue<TypeTag, Properties::RunAssemblyOnGpu>()) {
1858 const auto& state = this->simulator().vanguard().schedule()[this->episodeIndex()];
1859 if (state.events().hasEvent(ScheduleEvents::GEO_MODIFIER)) {
1860 OPM_THROW(std::runtime_error,
1861 "GPU assembly does not support GEO_MODIFIER schedule events.");
1863 if (state.oilvap().getType() == OilVaporizationProperties::OilVaporization::DRSDTCON) {
1864 OPM_THROW(std::runtime_error,
"GPU assembly does not support DRSDTCON.");
1879 bool episodeWillBeOver()
const override
1881 const auto currTime = this->simulator().time()
1882 + this->simulator().timeStepSize();
1884 const auto nextReportStep =
1885 this->simulator().vanguard().schedule()
1886 .seconds(this->simulator().episodeIndex() + 1);
1888 const auto isSubStep = (nextReportStep - currTime)
1889 > (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:389
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:407
bool enableDriftCompensationTemp_
Definition: FlowGenericProblem.hpp:408
bool enableTuning_
Definition: FlowGenericProblem.hpp:400
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemBlackoil.hpp:84
HybridNewton hybridNewton_
Definition: FlowProblemBlackoil.hpp:1850
void updateExplicitQuantities_(int episodeIdx, int timeStepSize, const bool first_step_after_restart) override
Definition: FlowProblemBlackoil.hpp:1153
bool updateMaxPolymerAdsorption_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblemBlackoil.hpp:1173
void writeOutput(const bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemBlackoil.hpp:538
void readInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1546
void readEquilInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1282
void handleSolventBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1560
bool checkAquiferEquilibration_
Definition: FlowProblemBlackoil.hpp:1833
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:869
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemBlackoil.hpp:733
void processRestartSaturations_(InitialFluidState &elemFluidState, Scalar &solventSaturation)
Definition: FlowProblemBlackoil.hpp:1512
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemBlackoil.hpp:730
FlowProblemBlackoil(Simulator &simulator)
Definition: FlowProblemBlackoil.hpp:185
bool enableEclOutput_
Definition: FlowProblemBlackoil.hpp:1821
PrevTimestepState prev_timestep_state_
Definition: FlowProblemBlackoil.hpp:1846
Scalar drsdtcon(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:964
void endStepApplyAction()
Definition: FlowProblemBlackoil.hpp:456
bool drsdtconIsActive(unsigned elemIdx, int episodeIdx) const
Definition: FlowProblemBlackoil.hpp:970
void handleMicrBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1576
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:880
std::vector< InitialFluidState > initialFluidStates_
Definition: FlowProblemBlackoil.hpp:1819
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemBlackoil.hpp:450
void updateMaxPolymerAdsorption_()
Definition: FlowProblemBlackoil.hpp:1163
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemBlackoil.hpp:727
void endEpisode() override
Called by the simulator after the end of an episode.
Definition: FlowProblemBlackoil.hpp:506
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemBlackoil.hpp:739
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemBlackoil.hpp:920
void checkNumericalAquiferEquilibration_() const
Definition: FlowProblemBlackoil.hpp:1686
Scalar initialFlowPressureDifference_(const unsigned cellIdx, const unsigned aquIdx, const FaceDir::DirEnum faceDir) const
Definition: FlowProblemBlackoil.hpp:1633
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemBlackoil.hpp:321
void finalizeOutput()
Definition: FlowProblemBlackoil.hpp:561
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemBlackoil.hpp:981
void handleOxygBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1584
InitialFluidState boundaryFluidState(unsigned globalDofIdx, const int directionId) const
Definition: FlowProblemBlackoil.hpp:745
std::unique_ptr< EclWriterType > eclWriter_
Definition: FlowProblemBlackoil.hpp:1822
void initialSolutionApplied() override
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblemBlackoil.hpp:573
void captureBeginTimeStepState_() override
Snapshot the mixing rate controls before the timestep runs.
Definition: FlowProblemBlackoil.hpp:1140
void readEclRestartSolution_()
Definition: FlowProblemBlackoil.hpp:1252
void readExplicitInitialCondition_() override
Definition: FlowProblemBlackoil.hpp:1297
void beginEpisode() override
Called by the simulator before an episode begins.
Definition: FlowProblemBlackoil.hpp:278
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:898
void handleUreaBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1592
LhsEval permFactTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Calculate the transmissibility multiplier due to porosity reduction.
Definition: FlowProblemBlackoil.hpp:707
void serializeOp(Serializer &serializer)
Definition: FlowProblemBlackoil.hpp:1131
MixingRateControls< FluidSystem > mixControls_
Definition: FlowProblemBlackoil.hpp:1829
void handlePolymerBC(const BCState::BCFace &bc, RateVector &rate) const override
Definition: FlowProblemBlackoil.hpp:1568
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemBlackoil.hpp:526
const EclWriterType & eclWriter() const
Definition: FlowProblemBlackoil.hpp:859
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemBlackoil.hpp:742
void addToSourceDense(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const override
Definition: FlowProblemBlackoil.hpp:600
void computeAndSetEqWeights_()
Definition: FlowProblemBlackoil.hpp:1185
void beginTimeStep() override
Called by the simulator before each time integration.
Definition: FlowProblemBlackoil.hpp:312
void updateExplicitQuantities_(const bool first_step_after_restart)
Definition: FlowProblemBlackoil.hpp:1602
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemBlackoil.hpp:171
ActionHandler< Scalar, IndexTraits > actionHandler_
Definition: FlowProblemBlackoil.hpp:1848
void readSolutionFromOutputModule(const int restart_step, bool fip_init)
Read simulator solution state from the outputmodule (used with restart)
Definition: FlowProblemBlackoil.hpp:1022
const EclipseIO & eclIO() const
Definition: FlowProblemBlackoil.hpp:736
void restoreBeginTimeStepState_() override
Restore mixing rate controls after a failed timestep.
Definition: FlowProblemBlackoil.hpp:1147
EclWriterType & eclWriter()
Definition: FlowProblemBlackoil.hpp:862
bool satfuncConsistencyRequirementsMet() const
Definition: FlowProblemBlackoil.hpp:1744
bool updateCompositionChangeLimits_()
Definition: FlowProblemBlackoil.hpp:1219
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:546
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:964
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:744
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:2122
@ 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:317
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:2128
@ enableThermalFluxBoundaries
Definition: FlowProblem.hpp:142
WellModel wellModel_
Definition: FlowProblem.hpp:2124
virtual void beginEpisode()
Called by the simulator before an episode begins.
Definition: FlowProblem.hpp:325
static constexpr bool enablePolymerMolarWeight
Definition: FlowProblem.hpp:134
virtual void beginTimeStep()
Called by the simulator before each time integration.
Definition: FlowProblem.hpp:384
@ gasPhaseIdx
Definition: FlowProblem.hpp:144
static constexpr bool enableSolvent
Definition: FlowProblem.hpp:135
@ numPhases
Definition: FlowProblem.hpp:123
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1430
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:2129
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:1439
@ oilCompIdx
Definition: FlowProblem.hpp:151
void initializeSimulatorTime_()
Definition: FlowProblem.hpp:1498
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:200
void updatePffDofData_()
Definition: FlowProblem.hpp:1892
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:1923
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:464
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:1522
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:1838
MixingRateControls< FluidSystem > mixControls
DRSDT / DRVDT.
Definition: FlowProblemBlackoil.hpp:1843
PrevTimestepState(const Schedule &schedule)
Definition: FlowProblemBlackoil.hpp:1839
Definition: SimulatorReport.hpp:202
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34