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
52
53#include <opm/output/eclipse/EclipseIO.hpp>
54
60// TODO: maybe we can name it FlowProblemProperties.hpp
68
72
73#include <opm/utility/CopyablePtr.hpp>
74
75#include <algorithm>
76#include <cstddef>
77#include <functional>
78#include <set>
79#include <stdexcept>
80#include <string>
81#include <vector>
82
83namespace Opm {
84
91template <class TypeTag>
92class FlowProblem : public GetPropType<TypeTag, Properties::BaseProblem>
93 , public FlowGenericProblem<GetPropType<TypeTag, Properties::GridView>,
94 GetPropType<TypeTag, Properties::FluidSystem>>
95{
96protected:
101
110
111 // Grid and world dimension
112 enum { dim = GridView::dimension };
113 enum { dimWorld = GridView::dimensionworld };
114
115 // copy some indices for convenience
116 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
117 enum { numPhases = FluidSystem::numPhases };
118 enum { numComponents = FluidSystem::numComponents };
119
120 static constexpr bool enableBioeffects = getPropValue<TypeTag, Properties::EnableBioeffects>();
121 static constexpr bool enableBrine = getPropValue<TypeTag, Properties::EnableBrine>();
122 static constexpr bool enableConvectiveMixing = getPropValue<TypeTag, Properties::EnableConvectiveMixing>();
123 static constexpr bool enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>();
124 static constexpr bool enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>();
125 static constexpr bool enableExtbo = getPropValue<TypeTag, Properties::EnableExtbo>();
126 static constexpr bool enableFoam = getPropValue<TypeTag, Properties::EnableFoam>();
127 static constexpr bool enablePolymer = getPropValue<TypeTag, Properties::EnablePolymer>();
128 static constexpr bool enablePolymerMolarWeight = getPropValue<TypeTag, Properties::EnablePolymerMW>();
129 static constexpr bool enableSolvent = getPropValue<TypeTag, Properties::EnableSolvent>();
130
131 static constexpr EnergyModules energyModuleType = getPropValue<TypeTag, Properties::EnergyModuleType>();
132 enum { enableFullyImplicitThermal = getPropValue<TypeTag, Properties::EnergyModuleType>() == EnergyModules::FullyImplicitThermal };
133 enum { enableExperiments = getPropValue<TypeTag, Properties::EnableExperiments>() };
134 enum { enableMICP = Indices::enableMICP };
135 enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
136 enum { enableThermalFluxBoundaries = getPropValue<TypeTag, Properties::EnableThermalFluxBoundaries>() };
137
138 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
139 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
140 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
141
142 // TODO: later, gasCompIdx, oilCompIdx and waterCompIdx should go to the FlowProblemBlackoil in the future
143 // we do not want them in the compositional setting
144 enum { gasCompIdx = FluidSystem::gasCompIdx };
145 enum { oilCompIdx = FluidSystem::oilCompIdx };
146 enum { waterCompIdx = FluidSystem::waterCompIdx };
147
151 using Element = typename GridView::template Codim<0>::Entity;
155 using MaterialLawParams = typename EclMaterialLawManager::MaterialLawParams;
156 using SolidEnergyLawParams = typename EclThermalLawManager::SolidEnergyLawParams;
157 using ThermalConductionLawParams = typename EclThermalLawManager::ThermalConductionLawParams;
164
165 using Toolbox = MathToolbox<Evaluation>;
166 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
167
170 using DirectionalMobilityPtr = Utility::CopyablePtr<DirectionalMobility<TypeTag>>;
171
172public:
178 using BaseType::lame;
181 using BaseType::porosity;
182
186 static void registerParameters()
187 {
188 ParentType::registerParameters();
189
190 registerFlowProblemParameters<Scalar>();
191 }
192
202 static int handlePositionalParameter(std::function<void(const std::string&,
203 const std::string&)> addKey,
204 std::set<std::string>& seenParams,
205 std::string& errorMsg,
206 int,
207 const char** argv,
208 int paramIdx,
209 int)
210 {
211 return detail::eclPositionalParameter(addKey,
212 seenParams,
213 errorMsg,
214 argv,
215 paramIdx);
216 }
217
221 explicit FlowProblem(Simulator& simulator)
222 : ParentType(simulator)
223 , BaseType(simulator.vanguard().eclState(),
224 simulator.vanguard().schedule(),
225 simulator.vanguard().gridView())
226 , transmissibilities_(simulator.vanguard().eclState(),
227 simulator.vanguard().gridView(),
228 simulator.vanguard().cartesianIndexMapper(),
229 simulator.vanguard().grid(),
230 simulator.vanguard().cellCentroids(),
231 (energyModuleType == EnergyModules::FullyImplicitThermal ||
232 energyModuleType == EnergyModules::SequentialImplicitThermal),
235 , wellModel_(simulator, this->iterationContext())
236 , aquiferModel_(simulator)
237 , pffDofData_(simulator.gridView(), this->elementMapper())
238 , tracerModel_(simulator)
239 , temperatureModel_(simulator)
240 {
241 if (! Parameters::Get<Parameters::CheckSatfuncConsistency>()) {
242 // User did not enable the "new" saturation function consistency
243 // check module. Run the original checker instead. This is a
244 // temporary measure.
245 RelpermDiagnostics relpermDiagnostics{};
246 relpermDiagnostics.diagnosis(simulator.vanguard().eclState(),
247 simulator.vanguard().levelCartesianIndexMapper());
248 }
249
250 if (energyModuleType == EnergyModules::SequentialImplicitThermal) {
251 this->enableDriftCompensationTemp_ = Parameters::Get<Parameters::EnableDriftCompensationTemp>();
252 }
253
254 }
255
256 virtual ~FlowProblem() = default;
257
258 void prefetch(const Element& elem) const
259 { this->pffDofData_.prefetch(elem); }
260
272 template <class Restarter>
273 void deserialize(Restarter& res)
274 {
275 // reload the current episode/report step from the deck
276 this->beginEpisode();
277
278 // deserialize the wells
279 wellModel_.deserialize(res);
280
281 // deserialize the aquifer
282 aquiferModel_.deserialize(res);
283 }
284
291 template <class Restarter>
292 void serialize(Restarter& res)
293 {
294 wellModel_.serialize(res);
295
296 aquiferModel_.serialize(res);
297 }
298
299 int episodeIndex() const
300 {
301 return std::max(this->simulator().episodeIndex(), 0);
302 }
303
307 virtual void beginEpisode()
308 {
309 OPM_TIMEBLOCK(beginEpisode);
310 // Proceed to the next report step
311 auto& simulator = this->simulator();
312 int episodeIdx = simulator.episodeIndex();
313 auto& eclState = simulator.vanguard().eclState();
314 const auto& schedule = simulator.vanguard().schedule();
315 const auto& events = schedule[episodeIdx].events();
316
317 if (episodeIdx >= 0 && events.hasEvent(ScheduleEvents::GEO_MODIFIER)) {
318 // bring the contents of the keywords to the current state of the SCHEDULE
319 // section.
320 //
321 // TODO (?): make grid topology changes possible (depending on what exactly
322 // has changed, the grid may need be re-created which has some serious
323 // implications on e.g., the solution of the simulation.)
324 const auto& miniDeck = schedule[episodeIdx].geo_keywords();
325 const auto& cc = simulator.vanguard().grid().comm();
326 eclState.apply_schedule_keywords( miniDeck );
327 eclBroadcast(cc, eclState.getTransMult() );
328
329 // Re-ordering in case of ALUGrid
330 std::function<unsigned int(unsigned int)> equilGridToGrid = [&simulator](unsigned int i) {
331 return simulator.vanguard().gridEquilIdxToGridIdx(i);
332 };
333
334 // re-compute all quantities which may possibly be affected.
335 using TransUpdateQuantities = typename Vanguard::TransmissibilityType::TransUpdateQuantities;
336 transmissibilities_.update(true, TransUpdateQuantities::All, equilGridToGrid);
337 this->referencePorosity_[1] = this->referencePorosity_[0];
339 this->rockFraction_[1] = this->rockFraction_[0];
342 this->model().linearizer().updateDiscretizationParameters();
343 }
344
345 bool tuningEvent = this->beginEpisode_(enableExperiments, this->episodeIndex());
346
347 // set up the wells for the next episode.
348 wellModel_.beginEpisode();
349
350 // set up the aquifers for the next episode.
351 aquiferModel_.beginEpisode();
352
353 // set the size of the initial time step of the episode
354 Scalar dt = limitNextTimeStepSize_(simulator.episodeLength());
355 // negative value of initialTimeStepSize_ indicates no active limit from TSINIT or NEXTSTEP
356 if ( (episodeIdx == 0 || tuningEvent) && this->initialTimeStepSize_ > 0)
357 // allow the size of the initial time step to be set via an external parameter
358 // if TUNING is enabled, also limit the time step size after a tuning event to TSINIT
359 dt = std::min(dt, this->initialTimeStepSize_);
360 simulator.setTimeStepSize(dt);
361 }
362
366 virtual void beginTimeStep()
367 {
368 OPM_TIMEBLOCK(beginTimeStep);
369 const int episodeIdx = this->episodeIndex();
370 const int timeStepSize = this->simulator().timeStepSize();
371
373 episodeIdx,
374 this->simulator().timeStepIndex(),
375 this->simulator().startTime(),
376 this->simulator().time(),
377 timeStepSize,
378 this->simulator().endTime());
379
380 // update maximum water saturation and minimum pressure
381 // used when ROCKCOMP is activated
382 // Do not update max RS first step after a restart
383 this->updateExplicitQuantities_(episodeIdx, timeStepSize, first_step_ && (episodeIdx > 0));
384 first_step_ = false;
385
387 this->model().linearizer().updateBoundaryConditionData();
388 }
389
390 wellModel_.beginTimeStep();
391 aquiferModel_.beginTimeStep();
392 tracerModel_.beginTimeStep();
393 temperatureModel_.beginTimeStep();
394
395 }
396
401 {
402 OPM_TIMEBLOCK(beginIteration);
403 wellModel_.beginIteration();
404 aquiferModel_.beginIteration();
405 }
406
411 {
412 OPM_TIMEBLOCK(endIteration);
413 wellModel_.endIteration();
414 aquiferModel_.endIteration();
415 }
416
420 virtual void endTimeStep()
421 {
422 OPM_TIMEBLOCK(endTimeStep);
423
424#ifndef NDEBUG
425 if constexpr (getPropValue<TypeTag, Properties::EnableDebuggingChecks>()) {
426 // in debug mode, we don't care about performance, so we check
427 // if the model does the right thing (i.e., the mass change
428 // inside the whole reservoir must be equivalent to the fluxes
429 // over the grid's boundaries plus the source rates specified by
430 // the problem).
431 const int rank = this->simulator().gridView().comm().rank();
432 if (rank == 0) {
433 std::cout << "checking conservativeness of solution\n";
434 }
435
436 this->model().checkConservativeness(/*tolerance=*/-1, /*verbose=*/true);
437 if (rank == 0) {
438 std::cout << "solution is sufficiently conservative\n";
439 }
440 }
441#endif // NDEBUG
442
443 auto& simulator = this->simulator();
444 simulator.setTimeStepIndex(simulator.timeStepIndex()+1);
445
446 this->wellModel_.endTimeStep();
447 this->aquiferModel_.endTimeStep();
448 this->tracerModel_.endTimeStep();
449
450 // Compute flux for output
451 this->model().linearizer().updateFlowsInfo();
452
454 OPM_TIMEBLOCK(driftCompansation);
455
456 const auto& residual = this->model().linearizer().residual();
457
458 for (unsigned globalDofIdx = 0; globalDofIdx < residual.size(); globalDofIdx ++) {
459 int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(globalDofIdx);
460 this->drift_[sfcdofIdx] = residual[sfcdofIdx] * simulator.timeStepSize();
461
462 if constexpr (getPropValue<TypeTag, Properties::UseVolumetricResidual>()) {
463 this->drift_[sfcdofIdx] *= this->model().dofTotalVolume(sfcdofIdx);
464 }
465 }
466 }
467
468 // Drift compensation needs to be updated before calling the temperature equation
469 if constexpr(energyModuleType == EnergyModules::SequentialImplicitThermal) {
470 this->temperatureModel_.endTimeStep(wellModel_.wellState());
471 }
472 }
473
477 virtual void endEpisode()
478 {
479 const int episodeIdx = this->episodeIndex();
480
481 this->wellModel_.endEpisode();
482 this->aquiferModel_.endEpisode();
483
484 const auto& schedule = this->simulator().vanguard().schedule();
485
486 // End simulation when completed.
487 if (episodeIdx + 1 >= static_cast<int>(schedule.size()) - 1) {
488 this->simulator().setFinished(true);
489 return;
490 }
491
492 // Otherwise, start next episode (report step).
493 this->simulator().startNextEpisode(schedule.stepLength(episodeIdx + 1));
494 }
495
500 virtual void writeOutput(bool verbose)
501 {
502 OPM_TIMEBLOCK(problemWriteOutput);
503
504 if (Parameters::Get<Parameters::EnableWriteAllSolutions>() ||
505 this->episodeWillBeOver())
506 {
507 // Create VTK output as needed.
508 ParentType::writeOutput(verbose);
509 }
510 }
511
515 template <class Context>
516 const DimMatrix& intrinsicPermeability(const Context& context,
517 unsigned spaceIdx,
518 unsigned timeIdx) const
519 {
520 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
521 return transmissibilities_.permeability(globalSpaceIdx);
522 }
523
530 const DimMatrix& intrinsicPermeability(unsigned globalElemIdx) const
531 { return transmissibilities_.permeability(globalElemIdx); }
532
536 template <class Context>
537 Scalar transmissibility(const Context& context,
538 [[maybe_unused]] unsigned fromDofLocalIdx,
539 unsigned toDofLocalIdx) const
540 {
541 assert(fromDofLocalIdx == 0);
542 return pffDofData_.get(context.element(), toDofLocalIdx).transmissibility;
543 }
544
548 Scalar transmissibility(unsigned globalCenterElemIdx, unsigned globalElemIdx) const
549 {
550 return transmissibilities_.transmissibility(globalCenterElemIdx, globalElemIdx);
551 }
552
556 template <class Context>
557 Scalar diffusivity(const Context& context,
558 [[maybe_unused]] unsigned fromDofLocalIdx,
559 unsigned toDofLocalIdx) const
560 {
561 assert(fromDofLocalIdx == 0);
562 return *pffDofData_.get(context.element(), toDofLocalIdx).diffusivity;
563 }
564
568 Scalar diffusivity(const unsigned globalCellIn, const unsigned globalCellOut) const{
569 return transmissibilities_.diffusivity(globalCellIn, globalCellOut);
570 }
571
575 Scalar dispersivity(const unsigned globalCellIn, const unsigned globalCellOut) const{
576 return transmissibilities_.dispersivity(globalCellIn, globalCellOut);
577 }
578
582 Scalar thermalTransmissibilityBoundary(const unsigned globalSpaceIdx,
583 const unsigned boundaryFaceIdx) const
584 {
585 return transmissibilities_.thermalTransmissibilityBoundary(globalSpaceIdx, boundaryFaceIdx);
586 }
587
588
589
590
594 template <class Context>
595 Scalar transmissibilityBoundary(const Context& elemCtx,
596 unsigned boundaryFaceIdx) const
597 {
598 unsigned elemIdx = elemCtx.globalSpaceIndex(/*dofIdx=*/0, /*timeIdx=*/0);
599 return transmissibilities_.transmissibilityBoundary(elemIdx, boundaryFaceIdx);
600 }
601
605 Scalar transmissibilityBoundary(const unsigned globalSpaceIdx,
606 const unsigned boundaryFaceIdx) const
607 {
608 return transmissibilities_.transmissibilityBoundary(globalSpaceIdx, boundaryFaceIdx);
609 }
610
611
615 Scalar thermalHalfTransmissibility(const unsigned globalSpaceIdxIn,
616 const unsigned globalSpaceIdxOut) const
617 {
618 return transmissibilities_.thermalHalfTrans(globalSpaceIdxIn,globalSpaceIdxOut);
619 }
620
624 template <class Context>
625 Scalar thermalHalfTransmissibilityIn(const Context& context,
626 unsigned faceIdx,
627 unsigned timeIdx) const
628 {
629 const auto& face = context.stencil(timeIdx).interiorFace(faceIdx);
630 unsigned toDofLocalIdx = face.exteriorIndex();
631 return *pffDofData_.get(context.element(), toDofLocalIdx).thermalHalfTransIn;
632 }
633
637 template <class Context>
639 unsigned faceIdx,
640 unsigned timeIdx) const
641 {
642 const auto& face = context.stencil(timeIdx).interiorFace(faceIdx);
643 unsigned toDofLocalIdx = face.exteriorIndex();
644 return *pffDofData_.get(context.element(), toDofLocalIdx).thermalHalfTransOut;
645 }
646
650 template <class Context>
652 unsigned boundaryFaceIdx) const
653 {
654 unsigned elemIdx = elemCtx.globalSpaceIndex(/*dofIdx=*/0, /*timeIdx=*/0);
655 return transmissibilities_.thermalHalfTransBoundary(elemIdx, boundaryFaceIdx);
656 }
657
661 const typename Vanguard::TransmissibilityType& eclTransmissibilities() const
662 { return transmissibilities_; }
663
664
666 { return tracerModel_; }
667
669 { return tracerModel_; }
670
671 TemperatureModel& temperatureModel() // need for restart
672 { return temperatureModel_; }
673
682 template <class Context>
683 Scalar porosity(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
684 {
685 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
686 return this->porosity(globalSpaceIdx, timeIdx);
687 }
688
695 template <class Context>
696 Scalar dofCenterDepth(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
697 {
698 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
699 return this->dofCenterDepth(globalSpaceIdx);
700 }
701
708 Scalar dofCenterDepth(unsigned globalSpaceIdx) const
709 {
710 return this->simulator().vanguard().cellCenterDepth(globalSpaceIdx);
711 }
712
716 template <class Context>
717 Scalar rockCompressibility(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
718 {
719 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
720 return this->rockCompressibility(globalSpaceIdx);
721 }
722
726 template <class Context>
727 Scalar rockBiotComp(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
728 {
729 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
730 return this->rockBiotComp(globalSpaceIdx);
731 }
732
736 template <class Context>
737 Scalar lame(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
738 {
739 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
740 return this->lame(globalSpaceIdx);
741 }
742
746 template <class Context>
747 Scalar biotCoeff(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
748 {
749 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
750 return this->biotCoeff(globalSpaceIdx);
751 }
752
756 template <class Context>
757 Scalar rockReferencePressure(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
758 {
759 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
760 return rockReferencePressure(globalSpaceIdx);
761 }
762
766 Scalar rockReferencePressure(unsigned globalSpaceIdx) const
767 {
768 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
769 if (rock_config.store()) {
770 return asImp_().initialFluidState(globalSpaceIdx).pressure(refPressurePhaseIdx_());
771 }
772 else {
773 if (this->rockParams_.empty())
774 return 1e5;
775
776 unsigned tableIdx = 0;
777 if (!this->rockTableIdx_.empty()) {
778 tableIdx = this->rockTableIdx_[globalSpaceIdx];
779 }
780 return this->rockParams_[tableIdx].referencePressure;
781 }
782 }
783
787 template <class Context>
788 const MaterialLawParams& materialLawParams(const Context& context,
789 unsigned spaceIdx, unsigned timeIdx) const
790 {
791 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
792 return this->materialLawParams(globalSpaceIdx);
793 }
794
795 const MaterialLawParams& materialLawParams(unsigned globalDofIdx) const
796 {
797 return materialLawManager_->materialLawParams(globalDofIdx);
798 }
799
800 const MaterialLawParams& materialLawParams(unsigned globalDofIdx, FaceDir::DirEnum facedir) const
801 {
802 return materialLawManager_->materialLawParams(globalDofIdx, facedir);
803 }
804
808 template <class Context>
810 solidEnergyLawParams(const Context& context,
811 unsigned spaceIdx,
812 unsigned timeIdx) const
813 {
814 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
815 return thermalLawManager_->solidEnergyLawParams(globalSpaceIdx);
816 }
817
821 template <class Context>
823 thermalConductionLawParams(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
824 {
825 unsigned globalSpaceIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
826 return thermalLawManager_->thermalConductionLawParams(globalSpaceIdx);
827 }
828
835 std::shared_ptr<const EclMaterialLawManager> materialLawManager() const
836 { return materialLawManager_; }
837
838 std::shared_ptr<const EclThermalLawManager> thermalLawManager() const
839 { return thermalLawManager_; }
840
841 template <class FluidState, class ...Args>
843 std::array<Evaluation,numPhases> &mobility,
845 FluidState &fluidState,
846 unsigned globalSpaceIdx) const
847 {
848 using ContainerT = std::array<Evaluation, numPhases>;
849 OPM_TIMEBLOCK_LOCAL(updateRelperms, Subsystem::SatProps);
850 {
851 // calculate relative permeabilities. note that we store the result into the
852 // mobility_ class attribute. the division by the phase viscosity happens later.
853 const auto& materialParams = materialLawParams(globalSpaceIdx);
854 MaterialLaw::template relativePermeabilities<ContainerT, FluidState, Args...>(mobility, materialParams, fluidState);
855 Valgrind::CheckDefined(mobility);
856 }
857 if (materialLawManager_->hasDirectionalRelperms()
858 || materialLawManager_->hasDirectionalImbnum())
859 {
860 using Dir = FaceDir::DirEnum;
861 constexpr int ndim = 3;
862 dirMob = std::make_unique<DirectionalMobility<TypeTag>>();
863 Dir facedirs[ndim] = {Dir::XPlus, Dir::YPlus, Dir::ZPlus};
864 for (int i = 0; i<ndim; i++) {
865 const auto& materialParams = materialLawParams(globalSpaceIdx, facedirs[i]);
866 auto& mob_array = dirMob->getArray(i);
867 MaterialLaw::template relativePermeabilities<ContainerT, FluidState, Args...>(mob_array, materialParams, fluidState);
868 }
869 }
870 }
871
875 std::shared_ptr<EclMaterialLawManager> materialLawManager()
876 { return materialLawManager_; }
877
882 template <class Context>
883 unsigned pvtRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
884 { return pvtRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
885
890 template <class Context>
891 unsigned satnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
892 { return this->satnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
893
898 template <class Context>
899 unsigned miscnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
900 { return this->miscnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
901
906 template <class Context>
907 unsigned plmixnumRegionIndex(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
908 { return this->plmixnumRegionIndex(context.globalSpaceIndex(spaceIdx, timeIdx)); }
909
910 // TODO: polymer related might need to go to the blackoil side
915 template <class Context>
916 Scalar maxPolymerAdsorption(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
917 { return this->maxPolymerAdsorption(context.globalSpaceIndex(spaceIdx, timeIdx)); }
918
922 std::string name() const
923 { return this->simulator().vanguard().caseName(); }
924
928 template <class Context>
929 Scalar temperature(const Context& context, unsigned spaceIdx, unsigned timeIdx) const
930 {
931 // use the initial temperature of the DOF if temperature is not a primary
932 // variable
933 unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
934 if constexpr (energyModuleType == EnergyModules::SequentialImplicitThermal)
935 return temperatureModel_.temperature(globalDofIdx);
936
937 return asImp_().initialFluidState(globalDofIdx).temperature(/*phaseIdx=*/0);
938 }
939
940
941 Scalar temperature(unsigned globalDofIdx, unsigned /*timeIdx*/) const
942 {
943 // use the initial temperature of the DOF if temperature is not a primary
944 // variable
945 if constexpr (energyModuleType == EnergyModules::SequentialImplicitThermal)
946 return temperatureModel_.temperature(globalDofIdx);
947
948 return asImp_().initialFluidState(globalDofIdx).temperature(/*phaseIdx=*/0);
949 }
950
952 solidEnergyLawParams(unsigned globalSpaceIdx,
953 unsigned /*timeIdx*/) const
954 {
955 return this->thermalLawManager_->solidEnergyLawParams(globalSpaceIdx);
956 }
958 thermalConductionLawParams(unsigned globalSpaceIdx,
959 unsigned /*timeIdx*/)const
960 {
961 return this->thermalLawManager_->thermalConductionLawParams(globalSpaceIdx);
962 }
963
973 Scalar maxOilSaturation(unsigned globalDofIdx) const
974 {
975 if (!this->vapparsActive(this->episodeIndex()))
976 return 0.0;
977
978 return this->maxOilSaturation_[globalDofIdx];
979 }
980
990 void setMaxOilSaturation(unsigned globalDofIdx, Scalar value)
991 {
992 if (!this->vapparsActive(this->episodeIndex()))
993 return;
994
995 this->maxOilSaturation_[globalDofIdx] = value;
996 }
997
1002 {
1003 // Calculate all intensive quantities.
1004 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx*/0);
1005
1006 // We also need the intensive quantities for timeIdx == 1
1007 // corresponding to the start of the current timestep, if we
1008 // do not use the storage cache, or if we cannot recycle the
1009 // first iteration storage.
1010 if (!this->model().enableStorageCache() || !this->recycleFirstIterationStorage()) {
1011 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx*/1);
1012 }
1013
1014 // initialize the wells. Note that this needs to be done after initializing the
1015 // intrinsic permeabilities and the after applying the initial solution because
1016 // the well model uses these...
1017 wellModel_.init();
1018
1019 aquiferModel_.initialSolutionApplied();
1020
1021 const bool invalidateFromHyst = updateHysteresis_();
1022 if (invalidateFromHyst) {
1023 OPM_TIMEBLOCK(beginTimeStepInvalidateIntensiveQuantities);
1024 this->model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
1025 }
1026 }
1027
1033 template <class Context>
1034 void source(RateVector& rate,
1035 const Context& context,
1036 unsigned spaceIdx,
1037 unsigned timeIdx) const
1038 {
1039 const unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
1040 source(rate, globalDofIdx, timeIdx);
1041 }
1042
1043 void source(RateVector& rate,
1044 unsigned globalDofIdx,
1045 unsigned timeIdx) const
1046 {
1047 OPM_TIMEBLOCK_LOCAL(eclProblemSource, Subsystem::Assembly);
1048 rate = 0.0;
1049
1050 // Add well contribution to source here.
1051 wellModel_.computeTotalRatesForDof(rate, globalDofIdx);
1052
1053 // convert the source term from the total mass rate of the
1054 // cell to the one per unit of volume as used by the model.
1055 for (unsigned eqIdx = 0; eqIdx < numEq; ++ eqIdx) {
1056 rate[eqIdx] /= this->model().dofTotalVolume(globalDofIdx);
1057
1058 Valgrind::CheckDefined(rate[eqIdx]);
1059 assert(isfinite(rate[eqIdx]));
1060 }
1061
1062 // Add non-well sources.
1063 addToSourceDense(rate, globalDofIdx, timeIdx);
1064 }
1065
1066 virtual void addToSourceDense(RateVector& rate,
1067 unsigned globalDofIdx,
1068 unsigned timeIdx) const = 0;
1069
1075 const WellModel& wellModel() const
1076 { return wellModel_; }
1077
1079 { return wellModel_; }
1080
1082 { return aquiferModel_; }
1083
1085 { return aquiferModel_; }
1086
1089
1097 {
1098 OPM_TIMEBLOCK(nexTimeStepSize);
1099 // allow external code to do the timestepping
1100 if (this->nextTimeStepSize_ > 0.0)
1101 return this->nextTimeStepSize_;
1102
1103 const auto& simulator = this->simulator();
1104 int episodeIdx = simulator.episodeIndex();
1105
1106 // for the initial episode, we use a fixed time step size
1107 if (episodeIdx < 0)
1108 return this->initialTimeStepSize_;
1109
1110 // ask the newton method for a suggestion. This suggestion will be based on how
1111 // well the previous time step converged. After that, apply the runtime time
1112 // stepping constraints.
1113 const auto& newtonMethod = this->model().newtonMethod();
1114 return limitNextTimeStepSize_(newtonMethod.suggestTimeStepSize(simulator.timeStepSize()));
1115 }
1116
1122 template <class LhsEval>
1123 LhsEval rockCompPoroMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx) const
1124 {
1125 OPM_TIMEBLOCK_LOCAL(rockCompPoroMultiplier, Subsystem::PvtProps);
1126 if (this->rockCompPoroMult_.empty() && this->rockCompPoroMultWc_.empty())
1127 return 1.0;
1128
1129 unsigned tableIdx = 0;
1130 if (!this->rockTableIdx_.empty())
1131 tableIdx = this->rockTableIdx_[elementIdx];
1132
1133 const auto& fs = intQuants.fluidState();
1134 LhsEval effectivePressure = decay<LhsEval>(fs.pressure(refPressurePhaseIdx_()));
1135 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
1136 if (!this->minRefPressure_.empty())
1137 // The pore space change is irreversible
1138 effectivePressure =
1139 min(decay<LhsEval>(fs.pressure(refPressurePhaseIdx_())),
1140 this->minRefPressure_[elementIdx]);
1141
1142 if (!this->overburdenPressure_.empty())
1143 effectivePressure -= this->overburdenPressure_[elementIdx];
1144
1145 if (rock_config.store()) {
1146 effectivePressure -= asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
1147 }
1148
1149 if (!this->rockCompPoroMult_.empty()) {
1150 return this->rockCompPoroMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
1151 }
1152
1153 // water compaction
1154 assert(!this->rockCompPoroMultWc_.empty());
1155 LhsEval SwMax = max(decay<LhsEval>(fs.saturation(waterPhaseIdx)), this->maxWaterSaturation_[elementIdx]);
1156 LhsEval SwDeltaMax = SwMax - asImp_().initialFluidStates()[elementIdx].saturation(waterPhaseIdx);
1157
1158 return this->rockCompPoroMultWc_[tableIdx].eval(effectivePressure, SwDeltaMax, /*extrapolation=*/true);
1159 }
1160
1166 template <class LhsEval>
1167 LhsEval rockCompTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx) const
1168 {
1169 auto obtain = [](const auto& value)
1170 {
1171 if constexpr (std::is_same_v<LhsEval, Scalar>) {
1172 return getValue(value);
1173 } else {
1174 return value;
1175 }
1176 };
1177 return rockCompTransMultiplier<LhsEval>(intQuants, elementIdx, obtain);
1178 }
1179
1180 template <class LhsEval, class Callback>
1181 LhsEval rockCompTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
1182 {
1183 const bool implicit = !this->explicitRockCompaction_;
1184 return implicit ? this->simulator().problem().template computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain)
1185 : this->simulator().problem().getRockCompTransMultVal(elementIdx);
1186 }
1187
1188 template <class LhsEval, class Callback>
1189 LhsEval wellTransMultiplier(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
1190 {
1191 OPM_TIMEBLOCK_LOCAL(wellTransMultiplier, Subsystem::Wells);
1192
1193 const bool implicit = !this->explicitRockCompaction_;
1194 LhsEval trans_mult = implicit ? this->simulator().problem().template computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain)
1195 : this->simulator().problem().getRockCompTransMultVal(elementIdx);
1196 trans_mult *= this->simulator().problem().template permFactTransMultiplier<LhsEval>(intQuants, elementIdx, obtain);
1197
1198 return trans_mult;
1199 }
1200
1201 std::pair<BCType, RateVector> boundaryCondition(const unsigned int globalSpaceIdx, const int directionId) const
1202 {
1203 OPM_TIMEBLOCK_LOCAL(boundaryCondition, Subsystem::Assembly);
1205 return { BCType::NONE, RateVector(0.0) };
1206 }
1207 FaceDir::DirEnum dir = FaceDir::FromIntersectionIndex(directionId);
1208 const auto& schedule = this->simulator().vanguard().schedule();
1209 if (bcindex_(dir)[globalSpaceIdx] == 0) {
1210 return { BCType::NONE, RateVector(0.0) };
1211 }
1212 if (schedule[this->episodeIndex()].bcprop.size() == 0) {
1213 return { BCType::NONE, RateVector(0.0) };
1214 }
1215 const auto& bc = schedule[this->episodeIndex()].bcprop[bcindex_(dir)[globalSpaceIdx]];
1216 if (bc.bctype!=BCType::RATE) {
1217 return { bc.bctype, RateVector(0.0) };
1218 }
1219
1220 RateVector rate = 0.0;
1221 switch (bc.component) {
1222 case BCComponent::OIL:
1223 rate[FluidSystem::canonicalToActiveCompIdx(oilCompIdx)] = bc.rate;
1224 break;
1225 case BCComponent::GAS:
1226 rate[FluidSystem::canonicalToActiveCompIdx(gasCompIdx)] = bc.rate;
1227 break;
1228 case BCComponent::WATER:
1229 rate[FluidSystem::canonicalToActiveCompIdx(waterCompIdx)] = bc.rate;
1230 break;
1231 case BCComponent::SOLVENT:
1232 this->handleSolventBC(bc, rate);
1233 break;
1234 case BCComponent::POLYMER:
1235 this->handlePolymerBC(bc, rate);
1236 break;
1237 case BCComponent::MICR:
1238 this->handleMicrBC(bc, rate);
1239 break;
1240 case BCComponent::OXYG:
1241 this->handleOxygBC(bc, rate);
1242 break;
1243 case BCComponent::UREA:
1244 this->handleUreaBC(bc, rate);
1245 break;
1246 case BCComponent::NONE:
1247 throw std::logic_error("you need to specify the component when RATE type is set in BC");
1248 break;
1249 }
1250 //TODO add support for enthalpy rate
1251 return {bc.bctype, rate};
1252 }
1253
1254
1255 template<class Serializer>
1256 void serializeOp(Serializer& serializer)
1257 {
1258 serializer(static_cast<BaseType&>(*this));
1259 serializer(drift_);
1260 serializer(wellModel_);
1261 serializer(aquiferModel_);
1262 serializer(tracerModel_);
1263 serializer(*materialLawManager_);
1264 }
1265
1266 const GlobalEqVector& drift() const
1267 {
1268 return drift_;
1269 }
1270
1271private:
1272 Implementation& asImp_()
1273 { return *static_cast<Implementation *>(this); }
1274
1275 const Implementation& asImp_() const
1276 { return *static_cast<const Implementation *>(this); }
1277
1278protected:
1279 template<class UpdateFunc>
1280 void updateProperty_(const std::string& failureMsg,
1281 UpdateFunc func)
1282 {
1283 OPM_TIMEBLOCK(updateProperty);
1284 const auto& model = this->simulator().model();
1285 const auto& primaryVars = model.solution(/*timeIdx*/0);
1286 const auto& vanguard = this->simulator().vanguard();
1287 std::size_t numGridDof = primaryVars.size();
1289#ifdef _OPENMP
1290#pragma omp parallel for
1291#endif
1292 for (unsigned dofIdx = 0; dofIdx < numGridDof; ++dofIdx) {
1293 const auto& iq = *model.cachedIntensiveQuantities(dofIdx, /*timeIdx=*/ 0);
1294 func(dofIdx, iq);
1295 }
1296 OPM_END_PARALLEL_TRY_CATCH(failureMsg, vanguard.grid().comm());
1297 }
1298
1300 {
1301 OPM_TIMEBLOCK(updateMaxOilSaturation);
1302 int episodeIdx = this->episodeIndex();
1303
1304 // we use VAPPARS
1305 if (this->vapparsActive(episodeIdx)) {
1306 this->updateProperty_("FlowProblem::updateMaxOilSaturation_() failed:",
1307 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1308 {
1309 this->updateMaxOilSaturation_(compressedDofIdx,iq);
1310 });
1311 return true;
1312 }
1313
1314 return false;
1315 }
1316
1317 bool updateMaxOilSaturation_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1318 {
1319 OPM_TIMEBLOCK_LOCAL(updateMaxOilSaturation, Subsystem::SatProps);
1320 const auto& fs = iq.fluidState();
1321 const Scalar So = decay<Scalar>(fs.saturation(refPressurePhaseIdx_()));
1322 auto& mos = this->maxOilSaturation_;
1323 if(mos[compressedDofIdx] < So){
1324 mos[compressedDofIdx] = So;
1325 return true;
1326 }else{
1327 return false;
1328 }
1329 }
1330
1332 {
1333 OPM_TIMEBLOCK(updateMaxWaterSaturation);
1334 // water compaction is activated in ROCKCOMP
1335 if (this->maxWaterSaturation_.empty())
1336 return false;
1337
1338 this->maxWaterSaturation_[/*timeIdx=*/1] = this->maxWaterSaturation_[/*timeIdx=*/0];
1339 this->updateProperty_("FlowProblem::updateMaxWaterSaturation_() failed:",
1340 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1341 {
1342 this->updateMaxWaterSaturation_(compressedDofIdx,iq);
1343 });
1344 return true;
1345 }
1346
1347
1348 bool updateMaxWaterSaturation_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1349 {
1350 OPM_TIMEBLOCK_LOCAL(updateMaxWaterSaturation, Subsystem::SatProps);
1351 const auto& fs = iq.fluidState();
1352 const Scalar Sw = decay<Scalar>(fs.saturation(waterPhaseIdx));
1353 auto& mow = this->maxWaterSaturation_;
1354 if(mow[compressedDofIdx]< Sw){
1355 mow[compressedDofIdx] = Sw;
1356 return true;
1357 }else{
1358 return false;
1359 }
1360 }
1361
1363 {
1364 OPM_TIMEBLOCK(updateMinPressure);
1365 // IRREVERS option is used in ROCKCOMP
1366 if (this->minRefPressure_.empty())
1367 return false;
1368
1369 this->updateProperty_("FlowProblem::updateMinPressure_() failed:",
1370 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1371 {
1372 this->updateMinPressure_(compressedDofIdx,iq);
1373 });
1374 return true;
1375 }
1376
1377 bool updateMinPressure_(unsigned compressedDofIdx, const IntensiveQuantities& iq){
1378 OPM_TIMEBLOCK_LOCAL(updateMinPressure, Subsystem::PvtProps);
1379 const auto& fs = iq.fluidState();
1380 const Scalar min_pressure = getValue(fs.pressure(refPressurePhaseIdx_()));
1381 auto& min_pressures = this->minRefPressure_;
1382 if(min_pressures[compressedDofIdx]> min_pressure){
1383 min_pressures[compressedDofIdx] = min_pressure;
1384 return true;
1385 }else{
1386 return false;
1387 }
1388 }
1389
1390 // \brief Function to assign field properties of type double, on the leaf grid view.
1391 //
1392 // For CpGrid with local grid refinement, the field property of a cell on the leaf
1393 // is inherited from its parent or equivalent (when has no parent) cell on level zero.
1394 std::function<std::vector<double>(const FieldPropsManager&, const std::string&)>
1396 {
1397 const auto& lookup = this->lookUpData_;
1398 return [&lookup](const FieldPropsManager& fieldPropManager, const std::string& propString)
1399 {
1400 return lookup.assignFieldPropsDoubleOnLeaf(fieldPropManager, propString);
1401 };
1402 }
1403
1404 // \brief Function to assign field properties of type int, unsigned int, ..., on the leaf grid view.
1405 //
1406 // For CpGrid with local grid refinement, the field property of a cell on the leaf
1407 // is inherited from its parent or equivalent (when has no parent) cell on level zero.
1408 template<typename IntType>
1409 std::function<std::vector<IntType>(const FieldPropsManager&, const std::string&, bool)>
1411 {
1412 const auto& lookup = this->lookUpData_;
1413 return [&lookup](const FieldPropsManager& fieldPropManager, const std::string& propString, bool needsTranslation)
1414 {
1415 return lookup.template assignFieldPropsIntOnLeaf<IntType>(fieldPropManager, propString, needsTranslation);
1416 };
1417 }
1418
1420 {
1421 OPM_TIMEBLOCK(readMaterialParameters);
1422 const auto& simulator = this->simulator();
1423 const auto& vanguard = simulator.vanguard();
1424 const auto& eclState = vanguard.eclState();
1425
1426 // the PVT and saturation region numbers
1428 this->updatePvtnum_();
1429 this->updateSatnum_();
1430
1431 // the MISC region numbers (solvent model)
1432 this->updateMiscnum_();
1433 // the PLMIX region numbers (polymer model)
1434 this->updatePlmixnum_();
1435
1436 OPM_END_PARALLEL_TRY_CATCH("Invalid region numbers: ", vanguard.gridView().comm());
1438 // porosity
1440 this->referencePorosity_[1] = this->referencePorosity_[0];
1442
1444 // rock fraction
1446 this->rockFraction_[1] = this->rockFraction_[0];
1448
1450 // fluid-matrix interactions (saturation functions; relperm/capillary pressure)
1451 materialLawManager_ = std::make_shared<EclMaterialLawManager>();
1452 materialLawManager_->initFromState(eclState);
1453 materialLawManager_->initParamsForElements(eclState, this->model().numGridDof(),
1454 this-> template fieldPropIntTypeOnLeafAssigner_<int>(),
1457 }
1458
1460 {
1461 if constexpr (energyModuleType == EnergyModules::FullyImplicitThermal ||
1462 energyModuleType == EnergyModules::SequentialImplicitThermal )
1463 {
1464 const auto& simulator = this->simulator();
1465 const auto& vanguard = simulator.vanguard();
1466 const auto& eclState = vanguard.eclState();
1467
1468 // fluid-matrix interactions (saturation functions; relperm/capillary pressure)
1469 thermalLawManager_ = std::make_shared<EclThermalLawManager>();
1470 thermalLawManager_->initParamsForElements(eclState, this->model().numGridDof(),
1472 this-> template fieldPropIntTypeOnLeafAssigner_<unsigned int>());
1473 }
1474 }
1475
1477 {
1478 const auto& simulator = this->simulator();
1479 const auto& vanguard = simulator.vanguard();
1480 const auto& eclState = vanguard.eclState();
1481
1482 std::size_t numDof = this->model().numGridDof();
1483
1484 this->referencePorosity_[/*timeIdx=*/0].resize(numDof);
1485
1486 const auto& fp = eclState.fieldProps();
1487 const std::vector<double> porvData = this -> fieldPropDoubleOnLeafAssigner_()(fp, "PORV");
1488 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1489 int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(dofIdx);
1490 Scalar poreVolume = porvData[dofIdx];
1491
1492 // we define the porosity as the accumulated pore volume divided by the
1493 // geometric volume of the element. Note that -- in pathetic cases -- it can
1494 // be larger than 1.0!
1495 Scalar dofVolume = simulator.model().dofTotalVolume(sfcdofIdx);
1496 assert(dofVolume > 0.0);
1497 this->referencePorosity_[/*timeIdx=*/0][sfcdofIdx] = poreVolume/dofVolume;
1498 }
1499 }
1500
1502
1503 const bool solveEnergyEquation = (energyModuleType == EnergyModules::FullyImplicitThermal ||
1504 energyModuleType == EnergyModules::SequentialImplicitThermal);
1505 if (!solveEnergyEquation)
1506 return;
1507
1508 const auto& simulator = this->simulator();
1509 const auto& vanguard = simulator.vanguard();
1510 const auto& eclState = vanguard.eclState();
1511
1512 std::size_t numDof = this->model().numGridDof();
1513 this->rockFraction_[/*timeIdx=*/0].resize(numDof);
1514 // For the energy equation, we need the volume of the rock.
1515 // The volume of the rock is computed by rockFraction * geometric volume of the element.
1516 // The reference porosity is defined as porosity * ntg * pore-volume-multiplier.
1517 // A common practice in reservoir simulation is to use large pore-volume-multipliers in boundary cells
1518 // to model boundary conditions other than no-flow. This may result in reference porosities that are larger than 1.
1519 // A simple (1-reference porosity) * geometric volume of the element may give unphysical results.
1520 // We therefore instead consider the pore-volume-multiplier as a volume multiplier. The rock fraction is thus given by
1521 // (1 - porosity * ntg) * pore-volume-multiplier = (1 - porosity * ntg) * reference porosity / (porosity * ntg)
1522 const auto& fp = eclState.fieldProps();
1523 const std::vector<double> poroData = this->fieldPropDoubleOnLeafAssigner_()(fp, "PORO");
1524 const std::vector<double> ntgData = this->fieldPropDoubleOnLeafAssigner_()(fp, "NTG");
1525
1526 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
1527 const auto ntg = ntgData[dofIdx];
1528 const auto poro_eff = ntg * poroData[dofIdx];
1529 const int sfcdofIdx = simulator.vanguard().gridEquilIdxToGridIdx(dofIdx);
1530 const auto rock_fraction = (1 - poro_eff) * this->referencePorosity_[/*timeIdx=*/0][sfcdofIdx] / poro_eff;
1531 this->rockFraction_[/*timeIdx=*/0][sfcdofIdx] = rock_fraction;
1532 }
1533 }
1534
1536 {
1537 // TODO: whether we should move this to FlowProblemBlackoil
1538 const auto& simulator = this->simulator();
1539 const auto& vanguard = simulator.vanguard();
1540 const auto& eclState = vanguard.eclState();
1541
1542 if (eclState.getInitConfig().hasEquil())
1544 else
1546
1547 //initialize min/max values
1548 std::size_t numElems = this->model().numGridDof();
1549 for (std::size_t elemIdx = 0; elemIdx < numElems; ++elemIdx) {
1550 const auto& fs = asImp_().initialFluidStates()[elemIdx];
1551 if (!this->maxWaterSaturation_.empty() && waterPhaseIdx > -1)
1552 this->maxWaterSaturation_[elemIdx] = std::max(this->maxWaterSaturation_[elemIdx], fs.saturation(waterPhaseIdx));
1553 if (!this->maxOilSaturation_.empty() && oilPhaseIdx > -1)
1554 this->maxOilSaturation_[elemIdx] = std::max(this->maxOilSaturation_[elemIdx], fs.saturation(oilPhaseIdx));
1555 if (!this->minRefPressure_.empty() && refPressurePhaseIdx_() > -1)
1556 this->minRefPressure_[elemIdx] = std::min(this->minRefPressure_[elemIdx], fs.pressure(refPressurePhaseIdx_()));
1557 }
1558 }
1559
1560 virtual void readEquilInitialCondition_() = 0;
1562
1563 // update the hysteresis parameters of the material laws for the whole grid
1565 {
1566 if (!materialLawManager_->enableHysteresis())
1567 return false;
1568
1569 // we need to update the hysteresis data for _all_ elements (i.e., not just the
1570 // interior ones) to avoid desynchronization of the processes in the parallel case!
1571 this->updateProperty_("FlowProblem::updateHysteresis_() failed:",
1572 [this](unsigned compressedDofIdx, const IntensiveQuantities& iq)
1573 {
1574 materialLawManager_->updateHysteresis(iq.fluidState(), compressedDofIdx);
1575 });
1576 return true;
1577 }
1578
1579
1580 bool updateHysteresis_(unsigned compressedDofIdx, const IntensiveQuantities& iq)
1581 {
1582 OPM_TIMEBLOCK_LOCAL(updateHysteresis_, Subsystem::SatProps);
1583 materialLawManager_->updateHysteresis(iq.fluidState(), compressedDofIdx);
1584 //TODO change materials to give a bool
1585 return true;
1586 }
1587
1588 Scalar getRockCompTransMultVal(std::size_t dofIdx) const
1589 {
1590 if (this->rockCompTransMultVal_.empty())
1591 return 1.0;
1592
1593 return this->rockCompTransMultVal_[dofIdx];
1594 }
1595
1596protected:
1598 {
1599 ConditionalStorage<enableFullyImplicitThermal, Scalar> thermalHalfTransIn;
1600 ConditionalStorage<enableFullyImplicitThermal, Scalar> thermalHalfTransOut;
1601 ConditionalStorage<enableDiffusion, Scalar> diffusivity;
1602 ConditionalStorage<enableDispersion, Scalar> dispersivity;
1604 };
1605
1606 // update the prefetch friendly data object
1608 {
1609 const auto& distFn =
1610 [this](PffDofData_& dofData,
1611 const Stencil& stencil,
1612 unsigned localDofIdx)
1613 -> void
1614 {
1615 const auto& elementMapper = this->model().elementMapper();
1616
1617 unsigned globalElemIdx = elementMapper.index(stencil.entity(localDofIdx));
1618 if (localDofIdx != 0) {
1619 unsigned globalCenterElemIdx = elementMapper.index(stencil.entity(/*dofIdx=*/0));
1620 dofData.transmissibility = transmissibilities_.transmissibility(globalCenterElemIdx, globalElemIdx);
1621
1622 if constexpr (enableFullyImplicitThermal) {
1623 *dofData.thermalHalfTransIn = transmissibilities_.thermalHalfTrans(globalCenterElemIdx, globalElemIdx);
1624 *dofData.thermalHalfTransOut = transmissibilities_.thermalHalfTrans(globalElemIdx, globalCenterElemIdx);
1625 }
1626 if constexpr (enableDiffusion)
1627 *dofData.diffusivity = transmissibilities_.diffusivity(globalCenterElemIdx, globalElemIdx);
1628 if (enableDispersion)
1629 dofData.dispersivity = transmissibilities_.dispersivity(globalCenterElemIdx, globalElemIdx);
1630 }
1631 };
1632
1633 pffDofData_.update(distFn);
1634 }
1635
1636 virtual void updateExplicitQuantities_(int episodeIdx, int timeStepSize, bool first_step_after_restart) = 0;
1637
1639 {
1640 const auto& simulator = this->simulator();
1641 const auto& vanguard = simulator.vanguard();
1642 const auto& bcconfig = vanguard.eclState().getSimulationConfig().bcconfig();
1643 if (bcconfig.size() > 0) {
1645
1646 std::size_t numCartDof = vanguard.cartesianSize();
1647 unsigned numElems = vanguard.gridView().size(/*codim=*/0);
1648 std::vector<int> cartesianToCompressedElemIdx(numCartDof, -1);
1649
1650 for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx)
1651 cartesianToCompressedElemIdx[vanguard.cartesianIndex(elemIdx)] = elemIdx;
1652
1653 bcindex_.resize(numElems, 0);
1654 auto loopAndApply = [&cartesianToCompressedElemIdx,
1655 &vanguard](const auto& bcface,
1656 auto apply)
1657 {
1658 for (int i = bcface.i1; i <= bcface.i2; ++i) {
1659 for (int j = bcface.j1; j <= bcface.j2; ++j) {
1660 for (int k = bcface.k1; k <= bcface.k2; ++k) {
1661 std::array<int, 3> tmp = {i,j,k};
1662 auto elemIdx = cartesianToCompressedElemIdx[vanguard.cartesianIndex(tmp)];
1663 if (elemIdx >= 0)
1664 apply(elemIdx);
1665 }
1666 }
1667 }
1668 };
1669 for (const auto& bcface : bcconfig) {
1670 std::vector<int>& data = bcindex_(bcface.dir);
1671 const int index = bcface.index;
1672 loopAndApply(bcface,
1673 [&data,index](int elemIdx)
1674 { data[elemIdx] = index; });
1675 }
1676 }
1677 }
1678
1679 // this method applies the runtime constraints specified via the deck and/or command
1680 // line parameters for the size of the next time step.
1682 {
1683 if constexpr (enableExperiments) {
1684 const auto& simulator = this->simulator();
1685 const auto& schedule = simulator.vanguard().schedule();
1686 int episodeIdx = simulator.episodeIndex();
1687
1688 // first thing in the morning, limit the time step size to the maximum size
1689 Scalar maxTimeStepSize = Parameters::Get<Parameters::SolverMaxTimeStepInDays<Scalar>>() * 24 * 60 * 60;
1690 int reportStepIdx = std::max(episodeIdx, 0);
1691 if (this->enableTuning_) {
1692 const auto& tuning = schedule[reportStepIdx].tuning();
1693 maxTimeStepSize = tuning.TSMAXZ;
1694 }
1695
1696 dtNext = std::min(dtNext, maxTimeStepSize);
1697
1698 Scalar remainingEpisodeTime =
1699 simulator.episodeStartTime() + simulator.episodeLength()
1700 - (simulator.startTime() + simulator.time());
1701 assert(remainingEpisodeTime >= 0.0);
1702
1703 // if we would have a small amount of time left over in the current episode, make
1704 // two equal time steps instead of a big and a small one
1705 if (remainingEpisodeTime/2.0 < dtNext && dtNext < remainingEpisodeTime*(1.0 - 1e-5))
1706 // note: limiting to the maximum time step size here is probably not strictly
1707 // necessary, but it should not hurt and is more fool-proof
1708 dtNext = std::min(maxTimeStepSize, remainingEpisodeTime/2.0);
1709
1710 if (simulator.episodeStarts()) {
1711 // if a well event occurred, respect the limit for the maximum time step after
1712 // that, too
1713 const auto& events = simulator.vanguard().schedule()[reportStepIdx].events();
1714 bool wellEventOccured =
1715 events.hasEvent(ScheduleEvents::NEW_WELL)
1716 || events.hasEvent(ScheduleEvents::PRODUCTION_UPDATE)
1717 || events.hasEvent(ScheduleEvents::INJECTION_UPDATE)
1718 || events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE);
1719 if (episodeIdx >= 0 && wellEventOccured && this->maxTimeStepAfterWellEvent_ > 0)
1720 dtNext = std::min(dtNext, this->maxTimeStepAfterWellEvent_);
1721 }
1722 }
1723
1724 return dtNext;
1725 }
1726
1728 if (FluidSystem::phaseIsActive(oilPhaseIdx)) {
1729 return oilPhaseIdx;
1730 }
1731 else if (FluidSystem::phaseIsActive(gasPhaseIdx)) {
1732 return gasPhaseIdx;
1733 }
1734 else {
1735 return waterPhaseIdx;
1736 }
1737 }
1738
1740 {
1741 const auto& model = this->simulator().model();
1742 std::size_t numGridDof = this->model().numGridDof();
1743 this->rockCompTransMultVal_.resize(numGridDof, 1.0);
1744 for (std::size_t elementIdx = 0; elementIdx < numGridDof; ++elementIdx) {
1745 const auto& iq = *model.cachedIntensiveQuantities(elementIdx, /*timeIdx=*/ 0);
1746 Scalar trans_mult = computeRockCompTransMultiplier_<Scalar>(iq, elementIdx);
1747 this->rockCompTransMultVal_[elementIdx] = trans_mult;
1748 }
1749 }
1750
1756 template <class LhsEval>
1757 LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities& intQuants, unsigned elementIdx) const
1758 {
1759 auto obtain = [](const auto& value)
1760 {
1761 if constexpr (std::is_same_v<LhsEval, Scalar>) {
1762 return getValue(value);
1763 } else {
1764 return value;
1765 }
1766 };
1767
1768 return computeRockCompTransMultiplier_<LhsEval>(intQuants, elementIdx, obtain);
1769 }
1770
1771 template <class LhsEval, class Callback>
1772 LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities& intQuants, unsigned elementIdx, Callback& obtain) const
1773 {
1774 OPM_TIMEBLOCK_LOCAL(computeRockCompTransMultiplier, Subsystem::PvtProps);
1775 if (this->rockCompTransMult_.empty() && this->rockCompTransMultWc_.empty())
1776 return 1.0;
1777
1778 unsigned tableIdx = 0;
1779 if (!this->rockTableIdx_.empty())
1780 tableIdx = this->rockTableIdx_[elementIdx];
1781
1782 const auto& fs = intQuants.fluidState();
1783 LhsEval effectivePressure = obtain(fs.pressure(refPressurePhaseIdx_()));
1784 const auto& rock_config = this->simulator().vanguard().eclState().getSimulationConfig().rock_config();
1785 if (!this->minRefPressure_.empty())
1786 // The pore space change is irreversible
1787 effectivePressure =
1788 min(obtain(fs.pressure(refPressurePhaseIdx_())),
1789 this->minRefPressure_[elementIdx]);
1790
1791 if (!this->overburdenPressure_.empty())
1792 effectivePressure -= this->overburdenPressure_[elementIdx];
1793
1794 if (rock_config.store()) {
1795 effectivePressure -= asImp_().initialFluidState(elementIdx).pressure(refPressurePhaseIdx_());
1796 }
1797
1798 if (!this->rockCompTransMult_.empty())
1799 return this->rockCompTransMult_[tableIdx].eval(effectivePressure, /*extrapolation=*/true);
1800
1801 // water compaction
1802 assert(!this->rockCompTransMultWc_.empty());
1803 LhsEval SwMax = max(obtain(fs.saturation(waterPhaseIdx)), this->maxWaterSaturation_[elementIdx]);
1804 LhsEval SwDeltaMax = SwMax - asImp_().initialFluidStates()[elementIdx].saturation(waterPhaseIdx);
1805
1806 return this->rockCompTransMultWc_[tableIdx].eval(effectivePressure, SwDeltaMax, /*extrapolation=*/true);
1807 }
1808
1809 typename Vanguard::TransmissibilityType transmissibilities_;
1810
1811 std::shared_ptr<EclMaterialLawManager> materialLawManager_;
1812 std::shared_ptr<EclThermalLawManager> thermalLawManager_;
1813
1815
1818
1822
1823 template<class T>
1824 struct BCData
1825 {
1826 std::array<std::vector<T>,6> data;
1827
1828 void resize(std::size_t size, T defVal)
1829 {
1830 for (auto& d : data)
1831 d.resize(size, defVal);
1832 }
1833
1834 const std::vector<T>& operator()(FaceDir::DirEnum dir) const
1835 {
1836 if (dir == FaceDir::DirEnum::Unknown)
1837 throw std::runtime_error("Tried to access BC data for the 'Unknown' direction");
1838 int idx = 0;
1839 int div = static_cast<int>(dir);
1840 while ((div /= 2) >= 1)
1841 ++idx;
1842 assert(idx >= 0 && idx <= 5);
1843 return data[idx];
1844 }
1845
1846 std::vector<T>& operator()(FaceDir::DirEnum dir)
1847 {
1848 return const_cast<std::vector<T>&>(std::as_const(*this)(dir));
1849 }
1850 };
1851
1852 virtual void handleSolventBC(const BCProp::BCFace&, RateVector&) const = 0;
1853
1854 virtual void handlePolymerBC(const BCProp::BCFace&, RateVector&) const = 0;
1855
1856 virtual void handleMicrBC(const BCProp::BCFace&, RateVector&) const = 0;
1857
1858 virtual void handleOxygBC(const BCProp::BCFace&, RateVector&) const = 0;
1859
1860 virtual void handleUreaBC(const BCProp::BCFace&, RateVector&) const = 0;
1861
1864 bool first_step_ = true;
1865
1868 virtual bool episodeWillBeOver() const
1869 {
1870 return this->simulator().episodeWillBeOver();
1871 }
1872};
1873
1874} // namespace Opm
1875
1876#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:192
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:158
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowGenericProblem.hpp:61
Scalar maxPolymerAdsorption(unsigned elemIdx) const
Returns the max polymer adsorption value.
Definition: FlowGenericProblem_impl.hpp:797
unsigned pvtRegionIndex(unsigned elemIdx) const
Returns the index the relevant PVT region given a cell index.
Definition: FlowGenericProblem_impl.hpp:756
std::array< std::vector< Scalar >, 2 > rockFraction_
Definition: FlowGenericProblem.hpp:338
std::function< unsigned(unsigned)> lookupIdxOnLevelZeroAssigner_()
Definition: FlowGenericProblem.hpp:384
std::vector< TabulatedTwoDFunction > rockCompPoroMultWc_
Definition: FlowGenericProblem.hpp:347
Scalar porosity(unsigned globalSpaceIdx, unsigned timeIdx) const
Direct indexed access to the porosity.
Definition: FlowGenericProblem_impl.hpp:338
Scalar rockCompressibility(unsigned globalSpaceIdx) const
Definition: FlowGenericProblem_impl.hpp:323
unsigned miscnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant MISC region given a cell index.
Definition: FlowGenericProblem_impl.hpp:776
unsigned satnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant saturation function region given a cell index.
Definition: FlowGenericProblem_impl.hpp:766
Scalar lame(unsigned elementIdx) const
Direct access to Lame's second parameter in an element.
Definition: FlowGenericProblem_impl.hpp:357
void beginTimeStep_(bool enableExperiments, int episodeIdx, int timeStepIndex, Scalar startTime, Scalar time, Scalar timeStepSize, Scalar endTime)
Definition: FlowGenericProblem_impl.hpp:508
std::vector< TabulatedTwoDFunction > rockCompTransMultWc_
Definition: FlowGenericProblem.hpp:348
unsigned plmixnumRegionIndex(unsigned elemIdx) const
Returns the index the relevant PLMIXNUM (for polymer module) region given a cell index.
Definition: FlowGenericProblem_impl.hpp:786
std::array< std::vector< Scalar >, 2 > referencePorosity_
Definition: FlowGenericProblem.hpp:337
Scalar rockBiotComp(unsigned elementIdx) const
Returns the rock compressibility of an element due to poroelasticity.
Definition: FlowGenericProblem_impl.hpp:346
bool beginEpisode_(bool enableExperiments, int episodeIdx)
Definition: FlowGenericProblem_impl.hpp:471
bool shouldWriteOutput() const
Always returns true. The ecl output writer takes care of the rest.
Definition: FlowGenericProblem.hpp:294
static std::string helpPreamble(int, const char **argv)
Definition: FlowGenericProblem_impl.hpp:115
bool shouldWriteRestartFile() const
Returns true if an eWoms restart file should be written to disk.
Definition: FlowGenericProblem.hpp:303
Scalar biotCoeff(unsigned elementIdx) const
Direct access to Biot coefficient in an element.
Definition: FlowGenericProblem_impl.hpp:388
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:95
virtual bool episodeWillBeOver() const
Definition: FlowProblem.hpp:1868
const WellModel & wellModel() const
Returns a reference to the ECL well manager used by the problem.
Definition: FlowProblem.hpp:1075
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:160
Scalar transmissibility(unsigned globalCenterElemIdx, unsigned globalElemIdx) const
Direct access to the transmissibility between two elements.
Definition: FlowProblem.hpp:548
static constexpr bool enableFoam
Definition: FlowProblem.hpp:126
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:202
bool nonTrivialBoundaryConditions() const
Definition: FlowProblem.hpp:1087
const GlobalEqVector & drift() const
Definition: FlowProblem.hpp:1266
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:500
std::function< std::vector< IntType >(const FieldPropsManager &, const std::string &, bool)> fieldPropIntTypeOnLeafAssigner_()
Definition: FlowProblem.hpp:1410
const DimMatrix & intrinsicPermeability(unsigned globalElemIdx) const
This method returns the intrinsic permeability tensor given a global element index.
Definition: FlowProblem.hpp:530
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:883
LhsEval wellTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:1189
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:683
void beginIteration()
Called by the simulator before each Newton-Raphson iteration.
Definition: FlowProblem.hpp:400
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:108
GetPropType< TypeTag, Properties::DofMapper > DofMapper
Definition: FlowProblem.hpp:159
Scalar rockBiotComp(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:727
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:102
typename EclThermalLawManager::SolidEnergyLawParams SolidEnergyLawParams
Definition: FlowProblem.hpp:156
bool updateHysteresis_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1580
GetPropType< TypeTag, Properties::BaseProblem > ParentType
Definition: FlowProblem.hpp:99
GetPropType< TypeTag, Properties::EqVector > EqVector
Definition: FlowProblem.hpp:107
@ waterCompIdx
Definition: FlowProblem.hpp:146
unsigned satnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:891
virtual void handleOxygBC(const BCProp::BCFace &, RateVector &) const =0
virtual void updateExplicitQuantities_(int episodeIdx, int timeStepSize, bool first_step_after_restart)=0
virtual void handleUreaBC(const BCProp::BCFace &, RateVector &) const =0
Scalar thermalHalfTransmissibilityOut(const Context &context, unsigned faceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:638
bool first_step_
Definition: FlowProblem.hpp:1864
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: FlowProblem.hpp:152
const ThermalConductionLawParams & thermalConductionLawParams(unsigned globalSpaceIdx, unsigned) const
Definition: FlowProblem.hpp:958
@ gasCompIdx
Definition: FlowProblem.hpp:144
AquiferModel aquiferModel_
Definition: FlowProblem.hpp:1817
GlobalEqVector drift_
Definition: FlowProblem.hpp:1814
bool updateMinPressure_()
Definition: FlowProblem.hpp:1362
std::function< std::vector< double >(const FieldPropsManager &, const std::string &)> fieldPropDoubleOnLeafAssigner_()
Definition: FlowProblem.hpp:1395
@ enableSaltPrecipitation
Definition: FlowProblem.hpp:135
Scalar transmissibilityBoundary(const Context &elemCtx, unsigned boundaryFaceIdx) const
Definition: FlowProblem.hpp:595
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:149
void updateReferencePorosity_()
Definition: FlowProblem.hpp:1476
Scalar thermalHalfTransmissibility(const unsigned globalSpaceIdxIn, const unsigned globalSpaceIdxOut) const
Definition: FlowProblem.hpp:615
LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:1772
BCData< int > bcindex_
Definition: FlowProblem.hpp:1862
GetPropType< TypeTag, Properties::TracerModel > TracerModel
Definition: FlowProblem.hpp:169
Scalar rockCompressibility(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:717
bool updateMaxWaterSaturation_()
Definition: FlowProblem.hpp:1331
Dune::FieldMatrix< Scalar, dimWorld, dimWorld > DimMatrix
Definition: FlowProblem.hpp:166
@ enableMICP
Definition: FlowProblem.hpp:134
Scalar maxOilSaturation(unsigned globalDofIdx) const
Returns an element's historic maximum oil phase saturation that was observed during the simulation.
Definition: FlowProblem.hpp:973
bool updateMinPressure_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1377
std::string name() const
The problem name.
Definition: FlowProblem.hpp:922
int episodeIndex() const
Definition: FlowProblem.hpp:299
LhsEval rockCompTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the transmissibility multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:1167
void endIteration()
Called by the simulator after each Newton-Raphson iteration.
Definition: FlowProblem.hpp:410
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:109
FlowProblem(Simulator &simulator)
Definition: FlowProblem.hpp:221
virtual void handleSolventBC(const BCProp::BCFace &, RateVector &) const =0
@ dim
Definition: FlowProblem.hpp:112
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: FlowProblem.hpp:106
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:150
const Vanguard::TransmissibilityType & eclTransmissibilities() const
Return a reference to the object that handles the "raw" transmissibilities.
Definition: FlowProblem.hpp:661
void source(RateVector &rate, unsigned globalDofIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:1043
@ dimWorld
Definition: FlowProblem.hpp:113
virtual void readEquilInitialCondition_()=0
Scalar nextTimeStepSize() const
Propose the size of the next time step to the simulator.
Definition: FlowProblem.hpp:1096
LhsEval computeRockCompTransMultiplier_(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the transmissibility multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:1757
std::pair< BCType, RateVector > boundaryCondition(const unsigned int globalSpaceIdx, const int directionId) const
Definition: FlowProblem.hpp:1201
typename EclMaterialLawManager::MaterialLawParams MaterialLawParams
Definition: FlowProblem.hpp:155
static constexpr bool enableDiffusion
Definition: FlowProblem.hpp:123
virtual ~FlowProblem()=default
PffGridVector< GridView, Stencil, PffDofData_, DofMapper > pffDofData_
Definition: FlowProblem.hpp:1819
const ThermalConductionLawParams & thermalConductionLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:823
Scalar transmissibility(const Context &context, unsigned fromDofLocalIdx, unsigned toDofLocalIdx) const
Definition: FlowProblem.hpp:537
TracerModel tracerModel_
Definition: FlowProblem.hpp:1820
@ numComponents
Definition: FlowProblem.hpp:118
virtual void handlePolymerBC(const BCProp::BCFace &, RateVector &) const =0
const TracerModel & tracerModel() const
Definition: FlowProblem.hpp:665
WellModel wellModel_
Definition: FlowProblem.hpp:1816
virtual void beginEpisode()
Called by the simulator before an episode begins.
Definition: FlowProblem.hpp:307
const SolidEnergyLawParams & solidEnergyLawParams(unsigned globalSpaceIdx, unsigned) const
Definition: FlowProblem.hpp:952
static constexpr bool enablePolymerMolarWeight
Definition: FlowProblem.hpp:128
Scalar getRockCompTransMultVal(std::size_t dofIdx) const
Definition: FlowProblem.hpp:1588
virtual void beginTimeStep()
Called by the simulator before each time integration.
Definition: FlowProblem.hpp:366
@ enableFullyImplicitThermal
Definition: FlowProblem.hpp:132
Scalar dofCenterDepth(unsigned globalSpaceIdx) const
Direct indexed acces to the depth of an degree of freedom [m].
Definition: FlowProblem.hpp:708
typename GetProp< TypeTag, Properties::MaterialLaw >::EclMaterialLawManager EclMaterialLawManager
Definition: FlowProblem.hpp:153
static constexpr bool enableSolvent
Definition: FlowProblem.hpp:129
const MaterialLawParams & materialLawParams(unsigned globalDofIdx, FaceDir::DirEnum facedir) const
Definition: FlowProblem.hpp:800
std::shared_ptr< const EclMaterialLawManager > materialLawManager() const
Returns the ECL material law manager.
Definition: FlowProblem.hpp:835
unsigned plmixnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:907
const MaterialLawParams & materialLawParams(unsigned globalDofIdx) const
Definition: FlowProblem.hpp:795
Scalar temperature(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:929
Scalar thermalHalfTransmissibilityBoundary(const Context &elemCtx, unsigned boundaryFaceIdx) const
Definition: FlowProblem.hpp:651
unsigned miscnumRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:899
void updateRockCompTransMultVal_()
Definition: FlowProblem.hpp:1739
std::shared_ptr< EclThermalLawManager > thermalLawManager_
Definition: FlowProblem.hpp:1812
Scalar limitNextTimeStepSize_(Scalar dtNext) const
Definition: FlowProblem.hpp:1681
@ waterPhaseIdx
Definition: FlowProblem.hpp:140
GetPropType< TypeTag, Properties::Stencil > Stencil
Definition: FlowProblem.hpp:104
typename GetProp< TypeTag, Properties::SolidEnergyLaw >::EclThermalLawManager EclThermalLawManager
Definition: FlowProblem.hpp:154
virtual void readExplicitInitialCondition_()=0
virtual void handleMicrBC(const BCProp::BCFace &, RateVector &) const =0
static constexpr bool enablePolymer
Definition: FlowProblem.hpp:127
GetPropType< TypeTag, Properties::WellModel > WellModel
Definition: FlowProblem.hpp:162
const DimMatrix & intrinsicPermeability(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:516
bool updateHysteresis_()
Definition: FlowProblem.hpp:1564
void readThermalParameters_()
Definition: FlowProblem.hpp:1459
void serializeOp(Serializer &serializer)
Definition: FlowProblem.hpp:1256
Scalar maxPolymerAdsorption(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the max polymer adsorption value.
Definition: FlowProblem.hpp:916
Scalar thermalHalfTransmissibilityIn(const Context &context, unsigned faceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:625
void setMaxOilSaturation(unsigned globalDofIdx, Scalar value)
Sets an element's maximum oil phase saturation observed during the simulation.
Definition: FlowProblem.hpp:990
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:810
typename EclThermalLawManager::ThermalConductionLawParams ThermalConductionLawParams
Definition: FlowProblem.hpp:157
Scalar dispersivity(const unsigned globalCellIn, const unsigned globalCellOut) const
Definition: FlowProblem.hpp:575
AquiferModel & mutableAquiferModel()
Definition: FlowProblem.hpp:1084
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: FlowProblem.hpp:161
Scalar temperature(unsigned globalDofIdx, unsigned) const
Definition: FlowProblem.hpp:941
Scalar lame(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:737
@ oilCompIdx
Definition: FlowProblem.hpp:145
@ numPhases
Definition: FlowProblem.hpp:117
GetPropType< TypeTag, Properties::AquiferModel > AquiferModel
Definition: FlowProblem.hpp:163
TemperatureModel temperatureModel_
Definition: FlowProblem.hpp:1821
static constexpr bool enableExtbo
Definition: FlowProblem.hpp:125
std::shared_ptr< EclMaterialLawManager > materialLawManager_
Definition: FlowProblem.hpp:1811
WellModel & wellModel()
Definition: FlowProblem.hpp:1078
static constexpr bool enableConvectiveMixing
Definition: FlowProblem.hpp:122
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:103
GetPropType< TypeTag, Properties::TemperatureModel > TemperatureModel
Definition: FlowProblem.hpp:168
void updateProperty_(const std::string &failureMsg, UpdateFunc func)
Definition: FlowProblem.hpp:1280
LhsEval rockCompTransMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx, Callback &obtain) const
Definition: FlowProblem.hpp:1181
@ enableThermalFluxBoundaries
Definition: FlowProblem.hpp:136
bool updateMaxOilSaturation_()
Definition: FlowProblem.hpp:1299
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:186
void updatePffDofData_()
Definition: FlowProblem.hpp:1607
static constexpr bool enableDispersion
Definition: FlowProblem.hpp:124
virtual void endEpisode()
Called by the simulator after the end of an episode.
Definition: FlowProblem.hpp:477
@ enableExperiments
Definition: FlowProblem.hpp:133
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:148
bool nonTrivialBoundaryConditions_
Definition: FlowProblem.hpp:1863
GetPropType< TypeTag, Properties::Problem > Implementation
Definition: FlowProblem.hpp:100
void readBoundaryConditions_()
Definition: FlowProblem.hpp:1638
void updateRelperms(std::array< Evaluation, numPhases > &mobility, DirectionalMobilityPtr &dirMob, FluidState &fluidState, unsigned globalSpaceIdx) const
Definition: FlowProblem.hpp:842
Vanguard::TransmissibilityType transmissibilities_
Definition: FlowProblem.hpp:1809
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:1034
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:420
TemperatureModel & temperatureModel()
Definition: FlowProblem.hpp:671
Utility::CopyablePtr< DirectionalMobility< TypeTag > > DirectionalMobilityPtr
Definition: FlowProblem.hpp:170
virtual void readInitialCondition_()
Definition: FlowProblem.hpp:1535
virtual void initialSolutionApplied()
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblem.hpp:1001
const MaterialLawParams & materialLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:788
Scalar thermalTransmissibilityBoundary(const unsigned globalSpaceIdx, const unsigned boundaryFaceIdx) const
Direct access to a boundary transmissibility.
Definition: FlowProblem.hpp:582
static constexpr EnergyModules energyModuleType
Definition: FlowProblem.hpp:131
Scalar diffusivity(const Context &context, unsigned fromDofLocalIdx, unsigned toDofLocalIdx) const
Definition: FlowProblem.hpp:557
Scalar rockReferencePressure(unsigned globalSpaceIdx) const
Definition: FlowProblem.hpp:766
void deserialize(Restarter &res)
This method restores the complete state of the problem and its sub-objects from disk.
Definition: FlowProblem.hpp:273
Scalar biotCoeff(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:747
std::shared_ptr< EclMaterialLawManager > materialLawManager()
Definition: FlowProblem.hpp:875
std::shared_ptr< const EclThermalLawManager > thermalLawManager() const
Definition: FlowProblem.hpp:838
bool updateMaxWaterSaturation_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1348
typename GridView::template Codim< 0 >::Entity Element
Definition: FlowProblem.hpp:151
Scalar dofCenterDepth(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the depth of an degree of freedom [m].
Definition: FlowProblem.hpp:696
bool updateMaxOilSaturation_(unsigned compressedDofIdx, const IntensiveQuantities &iq)
Definition: FlowProblem.hpp:1317
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:105
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:158
const AquiferModel & aquiferModel() const
Definition: FlowProblem.hpp:1081
@ oilPhaseIdx
Definition: FlowProblem.hpp:139
int refPressurePhaseIdx_() const
Definition: FlowProblem.hpp:1727
static constexpr bool enableBioeffects
Definition: FlowProblem.hpp:120
LhsEval rockCompPoroMultiplier(const IntensiveQuantities &intQuants, unsigned elementIdx) const
Calculate the porosity multiplier due to water induced rock compaction.
Definition: FlowProblem.hpp:1123
Scalar transmissibilityBoundary(const unsigned globalSpaceIdx, const unsigned boundaryFaceIdx) const
Direct access to a boundary transmissibility.
Definition: FlowProblem.hpp:605
TracerModel & tracerModel()
Definition: FlowProblem.hpp:668
void readMaterialParameters_()
Definition: FlowProblem.hpp:1419
static constexpr bool enableBrine
Definition: FlowProblem.hpp:121
void serialize(Restarter &res)
This method writes the complete state of the problem and its subobjects to disk.
Definition: FlowProblem.hpp:292
MathToolbox< Evaluation > Toolbox
Definition: FlowProblem.hpp:165
@ gasPhaseIdx
Definition: FlowProblem.hpp:138
Scalar rockReferencePressure(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:757
Scalar diffusivity(const unsigned globalCellIn, const unsigned globalCellOut) const
Definition: FlowProblem.hpp:568
@ numEq
Definition: FlowProblem.hpp:116
void updateRockFraction_()
Definition: FlowProblem.hpp:1501
void prefetch(const Element &elem) const
Definition: FlowProblem.hpp:258
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
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
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
Definition: FlowProblem.hpp:1825
const std::vector< T > & operator()(FaceDir::DirEnum dir) const
Definition: FlowProblem.hpp:1834
void resize(std::size_t size, T defVal)
Definition: FlowProblem.hpp:1828
std::vector< T > & operator()(FaceDir::DirEnum dir)
Definition: FlowProblem.hpp:1846
std::array< std::vector< T >, 6 > data
Definition: FlowProblem.hpp:1826
Definition: FlowProblem.hpp:1598
ConditionalStorage< enableFullyImplicitThermal, Scalar > thermalHalfTransOut
Definition: FlowProblem.hpp:1600
ConditionalStorage< enableFullyImplicitThermal, Scalar > thermalHalfTransIn
Definition: FlowProblem.hpp:1599
ConditionalStorage< enableDiffusion, Scalar > diffusivity
Definition: FlowProblem.hpp:1601
ConditionalStorage< enableDispersion, Scalar > dispersivity
Definition: FlowProblem.hpp:1602
Scalar transmissibility
Definition: FlowProblem.hpp:1603