30#ifndef OPM_FLOW_PROBLEM_COMP_HPP
31#define OPM_FLOW_PROBLEM_COMP_HPP
39#include <opm/grid/LookUpData.hh>
41#include <opm/material/fluidstates/CompositionalFluidState.hpp>
43#include <opm/material/thermal/EclThermalLawManager.hpp>
45#include <opm/input/eclipse/EclipseState/Compositional/CompositionalConfig.hpp>
59template <
class TypeTag>
89 using InitialFluidState = CompositionalFluidState<Scalar, FluidSystem>;
102 Parameters::SetDefault<Parameters::InputSkipMode>(
"300");
107 Parameters::SetDefault<Parameters::NewtonTolerance<Scalar>>(1e-7);
112 auto& simulator = this->simulator();
113 const auto& eclState = simulator.vanguard().eclState();
114 return eclState.compositionalConfig().eosType(0);
122 , thresholdPressures_(simulator)
124 eclWriter_ = std::make_unique<EclWriterType>(simulator);
125 enableEclOutput_ = Parameters::Get<Parameters::EnableEclOutput>();
133 FlowProblemType::finishInit();
135 auto& simulator = this->simulator();
136 const bool transmissibilitiesFinished =
138 if (!transmissibilitiesFinished) {
142 const auto& eclState = simulator.vanguard().eclState();
143 const auto& schedule = simulator.vanguard().schedule();
150 if (enableEclOutput_) {
151 eclWriter_->writeInit();
154 const auto& initconfig = eclState.getInitConfig();
155 if (initconfig.restartRequested())
162 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
163 const auto& vanguard = this->simulator().vanguard();
164 const auto& gridView = vanguard.gridView();
165 int numElements = gridView.size(0);
166 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
180 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
181 simulator.setTimeStepSize(0.0);
188 if (!initconfig.restartRequested()) {
189 simulator.startNextEpisode(schedule.seconds(1));
190 simulator.setEpisodeIndex(0);
191 simulator.setTimeStepIndex(0);
203 this->eclWriter_->mutableOutputModule().invalidateLocalData();
206 const auto& grid = this->simulator().vanguard().gridView().grid();
208 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
209 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
210 if (!isCpGrid || (grid.maxLevel() == 0)) {
216 if (enableEclOutput_){
217 eclWriter_->writeReports(timer);
229 if (! this->enableEclOutput_) {
235 if (!isSubStep || Parameters::Get<Parameters::EnableWriteAllSolutions>()) {
236 auto localCellData = data::Solution {};
238 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
239 this->simulator().vanguard().schedule()
240 .exitStatus().has_value());
249 template <
class Context>
251 const Context& context,
255 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
256 if (!context.intersection(spaceIdx).boundary())
262 throw std::logic_error(
"boundary condition is not supported by compostional modeling yet");
272 template <
class Context>
275 const unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
276 const auto& initial_fs = initialFluidStates_[globalDofIdx];
277 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
278 for (
unsigned p = 0; p < numPhases; ++p) {
280 fs.setPressure(p, initial_fs.pressure(p));
283 fs.setSaturation(p, initial_fs.saturation(p));
286 fs.setTemperature(initial_fs.temperature(p));
290 if (!zmf_initialization_) {
291 for (
unsigned p = 0; p < numPhases; ++p) {
292 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
293 fs.setMoleFraction(p, compIdx, initial_fs.moleFraction(p, compIdx));
299 typename FluidSystem::template ParameterCache<Scalar> paramCache(eos_type);
300 paramCache.updatePhase(fs, FluidSystem::oilPhaseIdx);
301 paramCache.updatePhase(fs, FluidSystem::gasPhaseIdx);
302 fs.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::oilPhaseIdx));
303 fs.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::gasPhaseIdx));
306 Dune::FieldVector<Scalar, numComponents> z(0.0);
308 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
309 if (Indices::waterEnabled && phaseIdx ==
static_cast<unsigned int>(waterPhaseIdx)){
312 const auto saturation = fs.saturation(phaseIdx);
313 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
314 Scalar tmp = fs.molarity(phaseIdx, compIdx) * saturation;
315 tmp = max(tmp, 1e-8);
321 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
322 fs.setMoleFraction(compIdx, z[compIdx]);
326 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
327 fs.setMoleFraction(compIdx, initial_fs.moleFraction(compIdx));
332 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
333 const auto& Ktmp = fs.wilsonK_(compIdx);
334 fs.setKvalue(compIdx, Ktmp);
337 const Scalar& Ltmp = -1.0;
340 values.assignNaive(fs);
349 {
return initialFluidStates_[globalDofIdx]; }
352 {
return initialFluidStates_; }
355 {
return initialFluidStates_; }
359 assert( !thresholdPressures_.enableThresholdPressure() &&
360 " Threshold Pressures are not supported by compostional simulation ");
361 return thresholdPressures_;
365 {
return *eclWriter_; }
368 {
return *eclWriter_; }
371 {
return eclWriter_->setSubStepReport(report); }
374 {
return eclWriter_->setSimulationReport(report); }
383 template<
class Serializer>
387 serializer(*eclWriter_);
398 const auto& simulator = this->simulator();
399 const auto& vanguard = simulator.vanguard();
400 const auto& eclState = vanguard.eclState();
406 std::vector<int> eqlnum(this->model().numGridDof(), 0);
407 if (eclState.fieldProps().has_int(
"EQLNUM")) {
409 lookUpData(vanguard.gridView());
410 eqlnum = lookUpData.template assignFieldPropsIntOnLeaf<int>(
411 eclState.fieldProps(),
"EQLNUM",
true);
416 std::vector<Scalar> connateWater, maxWater;
417 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
418 const auto numDof = this->model().numGridDof();
419 connateWater.resize(numDof);
420 maxWater.resize(numDof);
421 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
423 ->oilWaterScaledEpsInfoDrainage(
static_cast<int>(dofIdx));
424 connateWater[dofIdx] = eps.Swl;
425 maxWater[dofIdx] = eps.Swu;
432 vanguard.cellCenterDepths(),
434 vanguard.gridView().comm(),
435 this->gravity()[dimWorld - 1],
436 this->numPressurePointsEquil(),
440 initialFluidStates_ = std::move(initialState.
fluidStates());
445 for (std::size_t cell = 0; cell < initialFluidStates_.size(); ++cell) {
446 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
447 initialFluidStates_[cell].setPressure(phaseIdx,
452 zmf_initialization_ =
true;
457 throw std::logic_error(
"Restarting is not supported by compositional modeling yet");
467 const auto& simulator = this->simulator();
468 const auto& vanguard = simulator.vanguard();
469 const auto& eclState = vanguard.eclState();
470 const auto& fp = eclState.fieldProps();
471 const bool has_pressure = fp.has_double(
"PRESSURE");
473 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
474 "keyword if the model is initialized explicitly");
476 const bool has_xmf = fp.has_double(
"XMF");
477 const bool has_ymf = fp.has_double(
"YMF");
478 const bool has_zmf = fp.has_double(
"ZMF");
479 if ( !has_zmf && !(has_xmf && has_ymf) ) {
480 throw std::runtime_error(
"The ECL input file requires the presence of ZMF or XMF and YMF "
481 "keyword if the model is initialized explicitly");
484 if (has_zmf && (has_xmf || has_ymf)) {
485 throw std::runtime_error(
"The ECL input file can not handle explicit initialization "
486 "with both ZMF and XMF or YMF");
489 if (has_xmf != has_ymf) {
490 throw std::runtime_error(
"The ECL input file needs XMF and YMF combined to do the explicit "
491 "initializtion when using XMF or YMF");
494 const bool has_temp = fp.has_double(
"TEMPI");
497 assert(fp.has_double(
"SGAS"));
499 std::size_t numDof = this->model().numGridDof();
501 initialFluidStates_.resize(numDof);
503 std::vector<double> waterSaturationData;
504 std::vector<double> gasSaturationData;
505 std::vector<double> soilData;
506 std::vector<double> pressureData;
507 std::vector<double> tempiData;
509 const bool water_active = FluidSystem::phaseIsActive(waterPhaseIdx);
510 const bool gas_active = FluidSystem::phaseIsActive(gasPhaseIdx);
511 const bool oil_active = FluidSystem::phaseIsActive(oilPhaseIdx);
513 if (water_active && Indices::numPhases > 2)
514 waterSaturationData = fp.get_double(
"SWAT");
516 waterSaturationData.resize(numDof);
518 pressureData = fp.get_double(
"PRESSURE");
521 tempiData = fp.get_double(
"TEMPI");
527 gasSaturationData = fp.get_double(
"SGAS");
529 gasSaturationData.resize(numDof);
531 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
532 auto& dofFluidState = initialFluidStates_[dofIdx];
535 Scalar temperatureLoc = tempiData[dofIdx];
536 assert(std::isfinite(temperatureLoc) && temperatureLoc > 0);
537 dofFluidState.setTemperature(temperatureLoc);
540 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
541 gasSaturationData[dofIdx]);
544 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx,
546 - waterSaturationData[dofIdx]
547 - gasSaturationData[dofIdx]);
550 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
551 waterSaturationData[dofIdx]);
557 const Scalar pressure = pressureData[dofIdx];
560 const std::array<Scalar, numPhases> pc = {0};
561 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
562 if (!FluidSystem::phaseIsActive(phaseIdx))
565 if (Indices::oilEnabled)
566 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
567 else if (Indices::gasEnabled)
568 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
569 else if (Indices::waterEnabled)
571 dofFluidState.setPressure(phaseIdx, pressure);
574 if (has_xmf && has_ymf) {
575 const auto& xmfData = fp.get_double(
"XMF");
576 const auto& ymfData = fp.get_double(
"YMF");
577 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
578 const std::size_t data_idx = compIdx * numDof + dofIdx;
579 const Scalar xmf = xmfData[data_idx];
580 const Scalar ymf = ymfData[data_idx];
582 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
583 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
588 zmf_initialization_ =
true;
589 const auto& zmfData = fp.get_double(
"ZMF");
590 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
591 const std::size_t data_idx = compIdx * numDof + dofIdx;
592 const Scalar zmf = zmfData[data_idx];
593 dofFluidState.setMoleFraction(compIdx, zmf);
596 const auto ymf = (dofFluidState.saturation(FluidSystem::gasPhaseIdx) > 0.) ? zmf :
Scalar{0};
597 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
600 const auto xmf = (dofFluidState.saturation(FluidSystem::oilPhaseIdx) > 0.) ? zmf :
Scalar{0};
601 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
610 void handleSolventBC(
const BCState::BCFace& , RateVector& )
const override
612 throw std::logic_error(
"solvent is disabled for compositional modeling and you're trying to add solvent to BC");
615 void handlePolymerBC(
const BCState::BCFace& , RateVector& )
const override
617 throw std::logic_error(
"polymer is disabled for compositional modeling and you're trying to add polymer to BC");
620 void handleMicrBC(
const BCState::BCFace& , RateVector& )
const override
622 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add microbes to BC");
625 void handleOxygBC(
const BCState::BCFace& , RateVector& )
const override
627 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add oxygen to BC");
630 void handleUreaBC(
const BCState::BCFace& , RateVector& )
const override
632 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add urea to BC");
635 FlowThresholdPressure<TypeTag> thresholdPressures_;
637 std::vector<InitialFluidState> initialFluidStates_;
639 bool zmf_initialization_ {
false};
641 bool enableEclOutput_{
false};
642 std::unique_ptr<EclWriterType> eclWriter_;
Hydrostatic equilibration for the compositional simulator (EQUIL + ZMFVD/COMPVD).
Computes the initial state of a compositional model from hydrostatic equilibrium (the EQUIL and ZMFVD...
Definition: InitStateEquilComp.hpp:212
const std::vector< Scalar > & referencePressures() const
Definition: InitStateEquilComp.hpp:303
std::vector< FluidState > & fluidStates()
Definition: InitStateEquilComp.hpp:294
Collects necessary output values and pass it to opm-common's ECL output.
Definition: EclWriter.hpp:123
static void registerParameters()
Definition: EclWriter.hpp:151
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:377
void initFluidSystem_()
Definition: FlowGenericProblem_impl.hpp:638
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemComp.hpp:61
void writeOutput(bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemComp.hpp:225
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemComp.hpp:354
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemComp.hpp:131
Opm::CompositionalConfig::EOSType getEosType() const
Definition: FlowProblemComp.hpp:110
FlowProblemComp(Simulator &simulator)
Definition: FlowProblemComp.hpp:120
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemComp.hpp:215
void readExplicitInitialCondition_() override
Definition: FlowProblemComp.hpp:460
void readExplicitInitialConditionCompositional_()
Definition: FlowProblemComp.hpp:465
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemComp.hpp:198
const EclWriterType & eclWriter() const
Definition: FlowProblemComp.hpp:364
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemComp.hpp:351
const FlowThresholdPressure< TypeTag > & thresholdPressure() const
Definition: FlowProblemComp.hpp:357
void readEclRestartSolution_()
Definition: FlowProblemComp.hpp:455
void finalizeOutput()
Definition: FlowProblemComp.hpp:376
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemComp.hpp:348
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemComp.hpp:250
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemComp.hpp:273
void readEquilInitialCondition_() override
Definition: FlowProblemComp.hpp:396
void serializeOp(Serializer &serializer)
Definition: FlowProblemComp.hpp:384
void updateExplicitQuantities_(int, int, bool) override
Definition: FlowProblemComp.hpp:391
void addToSourceDense(RateVector &, unsigned, unsigned) const override
Definition: FlowProblemComp.hpp:343
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemComp.hpp:370
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemComp.hpp:99
EclWriterType & eclWriter()
Definition: FlowProblemComp.hpp:367
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemComp.hpp:373
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:98
virtual bool episodeWillBeOver() const
Definition: FlowProblem.hpp:2115
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:163
bool nonTrivialBoundaryConditions() const
Definition: FlowProblem.hpp:1146
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:539
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:942
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:722
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:111
@ numComponents
Definition: FlowProblem.hpp:121
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:105
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:152
@ waterPhaseIdx
Definition: FlowProblem.hpp:143
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:112
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:153
@ dimWorld
Definition: FlowProblem.hpp:116
@ gasPhaseIdx
Definition: FlowProblem.hpp:141
std::shared_ptr< const EclMaterialLawManager > materialLawManager() const
Returns the ECL material law manager.
Definition: FlowProblem.hpp:894
@ numPhases
Definition: FlowProblem.hpp:120
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1373
@ dim
Definition: FlowProblem.hpp:115
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:106
bool prepareTransmissibilityOutput_(EclWriterType &eclWriter, const bool enableEclOutput)
Definition: FlowProblem.hpp:1382
void initializeSimulatorTime_()
Definition: FlowProblem.hpp:1441
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:196
void updatePffDofData_()
Definition: FlowProblem.hpp:1835
@ oilPhaseIdx
Definition: FlowProblem.hpp:142
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:151
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:457
virtual void readInitialCondition_()
Definition: FlowProblem.hpp:1743
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:108
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:161
void initializeModelProperties_()
Definition: FlowProblem.hpp:1465
This class calculates the threshold pressure for grid faces according to the Eclipse Reference Manual...
Definition: FlowThresholdPressure.hpp:59
Definition: FlowGenericProblem.hpp:51
Definition: SimulatorTimer.hpp:38
Definition: blackoilbioeffectsmodules.hh:45
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
Definition: SimulatorReport.hpp:202
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34