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)
82 ? Parameters::Get<Parameters::NumPressurePointsEquil>()
83 : eclState.getTableManager().getEqldims().getNumDepthNodesP();
88template<
class Gr
idView,
class Flu
idSystem>
92 const Schedule& schedule,
93 const GridView& gridView)
108template<
class Gr
idView,
class Flu
idSystem>
119 "Usage: "+std::string(argv[0]) +
" [OPTIONS] [ECL_DECK_FILENAME]\n"
123template<
class Gr
idView,
class Flu
idSystem>
128 return briefDescription_;
131template<
class Gr
idView,
class Flu
idSystem>
134 std::function<std::array<int,3>(
const unsigned)> ijkIndex)
136 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
140 const auto& comp = rock_config.comp();
142 std::transform(comp.begin(), comp.end(), std::back_inserter(rockParams_),
145 return RockParams{static_cast<Scalar>(c.pref),
146 static_cast<Scalar>(c.compressibility)};
151 if (rock_config.store()) {
152 OpmLog::warning(
"ROCKOPTS item 2 set to STORE, ROCK item 1 replaced with initial (equilibrated) pressures");
156 readRockCompactionParameters_();
158 unsigned numElem = gridView_.size(0);
159 if (eclState_.fieldProps().has_int(rock_config.rocknum_property())) {
161 std::function<void(
int,
int)> valueCheck = [&ijkIndex,&rock_config,
this](
int fieldPropValue,
int coarseElemIdx)
163 auto fmtError = [fieldPropValue, coarseElemIdx,&ijkIndex,&rock_config](
const char* type, std::size_t size)
165 return fmt::format(
"{} table index {} for elem {} read from {}"
166 " is out of bounds for number of tables {}",
167 type, fieldPropValue,
168 ijkIndex(coarseElemIdx),
169 rock_config.rocknum_property(), size);
171 if (!rockCompPoroMult_.empty() &&
172 fieldPropValue >
static_cast<int>(rockCompPoroMult_.size())) {
173 throw std::runtime_error(fmtError(
"Rock compaction",
174 rockCompPoroMult_.size()));
176 if (!rockCompPoroMultWc_.empty() &&
177 fieldPropValue >
static_cast<int>(rockCompPoroMultWc_.size())) {
178 throw std::runtime_error(fmtError(
"Rock water compaction",
179 rockCompPoroMultWc_.size()));
183 rockTableIdx_ = this->lookUpData_.template assignFieldPropsIntOnLeaf<short unsigned int>(eclState_.fieldProps(),
184 rock_config.rocknum_property(),
190 const auto& overburdTables = eclState_.getTableManager().getOverburdTables();
191 if (!overburdTables.empty() && !rock_config.store()) {
192 overburdenPressure_.resize(numElem,0.0);
193 std::size_t numRocktabTables = rock_config.num_rock_tables();
195 if (overburdTables.size() != numRocktabTables)
196 throw std::runtime_error(
std::to_string(numRocktabTables) +
" OVERBURD tables is expected, but " +
std::to_string(overburdTables.size()) +
" is provided");
198 std::vector<Tabulated1DFunction<Scalar>> overburdenTables(numRocktabTables);
199 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
200 const OverburdTable& overburdTable = overburdTables.template getTable<OverburdTable>(regionIdx);
201 overburdenTables[regionIdx].setXYContainers(overburdTable.getDepthColumn(),overburdTable.getOverburdenPressureColumn());
204 for (std::size_t elemIdx = 0; elemIdx < numElem; ++ elemIdx) {
205 unsigned tableIdx = 0;
206 if (!rockTableIdx_.empty()) {
207 tableIdx = rockTableIdx_[elemIdx];
209 overburdenPressure_[elemIdx] =
210 overburdenTables[tableIdx].eval(cellCenterDepths[elemIdx],
true);
213 else if (!overburdTables.empty() && rock_config.store()) {
214 OpmLog::warning(
"ROCKOPTS item 2 set to STORE, OVERBURD ignored!");
218template<
class Gr
idView,
class Flu
idSystem>
222 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
224 if (!rock_config.active())
227 unsigned numElem = gridView_.size(0);
228 switch (rock_config.hysteresis_mode()) {
229 case RockConfig::Hysteresis::REVERS:
231 case RockConfig::Hysteresis::IRREVERS:
234 minRefPressure_.resize(numElem, 1e99);
237 throw std::runtime_error(
"Not support ROCKOMP hysteresis option ");
240 std::size_t numRocktabTables = rock_config.num_rock_tables();
241 bool waterCompaction = rock_config.water_compaction();
243 if (!waterCompaction) {
244 const auto& rocktabTables = eclState_.getTableManager().getRocktabTables();
245 if (rocktabTables.size() != numRocktabTables)
246 throw std::runtime_error(
"ROCKCOMP is activated." +
std::to_string(numRocktabTables)
247 +
" ROCKTAB tables is expected, but " +
std::to_string(rocktabTables.size()) +
" is provided");
249 rockCompPoroMult_.resize(numRocktabTables);
250 rockCompTransMult_.resize(numRocktabTables);
251 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
252 const auto& rocktabTable = rocktabTables.template getTable<RocktabTable>(regionIdx);
253 const auto& pressureColumn = rocktabTable.getPressureColumn();
254 const auto& poroColumn = rocktabTable.getPoreVolumeMultiplierColumn();
255 const auto& transColumn = rocktabTable.getTransmissibilityMultiplierColumn();
256 rockCompPoroMult_[regionIdx].setXYContainers(pressureColumn, poroColumn);
257 rockCompTransMult_[regionIdx].setXYContainers(pressureColumn, transColumn);
260 const auto& rock2dTables = eclState_.getTableManager().getRock2dTables();
261 const auto& rock2dtrTables = eclState_.getTableManager().getRock2dtrTables();
262 const auto& rockwnodTables = eclState_.getTableManager().getRockwnodTables();
263 maxWaterSaturation_.resize(numElem, 0.0);
265 if (rock2dTables.size() != numRocktabTables)
266 throw std::runtime_error(
"Water compation option is selected in ROCKCOMP." +
std::to_string(numRocktabTables)
267 +
" ROCK2D tables is expected, but " +
std::to_string(rock2dTables.size()) +
" is provided");
269 if (rockwnodTables.size() != numRocktabTables)
270 throw std::runtime_error(
"Water compation option is selected in ROCKCOMP." +
std::to_string(numRocktabTables)
271 +
" ROCKWNOD tables is expected, but " +
std::to_string(rockwnodTables.size()) +
" is provided");
273 rockCompPoroMultWc_.resize(numRocktabTables,
TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
274 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
275 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
276 const auto& rock2dTable = rock2dTables[regionIdx];
278 if (rockwnodTable.getSaturationColumn().size() != rock2dTable.sizeMultValues())
279 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2D needs to match.");
281 for (std::size_t xIdx = 0; xIdx < rock2dTable.size(); ++xIdx) {
282 rockCompPoroMultWc_[regionIdx].appendXPos(rock2dTable.getPressureValue(xIdx));
283 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
284 rockCompPoroMultWc_[regionIdx].appendSamplePoint(xIdx,
285 rockwnodTable.getSaturationColumn()[yIdx],
286 rock2dTable.getPvmultValue(xIdx, yIdx));
290 if (!rock2dtrTables.empty()) {
291 rockCompTransMultWc_.resize(numRocktabTables,
TabulatedTwoDFunction(TabulatedTwoDFunction::InterpolationPolicy::Vertical));
292 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
293 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
294 const auto& rock2dtrTable = rock2dtrTables[regionIdx];
296 if (rockwnodTable.getSaturationColumn().size() != rock2dtrTable.sizeMultValues())
297 throw std::runtime_error(
"Number of entries in ROCKWNOD and ROCK2DTR needs to match.");
299 for (std::size_t xIdx = 0; xIdx < rock2dtrTable.size(); ++xIdx) {
300 rockCompTransMultWc_[regionIdx].appendXPos(rock2dtrTable.getPressureValue(xIdx));
301 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
302 rockCompTransMultWc_[regionIdx].appendSamplePoint(xIdx,
303 rockwnodTable.getSaturationColumn()[yIdx],
304 rock2dtrTable.getTransMultValue(xIdx, yIdx));
311template<
class Gr
idView,
class Flu
idSystem>
316 if (this->rockParams_.empty())
319 unsigned tableIdx = 0;
320 if (!this->rockTableIdx_.empty()) {
321 tableIdx = this->rockTableIdx_[globalSpaceIdx];
323 return this->rockParams_[tableIdx].compressibility;
326template<
class Gr
idView,
class Flu
idSystem>
329porosity(
unsigned globalSpaceIdx,
unsigned timeIdx)
const
331 return this->referencePorosity_[timeIdx][globalSpaceIdx];
334template<
class Gr
idView,
class Flu
idSystem>
337rockFraction(
unsigned elementIdx,
unsigned timeIdx)
const
343 auto porosity = this->lookUpData_.fieldPropDouble(eclState_.fieldProps(),
"PORO", elementIdx);
344 return referencePorosity(elementIdx, timeIdx) / porosity * (1 - porosity);
347template<
class Gr
idView,
class Flu
idSystem>
350updateNum(
const std::string& name, std::vector<T>& numbers, std::size_t num_regions)
352 if (!eclState_.fieldProps().has_int(name))
355 std::function<void(T,
int)> valueCheck = [num_regions,name](T fieldPropValue, [[maybe_unused]]
int fieldPropIdx) {
356 if ( fieldPropValue > (
int)num_regions) {
357 throw std::runtime_error(
"Values larger than maximum number of regions "
360 if ( fieldPropValue <= 0) {
361 throw std::runtime_error(
"zero or negative values provided for region array: " + name);
365 numbers = this->lookUpData_.template assignFieldPropsIntOnLeaf<T>(eclState_.fieldProps(), name,
369template<
class Gr
idView,
class Flu
idSystem>
373 const auto num_regions = eclState_.getTableManager().getTabdims().getNumPVTTables();
374 updateNum(
"PVTNUM", pvtnum_, num_regions);
377template<
class Gr
idView,
class Flu
idSystem>
381 const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
382 updateNum(
"SATNUM", satnum_, num_regions);
385template<
class Gr
idView,
class Flu
idSystem>
389 const auto num_regions = 1;
390 updateNum(
"MISCNUM", miscnum_, num_regions);
393template<
class Gr
idView,
class Flu
idSystem>
397 const auto num_regions = 1;
398 updateNum(
"PLMIXNUM", plmixnum_, num_regions);
401template<
class Gr
idView,
class Flu
idSystem>
405 const auto& oilVaporizationControl = schedule_[episodeIdx].oilvap();
406 return (oilVaporizationControl.getType() == OilVaporizationProperties::OilVaporization::VAPPARS);
409template<
class Gr
idView,
class Flu
idSystem>
414 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
417 std::ostringstream ss;
418 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
419 boost::posix_time::ptime curDateTime =
420 boost::posix_time::from_time_t(schedule_.simTime(episodeIdx));
421 ss.imbue(std::locale(std::locale::classic(), facet));
422 ss <<
"Report step " << episodeIdx + 1
423 <<
"/" << schedule_.size() - 1
424 <<
" at day " << schedule_.seconds(episodeIdx)/(24*3600)
425 <<
"/" << schedule_.seconds(schedule_.size() - 1)/(24*3600)
426 <<
", date = " << curDateTime.date()
428 OpmLog::info(ss.str());
431 const auto& events = schedule_[episodeIdx].events();
434 if (episodeIdx > 0 && enableTuning_ && events.hasEvent(ScheduleEvents::TUNING_CHANGE))
436 const auto& sched_state = schedule_[episodeIdx];
437 const auto& tuning = sched_state.tuning();
438 initialTimeStepSize_ = sched_state.max_next_tstep(enableTuning_);
439 maxTimeStepAfterWellEvent_ = tuning.TMAXWC;
446template<
class Gr
idView,
class Flu
idSystem>
456 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
457 std::ostringstream ss;
458 boost::posix_time::time_facet* facet =
new boost::posix_time::time_facet(
"%d-%b-%Y");
459 boost::posix_time::ptime date = boost::posix_time::from_time_t(startTime) + boost::posix_time::milliseconds(
static_cast<long long>(time / prefix::milli));
460 ss.imbue(std::locale(std::locale::classic(), facet));
461 ss <<
"\nTime step " << timeStepIndex <<
", stepsize "
462 << unit::convert::to(timeStepSize, unit::day) <<
" days,"
463 <<
" at day " << (double)unit::convert::to(time, unit::day)
464 <<
"/" << (double)unit::convert::to(endTime, unit::day)
465 <<
", date = " << date;
466 OpmLog::info(ss.str());
470template<
class Gr
idView,
class Flu
idSystem>
474 FluidSystem::initFromState(eclState_, schedule_);
477template<
class Gr
idView,
class Flu
idSystem>
482 bool enablePolymerMolarWeight,
485 auto getArray = [](
const std::vector<double>& input)
487 if constexpr (std::is_same_v<Scalar,double>) {
490 return std::vector<Scalar>{input.begin(), input.end()};
495 if (eclState_.fieldProps().has_double(
"SSOL")) {
496 solventSaturation_ = getArray(eclState_.fieldProps().get_double(
"SSOL"));
498 solventSaturation_.resize(numDof, 0.0);
501 solventRsw_.resize(numDof, 0.0);
505 if (eclState_.fieldProps().has_double(
"SPOLY")) {
506 polymer_.concentration = getArray(eclState_.fieldProps().get_double(
"SPOLY"));
508 polymer_.concentration.resize(numDof, 0.0);
512 if (enablePolymerMolarWeight) {
513 if (eclState_.fieldProps().has_double(
"SPOLYMW")) {
514 polymer_.moleWeight = getArray(eclState_.fieldProps().get_double(
"SPOLYMW"));
516 polymer_.moleWeight.resize(numDof, 0.0);
521 if (eclState_.fieldProps().has_double(
"SMICR")) {
522 micp_.microbialConcentration = getArray(eclState_.fieldProps().get_double(
"SMICR"));
524 micp_.microbialConcentration.resize(numDof, 0.0);
526 if (eclState_.fieldProps().has_double(
"SOXYG")) {
527 micp_.oxygenConcentration = getArray(eclState_.fieldProps().get_double(
"SOXYG"));
529 micp_.oxygenConcentration.resize(numDof, 0.0);
531 if (eclState_.fieldProps().has_double(
"SUREA")) {
532 micp_.ureaConcentration = getArray(eclState_.fieldProps().get_double(
"SUREA"));
534 micp_.ureaConcentration.resize(numDof, 0.0);
536 if (eclState_.fieldProps().has_double(
"SBIOF")) {
537 micp_.biofilmConcentration = getArray(eclState_.fieldProps().get_double(
"SBIOF"));
539 micp_.biofilmConcentration.resize(numDof, 0.0);
541 if (eclState_.fieldProps().has_double(
"SCALC")) {
542 micp_.calciteConcentration = getArray(eclState_.fieldProps().get_double(
"SCALC"));
544 micp_.calciteConcentration.resize(numDof, 0.0);
549template<
class Gr
idView,
class Flu
idSystem>
554 if (maxWaterSaturation_.empty())
557 return maxWaterSaturation_[globalDofIdx];
560template<
class Gr
idView,
class Flu
idSystem>
565 if (minRefPressure_.empty())
568 return minRefPressure_[globalDofIdx];
571template<
class Gr
idView,
class Flu
idSystem>
576 if (overburdenPressure_.empty())
579 return overburdenPressure_[elementIdx];
582template<
class Gr
idView,
class Flu
idSystem>
587 if (solventSaturation_.empty())
590 return solventSaturation_[elemIdx];
593template<
class Gr
idView,
class Flu
idSystem>
598 if (solventRsw_.empty())
601 return solventRsw_[elemIdx];
606template<
class Gr
idView,
class Flu
idSystem>
611 if (polymer_.concentration.empty()) {
615 return polymer_.concentration[elemIdx];
618template<
class Gr
idView,
class Flu
idSystem>
623 if (polymer_.moleWeight.empty()) {
627 return polymer_.moleWeight[elemIdx];
630template<
class Gr
idView,
class Flu
idSystem>
635 if (micp_.microbialConcentration.empty()) {
642template<
class Gr
idView,
class Flu
idSystem>
647 if (micp_.oxygenConcentration.empty()) {
654template<
class Gr
idView,
class Flu
idSystem>
659 if (micp_.ureaConcentration.empty()) {
666template<
class Gr
idView,
class Flu
idSystem>
671 if (micp_.biofilmConcentration.empty()) {
678template<
class Gr
idView,
class Flu
idSystem>
683 if (micp_.calciteConcentration.empty()) {
690template<
class Gr
idView,
class Flu
idSystem>
697 return pvtnum_[elemIdx];
700template<
class Gr
idView,
class Flu
idSystem>
707 return satnum_[elemIdx];
710template<
class Gr
idView,
class Flu
idSystem>
714 if (miscnum_.empty())
717 return miscnum_[elemIdx];
720template<
class Gr
idView,
class Flu
idSystem>
724 if (plmixnum_.empty())
727 return plmixnum_[elemIdx];
730template<
class Gr
idView,
class Flu
idSystem>
735 if (polymer_.maxAdsorption.empty()) {
739 return polymer_.maxAdsorption[elemIdx];
742template<
class Gr
idView,
class Flu
idSystem>
752 this->micp_ == rhs.
micp_;
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:645
Scalar microbialConcentration(unsigned elemIdx) const
Returns the initial microbial concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:633
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:334
static std::string briefDescription()
Returns a human readable description of the problem for the help message.
Definition: FlowGenericProblem_impl.hpp:126
Scalar initialTimeStepSize_
Definition: FlowGenericProblem.hpp:345
std::vector< Scalar > solventSaturation_
Definition: FlowGenericProblem.hpp:339
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:351
static FlowGenericProblem serializationTestObject(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:91
FlowGenericProblem(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:60
bool enableTuning_
Definition: FlowGenericProblem.hpp:344
Scalar biofilmConcentration(unsigned elemIdx) const
Returns the initial biofilm concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:669
MICPSolutionContainer< Scalar > micp_
Definition: FlowGenericProblem.hpp:341
void readRockParameters_(const std::vector< Scalar > &cellCenterDepths, std::function< std::array< int, 3 >(const unsigned)> ijkIndex)
Definition: FlowGenericProblem_impl.hpp:133
std::vector< Scalar > maxOilSaturation_
Definition: FlowGenericProblem.hpp:335
int numPressurePointsEquil_
Definition: FlowGenericProblem.hpp:349
std::vector< Scalar > maxWaterSaturation_
Definition: FlowGenericProblem.hpp:336
Scalar maxTimeStepAfterWellEvent_
Definition: FlowGenericProblem.hpp:346
Scalar calciteConcentration(unsigned elemIdx) const
Returns the initial calcite concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:681
Scalar ureaConcentration(unsigned elemIdx) const
Returns the initial urea concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:657
std::vector< Scalar > minRefPressure_
Definition: FlowGenericProblem.hpp:337
std::vector< Scalar > solventRsw_
Definition: FlowGenericProblem.hpp:340
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:111
std::vector< Scalar > overburdenPressure_
Definition: FlowGenericProblem.hpp:338
bool explicitRockCompaction_
Definition: FlowGenericProblem.hpp:352
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:185
Definition: blackoilboundaryratevector.hh:39
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 MICPSolutionContainer serializationTestObject()
Definition: EclTimeSteppingParams.hpp:45
static PolymerSolutionContainer serializationTestObject()