23#ifndef OPM_FLOW_GENERIC_PROBLEM_IMPL_HPP
24#define OPM_FLOW_GENERIC_PROBLEM_IMPL_HPP
26#ifndef OPM_FLOW_GENERIC_PROBLEM_HPP
31#include <dune/common/parametertree.hh>
33#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
34#include <opm/input/eclipse/EclipseState/Tables/OverburdTable.hpp>
35#include <opm/input/eclipse/EclipseState/Tables/RockwnodTable.hpp>
36#include <opm/input/eclipse/Schedule/Schedule.hpp>
37#include <opm/input/eclipse/Units/Units.hpp>
48#include <boost/date_time.hpp>
50#include <fmt/format.h>
51#include <fmt/ranges.h>
58template<
class Gr
idView,
class Flu
idSystem>
61 const Schedule& schedule,
62 const GridView& gridView)
66 , lookUpData_(gridView)
85 ? Parameters::Get<Parameters::NumPressurePointsEquil>()
86 : eclState.getTableManager().getEqldims().getNumDepthNodesP();
91template<
class Gr
idView,
class Flu
idSystem>
95 const Schedule& schedule,
96 const GridView& gridView)
112template<
class Gr
idView,
class Flu
idSystem>
123 "Usage: "+std::string(argv[0]) +
" [OPTIONS] [ECL_DECK_FILENAME]\n"
127template<
class Gr
idView,
class Flu
idSystem>
132 return briefDescription_;
135template<
class Gr
idView,
class Flu
idSystem>
138 std::function<std::array<int,3>(
const unsigned)> ijkIndex)
140 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
144 const auto& comp = rock_config.comp();
146 std::transform(comp.begin(), comp.end(), std::back_inserter(rockParams_),
149 return RockParams{static_cast<Scalar>(c.pref),
150 static_cast<Scalar>(c.compressibility)};
155 if (rock_config.store()) {
156 OpmLog::warning(
"ROCKOPTS item 2 set to STORE, ROCK item 1 replaced with initial (equilibrated) pressures");
160 readRockCompactionParameters_();
162 unsigned numElem = gridView_.size(0);
163 if (eclState_.fieldProps().has_int(rock_config.rocknum_property())) {
165 std::function<void(
int,
int)> valueCheck = [&ijkIndex,&rock_config,
this](
int fieldPropValue,
int coarseElemIdx)
167 auto fmtError = [fieldPropValue, coarseElemIdx,&ijkIndex,&rock_config](
const char* type, std::size_t size)
169 return fmt::format(
"{} table index {} for elem {} read from {}"
170 " is out of bounds for number of tables {}",
171 type, fieldPropValue,
172 ijkIndex(coarseElemIdx),
173 rock_config.rocknum_property(), size);
175 if (!rockCompPoroMult_.empty() &&
176 fieldPropValue >
static_cast<int>(rockCompPoroMult_.size())) {
177 throw std::runtime_error(fmtError(
"Rock compaction",
178 rockCompPoroMult_.size()));
180 if (!rockCompPoroMultWc_.empty() &&
181 fieldPropValue >
static_cast<int>(rockCompPoroMultWc_.size())) {
182 throw std::runtime_error(fmtError(
"Rock water compaction",
183 rockCompPoroMultWc_.size()));
187 rockTableIdx_ = this->lookUpData_.template assignFieldPropsIntOnLeaf<short unsigned int>(eclState_.fieldProps(),
188 rock_config.rocknum_property(),
194 const auto& overburdTables = eclState_.getTableManager().getOverburdTables();
195 if (!overburdTables.empty() && !rock_config.store()) {
196 overburdenPressure_.resize(numElem,0.0);
197 std::size_t numRocktabTables = rock_config.num_rock_tables();
199 if (overburdTables.size() != numRocktabTables)
200 throw std::runtime_error(fmt::format(
"{} OVERBURD tables is expected, but {} is provided",
201 numRocktabTables, overburdTables.size()));
203 std::vector<Tabulated1DFunction<Scalar>> overburdenTables(numRocktabTables);
204 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
205 const OverburdTable& overburdTable = overburdTables.template getTable<OverburdTable>(regionIdx);
206 overburdenTables[regionIdx].setXYContainers(overburdTable.getDepthColumn(),overburdTable.getOverburdenPressureColumn());
209 for (std::size_t elemIdx = 0; elemIdx < numElem; ++ elemIdx) {
210 unsigned tableIdx = 0;
211 if (!rockTableIdx_.empty()) {
212 tableIdx = rockTableIdx_[elemIdx];
214 overburdenPressure_[elemIdx] =
215 overburdenTables[tableIdx].eval(cellCenterDepths[elemIdx],
true);
218 else if (!overburdTables.empty() && rock_config.store()) {
219 OpmLog::warning(
"ROCKOPTS item 2 set to STORE, OVERBURD ignored!");
223template<
class Gr
idView,
class Flu
idSystem>
227 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
229 if (!rock_config.active())
232 unsigned numElem = gridView_.size(0);
233 switch (rock_config.hysteresis_mode()) {
234 case RockConfig::Hysteresis::REVERS:
236 case RockConfig::Hysteresis::IRREVERS:
239 minRefPressure_.resize(numElem, 1e99);
242 throw std::runtime_error(
"Not support ROCKOMP hysteresis option ");
245 std::size_t numRocktabTables = rock_config.num_rock_tables();
246 bool waterCompaction = rock_config.water_compaction();
248 if (!waterCompaction) {
249 const auto& rocktabTables = eclState_.getTableManager().getRocktabTables();
250 if (rocktabTables.size() != numRocktabTables)
251 throw std::runtime_error(
"ROCKCOMP is activated." +
std::to_string(numRocktabTables)
252 +
" ROCKTAB tables is expected, but " +
std::to_string(rocktabTables.size()) +
" is provided");
254 rockCompPoroMult_.resize(numRocktabTables);
255 rockCompTransMult_.resize(numRocktabTables);
256 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
257 const auto& rocktabTable = rocktabTables.template getTable<RocktabTable>(regionIdx);
258 const auto& pressureColumn = rocktabTable.getPressureColumn();
259 const auto& poroColumn = rocktabTable.getPoreVolumeMultiplierColumn();
260 const auto& transColumn = rocktabTable.getTransmissibilityMultiplierColumn();
261 rockCompPoroMult_[regionIdx].setXYContainers(pressureColumn, poroColumn);
262 rockCompTransMult_[regionIdx].setXYContainers(pressureColumn, transColumn);
265 const auto& rock2dTables = eclState_.getTableManager().getRock2dTables();
266 const auto& rock2dtrTables = eclState_.getTableManager().getRock2dtrTables();
267 const auto& rockwnodTables = eclState_.getTableManager().getRockwnodTables();
268 maxWaterSaturation_.resize(numElem, 0.0);
270 if (rock2dTables.size() != numRocktabTables)
271 throw std::runtime_error(fmt::format(
"Water compation option is selected in ROCKCOMP."
272 " {} ROCK2D tables is expected, but {} is provided",
273 numRocktabTables, rock2dTables.size()));
275 if (rockwnodTables.size() != numRocktabTables)
276 throw std::runtime_error(fmt::format(
"Water compation option is selected in ROCKCOMP."
277 " {} ROCKWNOD tables is expected, but {} is provided",
278 numRocktabTables, rockwnodTables.size()));
280 rockCompPoroMultWc_.resize(numRocktabTables,
TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
281 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
282 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
283 const auto& rock2dTable = rock2dTables[regionIdx];
285 if (rockwnodTable.getSaturationColumn().size() != rock2dTable.sizeMultValues())
286 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2D needs to match.");
288 for (std::size_t xIdx = 0; xIdx < rock2dTable.size(); ++xIdx) {
289 rockCompPoroMultWc_[regionIdx].appendXPos(rock2dTable.getPressureValue(xIdx));
290 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
291 rockCompPoroMultWc_[regionIdx].appendSamplePoint(xIdx,
292 rockwnodTable.getSaturationColumn()[yIdx],
293 rock2dTable.getPvmultValue(xIdx, yIdx));
297 if (!rock2dtrTables.empty()) {
298 rockCompTransMultWc_.resize(numRocktabTables, TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
299 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
300 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
301 const auto& rock2dtrTable = rock2dtrTables[regionIdx];
303 if (rockwnodTable.getSaturationColumn().size() != rock2dtrTable.sizeMultValues())
304 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2DTR needs to match.");
306 for (std::size_t xIdx = 0; xIdx < rock2dtrTable.size(); ++xIdx) {
307 rockCompTransMultWc_[regionIdx].appendXPos(rock2dtrTable.getPressureValue(xIdx));
308 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
309 rockCompTransMultWc_[regionIdx].appendSamplePoint(xIdx,
310 rockwnodTable.getSaturationColumn()[yIdx],
311 rock2dtrTable.getTransMultValue(xIdx, yIdx));
318template<
class Gr
idView,
class Flu
idSystem>
319typename FlowGenericProblem<GridView,FluidSystem>::Scalar
323 if (this->rockParams_.empty())
326 unsigned tableIdx = 0;
327 if (!this->rockTableIdx_.empty()) {
328 tableIdx = this->rockTableIdx_[globalSpaceIdx];
330 return this->rockParams_[tableIdx].compressibility;
333template<
class Gr
idView,
class Flu
idSystem>
336porosity(
unsigned globalSpaceIdx,
unsigned timeIdx)
const
338 return this->referencePorosity_[timeIdx][globalSpaceIdx];
341template<
class Gr
idView,
class Flu
idSystem>
344rockFraction(
unsigned elementIdx,
unsigned timeIdx)
const
354 const auto ntg = this->lookUpData_.fieldPropDouble(eclState_.fieldProps(),
"NTG", elementIdx);
355 const auto poro_eff = ntg * this->lookUpData_.fieldPropDouble(eclState_.fieldProps(),
"PORO", elementIdx);
356 return (1 - poro_eff) * referencePorosity(elementIdx, timeIdx) / poro_eff;
359template<
class Gr
idView,
class Flu
idSystem>
362updateNum(
const std::string& name, std::vector<T>& numbers, std::size_t num_regions)
364 if (!eclState_.fieldProps().has_int(name))
367 std::function<void(T,
int)> valueCheck = [num_regions,name](T fieldPropValue, [[maybe_unused]]
int fieldPropIdx) {
368 if (fieldPropValue >
static_cast<int>(num_regions)) {
369 throw std::runtime_error(fmt::format(
"Values larger than maximum number of regions {} provided in {}",
372 if (fieldPropValue <= 0) {
373 throw std::runtime_error(
"zero or negative values provided for region array: " + name);
377 numbers = this->lookUpData_.template assignFieldPropsIntOnLeaf<T>(eclState_.fieldProps(), name,
381template<
class Gr
idView,
class Flu
idSystem>
385 const auto num_regions = eclState_.getTableManager().getTabdims().getNumPVTTables();
386 updateNum(
"PVTNUM", pvtnum_, num_regions);
389template<
class Gr
idView,
class Flu
idSystem>
393 const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
394 updateNum(
"SATNUM", satnum_, num_regions);
397template<
class Gr
idView,
class Flu
idSystem>
401 const auto num_regions = 1;
402 updateNum(
"MISCNUM", miscnum_, num_regions);
405template<
class Gr
idView,
class Flu
idSystem>
409 const auto num_regions = 1;
410 updateNum(
"PLMIXNUM", plmixnum_, num_regions);
413template<
class Gr
idView,
class Flu
idSystem>
417 const auto& oilVaporizationControl = schedule_[episodeIdx].oilvap();
418 return (oilVaporizationControl.getType() == OilVaporizationProperties::OilVaporization::VAPPARS);
421template<
class Gr
idView,
class Flu
idSystem>
426 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
429 std::ostringstream ss;
430 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
431 boost::posix_time::ptime curDateTime =
432 boost::posix_time::from_time_t(schedule_.simTime(episodeIdx));
433 ss.imbue(std::locale(std::locale::classic(), facet));
434 ss <<
"Report step " << episodeIdx + 1
435 <<
"/" << schedule_.size() - 1
436 <<
" at day " << schedule_.seconds(episodeIdx)/(24*3600)
437 <<
"/" << schedule_.seconds(schedule_.size() - 1)/(24*3600)
438 <<
", date = " << curDateTime.date()
440 OpmLog::info(ss.str());
443 const auto& events = schedule_[episodeIdx].events();
446 if (episodeIdx > 0 && enableTuning_ && events.hasEvent(ScheduleEvents::TUNING_CHANGE))
448 const auto& sched_state = schedule_[episodeIdx];
449 const auto& tuning = sched_state.tuning();
450 initialTimeStepSize_ = sched_state.max_next_tstep(enableTuning_);
451 maxTimeStepAfterWellEvent_ = tuning.TMAXWC;
458template<
class Gr
idView,
class Flu
idSystem>
468 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
469 std::ostringstream ss;
470 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
471 boost::posix_time::ptime date = boost::posix_time::from_time_t(startTime) +
472 boost::posix_time::milliseconds(
static_cast<long long>(time / prefix::milli));
473 ss.imbue(std::locale(std::locale::classic(), facet));
474 ss <<
"\nTime step " << timeStepIndex <<
", stepsize "
475 << unit::convert::to(timeStepSize, unit::day) <<
" days,"
476 <<
" at day " << (double)unit::convert::to(time, unit::day)
477 <<
"/" << (double)unit::convert::to(endTime, unit::day)
478 <<
", date = " << date;
479 OpmLog::info(ss.str());
483template<
class Gr
idView,
class Flu
idSystem>
487 FluidSystem::initFromState(eclState_, schedule_);
490template<
class Gr
idView,
class Flu
idSystem>
495 bool enablePolymerMolarWeight,
496 bool enableBioeffects,
499 auto getArray = [](
const std::vector<double>& input)
501 if constexpr (std::is_same_v<Scalar,double>) {
504 return std::vector<Scalar>{input.begin(), input.end()};
509 if (eclState_.fieldProps().has_double(
"SSOL")) {
510 solventSaturation_ = getArray(eclState_.fieldProps().get_double(
"SSOL"));
512 solventSaturation_.resize(numDof, 0.0);
515 solventRsw_.resize(numDof, 0.0);
519 if (eclState_.fieldProps().has_double(
"SPOLY")) {
520 polymer_.concentration = getArray(eclState_.fieldProps().get_double(
"SPOLY"));
522 polymer_.concentration.resize(numDof, 0.0);
526 if (enablePolymerMolarWeight) {
527 if (eclState_.fieldProps().has_double(
"SPOLYMW")) {
528 polymer_.moleWeight = getArray(eclState_.fieldProps().get_double(
"SPOLYMW"));
530 polymer_.moleWeight.resize(numDof, 0.0);
534 if (enableBioeffects) {
535 if (eclState_.fieldProps().has_double(
"SMICR")) {
536 bioeffects_.microbialConcentration = getArray(eclState_.fieldProps().get_double(
"SMICR"));
538 bioeffects_.microbialConcentration.resize(numDof, 0.0);
540 if (eclState_.fieldProps().has_double(
"SBIOF")) {
541 bioeffects_.biofilmVolumeFraction = getArray(eclState_.fieldProps().get_double(
"SBIOF"));
543 bioeffects_.biofilmVolumeFraction.resize(numDof, 0.0);
546 if (eclState_.fieldProps().has_double(
"SOXYG")) {
547 bioeffects_.oxygenConcentration = getArray(eclState_.fieldProps().get_double(
"SOXYG"));
549 bioeffects_.oxygenConcentration.resize(numDof, 0.0);
551 if (eclState_.fieldProps().has_double(
"SUREA")) {
552 bioeffects_.ureaConcentration = getArray(eclState_.fieldProps().get_double(
"SUREA"));
554 bioeffects_.ureaConcentration.resize(numDof, 0.0);
556 if (eclState_.fieldProps().has_double(
"SCALC")) {
557 bioeffects_.calciteVolumeFraction = getArray(eclState_.fieldProps().get_double(
"SCALC"));
559 bioeffects_.calciteVolumeFraction.resize(numDof, 0.0);
565template<
class Gr
idView,
class Flu
idSystem>
570 if (maxWaterSaturation_.empty())
573 return maxWaterSaturation_[globalDofIdx];
576template<
class Gr
idView,
class Flu
idSystem>
581 if (minRefPressure_.empty())
584 return minRefPressure_[globalDofIdx];
587template<
class Gr
idView,
class Flu
idSystem>
592 if (overburdenPressure_.empty())
595 return overburdenPressure_[elementIdx];
598template<
class Gr
idView,
class Flu
idSystem>
603 if (solventSaturation_.empty())
606 return solventSaturation_[elemIdx];
609template<
class Gr
idView,
class Flu
idSystem>
614 if (solventRsw_.empty())
617 return solventRsw_[elemIdx];
622template<
class Gr
idView,
class Flu
idSystem>
627 if (polymer_.concentration.empty()) {
631 return polymer_.concentration[elemIdx];
634template<
class Gr
idView,
class Flu
idSystem>
639 if (polymer_.moleWeight.empty()) {
643 return polymer_.moleWeight[elemIdx];
646template<
class Gr
idView,
class Flu
idSystem>
651 if (bioeffects_.microbialConcentration.empty()) {
658template<
class Gr
idView,
class Flu
idSystem>
663 if (bioeffects_.oxygenConcentration.empty()) {
670template<
class Gr
idView,
class Flu
idSystem>
675 if (bioeffects_.ureaConcentration.empty()) {
682template<
class Gr
idView,
class Flu
idSystem>
687 if (bioeffects_.biofilmVolumeFraction.empty()) {
694template<
class Gr
idView,
class Flu
idSystem>
699 if (bioeffects_.calciteVolumeFraction.empty()) {
706template<
class Gr
idView,
class Flu
idSystem>
713 return pvtnum_[elemIdx];
716template<
class Gr
idView,
class Flu
idSystem>
723 return satnum_[elemIdx];
726template<
class Gr
idView,
class Flu
idSystem>
730 if (miscnum_.empty())
733 return miscnum_[elemIdx];
736template<
class Gr
idView,
class Flu
idSystem>
740 if (plmixnum_.empty())
743 return plmixnum_[elemIdx];
746template<
class Gr
idView,
class Flu
idSystem>
751 if (polymer_.maxAdsorption.empty()) {
755 return polymer_.maxAdsorption[elemIdx];
758template<
class Gr
idView,
class Flu
idSystem>
Defines some fundamental parameters for all models.
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowGenericProblem.hpp:61
UniformXTabulated2DFunction< Scalar > TabulatedTwoDFunction
Definition: FlowGenericProblem.hpp:64
Scalar oxygenConcentration(unsigned elemIdx) const
Returns the initial oxygen concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:661
Scalar microbialConcentration(unsigned elemIdx) const
Returns the initial microbial concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:649
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:335
static std::string briefDescription()
Returns a human readable description of the problem for the help message.
Definition: FlowGenericProblem_impl.hpp:130
Scalar initialTimeStepSize_
Definition: FlowGenericProblem.hpp:347
std::vector< Scalar > solventSaturation_
Definition: FlowGenericProblem.hpp:340
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:353
static FlowGenericProblem serializationTestObject(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:94
Scalar calciteVolumeFraction(unsigned elemIdx) const
Returns the initial calcite volume fraction for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:697
CO2H2SolutionContainer< Scalar > CO2H2_
Definition: FlowGenericProblem.hpp:343
FlowGenericProblem(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:60
BioeffectsSolutionContainer< Scalar > bioeffects_
Definition: FlowGenericProblem.hpp:342
bool enableTuning_
Definition: FlowGenericProblem.hpp:346
void readRockParameters_(const std::vector< Scalar > &cellCenterDepths, std::function< std::array< int, 3 >(const unsigned)> ijkIndex)
Definition: FlowGenericProblem_impl.hpp:137
std::vector< Scalar > maxOilSaturation_
Definition: FlowGenericProblem.hpp:336
int numPressurePointsEquil_
Definition: FlowGenericProblem.hpp:351
std::vector< Scalar > maxWaterSaturation_
Definition: FlowGenericProblem.hpp:337
void initFluidSystem_()
Definition: FlowGenericProblem_impl.hpp:485
Scalar maxTimeStepAfterWellEvent_
Definition: FlowGenericProblem.hpp:348
Scalar ureaConcentration(unsigned elemIdx) const
Returns the initial urea concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:673
std::vector< Scalar > minRefPressure_
Definition: FlowGenericProblem.hpp:338
Scalar biofilmVolumeFraction(unsigned elemIdx) const
Returns the initial biofilm volume fraction for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:685
std::vector< Scalar > solventRsw_
Definition: FlowGenericProblem.hpp:341
static std::string helpPreamble(int, const char **argv)
Returns the string that is printed before the list of command line parameters in the help message.
Definition: FlowGenericProblem_impl.hpp:115
std::vector< Scalar > overburdenPressure_
Definition: FlowGenericProblem.hpp:339
bool explicitRockCompaction_
Definition: FlowGenericProblem.hpp:355
typename FluidSystem::Scalar Scalar
Definition: FlowGenericProblem.hpp:63
Declare the properties used by the infrastructure code of the finite volume discretizations.
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition: parametersystem.hpp:187
Definition: blackoilbioeffectsmodules.hh:43
bool operator==(const aligned_allocator< T1, Alignment > &, const aligned_allocator< T2, Alignment > &) noexcept
Definition: alignedallocator.hh:200
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
This file provides the infrastructure to retrieve run-time parameters.
static BioeffectsSolutionContainer serializationTestObject()
static CO2H2SolutionContainer serializationTestObject()
Definition: EclTimeSteppingParams.hpp:45
static PolymerSolutionContainer serializationTestObject()