FlowProblem.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 Copyright 2023 INRIA
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20
21 Consult the COPYING file in the top-level source directory of this
22 module for the precise wording of the license and the list of
23 copyright holders.
24*/
30#ifndef OPM_FLOW_PROBLEM_HPP
31#define OPM_FLOW_PROBLEM_HPP
32
33#include <dune/common/version.hh>
34#include <dune/common/fvector.hh>
35#include <dune/common/fmatrix.hh>
36
37#include <opm/common/utility/TimeService.hpp>
38
39#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
40#include <opm/input/eclipse/Schedule/Schedule.hpp>
41#include <opm/input/eclipse/Units/Units.hpp>
42
43#include <opm/material/common/ConditionalStorage.hpp>
44#include <opm/material/common/Valgrind.hpp>
45#include <opm/material/densead/Evaluation.hpp>
46#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
47#include <opm/material/thermal/EclThermalLawManager.hpp>
48
54
55#include <opm/output/eclipse/EclipseIO.hpp>
56
62// TODO: maybe we can name it FlowProblemProperties.hpp
73
77
78#include <opm/utility/CopyablePtr.hpp>
79
80#include <algorithm>
81#include <cstddef>
82#include <functional>
83#include <set>
84#include <stdexcept>
85#include <string>
86#include <type_traits>
87#include <vector>
88
89namespace Opm {
90
97template <class TypeTag>
98class FlowProblem : public GetPropType<TypeTag, Properties::BaseProblem>
99 , public FlowGenericProblem<GetPropType<TypeTag, Properties::GridView>,
100 GetPropType<TypeTag, Properties::FluidSystem>>
101{
102protected:
107
116
117 // Grid and world dimension
118 enum { dim = GridView::dimension };
119 enum { dimWorld = GridView::dimensionworld };
120
121 // copy some indices for convenience
122 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
123 enum { numPhases = FluidSystem::numPhases };
124 enum { numComponents = FluidSystem::numComponents };
125
126 static constexpr bool enableBioeffects = getPropValue<TypeTag, Properties::EnableBioeffects>();
127 static constexpr bool enableBrine = getPropValue<TypeTag, Properties::EnableBrine>();
128 static constexpr bool enableConvectiveMixing = getPropValue<TypeTag, Properties::EnableConvectiveMixing>();
129 static constexpr bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
130 static constexpr bool enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>();
131 static constexpr bool enableExtbo = getPropValue<TypeTag, Properties::EnableExtbo>();
132 static constexpr bool enableFoam = getPropValue<TypeTag, Properties::EnableFoam>();
133 static constexpr bool enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>();
134 static constexpr bool enablePolymerMolarWeight = getPropValue<TypeTag, Properties::EnablePolymerMW>();
135 static constexpr bool enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>();
136
137 static constexpr EnergyModules energyModuleType = getPropValue<TypeTag, Properties::EnergyModuleType>();
138 enum { enableFullyImplicitThermal = getPropValue<TypeTag, Properties::EnergyModuleType>() == EnergyModules::FullyImplicitThermal };
139 enum { enableExperiments = getPropValue<TypeTag, Properties::EnableExperiments>() };
140 enum { enableMICP = Indices::enableMICP };
141 enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
142 enum { enableThermalFluxBoundaries = getPropValue<TypeTag, Properties::EnableThermalFluxBoundaries>() };
143
144 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
145 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
146 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
147
148 // TODO: later, gasCompIdx, oilCompIdx and waterCompIdx should go to the FlowProblemBlackoil in the future
149 // we do not want them in the compositional setting
150 enum { gasCompIdx = FluidSystem::gasCompIdx };
151 enum { oilCompIdx = FluidSystem::oilCompIdx };
152 enum { waterCompIdx = FluidSystem::waterCompIdx };
153
157 using Element = typename GridView::template Codim<0>::Entity;
161 using MaterialLawParams = typename EclMaterialLawManager::MaterialLawParams;
162 using SolidEnergyLawParams = typename EclThermalLawManager::SolidEnergyLawParams;
163 using ThermalConductionLawParams = typename EclThermalLawManager::ThermalConductionLawParams;
170
171 using Toolbox = MathToolbox<Evaluation>;
172 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
173
176 using DirectionalMobilityPtr = Utility::CopyablePtr<DirectionalMobility<TypeTag>>;
178
179public:
180
183 std::string extraTrailerSummary() const
184 { return {}; }
191 using BaseType::lame;
193 using BaseType::biotTemp;
195 using BaseType::porosity;
196
200 static void registerParameters()
201 {
202 ParentType::registerParameters();
203
204 registerFlowProblemParameters<Scalar>();
205 }
206
216 static int handlePositionalParameter(std::function<void(const std::string&,
217 const std::string&)> addKey,
218 std::set<std::string>& seenParams,
219 std::string& errorMsg,
220 int,
221 const char** argv,
222 int paramIdx,
223 int)
224 {
225 return detail::eclPositionalParameter(addKey,
226 seenParams,
227 errorMsg,
228 argv,
229 paramIdx);
230 }
231
235 explicit FlowProblem(Simulator& simulator)
236 : ParentType(simulator)
237 , BaseType(simulator.vanguard().eclState(),
238 simulator.vanguard().schedule(),
239 simulator.vanguard().gridView())
240 , transmissibilities_(simulator.vanguard().eclState(),
241 simulator.vanguard().gridView(),
242 simulator.vanguard().cartesianIndexMapper(),
243 simulator.vanguard().grid(),
244 simulator.vanguard().cellCentroids(),
245 (energyModuleType == EnergyModules::FullyImplicitThermal ||
246 energyModuleType == EnergyModules::SequentialImplicitThermal),
249 , wellModel_(simulator, this->iterationContext())
250 , aquiferModel_(simulator)
251 , pffDofData_(simulator.gridView(), this->elementMapper())
252 , tracerModel_(simulator)
253 , temperatureModel_(simulator)
254 , thresholdPressures_(simulator)
255 , enable_state_rollback_(Parameters::Get<Parameters::EnableStateRollback>())
256 {
257 if (! Parameters::Get<Parameters::CheckSatfuncConsistency>()) {
258 // User did not enable the "new" saturation function consistency
259 // check module. Run the original checker instead. This is a
260 // temporary measure.
261 RelpermDiagnostics relpermDiagnostics{};
262 relpermDiagnostics.diagnosis(simulator.vanguard().eclState(),
263 simulator.vanguard().levelCartesianIndexMapper());
264 }
265
266 if (energyModuleType == EnergyModules::SequentialImplicitThermal) {
267 this->enableDriftCompensationTemp_ = Parameters::Get<Parameters::EnableDriftCompensationTemp>();
268 }
269
271 = Parameters::Get<Parameters::SaturationWeightedDensity>();
272 }
273
274 virtual ~FlowProblem() = default;
275
276 void prefetch(const Element& elem) const
277 { this->pffDofData_.prefetch(elem); }
278
290 template <class Restarter>
291 void deserialize(Restarter& res)
292 {
293 // reload the current episode/report step from the deck
294 this->beginEpisode();
295
296 // deserialize the wells
297 wellModel_.deserialize(res);
298
299 // deserialize the aquifer
300 aquiferModel_.deserialize(res);
301 }
302
309 template <class Restarter>
310 void serialize(Restarter& res)
311 {
312 wellModel_.serialize(res);
313
314 aquiferModel_.serialize(res);
315 }
316
317 int episodeIndex() const
318 {
319 return std::max(this->simulator().episodeIndex(), 0);
320 }
321
325 virtual void beginEpisode()
326 {
327 OPM_TIMEBLOCK(beginEpisode);
328 // Proceed to the next report step
329 auto& simulator = this->simulator();
330 int episodeIdx = simulator.episodeIndex();
331 auto& eclState = simulator.vanguard().eclState();
332 const auto& schedule = simulator.vanguard().schedule();
333 const auto& events = schedule[episodeIdx].events();
334
335 if (episodeIdx >= 0 && events.hasEvent(ScheduleEvents::GEO_MODIFIER)) {
336 // bring the contents of the keywords to the current state of the SCHEDULE
337 // section.
338 //
339 // TODO (?): make grid topology changes possible (depending on what exactly
340 // has changed, the grid may need be re-created which has some serious
341 // implications on e.g., the solution of the simulation.)
342 const auto& miniDeck = schedule[episodeIdx].geo_keywords();
343 const auto& cc = simulator.vanguard().grid().comm();
344 eclState.apply_schedule_keywords( miniDeck );
345 eclBroadcast(cc, eclState.getTransMult() );
346
347 // Re-ordering in case of ALUGrid
348 std::function<unsigned int(unsigned int)> equilGridToGrid = [&simulator](unsigned int i) {
349 return simulator.vanguard().gridEquilIdxToGridIdx(i);
350 };
351
352 // re-compute all quantities which may possibly be affected.
353 using TransUpdateQuantities = typename Vanguard::TransmissibilityType::TransUpdateQuantities;
354 transmissibilities_.update(true, TransUpdateQuantities::All, equilGridToGrid);
355 this->referencePorosity_[1] = this->referencePorosity_[0];
357 this->rockFraction_[1] = this->rockFraction_[0];
360 this->model().linearizer().updateDiscretizationParameters();
361 }
362
363 bool tuningEvent = this->beginEpisode_(enableExperiments, this->episodeIndex());
364
365 // set up the wells for the next episode.
366 wellModel_.beginEpisode();
367
368 // set up the aquifers for the next episode.
369 aquiferModel_.beginEpisode();
370
371 // set the size of the initial time step of the episode
372 Scalar dt = limitNextTimeStepSize_(simulator.episodeLength());
373 // negative value of initialTimeStepSize_ indicates no active limit from TSINIT or NEXTSTEP
374 if ( (episodeIdx == 0 || tuningEvent) && this->initialTimeStepSize_ > 0)
375 // allow the size of the initial time step to be set via an external parameter
376 // if TUNING is enabled, also limit the time step size after a tuning event to TSINIT
377 dt = std::min(dt, this->initialTimeStepSize_);
378 simulator.setTimeStepSize(dt);
379 }
380
384 virtual void beginTimeStep()
385 {
386 OPM_TIMEBLOCK(beginTimeStep);
387 const int episodeIdx = this->episodeIndex();
388 const int timeStepSize = this->simulator().timeStepSize();
389
392 }
393
395 episodeIdx,
396 this->simulator().timeStepIndex(),
397 this->simulator().startTime(),
398 this->simulator().time(),
399 timeStepSize,
400 this->simulator().endTime());
401
402 // update maximum water saturation and minimum pressure
403 // used when ROCKCOMP is activated
404 // Do not update max RS first step after a restart
405 this->updateExplicitQuantities_(episodeIdx, timeStepSize, first_step_ && (episodeIdx > 0));
406 first_step_ = false;
407
409 this->model().linearizer().updateBoundaryConditionData();
410 }
411
412 wellModel_.beginTimeStep();
413 aquiferModel_.beginTimeStep();
414 tracerModel_.beginTimeStep();
415 temperatureModel_.beginTimeStep();
416 }
417
423 {
426 }
427 wellModel_.updateFailed();
428 this->model().updateFailed();
429 }
430
436 {
437 this->model().advanceTimeLevel();
438 wellModel_.advanceTimeLevel();
439 }
440
445 {
446 OPM_TIMEBLOCK(beginIteration);
447 wellModel_.beginIteration();
448 aquiferModel_.beginIteration();
449 }
450
455 {
456 OPM_TIMEBLOCK(endIteration);
457 wellModel_.endIteration();
458 aquiferModel_.endIteration();
459 }
460
464 virtual void endTimeStep()
465 {
466 OPM_TIMEBLOCK(endTimeStep);
467
468#ifndef NDEBUG
469 if constexpr (getPropValue<TypeTag, Properties::EnableDebuggingChecks>()) {
470 // in debug mode, we don't care about performance, so we check
471 // if the model does the right thing (i.e., the mass change
472 // inside the whole reservoir must be equivalent to the fluxes
473 // over the grid's boundaries plus the source rates specified by
474 // the problem).
475 const int rank = this->simulator().gridView().comm().rank();
476 if (rank == 0) {
477 std::cout << "checking conservativeness of solution\n";
478 }
479
480 this->model().checkConservativeness(/*tolerance=*/-1, /*verbose=*/true);
481 if (rank == 0) {
482 std::cout << "solution is sufficiently conservative\n";
483 }
484 }
485#endif // NDEBUG
486
487 auto& simulator = this->simulator();
488 simulator.setTimeStepIndex(simulator.timeStepIndex()+1);
489
490 this->wellModel_.endTimeStep();
491 this->aquiferModel_.endTimeStep();
492 this->tracerModel_.endTimeStep();
493
494 // Compute flux for output
495 this->model().linearizer().updateFlowsInfo();
496
498 OPM_TIMEBLOCK(driftCompansation);
499
500 const auto& residual = this->model().linearizer().residual();
501
502 for (unsigned globalDofIdx = 0; globalDofIdx < residual.size(); globalDofIdx ++) {
503 int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(globalDofIdx);
504 this->drift_[sfcdofIdx] = residual[sfcdofIdx] * simulator.timeStepSize();
505
506 if constexpr (getPropValue<TypeTag, Properties::UseVolumetricResidual>()) {
507 this->drift_[sfcdofIdx] *= this->model().dofTotalVolume(sfcdofIdx);
508 }
509 }
510 }
511
512 // For sequential implicit thermal: finalize TEMP solve,
513 // then refresh cached intensive quantities (temperature-dependent).
514 if constexpr(energyModuleType == EnergyModules::SequentialImplicitThermal) {
515 this->temperatureModel_.endTimeStep(wellModel_.wellState());
516 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
517 }
518 }
519
523 virtual void endEpisode()
524 {
525 const int episodeIdx = this->episodeIndex();
526
527 this->wellModel_.endEpisode();
528 this->aquiferModel_.endEpisode();
529
530 const auto& schedule = this->simulator().vanguard().schedule();
531
532 // End simulation when completed.
533 if (episodeIdx + 1 >= static_cast<int>(schedule.size()) - 1) {
534 this->simulator().setFinished(true);
535 return;
536 }
537
538 // Otherwise, start next episode (report step).
539 this->simulator().startNextEpisode(schedule.stepLength(episodeIdx + 1));
540 }
541
546 virtual void writeOutput(bool verbose)
547 {
548 OPM_TIMEBLOCK(problemWriteOutput);
549
550 if (Parameters::Get<Parameters::EnableWriteAllSolutions>() ||
551 this->episodeWillBeOver())
552 {
553 // Create VTK output as needed.
554 ParentType::writeOutput(verbose);
555 }
556 }
557
561 template <class Context>
562 const DimMatrix& intrinsicPermeability(const Context& context,
563 unsigned spaceIdx,
564 unsigned timeIdx) const
565 {
566 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
567 return transmissibilities_.permeability(globalSpaceIdx);
568 }
569
576 const DimMatrix& intrinsicPermeability(unsigned globalElemIdx) const
577 { return transmissibilities_.permeability(globalElemIdx); }
578
582 template <class Context>
583 Scalar transmissibility(const Context& context,
584 [[maybe_unused]] unsigned fromDofLocalIdx,
585 unsigned toDofLocalIdx) const
586 {
587 assert(fromDofLocalIdx == 0);
588 return pffDofData_.get(context.element(), toDofLocalIdx).transmissibility;
589 }
590
594 Scalar transmissibility(unsigned globalCenterElemIdx, unsigned globalElemIdx) const
595 {
596 return transmissibilities_.transmissibility(globalCenterElemIdx, globalElemIdx);
597 }
598
602 Scalar thresholdPressure(unsigned elem1Idx, unsigned elem2Idx) const
603 { return thresholdPressures_.thresholdPressure(elem1Idx, elem2Idx); }
604
606 { return thresholdPressures_; }
607
609 { return thresholdPressures_; }
610
612 { return moduleParams_; }
613
617 template <class Context>
618 Scalar diffusivity(const Context& context,
619 [[maybe_unused]] unsigned fromDofLocalIdx,
620 unsigned toDofLocalIdx) const
621 {
622 assert(fromDofLocalIdx == 0);
623 return *pffDofData_.get(context.element(), toDofLocalIdx).diffusivity;
624 }
625
629 Scalar diffusivity(const unsigned globalCellIn, const unsigned globalCellOut) const{
630 return transmissibilities_.diffusivity(globalCellIn, globalCellOut);
631 }
632
636 Scalar dispersivity(const unsigned globalCellIn, const unsigned globalCellOut) const{
637 return transmissibilities_.dispersivity(globalCellIn, globalCellOut);
638 }
639
643 Scalar thermalTransmissibilityBoundary(const unsigned globalSpaceIdx,
644 const unsigned boundaryFaceIdx) const
645 {
646 return transmissibilities_.thermalTransmissibilityBoundary(globalSpaceIdx, boundaryFaceIdx);
647 }
648
649
650
651
655 template <class Context>
656 Scalar transmissibilityBoundary(const Context& elemCtx,
657 unsigned boundaryFaceIdx) const
658 {
659 unsigned elemIdx = elemCtx.globalSpaceIndex(/*dofIdx=*/0, /*timeIdx=*/0);
660 return transmissibilities_.transmissibilityBoundary(elemIdx, boundaryFaceIdx);
661 }
662
666 Scalar transmissibilityBoundary(const unsigned globalSpaceIdx,
667 const unsigned boundaryFaceIdx) const
668 {
669 return transmissibilities_.transmissibilityBoundary(globalSpaceIdx, boundaryFaceIdx);
670 }
671
672
676 Scalar thermalHalfTransmissibility(const unsigned globalSpaceIdxIn,
677 const unsigned globalSpaceIdxOut) const
678 {
679 return transmissibilities_.thermalHalfTrans(globalSpaceIdxIn,globalSpaceIdxOut);
680 }
681
685 template <class Context>
686 Scalar thermalHalfTransmissibilityIn(const Context& context,
687 unsigned faceIdx,
688 unsigned timeIdx) const
689 {
690 const auto& face = context.stencil(timeIdx).interiorFace(faceIdx);
691 unsigned toDofLocalIdx = face.exteriorIndex();
692 return *pffDofData_.get(context.element(), toDofLocalIdx).thermalHalfTransIn;
693 }
694
698 template <class Context>
700 unsigned faceIdx,
701 unsigned timeIdx) const
702 {
703 const auto& face = context.stencil(timeIdx).interiorFace(faceIdx);
704 unsigned toDofLocalIdx = face.exteriorIndex();
705 return *pffDofData_.get(context.element(), toDofLocalIdx).thermalHalfTransOut;
706 }
707
711 template <class Context>
713 unsigned boundaryFaceIdx) const
714 {
715 unsigned elemIdx = elemCtx.globalSpaceIndex(/*dofIdx=*/0, /*timeIdx=*/0);
716 return transmissibilities_.thermalHalfTransBoundary(elemIdx, boundaryFaceIdx);
717 }
718
722 const typename Vanguard::TransmissibilityType& eclTransmissibilities() const
723 { return transmissibilities_; }
724
725
727 { return tracerModel_; }
728
730 { return tracerModel_; }
731
732 TemperatureModel& temperatureModel() // need for restart
733 { return temperatureModel_; }
734
743 template <class Context>
744 Scalar porosity(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
745 {
746 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
747 return this->porosity(globalSpaceIdx, timeIdx);
748 }
749
756 template <class Context>
757 Scalar dofCenterDepth(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
758 {
759 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
760 return this->dofCenterDepth(globalSpaceIdx);
761 }
762
769 Scalar dofCenterDepth(unsigned globalSpaceIdx) const
770 {
771 return this->simulator().vanguard().cellCenterDepth(globalSpaceIdx);
772 }
773
777 template <class Context>
778 Scalar rockCompressibility(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
779 {
780 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
781 return this->rockCompressibility(globalSpaceIdx);
782 }
783
787 template <class Context>
788 Scalar rockBiotComp(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
789 {
790 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
791 return this->rockBiotComp(globalSpaceIdx);
792 }
793
797 template <class Context>
798 Scalar rockBiotTemp(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
799 {
800 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
801 return this->rockBiotTemp(globalSpaceIdx);
802 }
803
807 template <class Context>
808 Scalar lame(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
809 {
810 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
811 return this->lame(globalSpaceIdx);
812 }
813
817 template <class Context>
818 Scalar biotCoeff(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
819 {
820 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
821 return this->biotCoeff(globalSpaceIdx);
822 }
823
827 template <class Context>
828 Scalar biotTemp(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
829 {
830 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
831 return this->biotTemp(globalSpaceIdx);
832 }
833
837 template <class Context>
838 Scalar rockReferencePressure(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
839 {
840 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
841 return rockReferencePressure(globalSpaceIdx);
842 }
843
847 Scalar rockReferencePressure(unsigned globalSpaceIdx) const
848 {
849 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
850 if (rock_config.store()) {
851 return asImp_().initialFluidState(globalSpaceIdx).pressure(refPressurePhaseIdx_());
852 }
853 else {
854 if (this->rockParams_.empty())
855 return 1e5;
856
857 unsigned tableIdx = 0;
858 if (!this->rockTableIdx_.empty()) {
859 tableIdx = this->rockTableIdx_[globalSpaceIdx];
860 }
861 return this->rockParams_[tableIdx].referencePressure;
862 }
863 }
864
868 template <class Context>
869 const MaterialLawParams& materialLawParams(const Context& context,
870 unsigned spaceIdx, unsigned timeIdx) const
871 {
872 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
873 return this->materialLawParams(globalSpaceIdx);
874 }
875
876 const MaterialLawParams& materialLawParams(unsigned globalDofIdx) const
877 {
878 return materialLawManager_->materialLawParams(globalDofIdx);
879 }
880
881 const MaterialLawParams& materialLawParams(unsigned globalDofIdx, FaceDir::DirEnum facedir) const
882 {
883 return materialLawManager_->materialLawParams(globalDofIdx, facedir);
884 }
885
889 template <class Context>
891 solidEnergyLawParams(const Context& context,
892 unsigned spaceIdx,
893 unsigned timeIdx) const
894 {
895 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
896 return thermalLawManager_->solidEnergyLawParams(globalSpaceIdx);
897 }
898
902 template <class Context>
904 thermalConductionLawParams(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
905 {
906 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
907 return thermalLawManager_->thermalConductionLawParams(globalSpaceIdx);
908 }
909
917 { return *materialLawManager_; }
918
919 std::shared_ptr<const EclThermalLawManager> thermalLawManager() const
920 { return thermalLawManager_; }
921
922 template <class FluidState, class ...Args>
924 std::array<Evaluation,numPhases> &mobility,
926 FluidState &fluidState,
927 unsigned globalSpaceIdx) const
928 {
929 using ContainerT = std::array<Evaluation, numPhases>;
930 OPM_TIMEBLOCK_LOCAL(updateRelperms, Subsystem::SatProps);
931 {
932 // calculate relative permeabilities. note that we store the result into the
933 // mobility_ class attribute. the division by the phase viscosity happens later.
934 const auto& materialParams = materialLawParams(globalSpaceIdx);
935 MaterialLaw::template relativePermeabilities<ContainerT, FluidState, Args...>(mobility, materialParams, fluidState);
936 Valgrind::CheckDefined(mobility);
937 }
938 if (materialLawManager_->hasDirectionalRelperms()
939 || materialLawManager_->hasDirectionalImbnum())
940 {
941 using Dir = FaceDir::DirEnum;
942 constexpr int ndim = 3;
943 dirMob = std::make_unique<DirectionalMobility<TypeTag>>();
944 Dir facedirs[ndim] = {Dir::XPlus, Dir::YPlus, Dir::ZPlus};
945 for (int i = 0; i<ndim; i++) {
946 const auto& materialParams = materialLawParams(globalSpaceIdx, facedirs[i]);
947 auto& mob_array = dirMob->getArray(i);
948 MaterialLaw::template relativePermeabilities<ContainerT, FluidState, Args...>(mob_array, materialParams, fluidState);
949 }
950 }
951 }
952
957 { return *materialLawManager_; }
958
963 template <class Context>
964 unsigned pvtRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
965 { return pvtRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
966
971 template <class Context>
972 unsigned satnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
973 { return this->satnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
974
979 template <class Context>
980 unsigned miscnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
981 { return this->miscnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
982
987 template <class Context>
988 unsigned plmixnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
989 { return this->plmixnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
990
991 // TODO: polymer related might need to go to the blackoil side
996 template <class Context>
997 Scalar maxPolymerAdsorption(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
998 { return this->maxPolymerAdsorption(context.globalSpaceIndex(spaceIdx, timeIdx)); }
999
1003 std::string name() const
1004 { return this->simulator().vanguard().caseName(); }
1005
1009 template <class Context>
1010 Scalar temperature(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
1011 {
1012 // use the initial temperature of the DOF if temperature is not a primary
1013 // variable
1014 unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
1015 if constexpr (energyModuleType == EnergyModules::SequentialImplicitThermal)
1016 return temperatureModel_.temperature(globalDofIdx);
1017
1018 return asImp_().initialFluidState(globalDofIdx).temperature(/*phaseIdx=*/0);
1019 }
1020
1021
1022 Scalar temperature(unsigned globalDofIdx, unsigned /*timeIdx*/) const
1023 {
1024 // use the initial temperature of the DOF if temperature is not a primary
1025 // variable
1026 if constexpr (energyModuleType == EnergyModules::SequentialImplicitThermal)
1027 return temperatureModel_.temperature(globalDofIdx);
1028
1029 return asImp_().initialFluidState(globalDofIdx).temperature(/*phaseIdx=*/0);
1030 }
1031
1033 solidEnergyLawParams(unsigned globalSpaceIdx,
1034 unsigned /*timeIdx*/) const
1035 {
1036 return this->thermalLawManager_->solidEnergyLawParams(globalSpaceIdx);
1037 }
1039 thermalConductionLawParams(unsigned globalSpaceIdx,
1040 unsigned /*timeIdx*/)const
1041 {
1042 return this->thermalLawManager_->thermalConductionLawParams(globalSpaceIdx);
1043 }
1044
1054 Scalar maxOilSaturation(unsigned globalDofIdx) const
1055 {
1056 if (!this->vapparsActive(this->episodeIndex()))
1057 return 0.0;
1058
1059 return this->maxOilSaturation_[globalDofIdx];
1060 }
1061
1071 void setMaxOilSaturation(unsigned globalDofIdx, Scalar value)
1072 {
1073 if (!this->vapparsActive(this->episodeIndex()))
1074 return;
1075
1076 this->maxOilSaturation_[globalDofIdx] = value;
1077 }
1078
1083 {
1084 // Calculate all intensive quantities.
1085 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx*/0);
1086
1087 // We also need the intensive quantities for timeIdx == 1
1088 // corresponding to the start of the current timestep, if we
1089 // do not use the storage cache, or if we cannot recycle the
1090 // first iteration storage.
1091 if (!this->model().enableStorageCache() || !this->recycleFirstIterationStorage()) {
1092 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx*/1);
1093 }
1094
1095 // initialize the wells. Note that this needs to be done after initializing the
1096 // intrinsic permeabilities and the after applying the initial solution because
1097 // the well model uses these...
1098 wellModel_.init();
1099
1100 aquiferModel_.initialSolutionApplied();
1101
1102 const bool invalidateFromHyst = updateHysteresis_();
1103 if (invalidateFromHyst) {
1104 OPM_TIMEBLOCK(beginTimeStepInvalidateIntensiveQuantities);
1105 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
1106 }
1107 }
1108
1114 template <class Context>
1115 void source(RateVector& rate,
1116 const Context& context,
1117 unsigned spaceIdx,
1118 unsigned timeIdx) const
1119 {
1120 const unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
1121 source(rate, globalDofIdx, timeIdx);
1122 }
1123
1124 void source(RateVector& rate,
1125 unsigned globalDofIdx,
1126 unsigned timeIdx) const
1127 {
1128 OPM_TIMEBLOCK_LOCAL(eclProblemSource, Subsystem::Assembly);
1129 rate = 0.0;
1130
1131 // Add well contribution to source here.
1132 wellModel_.computeTotalRatesForDof(rate, globalDofIdx);
1133
1134 // convert the source term from the total mass rate of the
1135 // cell to the one per unit of volume as used by the model.
1136 for (unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
1137 rate[eqIdx] /= this->model().dofTotalVolume(globalDofIdx);
1138
1139 Valgrind::CheckDefined(rate[eqIdx]);
1140 assert(isfinite(rate[eqIdx]));
1141 }
1142
1143 // Add non-well sources.
1144 addToSourceDense(rate, globalDofIdx, timeIdx);
1145 }
1146
1147 virtual void addToSourceDense(RateVector& rate,
1148 unsigned globalDofIdx,
1149 unsigned timeIdx) const = 0;
1150
1156 const WellModel& wellModel() const
1157 { return wellModel_; }
1158
1160 { return wellModel_; }
1161
1163 { return aquiferModel_; }
1164
1166 { return aquiferModel_; }
1167
1170
1178 {
1179 OPM_TIMEBLOCK(nexTimeStepSize);
1180 // allow external code to do the timestepping
1181 if (this->nextTimeStepSize_ > 0.0)
1182 return this->nextTimeStepSize_;
1183
1184 const auto& simulator = this->simulator();
1185 int episodeIdx = simulator.episodeIndex();
1186
1187 // for the initial episode, we use a fixed time step size
1188 if (episodeIdx < 0)
1189 return this->initialTimeStepSize_;
1190
1191 // ask the newton method for a suggestion. This suggestion will be based on how
1192 // well the previous time step converged. After that, apply the runtime time
1193 // stepping constraints.
1194 const auto& newtonMethod = this->model().newtonMethod();
1195 return limitNextTimeStepSize_(newtonMethod.suggestTimeStepSize(simulator.timeStepSize()));
1196 }
1197
1203 template <class LhsEval>
1204 LhsEval rockCompPoroMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx) const
1205 {
1206 OPM_TIMEBLOCK_LOCAL(rockCompPoroMultiplier, Subsystem::PvtProps);
1207 if (this->rockCompPoroMult_.empty() && this->rockCompPoroMultWc_.empty())
1208 return 1.0;
1209
1210 unsigned tableIdx = 0;
1211 if (!this->rockTableIdx_.empty())
1212 tableIdx = this->rockTableIdx_[elementIdx];
1213
1214 const auto& fs = intQuants.fluidState();
1215 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
1216
1217 if (!this->rockCompPoroMultElastic_.empty()) {
1218 // ROCKCOMP HYSTERESIS=HYSTER: follow the deflation (virgin/plastic) curve
1219 // at or below the lowest pressure ever reached by this cell, and the
1220 // reversible elastic reload curve, anchored at that turning pressure,
1221 // above it.
1222 LhsEval effectivePressure = decay<LhsEval>(fs.pressure(refPressurePhaseIdx_()));
1223 LhsEval turningPressure = this->minRefPressure_[elementIdx];
1224
1225 if (!this->overburdenPressure_.empty()) {
1226 effectivePressure -= this->overburdenPressure_[elementIdx];
1227 turningPressure -= this->overburdenPressure_[elementIdx];
1228 }
1229
1230 if (rock_config.store()) {
1231 const auto& initialPressure = asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
1232 effectivePressure -= initialPressure;
1233 turningPressure -= initialPressure;
1234 }
1235
1236 if (effectivePressure <= turningPressure)
1237 return this->rockCompPoroMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
1238
1239 return this->rockCompPoroMultElastic_[tableIdx].eval(turningPressure, effectivePressure, /*extrapolation=*/true);
1240 }
1241
1242 LhsEval effectivePressure = decay<LhsEval>(fs.pressure(refPressurePhaseIdx_()));
1243 if (!this->minRefPressure_.empty())
1244 // The pore space change is irreversible
1245 effectivePressure =
1246 min(decay<LhsEval>(fs.pressure(refPressurePhaseIdx_())),
1247 this->minRefPressure_[elementIdx]);
1248
1249 if (!this->overburdenPressure_.empty())
1250 effectivePressure -= this->overburdenPressure_[elementIdx];
1251
1252 if (rock_config.store()) {
1253 effectivePressure -= asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
1254 }
1255
1256 if (!this->rockCompPoroMult_.empty()) {
1257 return this->rockCompPoroMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
1258 }
1259
1260 // water compaction
1261 assert(!this->rockCompPoroMultWc_.empty());
1262 LhsEval SwMax = max(decay<LhsEval>(fs.saturation(waterPhaseIdx)), this->maxWaterSaturation_[elementIdx]);
1263 LhsEval SwDeltaMax = SwMax - asImp_().initialFluidStates()[elementIdx].saturation(waterPhaseIdx);
1264
1265 return this->rockCompPoroMultWc_[tableIdx].eval(effectivePressure, SwDeltaMax, /*extrapolation=*/true);
1266 }
1267
1273 template <class LhsEval>
1274 LhsEval rockCompTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx) const
1275 {
1276 auto obtain = [](const auto& value)
1277 {
1278 if constexpr (std::is_same_v<LhsEval, Scalar>) {
1279 return getValue(value);
1280 } else {
1281 return value;
1282 }
1283 };
1284 return rockCompTransMultiplier<LhsEval>(intQuants, elementIdx, obtain);
1285 }
1286
1287 template <class LhsEval, class Callback>
1288 LhsEval rockCompTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
1289 {
1290 const bool implicit = !this->explicitRockCompaction_;
1291 return implicit ? this->simulator().problem().template computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain)
1292 : this->simulator().problem().getRockCompTransMultVal(elementIdx);
1293 }
1294
1295 template <class LhsEval, class Callback>
1296 LhsEval wellTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
1297 {
1298 OPM_TIMEBLOCK_LOCAL(wellTransMultiplier, Subsystem::Wells);
1299
1300 const bool implicit = !this->explicitRockCompaction_;
1301 LhsEval trans_mult = implicit ? this->simulator().problem().template computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain)
1302 : this->simulator().problem().getRockCompTransMultVal(elementIdx);
1303 trans_mult *= this->simulator().problem().template permFactTransMultiplier<LhsEval>(intQuants, elementIdx, obtain);
1304
1305 return trans_mult;
1306 }
1307
1309 int boundaryConditionIndex(const unsigned int globalSpaceIdx, const int directionId) const
1310 {
1312 return 0;
1313 }
1314 return bcindex_(FaceDir::FromIntersectionIndex(directionId))[globalSpaceIdx];
1315 }
1316
1317 std::pair<BCType, RateVector> boundaryCondition(const unsigned int globalSpaceIdx, const int directionId) const
1318 {
1319 OPM_TIMEBLOCK_LOCAL(boundaryCondition, Subsystem::Assembly);
1321 return { BCType::NONE, RateVector(0.0) };
1322 }
1323 FaceDir::DirEnum dir = FaceDir::FromIntersectionIndex(directionId);
1324 const auto& schedule = this->simulator().vanguard().schedule();
1325 if (bcindex_(dir)[globalSpaceIdx] == 0) {
1326 return { BCType::NONE, RateVector(0.0) };
1327 }
1328 if (schedule[this->episodeIndex()].bcstate.size() == 0) {
1329 return { BCType::NONE, RateVector(0.0) };
1330 }
1331 const auto& bc = schedule[this->episodeIndex()].bcstate[bcindex_(dir)[globalSpaceIdx]];
1332 if (bc.bctype!=BCType::RATE) {
1333 return { bc.bctype, RateVector(0.0) };
1334 }
1335
1336 RateVector rate = 0.0;
1337 switch (bc.component) {
1338 case BCComponent::OIL:
1339 rate[FluidSystem::canonicalToActiveCompIdx(oilCompIdx)] = bc.rate;
1340 break;
1341 case BCComponent::GAS:
1342 rate[FluidSystem::canonicalToActiveCompIdx(gasCompIdx)] = bc.rate;
1343 break;
1344 case BCComponent::WATER:
1345 rate[FluidSystem::canonicalToActiveCompIdx(waterCompIdx)] = bc.rate;
1346 break;
1347 case BCComponent::SOLVENT:
1348 this->handleSolventBC(bc, rate);
1349 break;
1350 case BCComponent::POLYMER:
1351 this->handlePolymerBC(bc, rate);
1352 break;
1353 case BCComponent::MICR:
1354 this->handleMicrBC(bc, rate);
1355 break;
1356 case BCComponent::OXYG:
1357 this->handleOxygBC(bc, rate);
1358 break;
1359 case BCComponent::UREA:
1360 this->handleUreaBC(bc, rate);
1361 break;
1362 case BCComponent::NONE:
1363 throw std::logic_error("you need to specify the component when RATE type is set in BC");
1364 break;
1365 }
1366 //TODO add support for enthalpy rate
1367 return {bc.bctype, rate};
1368 }
1369
1370
1371 template<class Serializer>
1372 void serializeOp(Serializer& serializer)
1373 {
1374 serializer(static_cast<BaseType&>(*this));
1375 serializer(first_step_);
1376 serializer(drift_);
1377 serializer(wellModel_);
1378 serializer(aquiferModel_);
1379 serializer(tracerModel_);
1380 serializer(temperatureModel_);
1381 serializer(*materialLawManager_);
1382 }
1383
1384 const GlobalEqVector& drift() const
1385 {
1386 return drift_;
1387 }
1388
1389private:
1390 Implementation& asImp_()
1391 { return *static_cast<Implementation *>(this); }
1392
1393 const Implementation& asImp_() const
1394 { return *static_cast<const Implementation *>(this); }
1395
1396protected:
1404 {
1411 if (materialLawManager_ && materialLawManager_->enableHysteresis()) {
1412 materialLawManager_->captureBeginTimeStepState();
1413 }
1414 }
1415
1418 {
1425 if (materialLawManager_ && materialLawManager_->enableHysteresis()) {
1426 materialLawManager_->restoreBeginTimeStepState();
1427 }
1428 }
1429
1431 {
1432 this->transmissibilities_.finishInit(
1433 [&vg = this->simulator().vanguard()](const unsigned int index) {
1434 return vg.gridIdxToEquilGridIdx(index);
1435 });
1436 }
1437
1438 template<class EclWriterType>
1439 bool prepareTransmissibilityOutput_(EclWriterType& eclWriter,
1440 const bool enableEclOutput)
1441 {
1442 auto& simulator = this->simulator();
1443 bool localTransmissibilitiesFinished = false;
1444
1445 if (enableEclOutput) {
1446 // Parallel TRANX, TRANY, TRANZ and NNC output requires the global
1447 // grid's transmissibilities on the I/O rank -- except with LGRs, below.
1448 if (simulator.vanguard().grid().comm().size() > 1) {
1449 bool wholeGridTransNeeded = simulator.vanguard().grid().comm().rank() == 0;
1450 // Parallel LGR: reuse the simulator's own (distributed) transmissibilities for the
1451 // INIT output -- each rank contributes its interior connections, gathered on the
1452 // I/O rank and keyed by level-Cartesian indices so the output walk over the global
1453 // (equil) grid can look them up directly. This reuses the values already computed
1454 // in parallel for the simulation itself instead of recomputing a whole-grid
1455 // transmissibility. The local transmissibilities are built here, before the INIT
1456 // write, and reported as finished so that they are not built again.
1457 if constexpr (std::is_same_v<GetPropType<TypeTag, Properties::Grid>, Dune::CpGrid>) {
1458 // Gate on the deck's LGRs -- the same condition the writer keys its LGR
1459 // output walk on (writeInit / extractOutputTransAndNNC). Grid refinement
1460 // alone (grid().maxLevel() > 0, e.g. after adapt()) must not enable the
1461 // gathered mode: the writer would look up different keys than the ones
1462 // the leaf-grid walk records.
1463 if (simulator.vanguard().eclState().getLgrs().size() > 0) {
1465 localTransmissibilitiesFinished = true;
1466 const auto& localTrans = simulator.problem().eclTransmissibilities();
1467 eclWriter.setGatheredLgrTrans(
1468 gatherLgrOutputTrans(simulator.vanguard().grid(),
1469 simulator.vanguard().gridView(),
1470 [&localTrans](unsigned c1, unsigned c2)
1471 { return static_cast<double>(localTrans.transmissibility(c1, c2)); }));
1472 // All output values (TRANX/Y/Z and NNC) come from the gathered records --
1473 // no whole-grid transmissibility object is needed on the I/O rank.
1474 wholeGridTransNeeded = false;
1475 }
1476 }
1477 if (wholeGridTransNeeded) {
1478 eclWriter.setTransmissibilities(&simulator.vanguard().globalTransmissibility());
1479 }
1480 }
1481 else {
1483 localTransmissibilitiesFinished = true;
1484 eclWriter.setTransmissibilities(&simulator.problem().eclTransmissibilities());
1485 }
1486
1487 std::function<unsigned int(unsigned int)> equilGridToGrid =
1488 [&simulator](const unsigned int index) {
1489 return simulator.vanguard().gridEquilIdxToGridIdx(index);
1490 };
1491 eclWriter.extractOutputTransAndNNC(equilGridToGrid);
1492 }
1493
1494 simulator.vanguard().releaseGlobalTransmissibilities();
1495 return localTransmissibilitiesFinished;
1496 }
1497
1499 {
1500 auto& simulator = this->simulator();
1501 const auto& eclState = simulator.vanguard().eclState();
1502 const auto& schedule = simulator.vanguard().schedule();
1503
1504 simulator.setStartTime(TimeService::to_time_t(schedule.getStartTime()));
1505 simulator.setEndTime(TimeService::to_time_t(schedule.simTime(schedule.size() - 1)));
1506
1507 // Represent initialization as a zero-length episode before report step zero.
1508 simulator.setEpisodeIndex(-1);
1509 simulator.setEpisodeLength(0.0);
1510
1511 this->initGravity_(eclState);
1512
1513 if (this->enableTuning_) {
1514 // If support for the TUNING keyword is enabled, get the initial time
1515 // stepping parameters from it instead of from command line parameters.
1516 const auto& tuning = schedule[0].tuning();
1517 this->initialTimeStepSize_ = tuning.TSINIT.value_or(-1.0);
1518 this->maxTimeStepAfterWellEvent_ = tuning.TMAXWC;
1519 }
1520 }
1521
1523 {
1524 auto& simulator = this->simulator();
1525
1526 if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) &&
1527 FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
1528 this->maxOilSaturation_.resize(this->model().numGridDof(), 0.0);
1529 }
1530
1531 this->readRockParameters_(
1532 simulator.vanguard().cellCenterDepths(),
1533 [&simulator](const unsigned int index) {
1534 std::array<int, dim> coords;
1535 simulator.vanguard().cartesianCoordinate(index, coords);
1536 std::ranges::transform(coords, coords.begin(),
1537 [](const auto coordinate) { return coordinate + 1; });
1538 return coords;
1539 });
1540
1542 this->readThermalParameters_();
1543 }
1544
1545 template<class UpdateFunc>
1546 void updateProperty_(const std::string& failureMsg,
1547 UpdateFunc func)
1548 {
1549 OPM_TIMEBLOCK(updateProperty);
1550 const auto& model = this->simulator().model();
1551 const auto& primaryVars = model.solution(/*timeIdx*/0);
1552 const auto& vanguard = this->simulator().vanguard();
1553 std::size_t numGridDof = primaryVars.size();
1555#ifdef _OPENMP
1556#pragma omp parallel for
1557#endif
1558 for (unsigned dofIdx = 0; dofIdx < numGridDof; ++dofIdx) {
1559 const auto& iq = model.intensiveQuantities(dofIdx, /*timeIdx=*/ 0);
1560 func(dofIdx, iq);
1561 }
1562 OPM_END_PARALLEL_TRY_CATCH(failureMsg, vanguard.grid().comm());
1563 }
1564
1566 {
1567 OPM_TIMEBLOCK(updateMaxOilSaturation);
1568 int episodeIdx = this->episodeIndex();
1569
1570 // we use VAPPARS
1571 if (this->vapparsActive(episodeIdx)) {
1572 this->updateProperty_("FlowProblem::updateMaxOilSaturation_() failed:",
1573 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1574 {
1575 this->updateMaxOilSaturation_(compressedDofIdx,iq);
1576 });
1577 return true;
1578 }
1579
1580 return false;
1581 }
1582
1583 bool updateMaxOilSaturation_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1584 {
1585 OPM_TIMEBLOCK_LOCAL(updateMaxOilSaturation, Subsystem::SatProps);
1586 const auto& fs = iq.fluidState();
1587 const Scalar So = decay<Scalar>(fs.saturation(refPressurePhaseIdx_()));
1588 auto& mos = this->maxOilSaturation_;
1589 if(mos[compressedDofIdx] < So){
1590 mos[compressedDofIdx] = So;
1591 return true;
1592 }else{
1593 return false;
1594 }
1595 }
1596
1598 {
1599 OPM_TIMEBLOCK(updateMaxWaterSaturation);
1600 // water compaction is activated in ROCKCOMP
1601 if (this->maxWaterSaturation_.empty())
1602 return false;
1603
1604 this->updateProperty_("FlowProblem::updateMaxWaterSaturation_() failed:",
1605 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1606 {
1607 this->updateMaxWaterSaturation_(compressedDofIdx,iq);
1608 });
1609 return true;
1610 }
1611
1612
1613 bool updateMaxWaterSaturation_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1614 {
1615 OPM_TIMEBLOCK_LOCAL(updateMaxWaterSaturation, Subsystem::SatProps);
1616 const auto& fs = iq.fluidState();
1617 const Scalar Sw = decay<Scalar>(fs.saturation(waterPhaseIdx));
1618 auto& mow = this->maxWaterSaturation_;
1619 if(mow[compressedDofIdx]< Sw){
1620 mow[compressedDofIdx] = Sw;
1621 return true;
1622 }else{
1623 return false;
1624 }
1625 }
1626
1628 {
1629 OPM_TIMEBLOCK(updateMinPressure);
1630 // IRREVERS option is used in ROCKCOMP
1631 if (this->minRefPressure_.empty())
1632 return false;
1633
1634 this->updateProperty_("FlowProblem::updateMinPressure_() failed:",
1635 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1636 {
1637 this->updateMinPressure_(compressedDofIdx,iq);
1638 });
1639 return true;
1640 }
1641
1642 bool updateMinPressure_(unsigned compressedDofIdx, const IntensiveQuantities& iq){
1643 OPM_TIMEBLOCK_LOCAL(updateMinPressure, Subsystem::PvtProps);
1644 const auto& fs = iq.fluidState();
1645 const Scalar min_pressure = getValue(fs.pressure(refPressurePhaseIdx_()));
1646 auto& min_pressures = this->minRefPressure_;
1647 if(min_pressures[compressedDofIdx]> min_pressure){
1648 min_pressures[compressedDofIdx] = min_pressure;
1649 return true;
1650 }else{
1651 return false;
1652 }
1653 }
1654
1655 // \brief Function to assign field properties of type double, on the leaf grid view.
1656 //
1657 // For CpGrid with local grid refinement, the field property of a cell on the leaf
1658 // is inherited from its parent or equivalent (when has no parent) cell on level zero.
1659 std::function<std::vector<double>(const FieldPropsManager&, const std::string&)>
1661 {
1662 const auto& lookup = this->lookUpData_;
1663 return [&lookup](const FieldPropsManager& fieldPropManager, const std::string& propString)
1664 {
1665 return lookup.assignFieldPropsDoubleOnLeaf(fieldPropManager, propString);
1666 };
1667 }
1668
1669 // \brief Function to assign field properties of type int, unsigned int, ..., on the leaf grid view.
1670 //
1671 // For CpGrid with local grid refinement, the field property of a cell on the leaf
1672 // is inherited from its parent or equivalent (when has no parent) cell on level zero.
1673 template<typename IntType>
1674 std::function<std::vector<IntType>(const FieldPropsManager&, const std::string&, bool)>
1676 {
1677 const auto& lookup = this->lookUpData_;
1678 return [&lookup](const FieldPropsManager& fieldPropManager, const std::string& propString, bool needsTranslation)
1679 {
1680 return lookup.template assignFieldPropsIntOnLeaf<IntType>(fieldPropManager, propString, needsTranslation);
1681 };
1682 }
1683
1685 {
1686 OPM_TIMEBLOCK(readMaterialParameters);
1687 const auto& simulator = this->simulator();
1688 const auto& vanguard = simulator.vanguard();
1689 const auto& eclState = vanguard.eclState();
1690
1691 // the PVT and saturation region numbers
1693 this->updatePvtnum_();
1694 this->updateSatnum_();
1695
1696 // the MISC region numbers (solvent model)
1697 this->updateMiscnum_();
1698 // the PLMIX region numbers (polymer model)
1699 this->updatePlmixnum_();
1700
1701 OPM_END_PARALLEL_TRY_CATCH("Invalid region numbers: ", vanguard.gridView().comm());
1703 // porosity
1704 updateReferencePorosity_();
1705 this->referencePorosity_[1] = this->referencePorosity_[0];
1707
1709 // rock fraction
1710 updateRockFraction_();
1711 this->rockFraction_[1] = this->rockFraction_[0];
1713
1715 // fluid-matrix interactions (saturation functions; relperm/capillary pressure)
1716 materialLawManager_ = std::make_shared<EclMaterialLawManager>();
1717 materialLawManager_->initFromState(eclState);
1718 materialLawManager_->initParamsForElements(eclState, this->model().numGridDof(),
1719 this-> template fieldPropIntTypeOnLeafAssigner_<int>(),
1720 this-> lookupIdxOnLevelZeroAssigner_());
1722 }
1723
1725 {
1726 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal ||
1727 energyModuleType == EnergyModules::SequentialImplicitThermal )
1728 {
1729 const auto& simulator = this->simulator();
1730 const auto& vanguard = simulator.vanguard();
1731 const auto& eclState = vanguard.eclState();
1732
1733 // fluid-matrix interactions (saturation functions; relperm/capillary pressure)
1734 thermalLawManager_ = std::make_shared<EclThermalLawManager>();
1735 thermalLawManager_->initParamsForElements(eclState, this->model().numGridDof(),
1736 this-> fieldPropDoubleOnLeafAssigner_(),
1737 this-> template fieldPropIntTypeOnLeafAssigner_<unsigned int>());
1738 }
1739 }
1740
1742 {
1743 const auto& simulator = this->simulator();
1744 const auto& vanguard = simulator.vanguard();
1745 const auto& eclState = vanguard.eclState();
1746
1747 std::size_t numDof = this->model().numGridDof();
1748
1749 this->referencePorosity_[/*timeIdx=*/0].resize(numDof);
1750
1751 const auto& fp = eclState.fieldProps();
1752 const std::vector<double> porvData = this -> fieldPropDoubleOnLeafAssigner_()(fp, "PORV");
1753 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1754 int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(dofIdx);
1755 Scalar poreVolume = porvData[dofIdx];
1756
1757 // we define the porosity as the accumulated pore volume divided by the
1758 // geometric volume of the element. Note that -- in pathetic cases -- it can
1759 // be larger than 1.0!
1760 Scalar dofVolume = simulator.model().dofTotalVolume(sfcdofIdx);
1761 assert(dofVolume > 0.0);
1762 this->referencePorosity_[/*timeIdx=*/0][sfcdofIdx] = poreVolume/dofVolume;
1763 }
1764 }
1765
1767
1768 const bool solveEnergyEquation = (energyModuleType == EnergyModules::FullyImplicitThermal ||
1769 energyModuleType == EnergyModules::SequentialImplicitThermal);
1770 if (!solveEnergyEquation)
1771 return;
1772
1773 const auto& simulator = this->simulator();
1774 const auto& vanguard = simulator.vanguard();
1775 const auto& eclState = vanguard.eclState();
1776
1777 std::size_t numDof = this->model().numGridDof();
1778 this->rockFraction_[/*timeIdx=*/0].resize(numDof);
1779 // For the energy equation, we need the volume of the rock.
1780 // The volume of the rock is computed by rockFraction * geometric volume of the element.
1781 // The reference porosity is defined as porosity * ntg * pore-volume-multiplier.
1782 // A common practice in reservoir simulation is to use large pore-volume-multipliers in boundary cells
1783 // to model boundary conditions other than no-flow. This may result in reference porosities that are larger than 1.
1784 // A simple (1-reference porosity) * geometric volume of the element may give unphysical results.
1785 // We therefore instead consider the pore-volume-multiplier as a volume multiplier. The rock fraction is thus given by
1786 // (1 - porosity * ntg) * pore-volume-multiplier = (1 - porosity * ntg) * reference porosity / (porosity * ntg)
1787 const auto& fp = eclState.fieldProps();
1788 const std::vector<double> poroData = this->fieldPropDoubleOnLeafAssigner_()(fp, "PORO");
1789 const std::vector<double> ntgData = this->fieldPropDoubleOnLeafAssigner_()(fp, "NTG");
1790
1791 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1792 const auto ntg = ntgData[dofIdx];
1793 const auto poro_eff = ntg * poroData[dofIdx];
1794 const int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(dofIdx);
1795 const auto rock_fraction = (1 - poro_eff) * this->referencePorosity_[/*timeIdx=*/0][sfcdofIdx] / poro_eff;
1796 this->rockFraction_[/*timeIdx=*/0][sfcdofIdx] = rock_fraction;
1797 }
1798 }
1799
1801 {
1802 // TODO: whether we should move this to FlowProblemBlackoil
1803 const auto& simulator = this->simulator();
1804 const auto& vanguard = simulator.vanguard();
1805 const auto& eclState = vanguard.eclState();
1806
1807 if (eclState.getInitConfig().hasEquil())
1808 readEquilInitialCondition_();
1809 else
1810 readExplicitInitialCondition_();
1811
1812 //initialize min/max values
1813 std::size_t numElems = this->model().numGridDof();
1814 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1815 const auto& fs = asImp_().initialFluidStates()[elemIdx];
1816 if (!this->maxWaterSaturation_.empty() && waterPhaseIdx > -1)
1817 this->maxWaterSaturation_[elemIdx] = std::max(this->maxWaterSaturation_[elemIdx], fs.saturation(waterPhaseIdx));
1818 if (!this->maxOilSaturation_.empty() && oilPhaseIdx > -1)
1819 this->maxOilSaturation_[elemIdx] = std::max(this->maxOilSaturation_[elemIdx], fs.saturation(oilPhaseIdx));
1820 if (!this->minRefPressure_.empty() && refPressurePhaseIdx_() > -1)
1821 this->minRefPressure_[elemIdx] = std::min(this->minRefPressure_[elemIdx], fs.pressure(refPressurePhaseIdx_()));
1822 }
1823 }
1824
1825 virtual void readEquilInitialCondition_() = 0;
1827
1828 // update the hysteresis parameters of the material laws for the whole grid
1830 {
1831 if (!materialLawManager_->enableHysteresis())
1832 return false;
1833
1834 // we need to update the hysteresis data for _all_ elements (i.e., not just the
1835 // interior ones) to avoid desynchronization of the processes in the parallel case!
1836 this->updateProperty_("FlowProblem::updateHysteresis_() failed:",
1837 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1838 {
1839 materialLawManager_->updateHysteresis(iq.fluidState(), compressedDofIdx);
1840 });
1841 return true;
1842 }
1843
1844
1845 bool updateHysteresis_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1846 {
1847 OPM_TIMEBLOCK_LOCAL(updateHysteresis_, Subsystem::SatProps);
1848 materialLawManager_->updateHysteresis(iq.fluidState(), compressedDofIdx);
1849 //TODO change materials to give a bool
1850 return true;
1851 }
1852
1853 Scalar getRockCompTransMultVal(std::size_t dofIdx) const
1854 {
1855 if (this->rockCompTransMultVal_.empty())
1856 return 1.0;
1857
1858 return this->rockCompTransMultVal_[dofIdx];
1859 }
1860
1861protected:
1870 void initGravity_(const EclipseState& eclState)
1871 {
1872 this->gravity_ = 0.0;
1873
1874 if (Parameters::Get<Parameters::EnableGravity>() &&
1875 eclState.getInitConfig().hasGravity())
1876 {
1877 // unit::gravity is 9.80665 m^2/s--i.e., standard measure at Tellus equator.
1878 this->gravity_[dim - 1] = unit::gravity;
1879 }
1880 }
1881
1883 {
1884 ConditionalStorage<enableFullyImplicitThermal, Scalar> thermalHalfTransIn;
1885 ConditionalStorage<enableFullyImplicitThermal, Scalar> thermalHalfTransOut;
1886 ConditionalStorage<enableDiffusion, Scalar> diffusivity;
1887 ConditionalStorage<enableDispersion, Scalar> dispersivity;
1889 };
1890
1891 // update the prefetch friendly data object
1893 {
1894 const auto& distFn =
1895 [this](PffDofData_& dofData,
1896 const Stencil& stencil,
1897 unsigned localDofIdx)
1898 -> void
1899 {
1900 const auto& elementMapper = this->model().elementMapper();
1901
1902 unsigned globalElemIdx = elementMapper.index(stencil.entity(localDofIdx));
1903 if (localDofIdx != 0) {
1904 unsigned globalCenterElemIdx = elementMapper.index(stencil.entity(/*dofIdx=*/0));
1905 dofData.transmissibility = transmissibilities_.transmissibility(globalCenterElemIdx, globalElemIdx);
1906
1907 if constexpr (enableFullyImplicitThermal) {
1908 *dofData.thermalHalfTransIn = transmissibilities_.thermalHalfTrans(globalCenterElemIdx, globalElemIdx);
1909 *dofData.thermalHalfTransOut = transmissibilities_.thermalHalfTrans(globalElemIdx, globalCenterElemIdx);
1910 }
1911 if constexpr (enableDiffusion)
1912 *dofData.diffusivity = transmissibilities_.diffusivity(globalCenterElemIdx, globalElemIdx);
1913 if (enableDispersion)
1914 dofData.dispersivity = transmissibilities_.dispersivity(globalCenterElemIdx, globalElemIdx);
1915 }
1916 };
1917
1918 pffDofData_.update(distFn);
1919 }
1920
1921 virtual void updateExplicitQuantities_(int episodeIdx, int timeStepSize, bool first_step_after_restart) = 0;
1922
1924 {
1925 const auto& simulator = this->simulator();
1926 const auto& vanguard = simulator.vanguard();
1927 const auto& bcconfig = vanguard.eclState().getSimulationConfig().bcconfig();
1928 if (bcconfig.size() > 0) {
1929 nonTrivialBoundaryConditions_ = true;
1930
1931 std::size_t numCartDof = vanguard.cartesianSize();
1932 unsigned numElems = vanguard.gridView().size(/*codim=*/0);
1933 std::vector<int> cartesianToCompressedElemIdx(numCartDof, -1);
1934
1935 for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx)
1936 cartesianToCompressedElemIdx[vanguard.cartesianIndex(elemIdx)] = elemIdx;
1937
1938 bcindex_.resize(numElems, 0);
1939 auto loopAndApply = [&cartesianToCompressedElemIdx,
1940 &vanguard](const auto& bcface,
1941 auto apply)
1942 {
1943 for (int i = bcface.i1; i <= bcface.i2; ++i) {
1944 for (int j = bcface.j1; j <= bcface.j2; ++j) {
1945 for (int k = bcface.k1; k <= bcface.k2; ++k) {
1946 std::array<int, 3> tmp = {i,j,k};
1947 auto elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
1948 if (elemIdx >= 0)
1949 apply(elemIdx);
1950 }
1951 }
1952 }
1953 };
1954 for (const auto& bcface : bcconfig) {
1955 std::vector<int>& data = bcindex_(bcface.dir);
1956 const int index = bcface.index;
1957 loopAndApply(bcface,
1958 [&data,index](int elemIdx)
1959 { data[elemIdx] = index; });
1960 }
1961 }
1962 }
1963
1964 // this method applies the runtime constraints specified via the deck and/or command
1965 // line parameters for the size of the next time step.
1967 {
1968 if constexpr (enableExperiments) {
1969 const auto& simulator = this->simulator();
1970 const auto& schedule = simulator.vanguard().schedule();
1971 int episodeIdx = simulator.episodeIndex();
1972
1973 // first thing in the morning, limit the time step size to the maximum size
1974 Scalar maxTimeStepSize = Parameters::Get<Parameters::SolverMaxTimeStepInDays<Scalar>>() * 24 * 60 * 60;
1975 int reportStepIdx = std::max(episodeIdx, 0);
1976 if (this->enableTuning_) {
1977 const auto& tuning = schedule[reportStepIdx].tuning();
1978 maxTimeStepSize = tuning.TSMAXZ;
1979 }
1980
1981 dtNext = std::min(dtNext, maxTimeStepSize);
1982
1983 Scalar remainingEpisodeTime =
1984 simulator.episodeStartTime() + simulator.episodeLength()
1985 - (simulator.startTime() + simulator.time());
1986 assert(remainingEpisodeTime >= 0.0);
1987
1988 // if we would have a small amount of time left over in the current episode, make
1989 // two equal time steps instead of a big and a small one
1990 if (remainingEpisodeTime/2.0 < dtNext && dtNext < remainingEpisodeTime*(1.0 - 1e-5))
1991 // note: limiting to the maximum time step size here is probably not strictly
1992 // necessary, but it should not hurt and is more fool-proof
1993 dtNext = std::min(maxTimeStepSize, remainingEpisodeTime/2.0);
1994
1995 if (simulator.episodeStarts()) {
1996 // if a well event occurred, respect the limit for the maximum time step after
1997 // that, too
1998 const auto& events = simulator.vanguard().schedule()[reportStepIdx].events();
1999 bool wellEventOccured =
2000 events.hasEvent(ScheduleEvents::NEW_WELL)
2001 || events.hasEvent(ScheduleEvents::PRODUCTION_UPDATE)
2002 || events.hasEvent(ScheduleEvents::INJECTION_UPDATE)
2003 || events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE);
2004 if (episodeIdx >= 0 && wellEventOccured && this->maxTimeStepAfterWellEvent_ > 0)
2005 dtNext = std::min(dtNext, this->maxTimeStepAfterWellEvent_);
2006 }
2007 }
2008
2009 return dtNext;
2010 }
2011
2013 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
2014 return oilPhaseIdx;
2015 }
2016 else if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
2017 return gasPhaseIdx;
2018 }
2019 else {
2020 return waterPhaseIdx;
2021 }
2022 }
2023
2025 {
2026 const auto& model = this->simulator().model();
2027 std::size_t numGridDof = this->model().numGridDof();
2028 this->rockCompTransMultVal_.resize(numGridDof, 1.0);
2029 for (std::size_t elementIdx = 0; elementIdx < numGridDof; ++elementIdx) {
2030 const auto& iq = model.intensiveQuantities(elementIdx, /*timeIdx=*/ 0);
2031 Scalar trans_mult = computeRockCompTransMultiplier_<Scalar>(iq, elementIdx);
2032 this->rockCompTransMultVal_[elementIdx] = trans_mult;
2033 }
2034 }
2035
2041 template <class LhsEval>
2042 LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities& intQuants, unsigned elementIdx) const
2043 {
2044 auto obtain = [](const auto& value)
2045 {
2046 if constexpr (std::is_same_v<LhsEval, Scalar>) {
2047 return getValue(value);
2048 } else {
2049 return value;
2050 }
2051 };
2052
2053 return computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain);
2054 }
2055
2056 template <class LhsEval, class Callback>
2057 LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
2058 {
2059 OPM_TIMEBLOCK_LOCAL(computeRockCompTransMultiplier, Subsystem::PvtProps);
2060 if (this->rockCompTransMult_.empty() && this->rockCompTransMultWc_.empty())
2061 return 1.0;
2062
2063 unsigned tableIdx = 0;
2064 if (!this->rockTableIdx_.empty())
2065 tableIdx = this->rockTableIdx_[elementIdx];
2066
2067 const auto& fs = intQuants.fluidState();
2068 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
2069
2070 if (!this->rockCompTransMultElastic_.empty()) {
2071 // ROCKCOMP HYSTERESIS=HYSTER: see rockCompPoroMultiplier() above.
2072 LhsEval effectivePressure = obtain(fs.pressure(refPressurePhaseIdx_()));
2073 LhsEval turningPressure = this->minRefPressure_[elementIdx];
2074
2075 if (!this->overburdenPressure_.empty()) {
2076 effectivePressure -= this->overburdenPressure_[elementIdx];
2077 turningPressure -= this->overburdenPressure_[elementIdx];
2078 }
2079
2080 if (rock_config.store()) {
2081 const auto& initialPressure = asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
2082 effectivePressure -= initialPressure;
2083 turningPressure -= initialPressure;
2084 }
2085
2086 if (effectivePressure <= turningPressure)
2087 return this->rockCompTransMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
2088
2089 return this->rockCompTransMultElastic_[tableIdx].eval(turningPressure, effectivePressure, /*extrapolation=*/true);
2090 }
2091
2092 LhsEval effectivePressure = obtain(fs.pressure(refPressurePhaseIdx_()));
2093 if (!this->minRefPressure_.empty())
2094 // The pore space change is irreversible
2095 effectivePressure =
2096 min(obtain(fs.pressure(refPressurePhaseIdx_())),
2097 this->minRefPressure_[elementIdx]);
2098
2099 if (!this->overburdenPressure_.empty())
2100 effectivePressure -= this->overburdenPressure_[elementIdx];
2101
2102 if (rock_config.store()) {
2103 effectivePressure -= asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
2104 }
2105
2106 if (!this->rockCompTransMult_.empty())
2107 return this->rockCompTransMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
2108
2109 // water compaction
2110 assert(!this->rockCompTransMultWc_.empty());
2111 LhsEval SwMax = max(obtain(fs.saturation(waterPhaseIdx)), this->maxWaterSaturation_[elementIdx]);
2112 LhsEval SwDeltaMax = SwMax - asImp_().initialFluidStates()[elementIdx].saturation(waterPhaseIdx);
2113
2114 return this->rockCompTransMultWc_[tableIdx].eval(effectivePressure, SwDeltaMax, /*extrapolation=*/true);
2115 }
2116
2117 typename Vanguard::TransmissibilityType transmissibilities_;
2118
2119 std::shared_ptr<EclMaterialLawManager> materialLawManager_;
2120 std::shared_ptr<EclThermalLawManager> thermalLawManager_;
2121
2123
2126
2130
2133
2134 template<class T>
2135 struct BCData
2136 {
2137 std::array<std::vector<T>,6> data;
2138
2139 void resize(std::size_t size, T defVal)
2140 {
2141 for (auto& d : data)
2142 d.resize(size, defVal);
2143 }
2144
2145 const std::vector<T>& operator()(FaceDir::DirEnum dir) const
2146 {
2147 if (dir == FaceDir::DirEnum::Unknown)
2148 throw std::runtime_error("Tried to access BC data for the 'Unknown' direction");
2149 int idx = 0;
2150 int div = static_cast<int>(dir);
2151 while ((div /= 2) >= 1)
2152 ++idx;
2153 assert(idx >= 0 && idx <= 5);
2154 return data[idx];
2155 }
2156
2157 std::vector<T>& operator()(FaceDir::DirEnum dir)
2158 {
2159 return const_cast<std::vector<T>&>(std::as_const(*this)(dir));
2160 }
2161 };
2162
2163 virtual void handleSolventBC(const BCState::BCFace&, RateVector&) const = 0;
2164
2165 virtual void handlePolymerBC(const BCState::BCFace&, RateVector&) const = 0;
2166
2167 virtual void handleMicrBC(const BCState::BCFace&, RateVector&) const = 0;
2168
2169 virtual void handleOxygBC(const BCState::BCFace&, RateVector&) const = 0;
2170
2171 virtual void handleUreaBC(const BCState::BCFace&, RateVector&) const = 0;
2172
2174 bool nonTrivialBoundaryConditions_ = false;
2175 bool first_step_ = true;
2176 bool enable_state_rollback_ = false;
2177
2185 {
2186 bool first_step = true;
2187 std::vector<Scalar> max_polymer_adsorption;
2188 std::vector<Scalar> max_oil_saturation;
2189 std::vector<Scalar> max_water_saturation;
2190 std::vector<Scalar> min_ref_pressure;
2191 std::vector<Scalar> rock_comp_trans_mult_val;
2192 };
2193
2195
2198 virtual bool episodeWillBeOver() const
2199 {
2200 return this->simulator().episodeWillBeOver();
2201 }
2202};
2203
2204} // namespace Opm
2205
2206#endif // OPM_FLOW_PROBLEM_HPP
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:197
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:160
Classes required for dynamic convective mixing.
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 rockBiotTemp(unsigned elementIdx) const
Returns the rock compressibility of an element due to thermoelasticity.
Definition: FlowGenericProblem_impl.hpp:428
std::array< std::vector< Scalar >, 2 > rockFraction_
Definition: FlowGenericProblem.hpp:368
std::vector< TabulatedTwoDFunction > rockCompPoroMultWc_
Definition: FlowGenericProblem.hpp:377
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
unsigned miscnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant MISC region given a cell index.
Definition: FlowGenericProblem_impl.hpp:950
unsigned satnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant saturation function region given a cell index.
Definition: FlowGenericProblem_impl.hpp:940
Scalar lame(unsigned elementIdx) const
Direct access to Lame's second parameter in an element.
Definition: FlowGenericProblem_impl.hpp:440
void beginTimeStep_(bool enableExperiments, int episodeIdx, int timeStepIndex, Scalar startTime, Scalar time, Scalar timeStepSize, Scalar endTime)
Definition: FlowGenericProblem_impl.hpp:666
std::vector< TabulatedTwoDFunction > rockCompPoroMultElastic_
Definition: FlowGenericProblem.hpp:385
unsigned plmixnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant PLMIXNUM (for polymer module) region given a cell index.
Definition: FlowGenericProblem_impl.hpp:960
void readRockParameters_(const std::vector< Scalar > &cellCenterDepths, std::function< std::array< int, 3 >(const unsigned)> ijkIndex)
Definition: FlowGenericProblem_impl.hpp:156
std::array< std::vector< Scalar >, 2 > referencePorosity_
Definition: FlowGenericProblem.hpp:367
Scalar rockBiotComp(unsigned elementIdx) const
Returns the rock compressibility of an element due to poroelasticity.
Definition: FlowGenericProblem_impl.hpp:417
bool beginEpisode_(bool enableExperiments, int episodeIdx)
Definition: FlowGenericProblem_impl.hpp:629
bool shouldWriteOutput() const
Always returns true. The ecl output writer takes care of the rest.
Definition: FlowGenericProblem.hpp:320
static std::string helpPreamble(int, const char **argv)
Definition: FlowGenericProblem_impl.hpp:134
Scalar biotTemp(unsigned elementIdx) const
Direct access to Biot temperature coefficient in an element.
Definition: FlowGenericProblem_impl.hpp:492
bool shouldWriteRestartFile() const
Returns true if an eWoms restart file should be written to disk.
Definition: FlowGenericProblem.hpp:329
Scalar biotCoeff(unsigned elementIdx) const
Direct access to Biot coefficient in an element.
Definition: FlowGenericProblem_impl.hpp:471
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:101
virtual bool episodeWillBeOver() const
Definition: FlowProblem.hpp:2198
const WellModel & wellModel() const
Returns a reference to the ECL well manager used by the problem.
Definition: FlowProblem.hpp:1156
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:166
Scalar transmissibility(unsigned globalCenterElemIdx, unsigned globalElemIdx) const
Direct access to the transmissibility between two elements.
Definition: FlowProblem.hpp:594
static constexpr bool enableFoam
Definition: FlowProblem.hpp:132
Scalar thresholdPressure(unsigned elem1Idx, unsigned elem2Idx) const
Threshold pressure [Pa] for the intersection between two elements.
Definition: FlowProblem.hpp:602
static int handlePositionalParameter(std::function< void(const std::string &, const std::string &)> addKey, std::set< std::string > &seenParams, std::string &errorMsg, int, const char **argv, int paramIdx, int)
Handles positional command line parameters.
Definition: FlowProblem.hpp:216
bool nonTrivialBoundaryConditions() const
Definition: FlowProblem.hpp:1168
const GlobalEqVector & drift() const
Definition: FlowProblem.hpp:1384
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:546
virtual void handleOxygBC(const BCState::BCFace &, RateVector &) const =0
std::function< std::vector< IntType >(const FieldPropsManager &, const std::string &, bool)> fieldPropIntTypeOnLeafAssigner_()
Definition: FlowProblem.hpp:1675
const DimMatrix & intrinsicPermeability(unsigned globalElemIdx) const
This method returns the intrinsic permeability tensor given a global element index.
Definition: FlowProblem.hpp:576
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:964
LhsEval wellTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:1296
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:744
virtual void handlePolymerBC(const BCState::BCFace &, RateVector &) const =0
void beginIteration()
Called by the simulator before each Newton-Raphson iteration.
Definition: FlowProblem.hpp:444
virtual void restoreBeginTimeStepState_()
Put the explicit quantities back as they were before the step.
Definition: FlowProblem.hpp:1417
int boundaryConditionIndex(const unsigned int globalSpaceIdx, const int directionId) const
Index of the BCCON region applied to the given face of a cell, 0 if none.
Definition: FlowProblem.hpp:1309
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:114
GetPropType< TypeTag, Properties::DofMapper > DofMapper
Definition: FlowProblem.hpp:165
Scalar rockBiotComp(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:788
@ numComponents
Definition: FlowProblem.hpp:124
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:108
typename EclThermalLawManager::SolidEnergyLawParams SolidEnergyLawParams
Definition: FlowProblem.hpp:162
bool updateHysteresis_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1845
GetPropType< TypeTag, Properties::BaseProblem > ParentType
Definition: FlowProblem.hpp:105
void initGravity_(const EclipseState &eclState)
Set the gravity vector from the run's configuration.
Definition: FlowProblem.hpp:1870
GetPropType< TypeTag, Properties::EqVector > EqVector
Definition: FlowProblem.hpp:113
unsigned satnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:972
virtual void updateExplicitQuantities_(int episodeIdx, int timeStepSize, bool first_step_after_restart)=0
Scalar thermalHalfTransmissibilityOut(const Context &context, unsigned faceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:699
bool first_step_
Definition: FlowProblem.hpp:2175
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: FlowProblem.hpp:158
const ThermalConductionLawParams & thermalConductionLawParams(unsigned globalSpaceIdx, unsigned) const
Definition: FlowProblem.hpp:1039
AquiferModel aquiferModel_
Definition: FlowProblem.hpp:2125
GlobalEqVector drift_
Definition: FlowProblem.hpp:2122
bool updateMinPressure_()
Definition: FlowProblem.hpp:1627
EclMaterialLawManager & materialLawManager()
Definition: FlowProblem.hpp:956
std::function< std::vector< double >(const FieldPropsManager &, const std::string &)> fieldPropDoubleOnLeafAssigner_()
Definition: FlowProblem.hpp:1660
virtual void handleSolventBC(const BCState::BCFace &, RateVector &) const =0
@ gasCompIdx
Definition: FlowProblem.hpp:150
Scalar transmissibilityBoundary(const Context &elemCtx, unsigned boundaryFaceIdx) const
Definition: FlowProblem.hpp:656
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:155
void updateReferencePorosity_()
Definition: FlowProblem.hpp:1741
Scalar thermalHalfTransmissibility(const unsigned globalSpaceIdxIn, const unsigned globalSpaceIdxOut) const
Definition: FlowProblem.hpp:676
LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:2057
BCData< int > bcindex_
Definition: FlowProblem.hpp:2173
GetPropType< TypeTag, Properties::TracerModel > TracerModel
Definition: FlowProblem.hpp:175
Scalar rockCompressibility(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:778
bool updateMaxWaterSaturation_()
Definition: FlowProblem.hpp:1597
virtual void handleUreaBC(const BCState::BCFace &, RateVector &) const =0
FlowThresholdPressure< TypeTag > thresholdPressures_
Definition: FlowProblem.hpp:2131
Dune::FieldMatrix< Scalar, dimWorld, dimWorld > DimMatrix
Definition: FlowProblem.hpp:172
@ waterPhaseIdx
Definition: FlowProblem.hpp:146
void advanceTimeLevel()
Called by the simulator to accept the current state as the new time level after a successful timestep...
Definition: FlowProblem.hpp:435
Scalar maxOilSaturation(unsigned globalDofIdx) const
Returns an element's historic maximum oil phase saturation that was observed during the simulation.
Definition: FlowProblem.hpp:1054
bool updateMinPressure_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1642
std::string name() const
The problem name.
Definition: FlowProblem.hpp:1003
int episodeIndex() const
Definition: FlowProblem.hpp:317
Scalar biotTemp(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:828
LhsEval rockCompTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the transmissibility multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:1274
void endIteration()
Called by the simulator after each Newton-Raphson iteration.
Definition: FlowProblem.hpp:454
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:115
const EclMaterialLawManager & materialLawManager() const
Returns the ECL material law manager.
Definition: FlowProblem.hpp:916
FlowProblem(Simulator &simulator)
Definition: FlowProblem.hpp:235
ModuleParams moduleParams_
Definition: FlowProblem.hpp:2132
@ enableFullyImplicitThermal
Definition: FlowProblem.hpp:138
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: FlowProblem.hpp:112
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:156
const Vanguard::TransmissibilityType & eclTransmissibilities() const
Return a reference to the object that handles the "raw" transmissibilities.
Definition: FlowProblem.hpp:722
void source(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:1124
@ enableExperiments
Definition: FlowProblem.hpp:139
virtual void readEquilInitialCondition_()=0
Scalar nextTimeStepSize() const
Propose the size of the next time step to the simulator.
Definition: FlowProblem.hpp:1177
LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the transmissibility multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:2042
std::pair< BCType, RateVector > boundaryCondition(const unsigned int globalSpaceIdx, const int directionId) const
Definition: FlowProblem.hpp:1317
typename EclMaterialLawManager::MaterialLawParams MaterialLawParams
Definition: FlowProblem.hpp:161
static constexpr bool enableDiffusion
Definition: FlowProblem.hpp:129
virtual ~FlowProblem()=default
PffGridVector< GridView, Stencil, PffDofData_, DofMapper > pffDofData_
Definition: FlowProblem.hpp:2127
@ dimWorld
Definition: FlowProblem.hpp:119
const FlowThresholdPressure< TypeTag > & thresholdPressure() const
Definition: FlowProblem.hpp:605
const ThermalConductionLawParams & thermalConductionLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:904
Scalar transmissibility(const Context &context, unsigned fromDofLocalIdx, unsigned toDofLocalIdx) const
Definition: FlowProblem.hpp:583
TracerModel tracerModel_
Definition: FlowProblem.hpp:2128
@ enableThermalFluxBoundaries
Definition: FlowProblem.hpp:142
const TracerModel & tracerModel() const
Definition: FlowProblem.hpp:726
WellModel wellModel_
Definition: FlowProblem.hpp:2124
virtual void beginEpisode()
Called by the simulator before an episode begins.
Definition: FlowProblem.hpp:325
const SolidEnergyLawParams & solidEnergyLawParams(unsigned globalSpaceIdx, unsigned) const
Definition: FlowProblem.hpp:1033
virtual void captureBeginTimeStepState_()
Snapshot the explicit quantities before the timestep runs.
Definition: FlowProblem.hpp:1403
static constexpr bool enablePolymerMolarWeight
Definition: FlowProblem.hpp:134
Scalar getRockCompTransMultVal(std::size_t dofIdx) const
Definition: FlowProblem.hpp:1853
virtual void beginTimeStep()
Called by the simulator before each time integration.
Definition: FlowProblem.hpp:384
@ gasPhaseIdx
Definition: FlowProblem.hpp:144
Scalar dofCenterDepth(unsigned globalSpaceIdx) const
Direct indexed acces to the depth of an degree of freedom [m].
Definition: FlowProblem.hpp:769
typename GetProp< TypeTag, Properties::MaterialLaw >::EclMaterialLawManager EclMaterialLawManager
Definition: FlowProblem.hpp:159
static constexpr bool enableSolvent
Definition: FlowProblem.hpp:135
const MaterialLawParams & materialLawParams(unsigned globalDofIdx, FaceDir::DirEnum facedir) const
Definition: FlowProblem.hpp:881
unsigned plmixnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:988
const MaterialLawParams & materialLawParams(unsigned globalDofIdx) const
Definition: FlowProblem.hpp:876
Scalar temperature(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:1010
Scalar thermalHalfTransmissibilityBoundary(const Context &elemCtx, unsigned boundaryFaceIdx) const
Definition: FlowProblem.hpp:712
unsigned miscnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:980
void updateRockCompTransMultVal_()
Definition: FlowProblem.hpp:2024
@ numPhases
Definition: FlowProblem.hpp:123
std::shared_ptr< EclThermalLawManager > thermalLawManager_
Definition: FlowProblem.hpp:2120
Scalar limitNextTimeStepSize_(Scalar dtNext) const
Definition: FlowProblem.hpp:1966
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1430
GetPropType< TypeTag, Properties::Stencil > Stencil
Definition: FlowProblem.hpp:110
typename GetProp< TypeTag, Properties::SolidEnergyLaw >::EclThermalLawManager EclThermalLawManager
Definition: FlowProblem.hpp:160
FlowThresholdPressure< TypeTag > & thresholdPressure()
Definition: FlowProblem.hpp:608
virtual void readExplicitInitialCondition_()=0
static constexpr bool enablePolymer
Definition: FlowProblem.hpp:133
GetPropType< TypeTag, Properties::WellModel > WellModel
Definition: FlowProblem.hpp:168
@ numEq
Definition: FlowProblem.hpp:122
const DimMatrix & intrinsicPermeability(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:562
PrevTimestepState prev_timestep_state_
Definition: FlowProblem.hpp:2194
void updateFailed()
Called by the simulator to restore the state captured at the beginning of the timestep after a failed...
Definition: FlowProblem.hpp:422
bool updateHysteresis_()
Definition: FlowProblem.hpp:1829
void readThermalParameters_()
Definition: FlowProblem.hpp:1724
void serializeOp(Serializer &serializer)
Definition: FlowProblem.hpp:1372
Scalar maxPolymerAdsorption(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the max polymer adsorption value.
Definition: FlowProblem.hpp:997
Scalar thermalHalfTransmissibilityIn(const Context &context, unsigned faceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:686
void setMaxOilSaturation(unsigned globalDofIdx, Scalar value)
Sets an element's maximum oil phase saturation observed during the simulation.
Definition: FlowProblem.hpp:1071
const SolidEnergyLawParams & solidEnergyLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Return the parameters for the energy storage law of the rock.
Definition: FlowProblem.hpp:891
typename EclThermalLawManager::ThermalConductionLawParams ThermalConductionLawParams
Definition: FlowProblem.hpp:163
Scalar dispersivity(const unsigned globalCellIn, const unsigned globalCellOut) const
Definition: FlowProblem.hpp:636
AquiferModel & mutableAquiferModel()
Definition: FlowProblem.hpp:1165
@ dim
Definition: FlowProblem.hpp:118
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: FlowProblem.hpp:167
Scalar temperature(unsigned globalDofIdx, unsigned) const
Definition: FlowProblem.hpp:1022
Scalar lame(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:808
Scalar rockBiotTemp(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:798
@ enableSaltPrecipitation
Definition: FlowProblem.hpp:141
GetPropType< TypeTag, Properties::AquiferModel > AquiferModel
Definition: FlowProblem.hpp:169
TemperatureModel temperatureModel_
Definition: FlowProblem.hpp:2129
static constexpr bool enableExtbo
Definition: FlowProblem.hpp:131
std::shared_ptr< EclMaterialLawManager > materialLawManager_
Definition: FlowProblem.hpp:2119
WellModel & wellModel()
Definition: FlowProblem.hpp:1159
const ModuleParams & moduleParams() const
Definition: FlowProblem.hpp:611
static constexpr bool enableConvectiveMixing
Definition: FlowProblem.hpp:128
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:109
GetPropType< TypeTag, Properties::TemperatureModel > TemperatureModel
Definition: FlowProblem.hpp:174
void updateProperty_(const std::string &failureMsg, UpdateFunc func)
Definition: FlowProblem.hpp:1546
bool prepareTransmissibilityOutput_(EclWriterType &eclWriter, const bool enableEclOutput)
Definition: FlowProblem.hpp:1439
LhsEval rockCompTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:1288
@ oilCompIdx
Definition: FlowProblem.hpp:151
void initializeSimulatorTime_()
Definition: FlowProblem.hpp:1498
bool updateMaxOilSaturation_()
Definition: FlowProblem.hpp:1565
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:200
void updatePffDofData_()
Definition: FlowProblem.hpp:1892
static constexpr bool enableDispersion
Definition: FlowProblem.hpp:130
virtual void endEpisode()
Called by the simulator after the end of an episode.
Definition: FlowProblem.hpp:523
@ oilPhaseIdx
Definition: FlowProblem.hpp:145
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:154
bool nonTrivialBoundaryConditions_
Definition: FlowProblem.hpp:2174
GetPropType< TypeTag, Properties::Problem > Implementation
Definition: FlowProblem.hpp:106
void readBoundaryConditions_()
Definition: FlowProblem.hpp:1923
void updateRelperms(std::array< Evaluation, numPhases > &mobility, DirectionalMobilityPtr &dirMob, FluidState &fluidState, unsigned globalSpaceIdx) const
Definition: FlowProblem.hpp:923
Vanguard::TransmissibilityType transmissibilities_
Definition: FlowProblem.hpp:2117
void source(RateVector &rate, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the source term for all phases within a given sub-control-volume.
Definition: FlowProblem.hpp:1115
virtual void addToSourceDense(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const =0
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:464
TemperatureModel & temperatureModel()
Definition: FlowProblem.hpp:732
Utility::CopyablePtr< DirectionalMobility< TypeTag > > DirectionalMobilityPtr
Definition: FlowProblem.hpp:176
virtual void readInitialCondition_()
Definition: FlowProblem.hpp:1800
virtual void initialSolutionApplied()
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblem.hpp:1082
const MaterialLawParams & materialLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:869
Scalar thermalTransmissibilityBoundary(const unsigned globalSpaceIdx, const unsigned boundaryFaceIdx) const
Direct access to a boundary transmissibility.
Definition: FlowProblem.hpp:643
static constexpr EnergyModules energyModuleType
Definition: FlowProblem.hpp:137
Scalar diffusivity(const Context &context, unsigned fromDofLocalIdx, unsigned toDofLocalIdx) const
Definition: FlowProblem.hpp:618
Scalar rockReferencePressure(unsigned globalSpaceIdx) const
Definition: FlowProblem.hpp:847
std::string extraTrailerSummary() const
Definition: FlowProblem.hpp:183
void deserialize(Restarter &res)
This method restores the complete state of the problem and its sub-objects from disk.
Definition: FlowProblem.hpp:291
bool enable_state_rollback_
Definition: FlowProblem.hpp:2176
Scalar biotCoeff(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:818
std::shared_ptr< const EclThermalLawManager > thermalLawManager() const
Definition: FlowProblem.hpp:919
bool updateMaxWaterSaturation_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1613
typename GridView::template Codim< 0 >::Entity Element
Definition: FlowProblem.hpp:157
Scalar dofCenterDepth(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the depth of an degree of freedom [m].
Definition: FlowProblem.hpp:757
bool updateMaxOilSaturation_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1583
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:111
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:164
const AquiferModel & aquiferModel() const
Definition: FlowProblem.hpp:1162
void initializeModelProperties_()
Definition: FlowProblem.hpp:1522
int refPressurePhaseIdx_() const
Definition: FlowProblem.hpp:2012
static constexpr bool enableBioeffects
Definition: FlowProblem.hpp:126
LhsEval rockCompPoroMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the porosity multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:1204
Scalar transmissibilityBoundary(const unsigned globalSpaceIdx, const unsigned boundaryFaceIdx) const
Direct access to a boundary transmissibility.
Definition: FlowProblem.hpp:666
TracerModel & tracerModel()
Definition: FlowProblem.hpp:729
void readMaterialParameters_()
Definition: FlowProblem.hpp:1684
static constexpr bool enableBrine
Definition: FlowProblem.hpp:127
void serialize(Restarter &res)
This method writes the complete state of the problem and its subobjects to disk.
Definition: FlowProblem.hpp:310
MathToolbox< Evaluation > Toolbox
Definition: FlowProblem.hpp:171
@ waterCompIdx
Definition: FlowProblem.hpp:152
virtual void handleMicrBC(const BCState::BCFace &, RateVector &) const =0
Scalar rockReferencePressure(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:838
Scalar diffusivity(const unsigned globalCellIn, const unsigned globalCellOut) const
Definition: FlowProblem.hpp:629
@ enableMICP
Definition: FlowProblem.hpp:140
void updateRockFraction_()
Definition: FlowProblem.hpp:1766
void prefetch(const Element &elem) const
Definition: FlowProblem.hpp:276
This class calculates the threshold pressure for grid faces according to the Eclipse Reference Manual...
Definition: FlowThresholdPressure.hpp:59
A random-access container which stores data attached to a grid's degrees of freedom in a prefetch fri...
Definition: pffgridvector.hh:50
Definition: RelpermDiagnostics.hpp:51
void diagnosis(const EclipseState &eclState, const LevelCartesianIndexMapper &levelCartesianIndexMapper)
This file contains definitions related to directional mobilities.
@ NONE
Definition: DeferredLogger.hpp:46
auto Get(bool errorIfNotRegistered=true)
Retrieve a runtime parameter.
Definition: parametersystem.hpp:198
static constexpr int dim
Definition: structuredgridvanguard.hh:68
int eclPositionalParameter(std::function< void(const std::string &, const std::string &)> addKey, std::set< std::string > &seenParams, std::string &errorMsg, const char **argv, int paramIdx)
Definition: blackoilbioeffectsmodules.hh:45
GatheredLgrOutputTrans gatherLgrOutputTrans(const Dune::CpGrid &grid, const GridView &gridView, TransFn &&transFn)
Definition: LgrOutputTransGather.hpp:118
void eclBroadcast(Parallel::Communication, T &)
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:224
bool saturationWeightedDensity
Definition: blackoilmoduleparams.hh:27
Definition: FlowProblem.hpp:2136
const std::vector< T > & operator()(FaceDir::DirEnum dir) const
Definition: FlowProblem.hpp:2145
void resize(std::size_t size, T defVal)
Definition: FlowProblem.hpp:2139
std::vector< T > & operator()(FaceDir::DirEnum dir)
Definition: FlowProblem.hpp:2157
std::array< std::vector< T >, 6 > data
Definition: FlowProblem.hpp:2137
Definition: FlowProblem.hpp:1883
ConditionalStorage< enableFullyImplicitThermal, Scalar > thermalHalfTransOut
Definition: FlowProblem.hpp:1885
ConditionalStorage< enableFullyImplicitThermal, Scalar > thermalHalfTransIn
Definition: FlowProblem.hpp:1884
ConditionalStorage< enableDiffusion, Scalar > diffusivity
Definition: FlowProblem.hpp:1886
ConditionalStorage< enableDispersion, Scalar > dispersivity
Definition: FlowProblem.hpp:1887
Scalar transmissibility
Definition: FlowProblem.hpp:1888
Explicit quantities as they stood at the start of the current timestep, restored if that timestep fai...
Definition: FlowProblem.hpp:2185
bool first_step
first step of the episode
Definition: FlowProblem.hpp:2186
std::vector< Scalar > min_ref_pressure
ROCKCOMP irreversible compaction.
Definition: FlowProblem.hpp:2190
std::vector< Scalar > rock_comp_trans_mult_val
ROCKCOMP transmissibility multiplier.
Definition: FlowProblem.hpp:2191
std::vector< Scalar > max_polymer_adsorption
POLYMER.
Definition: FlowProblem.hpp:2187
std::vector< Scalar > max_water_saturation
ROCKCOMP water-induced compaction.
Definition: FlowProblem.hpp:2189
std::vector< Scalar > max_oil_saturation
VAPPARS / DRSDT saturation history.
Definition: FlowProblem.hpp:2188