28#ifndef OPM_CO2PTFLASH_PROBLEM_HH
29#define OPM_CO2PTFLASH_PROBLEM_HH
31#include <opm/common/Exceptions.hpp>
33#include <opm/material/components/SimpleCO2.hpp>
34#include <opm/material/components/C10.hpp>
35#include <opm/material/components/C1.hpp>
36#include <opm/material/fluidmatrixinteractions/RegularizedBrooksCorey.hpp>
37#include <opm/material/fluidmatrixinteractions/BrooksCorey.hpp>
38#include <opm/material/constraintsolvers/PTFlash.hpp>
39#include <opm/material/fluidsystems/GenericOilGasFluidSystem.hpp>
40#include <opm/material/common/Valgrind.hpp>
49#include <dune/grid/yaspgrid.hh>
50#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
51#include <dune/common/version.hh>
52#include <dune/common/fvector.hh>
53#include <dune/common/fmatrix.hh>
59template <
class TypeTag>
69template <
class TypeTag,
class MyTypeTag>
72template <
class TypeTag>
73struct NumComp<TypeTag, TTag::CO2PTBaseProblem> {
74 static constexpr int value = 3;
78template <
class TypeTag>
79struct Grid<TypeTag, TTag::CO2PTBaseProblem> {
using type = Dune::YaspGrid<2>; };
82template <
class TypeTag>
83struct Problem<TypeTag, TTag::CO2PTBaseProblem>
87template <
class TypeTag>
95 using type = Opm::PTFlash<Scalar, FluidSystem>;
99template <
class TypeTag>
104 static constexpr int num_comp = getPropValue<TypeTag, Properties::NumComp>();
107 using type = Opm::GenericOilGasFluidSystem<Scalar, num_comp>;
111template <
class TypeTag>
115 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
116 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
119 using Traits = Opm::TwoPhaseMaterialTraits<Scalar,
121 FluidSystem::oilPhaseIdx,
122 FluidSystem::gasPhaseIdx>;
125 using EffMaterialLaw = Opm::NullMaterial<Traits>;
133template <
class TypeTag>
138template <
class TypeTag>
140 static constexpr bool value =
false;
148template<
class Scalar>
151template<
class Scalar>
157template<
class Scalar>
158struct Temperature {
static constexpr Scalar
value = 423.25; };
169template <
class TypeTag>
178 enum { dim = GridView::dimension };
179 enum { dimWorld = GridView::dimensionworld };
189 using Toolbox = Opm::MathToolbox<Evaluation>;
190 using CoordScalar =
typename GridView::ctype;
192 enum { numPhases = FluidSystem::numPhases };
193 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
194 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
195 enum { conti0EqIdx = Indices::conti0EqIdx };
196 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
197 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
198 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
200 using GlobalPosition = Dune::FieldVector<CoordScalar, dimWorld>;
201 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
202 using DimVector = Dune::FieldVector<Scalar, dimWorld>;
203 using ComponentVector = Dune::FieldVector<Evaluation, numComponents>;
207 using FluidState = Opm::CompositionalFluidState<Evaluation, FluidSystem, enableEnergy>;
212 : ParentType(simulator)
214 const Scalar epi_len = Parameters::Get<Parameters::EpisodeLength<Scalar>>();
215 simulator.setEpisodeLength(epi_len);
217 using CompParm =
typename FluidSystem::ComponentParam;
218 using CO2 = Opm::SimpleCO2<Scalar>;
219 using C1 = Opm::C1<Scalar>;
220 using C10 = Opm::C10<Scalar>;
221 FluidSystem::addComponent(CompParm {CO2::name(), CO2::molarMass(), CO2::criticalTemperature(),
222 CO2::criticalPressure(), CO2::criticalVolume(), CO2::acentricFactor()});
223 FluidSystem::addComponent(CompParm {C1::name(), C1::molarMass(), C1::criticalTemperature(),
224 C1::criticalPressure(), C1::criticalVolume(), C1::acentricFactor()});
225 FluidSystem::addComponent(CompParm{C10::name(), C10::molarMass(), C10::criticalTemperature(),
226 C10::criticalPressure(), C10::criticalVolume(), C10::acentricFactor()});
232 temperature_ = Parameters::Get<Parameters::Temperature<Scalar>>();
233 K_ = this->toDimMatrix_(9.869232667160131e-14);
238 template <
class Context>
240 gravity([[maybe_unused]]
const Context& context,
241 [[maybe_unused]]
unsigned spaceIdx,
242 [[maybe_unused]]
unsigned timeIdx)
const
257 ParentType::finishInit();
267 ParentType::registerParameters();
269 Parameters::Register<Parameters::Temperature<Scalar>>
270 (
"The temperature [K] in the reservoir");
271 Parameters::Register<Parameters::Initialpressure<Scalar>>
272 (
"The initial pressure [Pa s] in the reservoir");
273 Parameters::Register<Parameters::SimulationName>
274 (
"The name of the simulation used for the output files");
275 Parameters::Register<Parameters::EpisodeLength<Scalar>>
276 (
"Time interval [s] for episode length");
278 Parameters::SetDefault<Parameters::CellsX>(30);
279 Parameters::SetDefault<Parameters::DomainSizeX<Scalar>>(300.0);
281 if constexpr (dim > 1) {
282 Parameters::SetDefault<Parameters::CellsY>(1);
283 Parameters::SetDefault<Parameters::DomainSizeY<Scalar>>(1.0);
285 if constexpr (dim == 3) {
286 Parameters::SetDefault<Parameters::CellsZ>(1);
287 Parameters::SetDefault<Parameters::DomainSizeZ<Scalar>>(1.0);
290 Parameters::SetDefault<Parameters::EndTime<Scalar>>(60. * 60.);
291 Parameters::SetDefault<Parameters::InitialTimeStepSize<Scalar>>(0.1 * 60. * 60.);
292 Parameters::SetDefault<Parameters::NewtonMaxIterations>(30);
293 Parameters::SetDefault<Parameters::NewtonTargetIterations>(6);
294 Parameters::SetDefault<Parameters::NewtonTolerance<Scalar>>(1e-3);
295 Parameters::SetDefault<Parameters::VtkWriteFilterVelocities>(
true);
296 Parameters::SetDefault<Parameters::VtkWriteFugacityCoeffs>(
true);
297 Parameters::SetDefault<Parameters::VtkWritePotentialGradients>(
true);
298 Parameters::SetDefault<Parameters::VtkWriteTotalMassFractions>(
true);
299 Parameters::SetDefault<Parameters::VtkWriteTotalMoleFractions>(
true);
300 Parameters::SetDefault<Parameters::VtkWriteEquilibriumConstants>(
true);
301 Parameters::SetDefault<Parameters::VtkWriteLiquidMoleFractions>(
true);
303 Parameters::SetDefault<Parameters::LinearSolverAbsTolerance<Scalar>>(0.0);
304 Parameters::SetDefault<Parameters::LinearSolverTolerance<Scalar>>(1e-3);
312 std::ostringstream oss;
313 oss << Parameters::Get<Parameters::SimulationName>();
322 Scalar epi_len = Parameters::Get<Parameters::EpisodeLength<Scalar>>();
323 this->simulator().startNextEpisode(epi_len);
330 return this->simulator().episodeWillBeOver() || (this->simulator().timeStepIndex() == -1);
345 Scalar tol = this->model().newtonMethod().tolerance() * 1e5;
346 this->model().checkConservativeness(tol);
349 PrimaryVariables storageO, storageW;
350 this->model().globalPhaseStorage(storageO, oilPhaseIdx);
353 PrimaryVariables storageL, storageG;
354 this->model().globalPhaseStorage(storageL, 0);
355 this->model().globalPhaseStorage(storageG, 1);
367 template <
class Context>
368 void initial(PrimaryVariables& values,
const Context& context,
unsigned spaceIdx,
unsigned timeIdx)
const
370 Opm::CompositionalFluidState<Evaluation, FluidSystem> fs;
371 initialFluidState(fs, context, spaceIdx, timeIdx);
372 values.assignNaive(fs);
376 template <
class Context>
377 Scalar
temperature([[maybe_unused]]
const Context& context, [[maybe_unused]]
unsigned spaceIdx, [[maybe_unused]]
unsigned timeIdx)
const
384 template <
class Context>
386 [[maybe_unused]]
unsigned spaceIdx,
387 [[maybe_unused]]
unsigned timeIdx)
const
393 template <
class Context>
394 Scalar
porosity([[maybe_unused]]
const Context& context, [[maybe_unused]]
unsigned spaceIdx, [[maybe_unused]]
unsigned timeIdx)
const
396 int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
398 int prod = Parameters::Get<Parameters::CellsX>() - 1;
399 if (spatialIdx == inj || spatialIdx == prod) {
409 template <
class Context>
411 [[maybe_unused]]
unsigned spaceIdx,
412 [[maybe_unused]]
unsigned timeIdx)
const
419 template <
class Context>
424 { values.setNoFlow(); }
427 template <
class Context>
429 [[maybe_unused]]
const Context& context,
430 [[maybe_unused]]
unsigned spaceIdx,
431 [[maybe_unused]]
unsigned timeIdx)
const
433 source_rate = Scalar(0.0);
441 template <
class Flu
idState,
class Context>
442 void initialFluidState(
FluidState& fs,
const Context& context,
unsigned spaceIdx,
unsigned timeIdx)
const
449 int prod = Parameters::Get<Parameters::CellsX>() - 1;
450 int spatialIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
451 ComponentVector comp;
452 comp[0] = Evaluation::createVariable(0.5, 1);
453 comp[1] = Evaluation::createVariable(0.3, 2);
454 comp[2] = 1. - comp[0] - comp[1];
455 if (spatialIdx == inj) {
456 comp[0] = Evaluation::createVariable(0.99, 1);
457 comp[1] = Evaluation::createVariable(0.01 - 1e-3, 2);
458 comp[2] = 1. - comp[0] - comp[1];
462 sat[1] = 1.0 - sat[0];
464 Scalar p0 = Parameters::Get<Parameters::Initialpressure<Scalar>>();
468 if (spatialIdx == inj) {
471 if (spatialIdx == prod) {
474 Evaluation p_init = Evaluation::createVariable(p0, 0);
476 fs.setPressure(FluidSystem::oilPhaseIdx, p_init);
477 fs.setPressure(FluidSystem::gasPhaseIdx, p_init);
479 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
480 fs.setMoleFraction(FluidSystem::oilPhaseIdx, compIdx, comp[compIdx]);
481 fs.setMoleFraction(FluidSystem::gasPhaseIdx, compIdx, comp[compIdx]);
485 fs.setSaturation(FluidSystem::oilPhaseIdx, sat[0]);
486 fs.setSaturation(FluidSystem::gasPhaseIdx, sat[1]);
488 fs.setTemperature(temperature_);
492 typename FluidSystem::template ParameterCache<Evaluation> paramCache;
493 paramCache.updatePhase(fs, FluidSystem::oilPhaseIdx);
494 paramCache.updatePhase(fs, FluidSystem::gasPhaseIdx);
495 fs.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::oilPhaseIdx));
496 fs.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fs, paramCache, FluidSystem::gasPhaseIdx));
497 fs.setViscosity(FluidSystem::oilPhaseIdx, FluidSystem::viscosity(fs, paramCache, FluidSystem::oilPhaseIdx));
498 fs.setViscosity(FluidSystem::gasPhaseIdx, FluidSystem::viscosity(fs, paramCache, FluidSystem::gasPhaseIdx));
502 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
503 const Evaluation Ktmp = fs.wilsonK_(compIdx);
504 fs.setKvalue(compIdx, Ktmp);
507 const Evaluation& Ltmp = -1.0;
514 MaterialLawParams mat_;
3 component simple testproblem with ["CO2", "C1", "C10"]
Definition: co2ptflashproblem.hh:171
bool shouldWriteRestartFile()
Definition: co2ptflashproblem.hh:335
std::string name() const
The problem name.
Definition: co2ptflashproblem.hh:310
const DimMatrix & intrinsicPermeability(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:385
Scalar porosity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:394
const MaterialLawParams & materialLawParams(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:410
CO2PTProblem(Simulator &simulator)
Definition: co2ptflashproblem.hh:211
void source(RateVector &source_rate, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:428
void initial(PrimaryVariables &values, const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Evaluate the initial value for a control volume.
Definition: co2ptflashproblem.hh:368
Scalar temperature(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:377
static void registerParameters()
Definition: co2ptflashproblem.hh:265
const DimVector & gravity() const
Definition: co2ptflashproblem.hh:247
void boundary(BoundaryRateVector &values, const Context &, unsigned, unsigned) const
Definition: co2ptflashproblem.hh:420
void endTimeStep()
Called by the simulator after each time integration.
Definition: co2ptflashproblem.hh:343
Opm::CompositionalFluidState< Evaluation, FluidSystem, enableEnergy > FluidState
Definition: co2ptflashproblem.hh:207
bool shouldWriteOutput()
Definition: co2ptflashproblem.hh:328
void initPetrophysics()
Definition: co2ptflashproblem.hh:230
const DimVector & gravity(const Context &context, unsigned spaceIdx, unsigned timeIdx) const
Definition: co2ptflashproblem.hh:240
void finishInit()
Called by the Opm::Simulator in order to initialize the problem.
Definition: co2ptflashproblem.hh:255
void endEpisode()
Definition: co2ptflashproblem.hh:320
Helper class for grid instantiation of the lens problem.
Definition: structuredgridvanguard.hh:95
Definition: blackoilnewtonmethodparams.hpp:31
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
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:235
The Opm property system, traits with inheritance.
Provides convenience routines to bring up the simulation at runtime.
Definition: co2ptflashproblem.hh:149
static constexpr Scalar value
Definition: co2ptflashproblem.hh:149
Definition: co2ptflashproblem.hh:152
static constexpr Scalar value
Definition: co2ptflashproblem.hh:152
Definition: co2injectionproblem.hh:162
static constexpr auto value
Definition: co2injectionproblem.hh:162
static constexpr Scalar value
Definition: co2injectionproblem.hh:165
Specify whether energy should be considered as a conservation quantity or not.
Definition: multiphasebaseproperties.hh:76
Opm::PTFlash< Scalar, FluidSystem > type
Definition: co2ptflashproblem.hh:95
The type of the flash constraint solver.
Definition: flashproperties.hh:39
Opm::GenericOilGasFluidSystem< Scalar, num_comp > type
Definition: co2ptflashproblem.hh:107
The fluid systems including the information about the phases.
Definition: multiphasebaseproperties.hh:69
Dune::YaspGrid< 2 > type
Definition: co2ptflashproblem.hh:79
The type of the DUNE grid.
Definition: basicproperties.hh:100
EffMaterialLaw type
Definition: co2ptflashproblem.hh:129
The material law which ought to be used (extracted from the spatial parameters)
Definition: multiphasebaseproperties.hh:51
Definition: co2ptflashproblem.hh:70
The type of the problem.
Definition: fvbaseproperties.hh:81
Definition: co2ptflashproblem.hh:66
a tag to mark properties as undefined
Definition: propertysystem.hh:40
Property which provides a Vanguard (manages grids)
Definition: basicproperties.hh:96