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(
std::to_string(numRocktabTables) +
" OVERBURD tables is expected, but " +
std::to_string(overburdTables.size()) +
" is provided");
202 std::vector<Tabulated1DFunction<Scalar>> overburdenTables(numRocktabTables);
203 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
204 const OverburdTable& overburdTable = overburdTables.template getTable<OverburdTable>(regionIdx);
205 overburdenTables[regionIdx].setXYContainers(overburdTable.getDepthColumn(),overburdTable.getOverburdenPressureColumn());
208 for (std::size_t elemIdx = 0; elemIdx < numElem; ++ elemIdx) {
209 unsigned tableIdx = 0;
210 if (!rockTableIdx_.empty()) {
211 tableIdx = rockTableIdx_[elemIdx];
213 overburdenPressure_[elemIdx] =
214 overburdenTables[tableIdx].eval(cellCenterDepths[elemIdx],
true);
217 else if (!overburdTables.empty() && rock_config.store()) {
218 OpmLog::warning(
"ROCKOPTS item 2 set to STORE, OVERBURD ignored!");
222template<
class Gr
idView,
class Flu
idSystem>
226 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
228 if (!rock_config.active())
231 unsigned numElem = gridView_.size(0);
232 switch (rock_config.hysteresis_mode()) {
233 case RockConfig::Hysteresis::REVERS:
235 case RockConfig::Hysteresis::IRREVERS:
238 minRefPressure_.resize(numElem, 1e99);
241 throw std::runtime_error(
"Not support ROCKOMP hysteresis option ");
244 std::size_t numRocktabTables = rock_config.num_rock_tables();
245 bool waterCompaction = rock_config.water_compaction();
247 if (!waterCompaction) {
248 const auto& rocktabTables = eclState_.getTableManager().getRocktabTables();
249 if (rocktabTables.size() != numRocktabTables)
250 throw std::runtime_error(
"ROCKCOMP is activated." +
std::to_string(numRocktabTables)
251 +
" ROCKTAB tables is expected, but " +
std::to_string(rocktabTables.size()) +
" is provided");
253 rockCompPoroMult_.resize(numRocktabTables);
254 rockCompTransMult_.resize(numRocktabTables);
255 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
256 const auto& rocktabTable = rocktabTables.template getTable<RocktabTable>(regionIdx);
257 const auto& pressureColumn = rocktabTable.getPressureColumn();
258 const auto& poroColumn = rocktabTable.getPoreVolumeMultiplierColumn();
259 const auto& transColumn = rocktabTable.getTransmissibilityMultiplierColumn();
260 rockCompPoroMult_[regionIdx].setXYContainers(pressureColumn, poroColumn);
261 rockCompTransMult_[regionIdx].setXYContainers(pressureColumn, transColumn);
264 const auto& rock2dTables = eclState_.getTableManager().getRock2dTables();
265 const auto& rock2dtrTables = eclState_.getTableManager().getRock2dtrTables();
266 const auto& rockwnodTables = eclState_.getTableManager().getRockwnodTables();
267 maxWaterSaturation_.resize(numElem, 0.0);
269 if (rock2dTables.size() != numRocktabTables)
270 throw std::runtime_error(
"Water compation option is selected in ROCKCOMP." +
std::to_string(numRocktabTables)
271 +
" ROCK2D tables is expected, but " +
std::to_string(rock2dTables.size()) +
" is provided");
273 if (rockwnodTables.size() != numRocktabTables)
274 throw std::runtime_error(
"Water compation option is selected in ROCKCOMP." +
std::to_string(numRocktabTables)
275 +
" ROCKWNOD tables is expected, but " +
std::to_string(rockwnodTables.size()) +
" is provided");
277 rockCompPoroMultWc_.resize(numRocktabTables,
TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
278 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
279 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
280 const auto& rock2dTable = rock2dTables[regionIdx];
282 if (rockwnodTable.getSaturationColumn().size() != rock2dTable.sizeMultValues())
283 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2D needs to match.");
285 for (std::size_t xIdx = 0; xIdx < rock2dTable.size(); ++xIdx) {
286 rockCompPoroMultWc_[regionIdx].appendXPos(rock2dTable.getPressureValue(xIdx));
287 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
288 rockCompPoroMultWc_[regionIdx].appendSamplePoint(xIdx,
289 rockwnodTable.getSaturationColumn()[yIdx],
290 rock2dTable.getPvmultValue(xIdx, yIdx));
294 if (!rock2dtrTables.empty()) {
295 rockCompTransMultWc_.resize(numRocktabTables, TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
296 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
297 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
298 const auto& rock2dtrTable = rock2dtrTables[regionIdx];
300 if (rockwnodTable.getSaturationColumn().size() != rock2dtrTable.sizeMultValues())
301 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2DTR needs to match.");
303 for (std::size_t xIdx = 0; xIdx < rock2dtrTable.size(); ++xIdx) {
304 rockCompTransMultWc_[regionIdx].appendXPos(rock2dtrTable.getPressureValue(xIdx));
305 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
306 rockCompTransMultWc_[regionIdx].appendSamplePoint(xIdx,
307 rockwnodTable.getSaturationColumn()[yIdx],
308 rock2dtrTable.getTransMultValue(xIdx, yIdx));
315template<
class Gr
idView,
class Flu
idSystem>
320 if (this->rockParams_.empty())
323 unsigned tableIdx = 0;
324 if (!this->rockTableIdx_.empty()) {
325 tableIdx = this->rockTableIdx_[globalSpaceIdx];
327 return this->rockParams_[tableIdx].compressibility;
330template<
class Gr
idView,
class Flu
idSystem>
333porosity(
unsigned globalSpaceIdx,
unsigned timeIdx)
const
335 return this->referencePorosity_[timeIdx][globalSpaceIdx];
338template<
class Gr
idView,
class Flu
idSystem>
341rockFraction(
unsigned elementIdx,
unsigned timeIdx)
const
351 const auto ntg = this->lookUpData_.fieldPropDouble(eclState_.fieldProps(),
"NTG", elementIdx);
352 const auto poro_eff = ntg * this->lookUpData_.fieldPropDouble(eclState_.fieldProps(),
"PORO", elementIdx);
353 return (1 - poro_eff) * referencePorosity(elementIdx, timeIdx) / poro_eff;
356template<
class Gr
idView,
class Flu
idSystem>
359updateNum(
const std::string& name, std::vector<T>& numbers, std::size_t num_regions)
361 if (!eclState_.fieldProps().has_int(name))
364 std::function<void(T,
int)> valueCheck = [num_regions,name](T fieldPropValue, [[maybe_unused]]
int fieldPropIdx) {
365 if ( fieldPropValue > (
int)num_regions) {
366 throw std::runtime_error(
"Values larger than maximum number of regions "
369 if ( fieldPropValue <= 0) {
370 throw std::runtime_error(
"zero or negative values provided for region array: " + name);
374 numbers = this->lookUpData_.template assignFieldPropsIntOnLeaf<T>(eclState_.fieldProps(), name,
378template<
class Gr
idView,
class Flu
idSystem>
382 const auto num_regions = eclState_.getTableManager().getTabdims().getNumPVTTables();
383 updateNum(
"PVTNUM", pvtnum_, num_regions);
386template<
class Gr
idView,
class Flu
idSystem>
390 const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
391 updateNum(
"SATNUM", satnum_, num_regions);
394template<
class Gr
idView,
class Flu
idSystem>
398 const auto num_regions = 1;
399 updateNum(
"MISCNUM", miscnum_, num_regions);
402template<
class Gr
idView,
class Flu
idSystem>
406 const auto num_regions = 1;
407 updateNum(
"PLMIXNUM", plmixnum_, num_regions);
410template<
class Gr
idView,
class Flu
idSystem>
414 const auto& oilVaporizationControl = schedule_[episodeIdx].oilvap();
415 return (oilVaporizationControl.getType() == OilVaporizationProperties::OilVaporization::VAPPARS);
418template<
class Gr
idView,
class Flu
idSystem>
423 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
426 std::ostringstream ss;
427 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
428 boost::posix_time::ptime curDateTime =
429 boost::posix_time::from_time_t(schedule_.simTime(episodeIdx));
430 ss.imbue(std::locale(std::locale::classic(), facet));
431 ss <<
"Report step " << episodeIdx + 1
432 <<
"/" << schedule_.size() - 1
433 <<
" at day " << schedule_.seconds(episodeIdx)/(24*3600)
434 <<
"/" << schedule_.seconds(schedule_.size() - 1)/(24*3600)
435 <<
", date = " << curDateTime.date()
437 OpmLog::info(ss.str());
440 const auto& events = schedule_[episodeIdx].events();
443 if (episodeIdx > 0 && enableTuning_ && events.hasEvent(ScheduleEvents::TUNING_CHANGE))
445 const auto& sched_state = schedule_[episodeIdx];
446 const auto& tuning = sched_state.tuning();
447 initialTimeStepSize_ = sched_state.max_next_tstep(enableTuning_);
448 maxTimeStepAfterWellEvent_ = tuning.TMAXWC;
455template<
class Gr
idView,
class Flu
idSystem>
465 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
466 std::ostringstream ss;
467 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
468 boost::posix_time::ptime date = boost::posix_time::from_time_t(startTime) + boost::posix_time::milliseconds(
static_cast<long long>(time / prefix::milli));
469 ss.imbue(std::locale(std::locale::classic(), facet));
470 ss <<
"\nTime step " << timeStepIndex <<
", stepsize "
471 << unit::convert::to(timeStepSize, unit::day) <<
" days,"
472 <<
" at day " << (double)unit::convert::to(time, unit::day)
473 <<
"/" << (double)unit::convert::to(endTime, unit::day)
474 <<
", date = " << date;
475 OpmLog::info(ss.str());
479template<
class Gr
idView,
class Flu
idSystem>
483 FluidSystem::initFromState(eclState_, schedule_);
486template<
class Gr
idView,
class Flu
idSystem>
491 bool enablePolymerMolarWeight,
492 bool enableBioeffects,
495 auto getArray = [](
const std::vector<double>& input)
497 if constexpr (std::is_same_v<Scalar,double>) {
500 return std::vector<Scalar>{input.begin(), input.end()};
505 if (eclState_.fieldProps().has_double(
"SSOL")) {
506 solventSaturation_ = getArray(eclState_.fieldProps().get_double(
"SSOL"));
508 solventSaturation_.resize(numDof, 0.0);
511 solventRsw_.resize(numDof, 0.0);
515 if (eclState_.fieldProps().has_double(
"SPOLY")) {
516 polymer_.concentration = getArray(eclState_.fieldProps().get_double(
"SPOLY"));
518 polymer_.concentration.resize(numDof, 0.0);
522 if (enablePolymerMolarWeight) {
523 if (eclState_.fieldProps().has_double(
"SPOLYMW")) {
524 polymer_.moleWeight = getArray(eclState_.fieldProps().get_double(
"SPOLYMW"));
526 polymer_.moleWeight.resize(numDof, 0.0);
530 if (enableBioeffects) {
531 if (eclState_.fieldProps().has_double(
"SMICR")) {
532 bioeffects_.microbialConcentration = getArray(eclState_.fieldProps().get_double(
"SMICR"));
534 bioeffects_.microbialConcentration.resize(numDof, 0.0);
536 if (eclState_.fieldProps().has_double(
"SBIOF")) {
537 bioeffects_.biofilmVolumeFraction = getArray(eclState_.fieldProps().get_double(
"SBIOF"));
539 bioeffects_.biofilmVolumeFraction.resize(numDof, 0.0);
542 if (eclState_.fieldProps().has_double(
"SOXYG")) {
543 bioeffects_.oxygenConcentration = getArray(eclState_.fieldProps().get_double(
"SOXYG"));
545 bioeffects_.oxygenConcentration.resize(numDof, 0.0);
547 if (eclState_.fieldProps().has_double(
"SUREA")) {
548 bioeffects_.ureaConcentration = getArray(eclState_.fieldProps().get_double(
"SUREA"));
550 bioeffects_.ureaConcentration.resize(numDof, 0.0);
552 if (eclState_.fieldProps().has_double(
"SCALC")) {
553 bioeffects_.calciteVolumeFraction = getArray(eclState_.fieldProps().get_double(
"SCALC"));
555 bioeffects_.calciteVolumeFraction.resize(numDof, 0.0);
561template<
class Gr
idView,
class Flu
idSystem>
566 if (maxWaterSaturation_.empty())
569 return maxWaterSaturation_[globalDofIdx];
572template<
class Gr
idView,
class Flu
idSystem>
577 if (minRefPressure_.empty())
580 return minRefPressure_[globalDofIdx];
583template<
class Gr
idView,
class Flu
idSystem>
588 if (overburdenPressure_.empty())
591 return overburdenPressure_[elementIdx];
594template<
class Gr
idView,
class Flu
idSystem>
599 if (solventSaturation_.empty())
602 return solventSaturation_[elemIdx];
605template<
class Gr
idView,
class Flu
idSystem>
610 if (solventRsw_.empty())
613 return solventRsw_[elemIdx];
618template<
class Gr
idView,
class Flu
idSystem>
623 if (polymer_.concentration.empty()) {
627 return polymer_.concentration[elemIdx];
630template<
class Gr
idView,
class Flu
idSystem>
635 if (polymer_.moleWeight.empty()) {
639 return polymer_.moleWeight[elemIdx];
642template<
class Gr
idView,
class Flu
idSystem>
647 if (bioeffects_.microbialConcentration.empty()) {
654template<
class Gr
idView,
class Flu
idSystem>
659 if (bioeffects_.oxygenConcentration.empty()) {
666template<
class Gr
idView,
class Flu
idSystem>
671 if (bioeffects_.ureaConcentration.empty()) {
678template<
class Gr
idView,
class Flu
idSystem>
683 if (bioeffects_.biofilmVolumeFraction.empty()) {
690template<
class Gr
idView,
class Flu
idSystem>
695 if (bioeffects_.calciteVolumeFraction.empty()) {
702template<
class Gr
idView,
class Flu
idSystem>
709 return pvtnum_[elemIdx];
712template<
class Gr
idView,
class Flu
idSystem>
719 return satnum_[elemIdx];
722template<
class Gr
idView,
class Flu
idSystem>
726 if (miscnum_.empty())
729 return miscnum_[elemIdx];
732template<
class Gr
idView,
class Flu
idSystem>
736 if (plmixnum_.empty())
739 return plmixnum_[elemIdx];
742template<
class Gr
idView,
class Flu
idSystem>
747 if (polymer_.maxAdsorption.empty()) {
751 return polymer_.maxAdsorption[elemIdx];
754template<
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:657
Scalar microbialConcentration(unsigned elemIdx) const
Returns the initial microbial concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:645
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:693
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:481
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:669
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:681
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:354
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()