30#ifndef OPM_FLOW_PROBLEM_COMP_HPP
31#define OPM_FLOW_PROBLEM_COMP_HPP
38#include <opm/grid/LookUpData.hh>
40#include <opm/material/fluidstates/CompositionalFluidState.hpp>
42#include <opm/material/thermal/EclThermalLawManager.hpp>
44#include <opm/input/eclipse/EclipseState/Compositional/CompositionalConfig.hpp>
58template <
class TypeTag>
88 using InitialFluidState = CompositionalFluidState<Scalar, FluidSystem>;
101 Parameters::SetDefault<Parameters::InputSkipMode>(
"300");
106 Parameters::SetDefault<Parameters::NewtonTolerance<Scalar>>(1e-7);
111 auto& simulator = this->simulator();
112 const auto& eclState = simulator.vanguard().eclState();
113 return eclState.compositionalConfig().eosType(0);
122 eclWriter_ = std::make_unique<EclWriterType>(simulator);
123 enableEclOutput_ = Parameters::Get<Parameters::EnableEclOutput>();
131 FlowProblemType::finishInit();
133 auto& simulator = this->simulator();
134 const bool transmissibilitiesFinished =
136 if (!transmissibilitiesFinished) {
140 const auto& eclState = simulator.vanguard().eclState();
141 const auto& schedule = simulator.vanguard().schedule();
145 if (eclState.getSimulationConfig().rock_config().active()) {
146 throw std::runtime_error(
"Rock compaction (ROCKCOMP) is not supported "
147 "by compositional modeling yet");
152 if (enableEclOutput_) {
153 eclWriter_->writeInit();
156 const auto& initconfig = eclState.getInitConfig();
157 if (initconfig.restartRequested())
164 if constexpr (getPropValue<TypeTag, Properties::EnablePolymer>()) {
165 const auto& vanguard = this->simulator().vanguard();
166 const auto& gridView = vanguard.gridView();
167 int numElements = gridView.size(0);
168 this->
polymer_.maxAdsorption.resize(numElements, 0.0);
182 if (this->enableVtkOutput_() && eclState.getIOConfig().initOnly()) {
183 simulator.setTimeStepSize(0.0);
190 if (!initconfig.restartRequested()) {
191 simulator.startNextEpisode(schedule.seconds(1));
192 simulator.setEpisodeIndex(0);
193 simulator.setTimeStepIndex(0);
216 this->eclWriter_->mutableOutputModule().invalidateLocalData();
219 const auto& grid = this->simulator().vanguard().gridView().grid();
221 using GridType = std::remove_cv_t<std::remove_reference_t<
decltype(grid)>>;
222 constexpr bool isCpGrid = std::is_same_v<GridType, Dune::CpGrid>;
223 if (!isCpGrid || (grid.maxLevel() == 0)) {
229 if (enableEclOutput_){
230 eclWriter_->writeReports(timer);
242 if (! this->enableEclOutput_) {
248 if (!isSubStep || Parameters::Get<Parameters::EnableWriteAllSolutions>()) {
249 auto localCellData = data::Solution {};
251 this->eclWriter_->writeOutput(std::move(localCellData), isSubStep,
252 this->simulator().vanguard().schedule()
253 .exitStatus().has_value());
262 template <
class Context>
264 const Context& context,
268 OPM_TIMEBLOCK_LOCAL(eclProblemBoundary, Subsystem::Assembly);
269 if (!context.intersection(spaceIdx).boundary())
275 throw std::logic_error(
"boundary condition is not supported by compostional modeling yet");
285 template <
class Context>
288 const unsigned globalDofIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
289 const auto& initial_fs = initialFluidStates_[globalDofIdx];
290 Opm::CompositionalFluidState<Scalar, FluidSystem> fs;
291 for (
unsigned p = 0; p < numPhases; ++p) {
293 fs.setPressure(p, initial_fs.pressure(p));
296 fs.setSaturation(p, initial_fs.saturation(p));
299 fs.setTemperature(initial_fs.temperature(p));
303 if (!zmf_initialization_) {
304 for (
unsigned p = 0; p < numPhases; ++p) {
305 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
306 fs.setMoleFraction(p, compIdx, initial_fs.moleFraction(p, compIdx));
312 typename FluidSystem::template ParameterCache<Scalar> paramCache(eos_type);
313 paramCache.updatePhase(fs, FluidSystem::oilPhaseIdx);
314 paramCache.updatePhase(fs, FluidSystem::gasPhaseIdx);
315 fs.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::oilPhaseIdx));
316 fs.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::gasPhaseIdx));
319 Dune::FieldVector<Scalar, numComponents> z(0.0);
321 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
322 if (Indices::waterEnabled && phaseIdx ==
static_cast<unsigned int>(waterPhaseIdx)){
325 const auto saturation = fs.saturation(phaseIdx);
326 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
327 Scalar tmp = fs.molarity(phaseIdx, compIdx) * saturation;
328 tmp = max(tmp, 1e-8);
334 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
335 fs.setMoleFraction(compIdx, z[compIdx]);
339 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
340 fs.setMoleFraction(compIdx, initial_fs.moleFraction(compIdx));
345 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
346 const auto& Ktmp = fs.wilsonK_(compIdx);
347 fs.setKvalue(compIdx, Ktmp);
350 const Scalar& Ltmp = -1.0;
353 values.assignNaive(fs);
362 {
return initialFluidStates_[globalDofIdx]; }
365 {
return initialFluidStates_; }
368 {
return initialFluidStates_; }
371 {
return *eclWriter_; }
374 {
return *eclWriter_; }
377 {
return eclWriter_->setSubStepReport(report); }
380 {
return eclWriter_->setSimulationReport(report); }
389 template<
class Serializer>
393 serializer(*eclWriter_);
404 const auto& simulator = this->simulator();
405 const auto& vanguard = simulator.vanguard();
406 const auto& eclState = vanguard.eclState();
412 std::vector<int> eqlnum(this->model().numGridDof(), 0);
413 if (eclState.fieldProps().has_int(
"EQLNUM")) {
415 lookUpData(vanguard.gridView());
416 eqlnum = lookUpData.template assignFieldPropsIntOnLeaf<int>(
417 eclState.fieldProps(),
"EQLNUM",
true);
422 std::vector<Scalar> connateWater, maxWater;
423 if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
424 const auto numDof = this->model().numGridDof();
425 connateWater.resize(numDof);
426 maxWater.resize(numDof);
427 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
429 ->oilWaterScaledEpsInfoDrainage(
static_cast<int>(dofIdx));
430 connateWater[dofIdx] = eps.Swl;
431 maxWater[dofIdx] = eps.Swu;
438 vanguard.cellCenterDepths(),
440 vanguard.gridView().comm(),
441 this->gravity()[dimWorld - 1],
442 this->numPressurePointsEquil(),
446 initialFluidStates_ = std::move(initialState.
fluidStates());
451 for (std::size_t cell = 0; cell < initialFluidStates_.size(); ++cell) {
452 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
453 initialFluidStates_[cell].setPressure(phaseIdx,
458 zmf_initialization_ =
true;
463 throw std::logic_error(
"Restarting is not supported by compositional modeling yet");
473 const auto& simulator = this->simulator();
474 const auto& vanguard = simulator.vanguard();
475 const auto& eclState = vanguard.eclState();
476 const auto& fp = eclState.fieldProps();
477 const bool has_pressure = fp.has_double(
"PRESSURE");
479 throw std::runtime_error(
"The ECL input file requires the presence of the PRESSURE "
480 "keyword if the model is initialized explicitly");
482 const bool has_xmf = fp.has_double(
"XMF");
483 const bool has_ymf = fp.has_double(
"YMF");
484 const bool has_zmf = fp.has_double(
"ZMF");
485 if ( !has_zmf && !(has_xmf && has_ymf) ) {
486 throw std::runtime_error(
"The ECL input file requires the presence of ZMF or XMF and YMF "
487 "keyword if the model is initialized explicitly");
490 if (has_zmf && (has_xmf || has_ymf)) {
491 throw std::runtime_error(
"The ECL input file can not handle explicit initialization "
492 "with both ZMF and XMF or YMF");
495 if (has_xmf != has_ymf) {
496 throw std::runtime_error(
"The ECL input file needs XMF and YMF combined to do the explicit "
497 "initializtion when using XMF or YMF");
500 const bool has_temp = fp.has_double(
"TEMPI");
503 assert(fp.has_double(
"SGAS"));
505 std::size_t numDof = this->model().numGridDof();
507 initialFluidStates_.resize(numDof);
509 std::vector<double> waterSaturationData;
510 std::vector<double> gasSaturationData;
511 std::vector<double> soilData;
512 std::vector<double> pressureData;
513 std::vector<double> tempiData;
515 const bool water_active = FluidSystem::phaseIsActive(waterPhaseIdx);
516 const bool gas_active = FluidSystem::phaseIsActive(gasPhaseIdx);
517 const bool oil_active = FluidSystem::phaseIsActive(oilPhaseIdx);
519 if (water_active && Indices::numPhases > 2)
520 waterSaturationData = fp.get_double(
"SWAT");
522 waterSaturationData.resize(numDof);
524 pressureData = fp.get_double(
"PRESSURE");
527 tempiData = fp.get_double(
"TEMPI");
533 gasSaturationData = fp.get_double(
"SGAS");
535 gasSaturationData.resize(numDof);
537 for (std::size_t dofIdx = 0; dofIdx < numDof; ++dofIdx) {
538 auto& dofFluidState = initialFluidStates_[dofIdx];
541 Scalar temperatureLoc = tempiData[dofIdx];
542 assert(std::isfinite(temperatureLoc) && temperatureLoc > 0);
543 dofFluidState.setTemperature(temperatureLoc);
546 dofFluidState.setSaturation(FluidSystem::gasPhaseIdx,
547 gasSaturationData[dofIdx]);
550 dofFluidState.setSaturation(FluidSystem::oilPhaseIdx,
552 - waterSaturationData[dofIdx]
553 - gasSaturationData[dofIdx]);
556 dofFluidState.setSaturation(FluidSystem::waterPhaseIdx,
557 waterSaturationData[dofIdx]);
563 const Scalar pressure = pressureData[dofIdx];
566 const std::array<Scalar, numPhases> pc = {0};
567 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
568 if (!FluidSystem::phaseIsActive(phaseIdx))
571 if (Indices::oilEnabled)
572 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[oilPhaseIdx]));
573 else if (Indices::gasEnabled)
574 dofFluidState.setPressure(phaseIdx, pressure + (pc[phaseIdx] - pc[gasPhaseIdx]));
575 else if (Indices::waterEnabled)
577 dofFluidState.setPressure(phaseIdx, pressure);
580 if (has_xmf && has_ymf) {
581 const auto& xmfData = fp.get_double(
"XMF");
582 const auto& ymfData = fp.get_double(
"YMF");
583 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
584 const std::size_t data_idx = compIdx * numDof + dofIdx;
585 const Scalar xmf = xmfData[data_idx];
586 const Scalar ymf = ymfData[data_idx];
588 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
589 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
594 zmf_initialization_ =
true;
595 const auto& zmfData = fp.get_double(
"ZMF");
596 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
597 const std::size_t data_idx = compIdx * numDof + dofIdx;
598 const Scalar zmf = zmfData[data_idx];
599 dofFluidState.setMoleFraction(compIdx, zmf);
602 const auto ymf = (dofFluidState.saturation(FluidSystem::gasPhaseIdx) > 0.) ? zmf :
Scalar{0};
603 dofFluidState.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, ymf);
606 const auto xmf = (dofFluidState.saturation(FluidSystem::oilPhaseIdx) > 0.) ? zmf :
Scalar{0};
607 dofFluidState.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, xmf);
616 void handleSolventBC(
const BCState::BCFace& , RateVector& )
const override
618 throw std::logic_error(
"solvent is disabled for compositional modeling and you're trying to add solvent to BC");
621 void handlePolymerBC(
const BCState::BCFace& , RateVector& )
const override
623 throw std::logic_error(
"polymer is disabled for compositional modeling and you're trying to add polymer to BC");
626 void handleMicrBC(
const BCState::BCFace& , RateVector& )
const override
628 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add microbes to BC");
631 void handleOxygBC(
const BCState::BCFace& , RateVector& )
const override
633 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add oxygen to BC");
636 void handleUreaBC(
const BCState::BCFace& , RateVector& )
const override
638 throw std::logic_error(
"MICP is disabled for compositional modeling and you're trying to add urea to BC");
641 std::vector<InitialFluidState> initialFluidStates_;
643 bool zmf_initialization_ {
false};
645 bool enableEclOutput_{
false};
646 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:214
const std::vector< Scalar > & referencePressures() const
Definition: InitStateEquilComp.hpp:305
std::vector< FluidState > & fluidStates()
Definition: InitStateEquilComp.hpp:296
Collects necessary output values and pass it to opm-common's ECL output.
Definition: EclWriter.hpp:124
static void registerParameters()
Definition: EclWriter.hpp:152
PolymerSolutionContainer< Scalar > polymer_
Definition: FlowGenericProblem.hpp:383
void initFluidSystem_()
Definition: FlowGenericProblem_impl.hpp:683
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblemComp.hpp:60
void writeOutput(bool verbose) override
Write the requested quantities of the current solution into the output files.
Definition: FlowProblemComp.hpp:238
const std::vector< InitialFluidState > & initialFluidStates() const
Definition: FlowProblemComp.hpp:367
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: FlowProblemComp.hpp:129
Opm::CompositionalConfig::EOSType getEosType() const
Definition: FlowProblemComp.hpp:109
FlowProblemComp(Simulator &simulator)
Definition: FlowProblemComp.hpp:119
void writeReports(const SimulatorTimer &timer)
Definition: FlowProblemComp.hpp:228
void readExplicitInitialCondition_() override
Definition: FlowProblemComp.hpp:466
void readExplicitInitialConditionCompositional_()
Definition: FlowProblemComp.hpp:471
void endTimeStep() override
Called by the simulator after each time integration.
Definition: FlowProblemComp.hpp:211
const EclWriterType & eclWriter() const
Definition: FlowProblemComp.hpp:370
std::vector< InitialFluidState > & initialFluidStates()
Definition: FlowProblemComp.hpp:364
void readEclRestartSolution_()
Definition: FlowProblemComp.hpp:461
void finalizeOutput()
Definition: FlowProblemComp.hpp:382
const InitialFluidState & initialFluidState(unsigned globalDofIdx) const
Definition: FlowProblemComp.hpp:361
void boundary(BoundaryRateVector &values, const Context &context, unsigned spaceIdx, unsigned) const
Evaluate the boundary conditions for a boundary segment.
Definition: FlowProblemComp.hpp:263
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: FlowProblemComp.hpp:286
void readEquilInitialCondition_() override
Definition: FlowProblemComp.hpp:402
void serializeOp(Serializer &serializer)
Definition: FlowProblemComp.hpp:390
void updateExplicitQuantities_(int, int, bool) override
Definition: FlowProblemComp.hpp:397
void addToSourceDense(RateVector &, unsigned, unsigned) const override
Definition: FlowProblemComp.hpp:356
void setSubStepReport(const SimulatorReportSingle &report)
Definition: FlowProblemComp.hpp:376
void initialSolutionApplied() override
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblemComp.hpp:200
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblemComp.hpp:98
EclWriterType & eclWriter()
Definition: FlowProblemComp.hpp:373
void setSimulationReport(const SimulatorReport &report)
Definition: FlowProblemComp.hpp:379
This problem simulates an input file given in the data format used by the commercial ECLiPSE simulato...
Definition: FlowProblem.hpp:101
virtual bool episodeWillBeOver() const
Definition: FlowProblem.hpp:2191
GetPropType< TypeTag, Properties::Evaluation > Evaluation
Definition: FlowProblem.hpp:166
bool nonTrivialBoundaryConditions() const
Definition: FlowProblem.hpp:1170
virtual void writeOutput(bool verbose)
Write the requested quantities of the current solution into the output files.
Definition: FlowProblem.hpp:544
unsigned pvtRegionIndex(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Returns the index of the relevant region for thermodynmic properties.
Definition: FlowProblem.hpp:966
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: FlowProblem.hpp:742
GetPropType< TypeTag, Properties::Vanguard > Vanguard
Definition: FlowProblem.hpp:114
@ numComponents
Definition: FlowProblem.hpp:124
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: FlowProblem.hpp:108
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: FlowProblem.hpp:155
FlowThresholdPressure< TypeTag > thresholdPressures_
Definition: FlowProblem.hpp:2124
@ waterPhaseIdx
Definition: FlowProblem.hpp:146
GetPropType< TypeTag, Properties::Indices > Indices
Definition: FlowProblem.hpp:115
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: FlowProblem.hpp:156
@ dimWorld
Definition: FlowProblem.hpp:119
@ gasPhaseIdx
Definition: FlowProblem.hpp:144
std::shared_ptr< const EclMaterialLawManager > materialLawManager() const
Returns the ECL material law manager.
Definition: FlowProblem.hpp:914
@ numPhases
Definition: FlowProblem.hpp:123
void finishTransmissibilities_()
Definition: FlowProblem.hpp:1423
@ dim
Definition: FlowProblem.hpp:118
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowProblem.hpp:109
bool prepareTransmissibilityOutput_(EclWriterType &eclWriter, const bool enableEclOutput)
Definition: FlowProblem.hpp:1432
void initializeSimulatorTime_()
Definition: FlowProblem.hpp:1491
static void registerParameters()
Registers all available parameters for the problem and the model.
Definition: FlowProblem.hpp:200
void updatePffDofData_()
Definition: FlowProblem.hpp:1885
@ oilPhaseIdx
Definition: FlowProblem.hpp:145
GetPropType< TypeTag, Properties::PrimaryVariables > PrimaryVariables
Definition: FlowProblem.hpp:154
virtual void endTimeStep()
Called by the simulator after each time integration.
Definition: FlowProblem.hpp:462
virtual void readInitialCondition_()
Definition: FlowProblem.hpp:1793
virtual void initialSolutionApplied()
Callback used by the model to indicate that the initial solution has been determined for all degrees ...
Definition: FlowProblem.hpp:1084
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: FlowProblem.hpp:111
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: FlowProblem.hpp:164
void initializeModelProperties_()
Definition: FlowProblem.hpp:1515
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