28#ifndef OPM_CO2PTFLASH_PROBLEM_HH
29#define OPM_CO2PTFLASH_PROBLEM_HH
31#include <opm/common/Exceptions.hpp>
33#include <opm/input/eclipse/EclipseState/Compositional/CompositionalConfig.hpp>
35#include <opm/material/components/SimpleCO2.hpp>
36#include <opm/material/components/C10.hpp>
37#include <opm/material/components/C1.hpp>
38#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp>
39#include <opm/material/fluidmatrixinteractions/BrooksCorey.hpp>
40#include <opm/material/constraintsolvers/PTFlash.hpp>
41#include <opm/material/fluidsystems/GenericOilGasWaterFluidSystem.hpp>
42#include <opm/material/fluidsystems/blackoilpvt/ConstantCompressibilityWaterPvt.hpp>
43#include <opm/material/common/Valgrind.hpp>
52#include <dune/grid/yaspgrid.hh>
53#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
54#include <dune/common/version.hh>
55#include <dune/common/fvector.hh>
56#include <dune/common/fmatrix.hh>
62template <
class TypeTag>
72template <
class TypeTag,
class MyTypeTag>
75template <
class TypeTag>
76struct NumComp<TypeTag, TTag::CO2PTBaseProblem> {
77 static constexpr int value = 3;
80template <
class TypeTag,
class MyTypeTag>
83template <
class TypeTag>
85 static constexpr bool value =
true;
89template <
class TypeTag>
90struct Grid<TypeTag, TTag::CO2PTBaseProblem> {
using type = Dune::YaspGrid<2>; };
93template <
class TypeTag>
94struct Problem<TypeTag, TTag::CO2PTBaseProblem>
98template <
class TypeTag>
106 using type = Opm::PTFlash<Scalar, FluidSystem>;
110template <
class TypeTag>
115 static constexpr int num_comp = getPropValue<TypeTag, Properties::NumComp>();
116 static constexpr bool enable_water = getPropValue<TypeTag, Properties::EnableDummyWater>();
119 using type = Opm::GenericOilGasWaterFluidSystem<Scalar, num_comp, enable_water>;
123template <
class TypeTag>
127 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
128 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
131 using Traits = Opm::ThreePhaseMaterialTraits<Scalar,
132 FluidSystem::waterPhaseIdx,
133 FluidSystem::oilPhaseIdx,
134 FluidSystem::gasPhaseIdx,
139 using EffMaterialLaw = Opm::NullMaterial<Traits>;
147template <
class TypeTag>
152template <
class TypeTag>
154 static constexpr bool value =
false;
162template<
class Scalar>
165template<
class Scalar>
171template<
class Scalar>
172struct Temperature {
static constexpr Scalar
value = 423.25; };
183template <
class TypeTag>
192 enum { dim = GridView::dimension };
193 enum { dimWorld = GridView::dimensionworld };
203 using Toolbox = Opm::MathToolbox<Evaluation>;
204 using CoordScalar =
typename GridView::ctype;
206 enum { numPhases = FluidSystem::numPhases };
207 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
208 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
209 enum { conti0EqIdx = Indices::conti0EqIdx };
210 enum { pressure0Idx = Indices::pressure0Idx };
211 enum { z0Idx = Indices::z0Idx };
212 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
213 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
214 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
216 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
217 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
218 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
219 using ComponentVector = Dune::FieldVector<Evaluation, numComponents>;
223 using FluidState = Opm::CompositionalFluidState<Evaluation, FluidSystem, enableEnergy>;
228 : ParentType(simulator)
230 const Scalar epi_len = Parameters::Get<Parameters::EpisodeLength<Scalar>>();
231 simulator.setEpisodeLength(epi_len);
233 using CompParm =
typename FluidSystem::ComponentParam;
234 using CO2 = Opm::SimpleCO2<Scalar>;
235 using C1 = Opm::C1<Scalar>;
236 using C10 = Opm::C10<Scalar>;
237 FluidSystem::addComponent(CompParm {CO2::name(), CO2::molarMass(), CO2::criticalTemperature(),
238 CO2::criticalPressure(), CO2::criticalVolume(), CO2::acentricFactor()});
239 FluidSystem::addComponent(CompParm {C1::name(), C1::molarMass(), C1::criticalTemperature(),
240 C1::criticalPressure(), C1::criticalVolume(), C1::acentricFactor()});
241 FluidSystem::addComponent(CompParm{C10::name(), C10::molarMass(), C10::criticalTemperature(),
242 C10::criticalPressure(), C10::criticalVolume(), C10::acentricFactor()});
248 temperature_ = Parameters::Get<Parameters::Temperature<Scalar>>();
249 K_ = this->toDimMatrix_(9.869232667160131e-14);
256 using WaterPvt =
typename FluidSystem::WaterPvt;
257 std::shared_ptr<WaterPvt> waterPvt = std::make_shared<WaterPvt>();
258 waterPvt->setApproach(WaterPvtApproach::ConstantCompressibilityWater);
259 auto& ccWaterPvt = waterPvt->template getRealPvt<WaterPvtApproach::ConstantCompressibilityWater>();
260 ccWaterPvt.setNumRegions(1);
261 Scalar rhoRefW = 1037.0;
262 ccWaterPvt.setReferenceDensities(0, Scalar(0.0), Scalar(0.0), rhoRefW);
263 ccWaterPvt.setViscosity(0, 9.6e-4);
264 ccWaterPvt.setCompressibility(0, 1.450377e-10);
266 FluidSystem::setWaterPvt(waterPvt);
269 template <
class Context>
271 gravity([[maybe_unused]]
const Context& context,
272 [[maybe_unused]]
unsigned spaceIdx,
273 [[maybe_unused]]
unsigned timeIdx)
const
285 return Opm::CompositionalConfig::EOSType::PR;
293 ParentType::finishInit();
307 ParentType::registerParameters();
309 Parameters::Register<Parameters::Temperature<Scalar>>
310 (
"The temperature [K] in the reservoir");
311 Parameters::Register<Parameters::Initialpressure<Scalar>>
312 (
"The initial pressure [Pa s] in the reservoir");
313 Parameters::Register<Parameters::SimulationName>
314 (
"The name of the simulation used for the output files");
315 Parameters::Register<Parameters::EpisodeLength<Scalar>>
316 (
"Time interval [s] for episode length");
318 Parameters::SetDefault<Parameters::CellsX>(30);
319 Parameters::SetDefault<Parameters::DomainSizeX<Scalar>>(300.0);
321 if constexpr (dim > 1) {
322 Parameters::SetDefault<Parameters::CellsY>(1);
323 Parameters::SetDefault<Parameters::DomainSizeY<Scalar>>(1.0);
325 if constexpr (dim == 3) {
326 Parameters::SetDefault<Parameters::CellsZ>(1);
327 Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(1.0);
330 Parameters::SetDefault<Parameters::EndTime<Scalar>>(60. * 60.);
331 Parameters::SetDefault<Parameters::InitialTimeStepSize<Scalar>>(0.1 * 60. * 60.);
332 Parameters::SetDefault<Parameters::NewtonMaxIterations>(30);
333 Parameters::SetDefault<Parameters::NewtonTargetIterations>(6);
334 Parameters::SetDefault<Parameters::NewtonTolerance<Scalar>>(1e-3);
335 Parameters::SetDefault<Parameters::VtkWriteFilterVelocities>(
true);
336 Parameters::SetDefault<Parameters::VtkWriteFugacityCoeffs>(
true);
337 Parameters::SetDefault<Parameters::VtkWritePotentialGradients>(
true);
338 Parameters::SetDefault<Parameters::VtkWriteTotalMassFractions>(
true);
339 Parameters::SetDefault<Parameters::VtkWriteTotalMoleFractions>(
true);
340 Parameters::SetDefault<Parameters::VtkWriteEquilibriumConstants>(
true);
341 Parameters::SetDefault<Parameters::VtkWriteLiquidMoleFractions>(
true);
343 Parameters::SetDefault<Parameters::LinearSolverAbsTolerance<Scalar>>(0.0);
344 Parameters::SetDefault<Parameters::LinearSolverTolerance<Scalar>>(1e-3);
352 std::ostringstream oss;
353 oss << Parameters::Get<Parameters::SimulationName>();
362 Scalar epi_len = Parameters::Get<Parameters::EpisodeLength<Scalar>>();
363 this->simulator().startNextEpisode(epi_len);
370 return this->simulator().episodeWillBeOver() || (this->simulator().timeStepIndex() == -1);
385 Scalar tol = this->model().newtonMethod().tolerance() * 1e5;
386 this->model().checkConservativeness(tol);
389 PrimaryVariables storageO, storageW;
390 this->model().globalPhaseStorage(storageO, oilPhaseIdx);
393 PrimaryVariables storageL, storageG;
394 this->model().globalPhaseStorage(storageL, oilPhaseIdx);
395 this->model().globalPhaseStorage(storageG, gasPhaseIdx);
407 template <
class Context>
408 void initial(PrimaryVariables& values,
const Context& context,
unsigned spaceIdx,
unsigned timeIdx)
const
410 Opm::CompositionalFluidState<Evaluation, FluidSystem> fs;
411 initialFluidState(fs, context, spaceIdx, timeIdx);
412 values.assignNaive(fs);
416 template <
class Context>
417 Scalar
temperature([[maybe_unused]]
const Context& context, [[maybe_unused]]
unsigned spaceIdx, [[maybe_unused]]
unsigned timeIdx)
const
424 template <
class Context>
426 [[maybe_unused]]
unsigned spaceIdx,
427 [[maybe_unused]]
unsigned timeIdx)
const
433 template <
class Context>
434 Scalar
porosity([[maybe_unused]]
const Context& context, [[maybe_unused]]
unsigned spaceIdx, [[maybe_unused]]
unsigned timeIdx)
const
436 int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
438 int prod = Parameters::Get<Parameters::CellsX>() - 1;
439 if (spatialIdx == inj || spatialIdx == prod) {
449 template <
class Context>
451 [[maybe_unused]]
unsigned spaceIdx,
452 [[maybe_unused]]
unsigned timeIdx)
const
459 template <
class Context>
464 { values.setNoFlow(); }
467 template <
class Context>
469 [[maybe_unused]]
const Context& context,
470 [[maybe_unused]]
unsigned spaceIdx,
471 [[maybe_unused]]
unsigned timeIdx)
const
473 source_rate = Scalar(0.0);
481 template <
class Flu
idState,
class Context>
482 void initialFluidState(
FluidState& fs,
const Context& context,
unsigned spaceIdx,
unsigned timeIdx)
const
489 int prod = Parameters::Get<Parameters::CellsX>() - 1;
490 int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
491 ComponentVector comp;
492 comp[0] = Evaluation::createVariable(0.5, z0Idx);
493 comp[1] = Evaluation::createVariable(0.3, z0Idx + 1);
494 comp[2] = 1. - comp[0] - comp[1];
495 if (spatialIdx == inj) {
496 comp[0] = Evaluation::createVariable(0.99, z0Idx);
497 comp[1] = Evaluation::createVariable(0.01 - 1e-3, z0Idx + 1);
498 comp[2] = 1. - comp[0] - comp[1];
501 Scalar p0 = Parameters::Get<Parameters::Initialpressure<Scalar>>();
505 if (spatialIdx == inj) {
508 if (spatialIdx == prod) {
511 Evaluation p_init = Evaluation::createVariable(p0, pressure0Idx);
513 fs.setPressure(FluidSystem::oilPhaseIdx, p_init);
514 fs.setPressure(FluidSystem::gasPhaseIdx, p_init);
515 fs.setPressure(FluidSystem::waterPhaseIdx, p_init);
517 fs.setTemperature(temperature_);
519 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
520 fs.setMoleFraction(compIdx, comp[compIdx]);
524 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
525 const Evaluation Ktmp = fs.wilsonK_(compIdx);
526 fs.setKvalue(compIdx, Ktmp);
529 const Evaluation& Ltmp = -1.0;
536 MaterialLawParams mat_;
3 component simple testproblem with ["CO2", "C1", "C10"]
Definition: co2ptflashproblem.hh:185
bool shouldWriteRestartFile()
Definition: co2ptflashproblem.hh:375
std::string name() const
The problem name.
Definition: co2ptflashproblem.hh:350
const DimMatrix & intrinsicPermeability(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:425
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:434
const MaterialLawParams & materialLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:450
Opm::CompositionalConfig::EOSType getEosType() const
Definition: co2ptflashproblem.hh:283
CO2PTProblem(Simulator &simulator)
Definition: co2ptflashproblem.hh:227
void source(RateVector &source_rate, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:468
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: co2ptflashproblem.hh:408
Scalar temperature(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:417
static void registerParameters()
Definition: co2ptflashproblem.hh:305
const DimVector & gravity() const
Definition: co2ptflashproblem.hh:278
void boundary(BoundaryRateVector &values, const Context &, unsigned, unsigned) const
Definition: co2ptflashproblem.hh:460
void endTimeStep()
Called by the simulator after each time integration.
Definition: co2ptflashproblem.hh:383
Opm::CompositionalFluidState< Evaluation, FluidSystem, enableEnergy > FluidState
Definition: co2ptflashproblem.hh:223
bool shouldWriteOutput()
Definition: co2ptflashproblem.hh:368
void initPetrophysics()
Definition: co2ptflashproblem.hh:246
const DimVector & gravity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:271
void initWaterPVT()
Definition: co2ptflashproblem.hh:254
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: co2ptflashproblem.hh:291
void endEpisode()
Definition: co2ptflashproblem.hh:360
Helper class for grid instantiation of the lens problem.
Definition: structuredgridvanguard.hh:99
Definition: blackoilnewtonmethodparams.hpp:31
Definition: blackoilmodel.hh:79
Definition: blackoilbioeffectsmodules.hh:43
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
The Opm property system, traits with inheritance.
Provides convenience routines to bring up the simulation at runtime.
Definition: co2ptflashproblem.hh:163
static constexpr Scalar value
Definition: co2ptflashproblem.hh:163
Definition: co2ptflashproblem.hh:166
static constexpr Scalar value
Definition: co2ptflashproblem.hh:166
Definition: co2injectionproblem.hh:162
static constexpr auto value
Definition: co2injectionproblem.hh:162
static constexpr Scalar value
Definition: co2injectionproblem.hh:165
Definition: co2ptflashproblem.hh:81
Specify whether energy should be considered as a conservation quantity or not.
Definition: multiphasebaseproperties.hh:87
Opm::PTFlash< Scalar, FluidSystem > type
Definition: co2ptflashproblem.hh:106
The type of the flash constraint solver.
Definition: flashproperties.hh:39
Opm::GenericOilGasWaterFluidSystem< Scalar, num_comp, enable_water > type
Definition: co2ptflashproblem.hh:119
The fluid systems including the information about the phases.
Definition: multiphasebaseproperties.hh:79
Dune::YaspGrid< 2 > type
Definition: co2ptflashproblem.hh:90
The type of the DUNE grid.
Definition: basicproperties.hh:100
EffMaterialLaw type
Definition: co2ptflashproblem.hh:143
The material law which ought to be used (extracted from the spatial parameters)
Definition: multiphasebaseproperties.hh:55
Definition: co2ptflashproblem.hh:73
The type of the problem.
Definition: fvbaseproperties.hh:81
Definition: co2ptflashproblem.hh:69
a tag to mark properties as undefined
Definition: propertysystem.hh:38
Property which provides a Vanguard (manages grids)
Definition: basicproperties.hh:96