FlowGenericProblem_impl.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
23#ifndef OPM_FLOW_GENERIC_PROBLEM_IMPL_HPP
24#define OPM_FLOW_GENERIC_PROBLEM_IMPL_HPP
25
26#ifndef OPM_FLOW_GENERIC_PROBLEM_HPP
27#include <config.h>
29#endif
30
31#include <dune/common/parametertree.hh>
32
33#include <opm/common/ErrorMacros.hpp>
34#include <opm/common/utility/TimeService.hpp>
35
36#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
37#include <opm/input/eclipse/EclipseState/Tables/OverburdTable.hpp>
38#include <opm/input/eclipse/EclipseState/Tables/RockwnodTable.hpp>
39#include <opm/input/eclipse/Schedule/Schedule.hpp>
40#include <opm/input/eclipse/Units/Units.hpp>
41
45
48
50
51#include <boost/date_time.hpp>
52
53#include <fmt/format.h>
54#include <fmt/ranges.h>
55
56#include <iostream>
57#include <stdexcept>
58
59namespace Opm {
60
61template<class GridView, class FluidSystem>
63FlowGenericProblem(const EclipseState& eclState,
64 const Schedule& schedule,
65 const GridView& gridView)
66 : eclState_(eclState)
67 , schedule_(schedule)
68 , gridView_(gridView)
69 , lookUpData_(gridView)
70{
71 // we need to update the FluidSystem based on EclipseState before it is passed around
72 this->initFluidSystem_();
73
74 enableTuning_ = Parameters::Get<Parameters::EnableTuning>();
75 enableDriftCompensation_ = Parameters::Get<Parameters::EnableDriftCompensation>();
76 initialTimeStepSize_ = Parameters::Get<Parameters::InitialTimeStepSize<Scalar>>();
77 maxTimeStepAfterWellEvent_ = unit::convert::from
80 // The value N for this parameter is defined in the following order of precedence:
81 //
82 // 1. Command line value (--num-pressure-points-equil=N)
83 //
84 // 2. EQLDIMS item 2. Default value from
85 // opm-common/opm/input/eclipse/share/keywords/000_Eclipse100/E/EQLDIMS
87 if (Parameters::IsSet<Parameters::NumPressurePointsEquil>()) {
88 numPressurePointsEquil_ = Parameters::Get<Parameters::NumPressurePointsEquil>();
90 throw std::invalid_argument {
91 fmt::format("--num-pressure-points-equil must be at least 1, "
92 "but {} was given.", numPressurePointsEquil_)
93 };
94 }
95 }
96 else {
97 numPressurePointsEquil_ = eclState.getTableManager().getEqldims().getNumDepthNodesP();
99 throw std::invalid_argument {
100 fmt::format("EQLDIMS item 2, the number of depth nodes in the "
101 "equilibration pressure tables, must be at least 1, "
102 "but {} was given.", numPressurePointsEquil_)
103 };
104 }
105 }
106
107 explicitRockCompaction_ = Parameters::Get<Parameters::ExplicitRockCompaction>();
108}
109
110template<class GridView, class FluidSystem>
113serializationTestObject(const EclipseState& eclState,
114 const Schedule& schedule,
115 const GridView& gridView)
116{
117 FlowGenericProblem result(eclState, schedule, gridView);
118 result.maxOilSaturation_ = {1.0, 2.0};
119 result.maxWaterSaturation_ = {6.0};
120 result.minRefPressure_ = {7.0, 8.0, 9.0, 10.0};
121 result.overburdenPressure_ = {11.0};
122 result.solventSaturation_ = {15.0};
123 result.solventRsw_ = {18.0};
127
128 return result;
130
131template<class GridView, class FluidSystem>
132std::string
134helpPreamble(int,
135 const char **argv)
136{
137 std::string desc = FlowGenericProblem::briefDescription();
138 if (!desc.empty())
139 desc = desc + "\n";
140
141 return
142 "Usage: "+std::string(argv[0]) + " [OPTIONS] [DECK_FILENAME]\n"
143 + desc;
144}
145
146template<class GridView, class FluidSystem>
147std::string
150{
151 return briefDescription_;
152}
153
154template<class GridView, class FluidSystem>
156readRockParameters_(const std::vector<Scalar>& cellCenterDepths,
157 std::function<std::array<int,3>(const unsigned)> ijkIndex)
158{
159 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
160
161 // read the rock compressibility parameters
162 {
163 const auto& comp = rock_config.comp();
164 rockParams_.clear();
165 std::ranges::transform(comp, std::back_inserter(rockParams_),
166 [](const auto& c)
167 {
168 return RockParams{
169 static_cast<Scalar>(c.pref),
170 static_cast<Scalar>(c.compressibility)
171 };
172 });
173 }
174
175 // Warn that ROCK and ROCKOPTS item 2 = STORE is used together
176 if (rock_config.store()) {
177 OpmLog::warning("ROCKOPTS item 2 set to STORE, ROCK item 1 replaced with initial (equilibrated) pressures");
178 }
179
180 // read the parameters for water-induced rock compaction
181 readRockCompactionParameters_();
183 unsigned numElem = gridView_.size(0);
184 if (eclState_.fieldProps().has_int(rock_config.rocknum_property())) {
185 // Auxiliary function to check rockTableIdx_ values belong to the right range. Otherwise, throws.
186 std::function<void(int, int)> valueCheck = [&ijkIndex,&rock_config,this](int fieldPropValue, int coarseElemIdx)
188 auto fmtError = [fieldPropValue, coarseElemIdx,&ijkIndex,&rock_config](const char* type, std::size_t size)
189 {
190 return fmt::format("{} table index {} for elem {} read from {}"
191 " is out of bounds for number of tables {}",
192 type, fieldPropValue,
193 ijkIndex(coarseElemIdx),
194 rock_config.rocknum_property(), size);
195 };
196 if (!rockCompPoroMult_.empty() &&
197 fieldPropValue > static_cast<int>(rockCompPoroMult_.size())) {
198 throw std::runtime_error(fmtError("Rock compaction",
199 rockCompPoroMult_.size()));
200 }
201 if (!rockCompPoroMultWc_.empty() &&
202 fieldPropValue > static_cast<int>(rockCompPoroMultWc_.size())) {
203 throw std::runtime_error(fmtError("Rock water compaction",
204 rockCompPoroMultWc_.size()));
205 }
206 };
207
208 rockTableIdx_ = this->lookUpData_.template assignFieldPropsIntOnLeaf<short unsigned int>(eclState_.fieldProps(),
209 rock_config.rocknum_property(),
210 true /*needsTranslation*/,
211 valueCheck);
212 }
213
214 // Store overburden pressure pr element
215 const auto& overburdTables = eclState_.getTableManager().getOverburdTables();
216 if (!overburdTables.empty() && !rock_config.store()) {
217 overburdenPressure_.resize(numElem,0.0);
218 std::size_t numRocktabTables = rock_config.num_rock_tables();
219
220 if (overburdTables.size() != numRocktabTables)
221 throw std::runtime_error(fmt::format("{} OVERBURD tables is expected, but {} is provided",
222 numRocktabTables, overburdTables.size()));
223
224 std::vector<Tabulated1DFunction<Scalar>> overburdenTables(numRocktabTables);
225 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
226 const OverburdTable& overburdTable = overburdTables.template getTable<OverburdTable>(regionIdx);
227 overburdenTables[regionIdx].setXYContainers(overburdTable.getDepthColumn(),overburdTable.getOverburdenPressureColumn());
228 }
229
230 for (std::size_t elemIdx = 0; elemIdx < numElem; ++ elemIdx) {
231 unsigned tableIdx = 0;
232 if (!rockTableIdx_.empty()) {
233 tableIdx = rockTableIdx_[elemIdx];
234 }
235 overburdenPressure_[elemIdx] =
236 overburdenTables[tableIdx].eval(cellCenterDepths[elemIdx], /*extrapolation=*/true);
237 }
238 }
239 else if (!overburdTables.empty() && rock_config.store()) {
240 OpmLog::warning("ROCKOPTS item 2 set to STORE, OVERBURD ignored!");
241 }
242}
243
244template<class GridView, class FluidSystem>
247{
248 const auto& rock_config = eclState_.getSimulationConfig().rock_config();
249
250 if (!rock_config.active())
251 return; // deck does not enable rock compaction
252
253 unsigned numElem = gridView_.size(0);
254 switch (rock_config.hysteresis_mode()) {
255 case RockConfig::Hysteresis::REVERS:
256 break;
257 case RockConfig::Hysteresis::IRREVERS:
258 // interpolate the porv volume multiplier using the minimum pressure in the cell
259 // i.e. don't allow re-inflation.
260 minRefPressure_.resize(numElem, 1e99);
261 break;
262 case RockConfig::Hysteresis::HYSTER:
263 // Track the lowest pressure each cell has ever reached, exactly as for
264 // IRREVERS. It doubles as the "turning pressure" that selects/anchors
265 // the ROCKTABH elastic reload curve once the cell re-pressurizes above it.
266 minRefPressure_.resize(numElem, 1e99);
267 break;
268 default:
269 throw std::runtime_error("Not support ROCKOMP hysteresis option ");
270 }
271
272 std::size_t numRocktabTables = rock_config.num_rock_tables();
273 bool waterCompaction = rock_config.water_compaction();
274
275 if (waterCompaction && rock_config.hysteresis_mode() == RockConfig::Hysteresis::HYSTER)
276 throw std::runtime_error("ROCKCOMP: combining WATER_COMPACTION with HYSTERESIS=HYSTER is not supported");
277
278 if (!waterCompaction && rock_config.hysteresis_mode() == RockConfig::Hysteresis::HYSTER) {
279 const auto& rocktabhTables = eclState_.getTableManager().getRocktabhTables();
280 if (rocktabhTables.size() != numRocktabTables)
281 throw std::runtime_error("ROCKCOMP HYSTERESIS is set to HYSTER. " + std::to_string(numRocktabTables)
282 +" ROCKTABH tables is expected, but " + std::to_string(rocktabhTables.size()) +" is provided");
283
284 // The deflation (virgin/plastic loading) curve, taken from the first row of
285 // each of ROCKTABH's elastic curves, plays the same role that ROCKTAB plays
286 // for REVERS/IRREVERS, so it is stored in the very same tables.
287 rockCompPoroMult_.resize(numRocktabTables);
288 rockCompTransMult_.resize(numRocktabTables);
289 rockCompPoroMultElastic_.resize(numRocktabTables);
290 rockCompTransMultElastic_.resize(numRocktabTables);
291 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
292 const auto& rocktabhTable = rocktabhTables[regionIdx];
293
294 const auto& deflation = rocktabhTable.deflationCurve();
295 rockCompPoroMult_[regionIdx].setXYContainers(deflation.getColumn(0), deflation.getColumn(1));
296 rockCompTransMult_[regionIdx].setXYContainers(deflation.getColumn(0), deflation.getColumn(2));
297
298 TabulatedTwoDFunctionBuilder poroBuilder{TabulatedTwoDFunction::InterpolationPolicy::LeftExtreme};
299 TabulatedTwoDFunctionBuilder transBuilder{TabulatedTwoDFunction::InterpolationPolicy::LeftExtreme};
300 const std::size_t numCurves = rocktabhTable.numElasticCurves();
301 for (std::size_t curveIdx = 0; curveIdx < numCurves; ++curveIdx) {
302 const auto& curve = rocktabhTable.elasticCurve(curveIdx);
303 const auto& pressure = curve.getColumn(0);
304 const auto& poro = curve.getColumn(1);
305 const auto& trans = curve.getColumn(2);
306
307 poroBuilder.appendXPos(pressure[0]);
308 transBuilder.appendXPos(pressure[0]);
309 for (std::size_t rowIdx = 0; rowIdx < curve.numRows(); ++rowIdx) {
310 poroBuilder.appendSamplePoint(curveIdx, pressure[rowIdx], poro[rowIdx]);
311 transBuilder.appendSamplePoint(curveIdx, pressure[rowIdx], trans[rowIdx]);
312 }
313 }
314 rockCompPoroMultElastic_[regionIdx] = std::move(poroBuilder).build();
315 rockCompTransMultElastic_[regionIdx] = std::move(transBuilder).build();
316 }
317 } else if (!waterCompaction) {
318 const auto& rocktabTables = eclState_.getTableManager().getRocktabTables();
319 if (rocktabTables.size() != numRocktabTables)
320 throw std::runtime_error("ROCKCOMP is activated." + std::to_string(numRocktabTables)
321 +" ROCKTAB tables is expected, but " + std::to_string(rocktabTables.size()) +" is provided");
322
323 rockCompPoroMult_.resize(numRocktabTables);
324 rockCompTransMult_.resize(numRocktabTables);
325 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
326 const auto& rocktabTable = rocktabTables.template getTable<RocktabTable>(regionIdx);
327 const auto& pressureColumn = rocktabTable.getPressureColumn();
328 const auto& poroColumn = rocktabTable.getPoreVolumeMultiplierColumn();
329 const auto& transColumn = rocktabTable.getTransmissibilityMultiplierColumn();
330 rockCompPoroMult_[regionIdx].setXYContainers(pressureColumn, poroColumn);
331 rockCompTransMult_[regionIdx].setXYContainers(pressureColumn, transColumn);
333 } else {
334 const auto& rock2dTables = eclState_.getTableManager().getRock2dTables();
335 const auto& rock2dtrTables = eclState_.getTableManager().getRock2dtrTables();
336 const auto& rockwnodTables = eclState_.getTableManager().getRockwnodTables();
337 maxWaterSaturation_.resize(numElem, 0.0);
338
339 if (rock2dTables.size() != numRocktabTables)
340 throw std::runtime_error(fmt::format("Water compation option is selected in ROCKCOMP."
341 " {} ROCK2D tables is expected, but {} is provided",
342 numRocktabTables, rock2dTables.size()));
343
344 if (rockwnodTables.size() != numRocktabTables)
345 throw std::runtime_error(fmt::format("Water compation option is selected in ROCKCOMP."
346 " {} ROCKWNOD tables is expected, but {} is provided",
347 numRocktabTables, rockwnodTables.size()));
348 //TODO check size match
349 rockCompPoroMultWc_.resize(numRocktabTables);
350 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
351 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
352 const auto& rock2dTable = rock2dTables[regionIdx];
354 if (rockwnodTable.getSaturationColumn().size() != rock2dTable.sizeMultValues())
355 throw std::runtime_error("Number of entries in ROCKWNOD and ROCK2D needs to match.");
357 TabulatedTwoDFunctionBuilder builder{TabulatedTwoDFunction::InterpolationPolicy::Vertical};
358 for (std::size_t xIdx = 0; xIdx < rock2dTable.size(); ++xIdx) {
359 builder.appendXPos(rock2dTable.getPressureValue(xIdx));
360 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
361 builder.appendSamplePoint(xIdx,
362 rockwnodTable.getSaturationColumn()[yIdx],
363 rock2dTable.getPvmultValue(xIdx, yIdx));
364 }
365 rockCompPoroMultWc_[regionIdx] = std::move(builder).build();
366 }
367
368 if (!rock2dtrTables.empty()) {
369 rockCompTransMultWc_.resize(numRocktabTables);
370 for (std::size_t regionIdx = 0; regionIdx < numRocktabTables; ++regionIdx) {
371 const RockwnodTable& rockwnodTable = rockwnodTables.template getTable<RockwnodTable>(regionIdx);
372 const auto& rock2dtrTable = rock2dtrTables[regionIdx];
373
374 if (rockwnodTable.getSaturationColumn().size() != rock2dtrTable.sizeMultValues())
375 throw std::runtime_error("Number of entries in ROCKWNOD and ROCK2DTR needs to match.");
376
377 TabulatedTwoDFunctionBuilder builder{TabulatedTwoDFunction::InterpolationPolicy::Vertical};
378 for (std::size_t xIdx = 0; xIdx < rock2dtrTable.size(); ++xIdx) {
379 builder.appendXPos(rock2dtrTable.getPressureValue(xIdx));
380 for (std::size_t yIdx = 0; yIdx < rockwnodTable.getSaturationColumn().size(); ++yIdx)
381 builder.appendSamplePoint(xIdx,
382 rockwnodTable.getSaturationColumn()[yIdx],
383 rock2dtrTable.getTransMultValue(xIdx, yIdx));
384 }
385 rockCompTransMultWc_[regionIdx] = std::move(builder).build();
386 }
387 }
388 }
389}
390
391template<class GridView, class FluidSystem>
394rockCompressibility(unsigned globalSpaceIdx) const
395{
396 if (this->rockParams_.empty())
397 return 0.0;
398
399 unsigned tableIdx = 0;
400 if (!this->rockTableIdx_.empty()) {
401 tableIdx = this->rockTableIdx_[globalSpaceIdx];
402 }
403 return this->rockParams_[tableIdx].compressibility;
404}
405
406template<class GridView, class FluidSystem>
409porosity(unsigned globalSpaceIdx, unsigned timeIdx) const
410{
411 return this->referencePorosity_[timeIdx][globalSpaceIdx];
412}
413
414template<class GridView, class FluidSystem>
417rockBiotComp(unsigned elementIdx) const
418{
419 // Additional compressibility of the rock due to Biot poroelasticity
420 const auto biot = biotCoeff(elementIdx);
421 const auto lameParam = lame(elementIdx);
422 return biot * biot / lameParam;
423}
424
425template <class GridView, class FluidSystem>
428rockBiotTemp(unsigned elementIdx) const
429{
430 // Additional compressibility due to Biot thermoelasticity
431 const auto biotT = biotTemp(elementIdx);
432 const auto biotC = biotCoeff(elementIdx);
433 const auto lameParam = lame(elementIdx);
434 return biotC * biotT / lameParam;
435}
436
437template<class GridView, class FluidSystem>
440lame(unsigned elementIdx) const
441{
442 Scalar lameParam;
443 const auto& fp = eclState_.fieldProps();
444 if (fp.has_double("LAME")) {
445 lameParam = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "LAME", elementIdx);
446 }
447 else if (fp.has_double("YMODULE") && fp.has_double("SMODULUS")) {
448 const auto& yModulus = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "YMODULE", elementIdx);
449 const auto& sModulus = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "SMODULUS", elementIdx);
450 lameParam = sModulus * (yModulus - 2 * sModulus) / (3 * sModulus - yModulus);
451 }
452 else if (fp.has_double("YMODULE") && fp.has_double("PRATIO")) {
453 const auto& yModulus = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "YMODULE", elementIdx);
454 const auto& pRatio = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "PRATIO", elementIdx);
455 lameParam = yModulus * pRatio / ((1 + pRatio) * (1 - 2 * pRatio));
456 }
457 else if (fp.has_double("SMODULUS") && fp.has_double("PRATIO")) {
458 const auto& sModulus = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "SMODULUS", elementIdx);
459 const auto& pRatio = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "PRATIO", elementIdx);
460 lameParam = 2 * sModulus * pRatio / (1 - 2 * pRatio);
461 }
462 else {
463 return 0.0;
464 }
465 return lameParam;
466}
467
468template<class GridView, class FluidSystem>
471biotCoeff(unsigned elementIdx) const
472{
473 Scalar biotC;
474 const auto& fp = eclState_.fieldProps();
475 if (fp.has_double("BIOTCOEF")) {
476 biotC = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "BIOTCOEF", elementIdx);
477 }
478 else if (fp.has_double("POELCOEF") && fp.has_double("PRATIO")) {
479 const auto& poelC = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "POELCOEF", elementIdx);
480 const auto& pRatio = this->lookUpData_.fieldPropDouble(this->eclState_.fieldProps(), "PRATIO", elementIdx);
481 biotC = poelC * (1 - pRatio) / (1 - 2 * pRatio);
482 }
483 else {
484 return 0.0;
485 }
486 return biotC;
487}
488
489template <class GridView, class FluidSystem>
492biotTemp(unsigned elementIdx) const
493{
494 const auto& fp = eclState_.fieldProps();
495
496 // Return early if deck does not have necessary parameters
497 if (!fp.has_double("THERMEXR") && !fp.has_double("THELCOEF")) {
498 return 0.0;
499 }
500
501 // Calculate from THERMEXR or THELCOEF
502 // OBS: Only accept (YMODULE, PRATIO) or (LAME, SMODULUS) conversions for now
503 Scalar biotT = 0.0;
504 if (fp.has_double("THERMEXR") && !fp.has_double("THELCOEF")) {
505 const auto thermexr = this->lookUpData_.fieldPropDouble(fp, "THERMEXR", elementIdx);
506
507 if (fp.has_double("LAME") && fp.has_double("SMODULUS")) {
508 const auto lamParam = lame(elementIdx);
509 const auto sMod = this->lookUpData_.fieldPropDouble(fp, "SMODULUS", elementIdx);
510 biotT = thermexr * (3.0 * lamParam + 2.0 * sMod);
511 } else if (fp.has_double("YMODULE") && fp.has_double("PRATIO")) {
512 const auto yMod = this->lookUpData_.fieldPropDouble(fp, "YMODULE", elementIdx);
513 const auto pRatio = this->lookUpData_.fieldPropDouble(fp, "PRATIO", elementIdx);
514 biotT = thermexr * yMod / (1.0 - 2.0 * pRatio);
515 } else if (fp.has_double("LAME") && fp.has_double("PRATIO")) {
516 const auto lamParam = lame(elementIdx);
517 const auto pRatio = this->lookUpData_.fieldPropDouble(fp, "PRATIO", elementIdx);
518 biotT =
519 thermexr * lamParam * (1.0 / pRatio - 2.0 * pRatio - 1.0) / (1.0 - 2.0 * pRatio);
520 } else if (fp.has_double("SMODULUS") && fp.has_double("PRATIO")) {
521 const auto sMod = this->lookUpData_.fieldPropDouble(fp, "SMODULUS", elementIdx);
522 const auto pRatio = this->lookUpData_.fieldPropDouble(fp, "PRATIO", elementIdx);
523 biotT = thermexr * 2.0 * sMod * (1 + pRatio) / (1.0 - 2.0 * pRatio);
524 } else if (fp.has_double("YMODULE") && fp.has_double("SMODULUS")) {
525 const auto yMod = this->lookUpData_.fieldPropDouble(fp, "YMODULE", elementIdx);
526 const auto sMod = this->lookUpData_.fieldPropDouble(fp, "SMODULUS", elementIdx);
527 biotT = thermexr * yMod * sMod / (3.0 * sMod - yMod);
528 } else {
529 OPM_THROW(std::runtime_error,
530 "THERMEXR requires one of (LAME, SMODULUS), (YMODULE, PRATIO), "
531 "(LAME, PRATIO), (SMODULUS, PRATIO) or (YMODULE, SMODULUS) "
532 "to compute the Biot temperature coefficient. "
533 "(YMODULE, LAME) is not supported.");
534 }
535
536 } else if (!fp.has_double("THERMEXR") && fp.has_double("THELCOEF")) {
537 const auto thelcoef = this->lookUpData_.fieldPropDouble(fp, "THELCOEF", elementIdx);
538
539 if (fp.has_double("LAME") && fp.has_double("SMODULUS")) {
540 const auto lamParam = lame(elementIdx);
541 const auto sMod = this->lookUpData_.fieldPropDouble(fp, "SMODULUS", elementIdx);
542 biotT = thelcoef * (lamParam + 2 * sMod) / (2 * sMod);
543 } else if (fp.has_double("PRATIO")) {
544 const auto pRatio = this->lookUpData_.fieldPropDouble(fp, "PRATIO", elementIdx);
545 biotT = thelcoef * (1 - pRatio) / (1 - 2 * pRatio);
546 } else if (fp.has_double("YMODULE") && fp.has_double("SMODULUS")) {
547 const auto yMod = this->lookUpData_.fieldPropDouble(fp, "YMODULE", elementIdx);
548 const auto sMod = this->lookUpData_.fieldPropDouble(fp, "SMODULUS", elementIdx);
549 biotT = thelcoef * (4.0 * sMod - yMod) / (6.0 * sMod - 2.0 * yMod);
550 } else {
551 OPM_THROW(std::runtime_error,
552 "THELCOEF requires one of (LAME, SMODULUS), (YMODULE, SMODULUS) "
553 "to compute the Biot temperature coefficient. "
554 "(YMODULE, LAME) is not supported.");
555 }
556 } else {
557 OPM_THROW(std::runtime_error,
558 "THERMEXR and THELCOEF cannot both be specified for the "
559 "Biot temperature coefficient");
560 }
561
562 return biotT;
563}
564
565template<class GridView, class FluidSystem>
566template<class T>
568updateNum(const std::string& name, std::vector<T>& numbers, std::size_t num_regions)
569{
570 if (!eclState_.fieldProps().has_int(name))
571 return;
572
573 std::function<void(T, int)> valueCheck = [num_regions,name](T fieldPropValue, [[maybe_unused]] int fieldPropIdx) {
574 if (fieldPropValue > static_cast<int>(num_regions)) {
575 throw std::runtime_error(fmt::format("Values larger than maximum number of regions {} provided in {}",
576 num_regions, name));
577 }
578 if (fieldPropValue <= 0) {
579 throw std::runtime_error("zero or negative values provided for region array: " + name);
580 }
581 };
582
583 numbers = this->lookUpData_.template assignFieldPropsIntOnLeaf<T>(eclState_.fieldProps(), name,
584 true /*needsTranslation*/, valueCheck);
585}
586
587template<class GridView, class FluidSystem>
590{
591 const auto num_regions = eclState_.getTableManager().getTabdims().getNumPVTTables();
592 updateNum("PVTNUM", pvtnum_, num_regions);
593}
594
595template<class GridView, class FluidSystem>
598{
599 const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
600 updateNum("SATNUM", satnum_, num_regions);
601}
602
603template<class GridView, class FluidSystem>
606{
607 const auto num_regions = 1; // we only support single region
608 updateNum("MISCNUM", miscnum_, num_regions);
609}
610
611template<class GridView, class FluidSystem>
614{
615 const auto num_regions = 1; // we only support single region
616 updateNum("PLMIXNUM", plmixnum_, num_regions);
617}
618
619template<class GridView, class FluidSystem>
621vapparsActive(int episodeIdx) const
622{
623 const auto& oilVaporizationControl = schedule_[episodeIdx].oilvap();
624 return (oilVaporizationControl.getType() == OilVaporizationProperties::OilVaporization::VAPPARS);
625}
626
627template<class GridView, class FluidSystem>
629beginEpisode_(bool enableExperiments,
630 int episodeIdx)
631{
632 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
633 // print some useful information in experimental mode. (the production
634 // simulator does this externally.)
635 std::ostringstream ss;
636 boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%d-%b-%Y");
637 boost::posix_time::ptime curDateTime =
638 boost::posix_time::from_time_t(TimeService::to_time_t(schedule_.simTime(episodeIdx)));
639 ss.imbue(std::locale(std::locale::classic(), facet));
640 ss << "Report step " << episodeIdx + 1
641 << "/" << schedule_.size() - 1
642 << " at day " << schedule_.seconds(episodeIdx)/(24*3600)
643 << "/" << schedule_.seconds(schedule_.size() - 1)/(24*3600)
644 << ", date = " << curDateTime.date()
645 << "\n ";
646 OpmLog::info(ss.str());
647 }
648
649 const auto& events = schedule_[episodeIdx].events();
650
651 // react to TUNING changes
652 if (episodeIdx > 0 && enableTuning_ && events.hasEvent(ScheduleEvents::TUNING_CHANGE))
653 {
654 const auto& sched_state = schedule_[episodeIdx];
655 const auto& tuning = sched_state.tuning();
656 initialTimeStepSize_ = sched_state.max_next_tstep(enableTuning_);
657 maxTimeStepAfterWellEvent_ = tuning.TMAXWC;
658 return true;
659 }
660
661 return false;
662}
663
664template<class GridView, class FluidSystem>
666beginTimeStep_(bool enableExperiments,
667 int episodeIdx,
668 int timeStepIndex,
669 Scalar startTime,
670 Scalar time,
671 Scalar timeStepSize,
672 Scalar endTime)
673{
674 if (enableExperiments && gridView_.comm().rank() == 0 && episodeIdx >= 0) {
675 std::ostringstream ss;
676 boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%d-%b-%Y");
677 boost::posix_time::ptime date = boost::posix_time::from_time_t(startTime) +
678 boost::posix_time::milliseconds(static_cast<long long>(time / prefix::milli));
679 ss.imbue(std::locale(std::locale::classic(), facet));
680 ss <<"\nTime step " << timeStepIndex << ", stepsize "
681 << unit::convert::to(timeStepSize, unit::day) << " days,"
682 << " at day " << (double)unit::convert::to(time, unit::day)
683 << "/" << (double)unit::convert::to(endTime, unit::day)
684 << ", date = " << date;
685 OpmLog::info(ss.str());
686 }
687}
688
689template<class GridView, class FluidSystem>
692{
693 FluidSystem::initFromState(eclState_, schedule_);
694}
695
696template<class GridView, class FluidSystem>
699 bool enableSolvent,
700 bool enablePolymer,
701 bool enablePolymerMolarWeight,
702 bool enableBioeffects,
703 bool enableMICP)
704{
705 // LGR (local grid refinement / CARFIN) is supported for black-oil only. The
706 // solvent/polymer/biofilm/MICP initial conditions below are read straight
707 // from the input-grid field properties and indexed by leaf cell; they are
708 // NOT mapped onto refined cells (see the black-oil EQLNUM/FIPNUM handling via
709 // LookUpData), so refined cells would get wrong/out-of-range values. Fail
710 // early with a clear message rather than producing silently wrong results.
711 if ((enableSolvent || enablePolymer || enablePolymerMolarWeight ||
712 enableBioeffects || enableMICP) &&
713 (eclState_.getLgrs().size() > 0))
714 {
715 throw std::runtime_error(
716 "Local grid refinement (LGR/CARFIN) is only supported for black-oil "
717 "runs. It is not supported together with the solvent, polymer, "
718 "biofilm or MICP extensions.");
719 }
720
721 auto getArray = [](const std::vector<double>& input)
722 {
723 if constexpr (std::is_same_v<Scalar,double>) {
724 return input;
725 } else {
726 return std::vector<Scalar>{input.begin(), input.end()};
727 }
728 };
729
730 if (enableSolvent) {
731 if (eclState_.fieldProps().has_double("SSOL")) {
732 solventSaturation_ = getArray(eclState_.fieldProps().get_double("SSOL"));
733 } else {
734 solventSaturation_.resize(numDof, 0.0);
735 }
736
737 solventRsw_.resize(numDof, 0.0);
738 }
739
740 if (enablePolymer) {
741 if (eclState_.fieldProps().has_double("SPOLY")) {
742 polymer_.concentration = getArray(eclState_.fieldProps().get_double("SPOLY"));
743 } else {
744 polymer_.concentration.resize(numDof, 0.0);
745 }
746 }
747
748 if (enablePolymerMolarWeight) {
749 if (eclState_.fieldProps().has_double("SPOLYMW")) {
750 polymer_.moleWeight = getArray(eclState_.fieldProps().get_double("SPOLYMW"));
751 } else {
752 polymer_.moleWeight.resize(numDof, 0.0);
753 }
754 }
755
756 if (enableBioeffects) {
757 if (eclState_.fieldProps().has_double("SMICR")) {
758 bioeffects_.microbialConcentration = getArray(eclState_.fieldProps().get_double("SMICR"));
759 } else {
760 bioeffects_.microbialConcentration.resize(numDof, 0.0);
761 }
762 if (eclState_.fieldProps().has_double("SBIOF")) {
763 bioeffects_.biofilmVolumeFraction = getArray(eclState_.fieldProps().get_double("SBIOF"));
764 } else {
765 bioeffects_.biofilmVolumeFraction.resize(numDof, 0.0);
766 }
767 if (enableMICP) {
768 if (eclState_.fieldProps().has_double("SOXYG")) {
769 bioeffects_.oxygenConcentration = getArray(eclState_.fieldProps().get_double("SOXYG"));
770 } else {
771 bioeffects_.oxygenConcentration.resize(numDof, 0.0);
772 }
773 if (eclState_.fieldProps().has_double("SUREA")) {
774 bioeffects_.ureaConcentration = getArray(eclState_.fieldProps().get_double("SUREA"));
775 } else {
776 bioeffects_.ureaConcentration.resize(numDof, 0.0);
777 }
778 if (eclState_.fieldProps().has_double("SCALC")) {
779 bioeffects_.calciteVolumeFraction = getArray(eclState_.fieldProps().get_double("SCALC"));
780 } else {
781 bioeffects_.calciteVolumeFraction.resize(numDof, 0.0);
782 }
783 }
784 }
785}
786
787template<class GridView, class FluidSystem>
790maxWaterSaturation(unsigned globalDofIdx) const
791{
792 if (maxWaterSaturation_.empty())
793 return 0.0;
794
795 return maxWaterSaturation_[globalDofIdx];
796}
797
798template<class GridView, class FluidSystem>
801minOilPressure(unsigned globalDofIdx) const
802{
803 if (minRefPressure_.empty())
804 return 0.0;
805
806 return minRefPressure_[globalDofIdx];
807}
808
809template<class GridView, class FluidSystem>
812overburdenPressure(unsigned elementIdx) const
813{
814 if (overburdenPressure_.empty())
815 return 0.0;
816
817 return overburdenPressure_[elementIdx];
818}
819
820template<class GridView, class FluidSystem>
823solventSaturation(unsigned elemIdx) const
824{
825 if (solventSaturation_.empty())
826 return 0;
827
828 return solventSaturation_[elemIdx];
829}
830
831template<class GridView, class FluidSystem>
834solventRsw(unsigned elemIdx) const
835{
836 if (solventRsw_.empty())
837 return 0;
838
839 return solventRsw_[elemIdx];
840}
841
842
843
844template<class GridView, class FluidSystem>
847polymerConcentration(unsigned elemIdx) const
848{
849 if (polymer_.concentration.empty()) {
850 return 0;
851 }
852
853 return polymer_.concentration[elemIdx];
854}
855
856template<class GridView, class FluidSystem>
859polymerMolecularWeight(const unsigned elemIdx) const
860{
861 if (polymer_.moleWeight.empty()) {
862 return 0.0;
863 }
864
865 return polymer_.moleWeight[elemIdx];
866}
867
868template<class GridView, class FluidSystem>
871microbialConcentration(unsigned elemIdx) const
872{
873 if (bioeffects_.microbialConcentration.empty()) {
874 return 0;
875 }
876
877 return bioeffects_.microbialConcentration[elemIdx];
878}
879
880template<class GridView, class FluidSystem>
883oxygenConcentration(unsigned elemIdx) const
884{
885 if (bioeffects_.oxygenConcentration.empty()) {
886 return 0;
887 }
888
889 return bioeffects_.oxygenConcentration[elemIdx];
890}
891
892template<class GridView, class FluidSystem>
895ureaConcentration(unsigned elemIdx) const
896{
897 if (bioeffects_.ureaConcentration.empty()) {
898 return 0;
899 }
900
901 return bioeffects_.ureaConcentration[elemIdx];
902}
903
904template<class GridView, class FluidSystem>
907biofilmVolumeFraction(unsigned elemIdx) const
908{
909 if (bioeffects_.biofilmVolumeFraction.empty()) {
910 return 0;
911 }
912
913 return bioeffects_.biofilmVolumeFraction[elemIdx];
914}
915
916template<class GridView, class FluidSystem>
919calciteVolumeFraction(unsigned elemIdx) const
920{
921 if (bioeffects_.calciteVolumeFraction.empty()) {
922 return 0;
923 }
924
925 return bioeffects_.calciteVolumeFraction[elemIdx];
926}
927
928template<class GridView, class FluidSystem>
930pvtRegionIndex(unsigned elemIdx) const
931{
932 if (pvtnum_.empty())
933 return 0;
934
935 return pvtnum_[elemIdx];
936}
937
938template<class GridView, class FluidSystem>
940satnumRegionIndex(unsigned elemIdx) const
941{
942 if (satnum_.empty())
943 return 0;
944
945 return satnum_[elemIdx];
946}
947
948template<class GridView, class FluidSystem>
950miscnumRegionIndex(unsigned elemIdx) const
951{
952 if (miscnum_.empty())
953 return 0;
954
955 return miscnum_[elemIdx];
956}
957
958template<class GridView, class FluidSystem>
960plmixnumRegionIndex(unsigned elemIdx) const
961{
962 if (plmixnum_.empty())
963 return 0;
964
965 return plmixnum_[elemIdx];
966}
967
968template<class GridView, class FluidSystem>
971maxPolymerAdsorption(unsigned elemIdx) const
972{
973 if (polymer_.maxAdsorption.empty()) {
974 return 0;
975 }
976
977 return polymer_.maxAdsorption[elemIdx];
978}
979
980template<class GridView, class FluidSystem>
982operator==(const FlowGenericProblem& rhs) const
983{
984 return this->maxWaterSaturation_ == rhs.maxWaterSaturation_ &&
985 this->minRefPressure_ == rhs.minRefPressure_ &&
986 this->overburdenPressure_ == rhs.overburdenPressure_ &&
987 this->solventSaturation_ == rhs.solventSaturation_ &&
988 this->solventRsw_ == rhs.solventRsw_ &&
989 this->polymer_ == rhs.polymer_ &&
990 this->bioeffects_ == rhs.bioeffects_;
991}
992
993} // namespace Opm
994
995#endif // OPM_FLOW_GENERIC_PROBLEM_IMPL_HPP
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:62
Scalar maxPolymerAdsorption(unsigned elemIdx) const
Returns the max polymer adsorption value.
Definition: FlowGenericProblem_impl.hpp:971
unsigned pvtRegionIndex(unsigned elemIdx) const
Returns the index the relevant PVT region given a cell index.
Definition: FlowGenericProblem_impl.hpp:930
Scalar oxygenConcentration(unsigned elemIdx) const
Returns the initial oxygen concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:883
Scalar microbialConcentration(unsigned elemIdx) const
Returns the initial microbial concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:871
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:389
Scalar rockBiotTemp(unsigned elementIdx) const
Returns the rock compressibility of an element due to thermoelasticity.
Definition: FlowGenericProblem_impl.hpp:428
static std::string briefDescription()
Returns a human readable description of the problem for the help message.
Definition: FlowGenericProblem_impl.hpp:149
Scalar solventRsw(unsigned elemIdx) const
Returns the initial solvent dissolved in water for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:834
Scalar overburdenPressure(unsigned elementIdx) const
Get the pressure of the overburden.
Definition: FlowGenericProblem_impl.hpp:812
void updateMiscnum_()
Definition: FlowGenericProblem_impl.hpp:605
Scalar porosity(unsigned globalSpaceIdx, unsigned timeIdx) const
Direct indexed access to the porosity.
Definition: FlowGenericProblem_impl.hpp:409
Scalar rockCompressibility(unsigned globalSpaceIdx) const
Definition: FlowGenericProblem_impl.hpp:394
Scalar initialTimeStepSize_
Definition: FlowGenericProblem.hpp:401
unsigned miscnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant MISC region given a cell index.
Definition: FlowGenericProblem_impl.hpp:950
bool vapparsActive(int episodeIdx) const
Definition: FlowGenericProblem_impl.hpp:621
unsigned satnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant saturation function region given a cell index.
Definition: FlowGenericProblem_impl.hpp:940
Scalar maxWaterSaturation(unsigned globalDofIdx) const
Returns an element's historic maximum water phase saturation that was observed during the simulation.
Definition: FlowGenericProblem_impl.hpp:790
std::vector< Scalar > solventSaturation_
Definition: FlowGenericProblem.hpp:394
void readRockCompactionParameters_()
Definition: FlowGenericProblem_impl.hpp:246
void updateSatnum_()
Definition: FlowGenericProblem_impl.hpp:597
void updatePvtnum_()
Definition: FlowGenericProblem_impl.hpp:589
bool enableDriftCompensation_
Definition: FlowGenericProblem.hpp:407
Scalar lame(unsigned elementIdx) const
Direct access to Lame's second parameter in an element.
Definition: FlowGenericProblem_impl.hpp:440
static FlowGenericProblem serializationTestObject(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:113
void beginTimeStep_(bool enableExperiments, int episodeIdx, int timeStepIndex, Scalar startTime, Scalar time, Scalar timeStepSize, Scalar endTime)
Definition: FlowGenericProblem_impl.hpp:666
Scalar calciteVolumeFraction(unsigned elemIdx) const
Returns the initial calcite volume fraction for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:919
CO2H2SolutionContainer< Scalar > CO2H2_
Definition: FlowGenericProblem.hpp:397
unsigned plmixnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant PLMIXNUM (for polymer module) region given a cell index.
Definition: FlowGenericProblem_impl.hpp:960
FlowGenericProblem(const EclipseState &eclState, const Schedule &schedule, const GridView &gridView)
Definition: FlowGenericProblem_impl.hpp:63
BioeffectsSolutionContainer< Scalar > bioeffects_
Definition: FlowGenericProblem.hpp:396
bool enableTuning_
Definition: FlowGenericProblem.hpp:400
Scalar solventSaturation(unsigned elemIdx) const
Returns the initial solvent saturation for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:823
Scalar polymerMolecularWeight(const unsigned elemIdx) const
Returns the polymer molecule weight for a given cell index.
Definition: FlowGenericProblem_impl.hpp:859
void readRockParameters_(const std::vector< Scalar > &cellCenterDepths, std::function< std::array< int, 3 >(const unsigned)> ijkIndex)
Definition: FlowGenericProblem_impl.hpp:156
UniformXTabulated2DFunctionBuilder< Scalar > TabulatedTwoDFunctionBuilder
Definition: FlowGenericProblem.hpp:66
std::vector< Scalar > maxOilSaturation_
Definition: FlowGenericProblem.hpp:390
Scalar rockBiotComp(unsigned elementIdx) const
Returns the rock compressibility of an element due to poroelasticity.
Definition: FlowGenericProblem_impl.hpp:417
int numPressurePointsEquil_
Definition: FlowGenericProblem.hpp:405
Scalar minOilPressure(unsigned globalDofIdx) const
Returns an element's historic minimum pressure of the oil phase that was observed during the simulati...
Definition: FlowGenericProblem_impl.hpp:801
std::vector< Scalar > maxWaterSaturation_
Definition: FlowGenericProblem.hpp:391
void initFluidSystem_()
Definition: FlowGenericProblem_impl.hpp:691
bool operator==(const FlowGenericProblem &rhs) const
Definition: FlowGenericProblem_impl.hpp:982
Scalar maxTimeStepAfterWellEvent_
Definition: FlowGenericProblem.hpp:402
Scalar ureaConcentration(unsigned elemIdx) const
Returns the initial urea concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:895
std::vector< Scalar > minRefPressure_
Definition: FlowGenericProblem.hpp:392
bool beginEpisode_(bool enableExperiments, int episodeIdx)
Definition: FlowGenericProblem_impl.hpp:629
Scalar biofilmVolumeFraction(unsigned elemIdx) const
Returns the initial biofilm volume fraction for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:907
std::vector< Scalar > solventRsw_
Definition: FlowGenericProblem.hpp:395
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:134
std::vector< Scalar > overburdenPressure_
Definition: FlowGenericProblem.hpp:393
void readBlackoilExtentionsInitialConditions_(std::size_t numDof, bool enableSolvent, bool enablePolymer, bool enablePolymerMolarWeight, bool enableBioeffects, bool enableMICP)
Definition: FlowGenericProblem_impl.hpp:698
Scalar biotTemp(unsigned elementIdx) const
Direct access to Biot temperature coefficient in an element.
Definition: FlowGenericProblem_impl.hpp:492
Scalar biotCoeff(unsigned elementIdx) const
Direct access to Biot coefficient in an element.
Definition: FlowGenericProblem_impl.hpp:471
void updatePlmixnum_()
Definition: FlowGenericProblem_impl.hpp:613
bool explicitRockCompaction_
Definition: FlowGenericProblem.hpp:409
typename FluidSystem::Scalar Scalar
Definition: FlowGenericProblem.hpp:64
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
Scalar polymerConcentration(unsigned elemIdx) const
Returns the initial polymer concentration for a given a cell index.
Definition: FlowGenericProblem_impl.hpp:847
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:198
Definition: blackoilbioeffectsmodules.hh:45
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: FlowGenericProblem.hpp:69
Definition: EclTimeSteppingParams.hpp:49
static PolymerSolutionContainer serializationTestObject()