30#ifndef OPM_FLOW_PROBLEM_COMP_HPP
31#define OPM_FLOW_PROBLEM_COMP_HPP
44#include <opm/grid/LookUpData.hh>
46#include <opm/material/constraintsolvers/PTFlashMethod.hpp>
47#include <opm/material/fluidstates/CompositionalFluidState.hpp>
49#include <opm/material/thermal/EclThermalLawManager.hpp>
51#include <opm/common/OpmLog/OpmLog.hpp>
53#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquifers.hpp>
54#include <opm/input/eclipse/Schedule/BCState.hpp>
55#include <opm/input/eclipse/Schedule/RPTConfig.hpp>
57#include <dune/grid/common/rangegenerators.hh>
59#include <fmt/format.h>
90template <
class TypeTag>
121 using InitialFluidState = CompositionalFluidState<Scalar, FluidSystem>;
134 Parameters::SetDefault<Parameters::InputSkipMode>(
"300");
139 Parameters::SetDefault<Parameters::NewtonTolerance<Scalar>>(1e-7);
145 if constexpr (std::is_same_v<Backend, ISTLSolver<TypeTag>>
146 || std::is_same_v<Backend, ISTLSolverRuntimeOptionProxy<TypeTag>>) {
147 Parameters::SetDefault<Parameters::CprPreSmooth>(1);
150 Parameters::Register<Parameters::NormalizeExplicitSwat>(
151 "Treat the explicit initial saturations of compositional runs as "
152 "saturations before the hydrocarbon flash: SGAS and the oil "
153 "saturation 1 - SWAT - SGAS each hold their input composition at "
154 "the vapour or liquid equation-of-state root, and water and the "
155 "flashed phases are then rescaled to fill the pore volume. When "
156 "disabled (the default), the input SWAT is retained.");
162 {
return eosnum_.empty() ? 0 : eosnum_[globalDofIdx]; }
170 eclWriter_ = std::make_unique<EclWriterType>(simulator);
171 enableEclOutput_ = Parameters::Get<Parameters::EnableEclOutput>();
179 FlowProblemType::finishInit();
181 auto& simulator = this->simulator();
182 const bool transmissibilitiesFinished =
184 if (!transmissibilitiesFinished) {
188 const auto& eclState = simulator.vanguard().eclState();
189 const auto& schedule = simulator.vanguard().schedule();
193 if (eclState.getSimulationConfig().rock_config().active()) {
194 throw std::runtime_error(
"Rock compaction (ROCKCOMP) is not supported "
195 "by compositional modeling yet");
197 if (eclState.getSimulationConfig().bcconfig().size() > 0) {
198 throw std::runtime_error(
"Boundary conditions (BCCON) are not supported "
199 "by compositional modeling yet");
201 this->
updateNum(
"EOSNUM", eosnum_, eclState.getTableManager().getTabdims().getNumEosRes());
205 if (enableEclOutput_) {
206 eclWriter_->writeInit();
209 const auto& initconfig = eclState.getInitConfig();
210 if (initconfig.restartRequested())
217 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
218 const auto& vanguard = this->simulator().vanguard();
219 const auto& gridView = vanguard.gridView();
220 int numElements = gridView.size(0);
221 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
235 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
236 simulator.setTimeStepSize(0.0);
243 if (!initconfig.restartRequested()) {
244 simulator.startNextEpisode(schedule.seconds(1));
245 simulator.setEpisodeIndex(0);
246 simulator.setTimeStepIndex(0);
260 reportTwoPhaseEquilCells_();
271 this->eclWriter_->mutableOutputModule().invalidateLocalData();
274 const auto& grid = this->simulator().vanguard().gridView().grid();
276 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
277 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
278 if (!isCpGrid || (grid.maxLevel() == 0)) {
284 if (enableEclOutput_){
285 eclWriter_->writeReports(timer);
297 if (! this->enableEclOutput_) {
303 if (!isSubStep || Parameters::Get<Parameters::EnableWriteAllSolutions>()) {
304 auto localCellData = data::Solution {};
306 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
307 this->simulator().vanguard().schedule()
308 .exitStatus().has_value());
317 template <
class Context>
319 const Context& context,
323 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
324 if (!context.intersection(spaceIdx).boundary())
331 std::pair<BCType, RateVector>
337 typename IntensiveQuantities::ScalarFluidState
340 throw std::logic_error(
"Boundary conditions are not supported "
341 "by compositional modeling yet");
350 template <
class Context>
353 const unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
355 const auto& initial_fs = initialFluidStates_[globalDofIdx];
356 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
357 for (
unsigned p = 0; p < numPhases; ++p) {
359 fs.setPressure(p, initial_fs.pressure(p));
362 fs.setSaturation(p, initial_fs.saturation(p));
365 fs.setTemperature(initial_fs.temperature(p));
369 if (!zmf_initialization_) {
370 for (
unsigned p = 0; p < numPhases; ++p) {
371 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
372 fs.setMoleFraction(p, compIdx, initial_fs.moleFraction(p, compIdx));
377 typename FluidSystem::template ParameterCache<Scalar> paramCache(eosRegionIdx);
378 paramCache.updatePhase(fs, FluidSystem::oilPhaseIdx);
379 paramCache.updatePhase(fs, FluidSystem::gasPhaseIdx);
380 fs.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::oilPhaseIdx));
381 fs.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::gasPhaseIdx));
384 Dune::FieldVector<Scalar, numComponents> z(0.0);
386 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
387 if (Indices::waterEnabled && phaseIdx ==
static_cast<unsigned int>(waterPhaseIdx)){
390 const auto saturation = fs.saturation(phaseIdx);
391 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
392 Scalar tmp = fs.molarity(phaseIdx, compIdx) * saturation;
393 tmp = max(tmp, 1e-8);
399 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
400 fs.setMoleFraction(compIdx, z[compIdx]);
404 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
405 fs.setMoleFraction(compIdx, initial_fs.moleFraction(compIdx));
410 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
411 const auto& Ktmp = fs.wilsonK_(compIdx, eosRegionIdx);
412 fs.setKvalue(compIdx, Ktmp);
415 const Scalar& Ltmp = -1.0;
418 values.assignNaive(fs);
427 {
return initialFluidStates_[globalDofIdx]; }
430 {
return initialFluidStates_; }
433 {
return initialFluidStates_; }
436 {
return *eclWriter_; }
439 {
return *eclWriter_; }
442 {
return eclWriter_->setSubStepReport(report); }
445 {
return eclWriter_->setSimulationReport(report); }
454 template<
class Serializer>
458 serializer(*eclWriter_);
469 const auto& simulator = this->simulator();
470 const auto& vanguard = simulator.vanguard();
471 const auto& eclState = vanguard.eclState();
477 std::vector<int> eqlnum(this->model().numGridDof(), 0);
478 if (eclState.fieldProps().has_int(
"EQLNUM")) {
480 lookUpData(vanguard.gridView());
481 eqlnum = lookUpData.template assignFieldPropsIntOnLeaf<int>(
482 eclState.fieldProps(),
"EQLNUM",
true);
487 std::vector<Scalar> connateWater, maxWater;
488 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
489 const auto numDof = this->model().numGridDof();
490 connateWater.resize(numDof);
491 maxWater.resize(numDof);
492 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
494 .oilWaterScaledEpsInfoDrainage(
static_cast<int>(dofIdx));
495 connateWater[dofIdx] = eps.Swl;
496 maxWater[dofIdx] = eps.Swu;
503 vanguard.cellCenterDepths(),
506 vanguard.gridView().comm(),
507 this->gravity()[dimWorld - 1],
508 this->numPressurePointsEquil(),
512 const auto& rptsol = vanguard.schedule().initialReportConfiguration();
513 if (rptsol.has_value() && rptsol->contains(
"SOLVD") && (rptsol->at(
"SOLVD") > 0)) {
514 reportCompositionVersusDepth_(initialState, eqlnum);
517 initialFluidStates_ = std::move(initialState.
fluidStates());
523 for (std::size_t cell = 0; cell < initialFluidStates_.size(); ++cell) {
524 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
525 initialFluidStates_[cell].setPressure(phaseIdx,
531 zmf_initialization_ =
true;
540 const auto& vanguard = this->simulator().vanguard();
541 const auto aquiferCells
542 = vanguard.eclState().aquifer().numericalAquifers().allAquiferCells();
543 if (aquiferCells.empty()) {
547 if (!FluidSystem::phaseIsActive(waterPhaseIdx)) {
548 throw std::logic_error(
"Water phase has to be active for numerical aquifer case");
551 for (std::size_t cell = 0; cell < initialFluidStates_.size(); ++cell) {
552 const auto pos = aquiferCells.find(vanguard.cartesianIndex(cell));
553 if (pos == aquiferCells.end()) {
557 const auto* aquCell = pos->second;
558 auto& fs = initialFluidStates_[cell];
559 fs.setSaturation(oilPhaseIdx, 0.0);
560 fs.setSaturation(gasPhaseIdx, 0.0);
561 fs.setSaturation(waterPhaseIdx, 1.0);
562 if (aquCell->init_pressure) {
563 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
564 fs.setPressure(phaseIdx, *aquCell->init_pressure);
568 OpmLog::info(fmt::format(
"FOR AQUIFER CELL AT ({}, {}, {}) OF NUMERICAL "
569 "AQUIFER {}, WATER SATURATION IS SET TO BE UNITY",
573 aquCell->aquifer_id));
579 throw std::logic_error(
"Restarting is not supported by compositional modeling yet");
589 const auto& simulator = this->simulator();
590 const auto& vanguard = simulator.vanguard();
591 const auto& eclState = vanguard.eclState();
592 const auto& fp = eclState.fieldProps();
593 const bool has_pressure = fp.has_double(
"PRESSURE");
595 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
596 "keyword if the model is initialized explicitly");
598 const bool has_xmf = fp.has_double(
"XMF");
599 const bool has_ymf = fp.has_double(
"YMF");
600 const bool has_zmf = fp.has_double(
"ZMF");
601 if ( !has_zmf && !(has_xmf && has_ymf) ) {
602 throw std::runtime_error(
"The ECL input file requires the presence of ZMF or XMF and YMF "
603 "keyword if the model is initialized explicitly");
606 if (has_zmf && (has_xmf || has_ymf)) {
607 throw std::runtime_error(
"The ECL input file can not handle explicit initialization "
608 "with both ZMF and XMF or YMF");
611 if (has_xmf != has_ymf) {
612 throw std::runtime_error(
"The ECL input file needs XMF and YMF combined to do the explicit "
613 "initializtion when using XMF or YMF");
616 std::size_t numDof = this->model().numGridDof();
618 initialFluidStates_.resize(numDof);
620 const bool water_active = FluidSystem::phaseIsActive(waterPhaseIdx);
621 const bool gas_active = FluidSystem::phaseIsActive(gasPhaseIdx);
622 const bool oil_active = FluidSystem::phaseIsActive(oilPhaseIdx);
623 const std::array activePhases {water_active, oil_active, gas_active};
624 constexpr std::array saturationKeywords {
"SWAT",
"SOIL",
"SGAS"};
625 std::array<const std::vector<double>*, 3> saturationData {};
626 bool allActiveSaturationsSupplied =
true;
627 for (std::size_t phase = 0; phase < activePhases.size(); ++phase) {
628 if (!activePhases[phase]) {
631 if (fp.has_double(saturationKeywords[phase])) {
632 saturationData[phase] = &fp.get_double(saturationKeywords[phase]);
634 allActiveSaturationsSupplied =
false;
638 const auto& pressureData = fp.get_double(
"PRESSURE");
641 const auto& tempiData = fp.get_double(
"TEMPI");
643 const auto cellName = [&vanguard](
const std::size_t dofIdx) {
644 std::array<int, 3> ijk;
645 vanguard.cartesianCoordinate(dofIdx, ijk);
646 return fmt::format(
"cell ({}, {}, {})", ijk[0] + 1, ijk[1] + 1, ijk[2] + 1);
651 const auto& comm = vanguard.grid().comm();
653 std::vector<bool> ownedCells;
654 if (allActiveSaturationsSupplied) {
655 ownedCells.resize(numDof,
false);
656 for (
const auto& element : elements(vanguard.gridView(), Dune::Partitions::interior)) {
657 ownedCells[this->elementMapper().index(element)] =
true;
660 std::uint64_t normalizedCellCount = 0;
661 double maxNormalizationDeviation = 0.0;
663 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
664 auto& dofFluidState = initialFluidStates_[dofIdx];
667 std::array<std::optional<double>, 3> supplied;
668 for (std::size_t phase = 0; phase < saturationData.size(); ++phase) {
669 if (saturationData[phase]) {
670 supplied[phase] = (*saturationData[phase])[dofIdx];
676 }
catch (
const std::invalid_argument& error) {
677 throw std::invalid_argument(
"Invalid explicit saturations in "
678 + cellName(dofIdx) +
": " + error.what());
681 if (allActiveSaturationsSupplied && ownedCells[dofIdx]
683 ++normalizedCellCount;
684 maxNormalizationDeviation
688 const Scalar temperatureLoc = tempiData[dofIdx];
689 if (!std::isfinite(temperatureLoc) || temperatureLoc <= 0) {
690 throw std::invalid_argument(fmt::format(
"Invalid temperature in {}: "
691 "expected a finite, positive value, got {} K",
692 cellName(dofIdx), temperatureLoc));
694 dofFluidState.setTemperature(temperatureLoc);
697 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
701 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx,
705 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
712 const Scalar pressure = pressureData[dofIdx];
715 const std::array<Scalar, numPhases> pc = {0};
716 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
717 if (!FluidSystem::phaseIsActive(phaseIdx))
720 if (Indices::oilEnabled)
721 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
722 else if (Indices::gasEnabled)
723 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
724 else if (Indices::waterEnabled)
726 dofFluidState.setPressure(phaseIdx, pressure);
729 if (has_xmf && has_ymf) {
730 const auto& xmfData = fp.get_double(
"XMF");
731 const auto& ymfData = fp.get_double(
"YMF");
732 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
733 const std::size_t data_idx = compIdx * numDof + dofIdx;
734 const Scalar xmf = xmfData[data_idx];
735 const Scalar ymf = ymfData[data_idx];
737 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
738 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
743 zmf_initialization_ =
true;
744 const auto& zmfData = fp.get_double(
"ZMF");
745 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
746 const std::size_t data_idx = compIdx * numDof + dofIdx;
747 const Scalar zmf = zmfData[data_idx];
748 dofFluidState.setMoleFraction(compIdx, zmf);
751 const auto ymf = (dofFluidState.saturation(FluidSystem::gasPhaseIdx) > 0.) ? zmf :
Scalar{0};
752 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
755 const auto xmf = (dofFluidState.saturation(FluidSystem::oilPhaseIdx) > 0.) ? zmf :
Scalar{0};
756 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
762 "FlowProblemComp: invalid explicit initial state: ",
763 comm.rank() == 0, comm);
765 const auto globalNormalizedCellCount = comm.sum(normalizedCellCount);
766 const auto globalMaxDeviation = comm.max(maxNormalizationDeviation);
767 if (globalNormalizedCellCount > 0 && comm.rank() == 0) {
769 "EXPLICIT_SATURATION_NORMALIZATION",
770 fmt::format(
"Normalized explicit saturations in {} cells; "
771 "largest absolute deviation of their input sum from 1: {:.6g}",
772 globalNormalizedCellCount,
773 globalMaxDeviation));
776 if (water_active && Parameters::Get<Parameters::NormalizeExplicitSwat>()) {
792 const Scalar flash_tolerance = Parameters::Get<Parameters::FlashTolerance<Scalar>>();
793 const int flash_verbosity = Parameters::Get<Parameters::FlashVerbosity>();
794 const auto flash_method
795 = ptFlashMethodFromString(Parameters::Get<Parameters::FlashTwoPhaseMethod>());
796 bool zmf_oil_and_gas =
false;
799 const auto& comm = this->simulator().vanguard().grid().comm();
801 for (std::size_t cell = 0; cell < initialFluidStates_.size(); ++cell) {
802 auto& fs = initialFluidStates_[cell];
803 const Scalar sw_in = fs.saturation(FluidSystem::waterPhaseIdx);
804 if (sw_in <= 0.0 || sw_in >= 1.0) {
807 if (!zmf_oil_and_gas && zmf_initialization_
808 && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)
809 && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)
810 && fs.saturation(FluidSystem::oilPhaseIdx) > 0.0
811 && fs.saturation(FluidSystem::gasPhaseIdx) > 0.0) {
812 zmf_oil_and_gas =
true;
816 typename FluidSystem::template ParameterCache<Scalar> param_cache(eos_region);
821 Dune::FieldVector<Scalar, numComponents> moles(0.0);
823 for (
const unsigned phaseIdx : {FluidSystem::oilPhaseIdx, FluidSystem::gasPhaseIdx}) {
824 const Scalar saturation = fs.saturation(phaseIdx);
825 if (!FluidSystem::phaseIsActive(phaseIdx) || saturation <= 0.0) {
828 param_cache.updatePhase(fs, phaseIdx);
829 const Scalar phase_moles = saturation / param_cache.correctedMolarVolume(phaseIdx);
830 for (
unsigned c = 0; c < numComponents; ++c) {
831 moles[c] += phase_moles * fs.moleFraction(phaseIdx, c);
833 total_moles += phase_moles;
835 if (total_moles <= 0.0) {
841 Dune::FieldVector<Scalar, numComponents> z(0.0);
843 for (
unsigned c = 0; c < numComponents; ++c) {
844 z[c] = std::max(moles[c] / total_moles, IntensiveQuantities::compositionFloor);
848 InitialFluidState flash_fs;
849 flash_fs.setTemperature(fs.temperature(0));
850 flash_fs.setPressure(FluidSystem::oilPhaseIdx, fs.pressure(FluidSystem::oilPhaseIdx));
851 flash_fs.setPressure(FluidSystem::gasPhaseIdx, fs.pressure(FluidSystem::gasPhaseIdx));
852 for (
unsigned c = 0; c < numComponents; ++c) {
853 flash_fs.setMoleFraction(c, z[c] / sum_z);
854 flash_fs.setKvalue(c, flash_fs.wilsonK_(c, eos_region));
856 flash_fs.setLvalue(-1.0);
857 FlashSolver::flash_solve_scalar(
858 flash_fs, flash_method, flash_tolerance, eos_region, flash_verbosity);
861 const Scalar L = flash_fs.L();
864 param_cache.updatePhase(flash_fs, FluidSystem::oilPhaseIdx);
865 vm_flash += L * param_cache.correctedMolarVolume(FluidSystem::oilPhaseIdx);
868 param_cache.updatePhase(flash_fs, FluidSystem::gasPhaseIdx);
869 vm_flash += (1.0 - L) * param_cache.correctedMolarVolume(FluidSystem::gasPhaseIdx);
872 const Scalar sw = sw_in / (sw_in + total_moles * vm_flash);
873 const Scalar hc_scale = (1.0 - sw) / (1.0 - sw_in);
875 fs.setSaturation(FluidSystem::waterPhaseIdx, sw);
876 if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
877 fs.setSaturation(FluidSystem::gasPhaseIdx,
878 fs.saturation(FluidSystem::gasPhaseIdx) * hc_scale);
880 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
881 fs.setSaturation(FluidSystem::oilPhaseIdx,
882 fs.saturation(FluidSystem::oilPhaseIdx) * hc_scale);
887 if (comm.max(zmf_oil_and_gas ? 1 : 0) > 0 && comm.rank() == 0) {
888 OpmLog::warning(
"ZMF is given with both oil and gas saturations; both phases take "
889 "the ZMF composition when SWAT is normalized.");
897 void reportTwoPhaseEquilCells_()
899 if (!twoPhaseCheckRegions_.has_value()) {
903 const auto liquidFraction = [
this](
const std::size_t cell) {
904 const auto& intQuants
905 = this->model().intensiveQuantities(
static_cast<unsigned>(cell), 0);
906 return getValue(intQuants.fluidState().L());
908 const auto& vanguard = this->simulator().vanguard();
910 vanguard.cellCenterDepths(),
912 vanguard.eclState().getInitConfig().getEquil().size(),
913 vanguard.gridView().comm());
914 twoPhaseCheckRegions_.reset();
924 void reportCompositionVersusDepth_(
const EQUIL::Comp::InitialStateComputer<FluidSystem>& initialState,
925 const std::vector<int>& eqlnum)
const
927 const auto& vanguard = this->simulator().vanguard();
928 const auto& comm = vanguard.gridView().comm();
929 const auto numRegions = vanguard.eclState().getInitConfig().getEquil().size();
930 const auto count =
static_cast<int>(numRegions);
931 const auto& depths = vanguard.cellCenterDepths();
932 const auto aquiferCells =
933 vanguard.eclState().aquifer().numericalAquifers().allAquiferCells();
937 const auto halfThickness = [](
const auto& geometry) {
938 const auto depth = [&geometry](
const int corner) -> Scalar
939 {
return geometry.corner(corner)[dimWorld - 1]; };
940 if (geometry.corners() == 8) {
942 Scalar bottomFace = 0;
943 for (
int corner = 0; corner < 4; ++corner) {
944 topFace += depth(corner);
945 bottomFace += depth(corner + 4);
947 return std::abs(bottomFace - topFace) / 8;
949 Scalar shallowest = std::numeric_limits<Scalar>::max();
950 Scalar deepest = std::numeric_limits<Scalar>::lowest();
951 for (
int corner = 0; corner < geometry.corners(); ++corner) {
952 shallowest = std::min(shallowest, depth(corner));
953 deepest = std::max(deepest, depth(corner));
955 return (deepest - shallowest) / 2;
960 const auto representativeRank = [&aquiferCells,
961 numCartesian = vanguard.cartesianSize()](
const auto cartesianCell)
963 return static_cast<int>(cartesianCell)
964 + (aquiferCells.contains(cartesianCell) ? 0 : numCartesian);
967 std::vector<Scalar> top(numRegions, std::numeric_limits<Scalar>::max());
968 std::vector<Scalar> bottom(numRegions, std::numeric_limits<Scalar>::lowest());
969 std::vector<int> lastCell(numRegions, -1);
970 for (
const auto& element : elements(vanguard.gridView())) {
971 const auto cell = this->elementMapper().index(element);
972 const auto r =
static_cast<std::size_t
>(eqlnum[cell]);
973 const auto cartesianCell = vanguard.cartesianIndex(cell);
975 const Scalar half = aquiferCells.contains(cartesianCell)
976 ? Scalar{0} : halfThickness(element.geometry());
977 top[r] = std::min(top[r], depths[cell] - half);
978 bottom[r] = std::max(bottom[r], depths[cell] + half);
979 lastCell[r] = std::max(lastCell[r], representativeRank(cartesianCell));
981 comm.min(top.data(), count);
982 comm.max(bottom.data(), count);
983 comm.max(lastCell.data(), count);
985 const bool waterActive = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
986 std::vector<int> satTable(numRegions, -1);
987 std::vector<int> pvtRegion(numRegions, -1);
988 std::vector<Scalar> swl(numRegions, std::numeric_limits<Scalar>::lowest());
989 std::vector<Scalar> swu(numRegions, std::numeric_limits<Scalar>::lowest());
990 for (
const auto& element : elements(vanguard.gridView())) {
991 const auto cell = this->elementMapper().index(element);
992 const auto r =
static_cast<std::size_t
>(eqlnum[cell]);
993 if (representativeRank(vanguard.cartesianIndex(cell)) == lastCell[r]) {
1003 comm.max(satTable.data(), count);
1004 comm.max(pvtRegion.data(), count);
1005 comm.max(swl.data(), count);
1006 comm.max(swu.data(), count);
1008 if (comm.rank() != 0) {
1011 using ReportRegion =
typename EQUIL::Comp::InitialStateComputer<FluidSystem>::ReportRegion;
1012 std::vector<ReportRegion> regions(numRegions);
1013 for (std::size_t r = 0; r < numRegions; ++r) {
1015 if (satTable[r] < 0) {
1018 regions[r] = ReportRegion{top[r], bottom[r],
1019 waterActive ? swl[r] : Scalar{0},
1020 waterActive ? swu[r] : Scalar{1},
1021 static_cast<unsigned>(pvtRegion[r])};
1023 std::array<std::string_view, FluidSystem::numComponents> componentNames{};
1024 for (
unsigned c = 0; c < componentNames.size(); ++c) {
1025 componentNames[c] = FluidSystem::componentName(c);
1027 const auto rows = initialState.compositionVersusDepth(regions);
1029 for (std::size_t r = 0; r < numRegions; ++r) {
1030 if (!rows[r].empty()) {
1032 r + 1, satTable[r] + 1, rows[r], componentNames,
1033 vanguard.eclState().getDeckUnitSystem());
1036 OpmLog::note(report);
1039 void handleSolventBC(
const BCState::BCFace& , RateVector& )
const override
1041 throw std::logic_error(
"solvent is disabled for compositional modeling and you're trying to add solvent to BC");
1044 void handlePolymerBC(
const BCState::BCFace& , RateVector& )
const override
1046 throw std::logic_error(
"polymer is disabled for compositional modeling and you're trying to add polymer to BC");
1049 void handleMicrBC(
const BCState::BCFace& , RateVector& )
const override
1051 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add microbes to BC");
1054 void handleOxygBC(
const BCState::BCFace& , RateVector& )
const override
1056 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add oxygen to BC");
1059 void handleUreaBC(
const BCState::BCFace& , RateVector& )
const override
1061 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add urea to BC");
1064 std::vector<InitialFluidState> initialFluidStates_;
1067 std::optional<std::vector<int>> twoPhaseCheckRegions_;
1069 std::vector<int> eosnum_;
1071 bool zmf_initialization_ {
false};
1073 bool enableEclOutput_{
false};
1074 std::unique_ptr<EclWriterType> eclWriter_;
#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)
Catch exception, log, and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:207
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:197
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:160
Composition versus depth report (RPTSOL SOLVD) of the compositional equilibration.
Hydrostatic equilibration for the compositional simulator (EQUIL + ZMFVD/COMPVD).
Definition: DeferredLogger.hpp:57
Computes the initial state of a compositional model from hydrostatic equilibrium (the EQUIL and ZMFVD...
Definition: InitStateEquilComp.hpp:243
std::vector< int > & twoPhaseCheckRegions()
Definition: InitStateEquilComp.hpp:389
const std::vector< Scalar > & referencePressures() const
Definition: InitStateEquilComp.hpp:382
std::vector< FluidState > & fluidStates()
Definition: InitStateEquilComp.hpp:373
Collects necessary output values and pass it to opm-common's ECL output.
Definition: EclWriter.hpp:124
static void registerParameters()
Definition: EclWriter.hpp:152
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:389
std::vector< int > pvtnum_
Definition: FlowGenericProblem.hpp:370
void initFluidSystem_()
Definition: FlowGenericProblem_impl.hpp:691
void updateNum(const std::string &name, std::vector< T > &numbers, std::size_t num_regions)
Read a region keyword as zero-based indices, checked against num_regions.
Definition: FlowGenericProblem_impl.hpp:568
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemComp.hpp:92
void writeOutput(bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemComp.hpp:293
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemComp.hpp:432
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemComp.hpp:177
unsigned eosRegionIndex(const unsigned globalDofIdx) const
The zero-based reservoir EOS region of a cell.
Definition: FlowProblemComp.hpp:161
FlowProblemComp(Simulator &simulator)
Definition: FlowProblemComp.hpp:167
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemComp.hpp:283
void readExplicitInitialCondition_() override
Definition: FlowProblemComp.hpp:582
void applyNumericalAquifers_()
Definition: FlowProblemComp.hpp:538
void readExplicitInitialConditionCompositional_()
Definition: FlowProblemComp.hpp:587
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemComp.hpp:266
const EclWriterType & eclWriter() const
Definition: FlowProblemComp.hpp:435
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemComp.hpp:429
std::pair< BCType, RateVector > boundaryCondition(const unsigned int, const int) const
Boundary conditions are not supported; finishInit() rejects decks with BCCON.
Definition: FlowProblemComp.hpp:332
void readEclRestartSolution_()
Definition: FlowProblemComp.hpp:577
void normalizeExplicitSwat_()
Definition: FlowProblemComp.hpp:788
void finalizeOutput()
Definition: FlowProblemComp.hpp:447
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemComp.hpp:426
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemComp.hpp:318
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemComp.hpp:351
void readEquilInitialCondition_() override
Definition: FlowProblemComp.hpp:467
void serializeOp(Serializer &serializer)
Definition: FlowProblemComp.hpp:455
void updateExplicitQuantities_(int, int, bool) override
Definition: FlowProblemComp.hpp:462
void addToSourceDense(RateVector &, unsigned, unsigned) const override
Definition: FlowProblemComp.hpp:421
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemComp.hpp:441
void initialSolutionApplied() override
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblemComp.hpp:253
IntensiveQuantities::ScalarFluidState boundaryFluidState(unsigned, const int) const
Definition: FlowProblemComp.hpp:338
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemComp.hpp:131
EclWriterType & eclWriter()
Definition: FlowProblemComp.hpp:438
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemComp.hpp:444
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:101
virtual bool episodeWillBeOver() const
Definition: FlowProblem.hpp:2200
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:166
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::RateVector > RateVector
Definition: FlowProblem.hpp:155
FlowThresholdPressure< TypeTag > thresholdPressures_
Definition: FlowProblem.hpp:2133
@ waterPhaseIdx
Definition: FlowProblem.hpp:146
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:115
const EclMaterialLawManager & materialLawManager() const
Returns the ECL material law manager.
Definition: FlowProblem.hpp:916
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:156
@ dimWorld
Definition: FlowProblem.hpp:119
@ gasPhaseIdx
Definition: FlowProblem.hpp:144
@ numPhases
Definition: FlowProblem.hpp:123
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1430
@ dim
Definition: FlowProblem.hpp:118
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: FlowProblem.hpp:167
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:109
bool prepareTransmissibilityOutput_(EclWriterType &eclWriter, const bool enableEclOutput)
Definition: FlowProblem.hpp:1439
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:1894
@ oilPhaseIdx
Definition: FlowProblem.hpp:145
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:154
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:464
virtual void readInitialCondition_()
Definition: FlowProblem.hpp:1802
virtual void initialSolutionApplied()
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblem.hpp:1082
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:111
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:164
void initializeModelProperties_()
Definition: FlowProblem.hpp:1522
Definition: FlowGenericProblem.hpp:52
Definition: SimulatorTimer.hpp:38
std::string formatCompositionVersusDepth(const std::size_t region, const int satTable, const std::vector< CompositionVersusDepthRow< Scalar, NumComponents > > &rows, const std::array< std::string_view, NumComponents > &componentNames, const UnitSystem &units)
Definition: EquilCompReport.hpp:82
void reportTwoPhaseCells(const std::vector< int > &checkRegions, const std::vector< Scalar > &cellCenterDepth, const LiquidFraction &liquidFraction, const std::size_t numRegions, const Parallel::Communication &comm)
Definition: InitStateEquilComp.hpp:1666
@ NONE
Definition: DeferredLogger.hpp:46
Definition: blackoilnewtonmethodparams.hpp:31
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
ExplicitInitialSaturations completeExplicitSaturations(const std::array< std::optional< double >, 3 > &supplied, const std::array< bool, 3 > &active)
Declares the parameters for the compositional multi-phase model based on flash calculations.
Definition: ExplicitInitialSaturations.hpp:29
double normalizationDeviation
Absolute input closure error for a nontrivial normalization.
Definition: ExplicitInitialSaturations.hpp:32
std::array< double, 3 > saturations
Definition: ExplicitInitialSaturations.hpp:30
Definition: FlowProblemComp.hpp:78
static constexpr bool value
Definition: FlowProblemComp.hpp:78
Definition: SimulatorReport.hpp:202
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34