28 #ifndef EWOMS_BLACK_OIL_MODEL_HH
29 #define EWOMS_BLACK_OIL_MODEL_HH
31 #include <opm/material/densead/Math.hpp>
52 #include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
53 #include <opm/common/Unused.hpp>
54 #include <opm/common/ErrorMacros.hpp>
55 #include <opm/common/Exceptions.hpp>
61 template <
class TypeTag>
64 template <
class TypeTag>
69 namespace Properties {
118 typedef typename
GET_PROP_TYPE(TypeTag, Evaluation) Evaluation;
121 typedef Opm::FluidSystems::BlackOil<Scalar> type;
128 SET_BOOL_PROP(BlackOilModel, BlackoilConserveSurfaceVolume, false);
193 template<class TypeTag >
197 typedef typename GET_PROP_TYPE(TypeTag, Model) Implementation;
202 typedef typename
GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
204 typedef typename
GET_PROP_TYPE(TypeTag, Discretization) Discretization;
205 typedef typename
GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
206 typedef typename
GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
209 enum { numComponents = FluidSystem::numComponents };
212 static const bool compositionSwitchEnabled = Indices::gasEnabled;
213 static const bool waterEnabled = Indices::waterEnabled;
215 typedef BlackOilSolventModule<TypeTag> SolventModule;
216 typedef BlackOilPolymerModule<TypeTag> PolymerModule;
220 BlackOilModel(Simulator& simulator)
221 : ParentType(simulator)
229 ParentType::registerParameters();
231 SolventModule::registerParameters();
232 PolymerModule::registerParameters();
244 maxOilSaturation_.resize(this->numGridDof(), 0.0);
245 ParentType::finishInit();
247 Dune::FMatrixPrecision<Scalar>::set_singular_limit(1e-35);
254 {
return "blackoil"; }
261 std::ostringstream oss;
263 if (pvIdx == Indices::waterSaturationIdx)
264 oss <<
"saturation_" << FluidSystem::phaseName(FluidSystem::waterPhaseIdx);
265 else if (pvIdx == Indices::pressureSwitchIdx)
266 oss <<
"pressure_switching";
267 else if (static_cast<int>(pvIdx) == Indices::compositionSwitchIdx)
268 oss <<
"composition_switching";
269 else if (SolventModule::primaryVarApplies(pvIdx))
270 return SolventModule::primaryVarName(pvIdx);
271 else if (PolymerModule::primaryVarApplies(pvIdx))
272 return PolymerModule::primaryVarName(pvIdx);
284 std::ostringstream oss;
286 if (Indices::conti0EqIdx <= eqIdx && eqIdx < Indices::conti0EqIdx + numComponents)
287 oss <<
"conti_" << FluidSystem::phaseName(eqIdx - Indices::conti0EqIdx);
288 else if (SolventModule::eqApplies(eqIdx))
289 return SolventModule::eqName(eqIdx);
290 else if (PolymerModule::eqApplies(eqIdx))
291 return PolymerModule::eqName(eqIdx);
305 if (globalDofIdx >= this->numGridDof())
309 if (Indices::waterSaturationIdx == pvIdx)
314 else if (Indices::pressureSwitchIdx == pvIdx)
318 else if (SolventModule::primaryVarApplies(pvIdx))
319 return SolventModule::primaryVarWeight(pvIdx);
322 else if (PolymerModule::primaryVarApplies(pvIdx))
323 return PolymerModule::primaryVarWeight(pvIdx);
326 assert(Indices::compositionSwitchIdx == pvIdx);
328 auto pvMeaning = this->solution(0)[globalDofIdx].primaryVarsMeaning();
329 if (pvMeaning == PrimaryVariables::Sw_po_Sg)
331 else if (pvMeaning == PrimaryVariables::Sw_po_Rs)
334 assert(pvMeaning == PrimaryVariables::Sw_pg_Rv);
343 Scalar
eqWeight(
unsigned globalDofIdx,
unsigned eqIdx OPM_UNUSED)
const
347 if (globalDofIdx >= this->numGridDof())
350 else if (SolventModule::eqApplies(eqIdx))
351 return SolventModule::eqWeight(eqIdx);
353 else if (PolymerModule::eqApplies(eqIdx))
354 return PolymerModule::eqWeight(eqIdx);
368 template <
class DofEntity>
371 unsigned dofIdx =
static_cast<unsigned>(asImp_().dofMapper().index(dof));
374 if (!outstream.good()) {
375 OPM_THROW(std::runtime_error,
"Could not serialize degree of freedom " << dofIdx);
379 const auto& priVars = this->solution(0)[dofIdx];
380 for (
unsigned eqIdx = 0; eqIdx < numEq; ++eqIdx)
381 outstream << priVars[eqIdx] <<
" ";
384 outstream << priVars.primaryVarsMeaning() <<
" ";
385 outstream << priVars.pvtRegionIndex() <<
" ";
387 if (maxOilSaturation_.size() > 0)
388 outstream << maxOilSaturation_[dofIdx] <<
" ";
390 SolventModule::serializeEntity(*
this, outstream, dof);
391 PolymerModule::serializeEntity(*
this, outstream, dof);
403 template <
class DofEntity>
405 const DofEntity& dof)
407 unsigned dofIdx =
static_cast<unsigned>(asImp_().dofMapper().index(dof));
410 auto& priVars = this->solution(0)[dofIdx];
411 for (
unsigned eqIdx = 0; eqIdx < numEq; ++eqIdx) {
412 if (!instream.good())
413 OPM_THROW(std::runtime_error,
414 "Could not deserialize degree of freedom " << dofIdx);
415 instream >> priVars[eqIdx];
419 unsigned primaryVarsMeaning;
420 instream >> primaryVarsMeaning;
422 unsigned pvtRegionIdx;
423 instream >> pvtRegionIdx;
425 if (maxOilSaturation_.size() > 0)
426 instream >> maxOilSaturation_[dofIdx];
428 if (!instream.good())
429 OPM_THROW(std::runtime_error,
430 "Could not deserialize degree of freedom " << dofIdx);
432 SolventModule::deserializeEntity(*
this, instream, dof);
433 PolymerModule::deserializeEntity(*
this, instream, dof);
435 typedef typename PrimaryVariables::PrimaryVarsMeaning PVM;
436 priVars.setPrimaryVarsMeaning(static_cast<PVM>(primaryVarsMeaning));
437 priVars.setPvtRegionIndex(pvtRegionIdx);
447 template <
class Restarter>
450 ParentType::deserialize(res);
455 ElementContext elemCtx(this->simulator_);
456 auto elemIt = this->gridView().template begin<0>();
457 auto elemEndIt = this->gridView().template end<0>();
458 for (; elemIt != elemEndIt; ++ elemIt) {
459 elemCtx.updateStencil(*elemIt);
460 for (
unsigned dofIdx = 0; dofIdx < elemCtx.numPrimaryDof(0); ++dofIdx) {
461 unsigned globalDofIdx = elemCtx.globalSpaceIndex(dofIdx, 0);
462 updatePvtRegionIndex_(this->solution(0)[globalDofIdx],
469 this->solution(1) = this->solution(0);
480 {
return maxOilSaturation_[globalDofIdx]; }
487 { maxOilSaturation_[globalDofIdx] = value; }
499 if (maxOilSaturation_.size() > 0) {
500 unsigned nGridDofs = this->numGridDof();
501 assert(maxOilSaturation_.size() == nGridDofs);
502 for (
unsigned dofIdx = 0; dofIdx < nGridDofs; ++dofIdx) {
503 const PrimaryVariables& priVars = this->solution(0)[dofIdx];
505 switch (priVars.primaryVarsMeaning()) {
506 case PrimaryVariables::Sw_po_Sg:
509 So -= priVars[Indices::waterSaturationIdx];
510 if( compositionSwitchEnabled )
511 So -= priVars[Indices::compositionSwitchIdx];
513 case PrimaryVariables::Sw_pg_Rv:
516 case PrimaryVariables::Sw_po_Rs:
519 So -= priVars[Indices::waterSaturationIdx];
523 maxOilSaturation_[dofIdx] = std::max(maxOilSaturation_[dofIdx], So);
535 template <
class Context>
536 void supplementInitialSolution_(PrimaryVariables& priVars,
537 const Context& context,
540 { updatePvtRegionIndex_(priVars, context, dofIdx, timeIdx); }
542 void registerOutputModules_()
544 ParentType::registerOutputModules_();
547 SolventModule::registerOutputModules(*
this, this->simulator_);
548 PolymerModule::registerOutputModules(*
this, this->simulator_);
555 Implementation& asImp_()
556 {
return *
static_cast<Implementation*
>(
this); }
557 const Implementation& asImp_()
const
558 {
return *
static_cast<const Implementation*
>(
this); }
560 template <
class Context>
561 void updatePvtRegionIndex_(PrimaryVariables& priVars,
562 const Context& context,
566 unsigned regionIdx = context.problem().pvtRegionIndex(context, dofIdx, timeIdx);
567 priVars.setPvtRegionIndex(regionIdx);
570 std::vector<Scalar> maxOilSaturation_;
#define SET_BOOL_PROP(EffTypeTagName, PropTagName,...)
Set a property to a simple constant boolean value.
Definition: propertysystem.hh:361
void deserializeEntity(std::istream &instream, const DofEntity &dof)
Reads the current solution variables for a degree of freedom from a restart file. ...
Definition: blackoilmodel.hh:404
Base class for all problems which use the black-oil model.
Definition: blackoilmodel.hh:65
static void registerParameters()
Register all run-time parameters for the multi-phase VTK output module.
Definition: vtkblackoilmodule.hh:123
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkcompositionmodule.hh:105
Contains the quantities which are are constant within a finite volume in the black-oil model...
std::string primaryVarName(int pvIdx) const
Given an primary variable index, return a human readable name.
Definition: blackoilmodel.hh:259
void setMaxOilSaturation(const Scalar value, unsigned globalDofIdx)
Sets an elements maximum oil phase saturation observed during the simulation (used for restarting fro...
Definition: blackoilmodel.hh:486
void serializeEntity(std::ostream &outstream, const DofEntity &dof)
Write the current solution for a degree of freedom to a restart file.
Definition: blackoilmodel.hh:369
Implements a boundary vector for the fully implicit black-oil model.
Implements a vector representing mass, molar or volumetric rates for the black oil model...
Definition: blackoilratevector.hh:50
VTK output module for the black oil model's parameters.
Definition: vtkblackoilmodule.hh:89
std::string eqName(int eqIdx) const
Given an equation index, return a human readable name.
Definition: blackoilmodel.hh:282
#define GET_PROP_VALUE(TypeTag, PropTagName)
Access the value attribute of a property for a type tag.
Definition: propertysystem.hh:469
Contains the classes required to extend the black-oil model by solvents.
static std::string name()
Definition: blackoilmodel.hh:253
A newton solver which is specific to the black oil model.
Definition: blackoilnewtonmethod.hh:45
#define NEW_TYPE_TAG(...)
Define a new type tag.
Definition: propertysystem.hh:169
A fully-implicit black-oil flow model.
Definition: blackoilmodel.hh:62
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:486
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: blackoilmodel.hh:227
#define INHERITS_FROM(...)
Syntactic sugar for NEW_TYPE_TAG.
Definition: propertysystem.hh:230
Provides a Darcy flux module for the blackoil model.
Definition: blackoildarcyfluxmodule.hh:48
Declares the properties required by the black oil model.
This file contains the default flux module of the blackoil model.
Scalar maxOilSaturation(unsigned globalDofIdx) const
Returns an elements maximum oil phase saturation observed during the simulation.
Definition: blackoilmodel.hh:479
Calculates the local residual of the black oil model.
Base class for all problems which use the black-oil model.
Definition: blackoilproblem.hh:44
VTK output module for the fluid composition.
void deserialize(Restarter &res)
Deserializes the state of the model.
Definition: blackoilmodel.hh:448
Implements a boundary vector for the fully implicit black-oil model.
Definition: blackoilboundaryratevector.hh:44
Implements a vector representing mass, molar or volumetric rates for the black oil model...
The multi-dimensional Newton method.
Definition: newtonmethod.hh:56
Represents the primary variables used by the black-oil model.
Calculates the local residual of the black oil model.
Definition: blackoillocalresidual.hh:43
This template class contains the data which is required to calculate the fluxes of the fluid phases o...
#define SET_PROP(EffTypeTagName, PropTagName)
Set a property for a specific type tag.
Definition: propertysystem.hh:297
The primary variable and equation indices for the black-oil model.
Scalar primaryVarWeight(unsigned globalDofIdx, unsigned pvIdx) const
Returns the relative weight of a primary variable for calculating relative errors.
Definition: blackoilmodel.hh:301
VTK output module for the black oil model's parameters.
The primary variable and equation indices for the black-oil model.
Definition: blackoilindices.hh:39
void finishInit()
Apply the initial conditions to the model.
Definition: blackoilmodel.hh:242
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
void updateMaxOilSaturations()
Update the maximum oil saturation observed during the simulation for all elements.
Definition: blackoilmodel.hh:497
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Definition: multiphasebasemodel.hh:47
The primary variable and equation indices for the black-oil model.
Represents the primary variables used by the black-oil model.
Definition: blackoilprimaryvariables.hh:58
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:75
This template class contains the data which is required to calculate the fluxes of the fluid phases o...
Definition: blackoilextensivequantities.hh:52
VTK output module for the fluid composition.
Definition: vtkcompositionmodule.hh:77
#define SET_TYPE_PROP(EffTypeTagName, PropTagName,...)
Set a property which defines a type.
Definition: propertysystem.hh:377
A newton solver which is specific to the black oil model.
Contains the classes required to extend the black-oil model by polymer.
Contains the quantities which are are constant within a finite volume in the black-oil model...
Definition: blackoilintensivequantities.hh:54
Scalar eqWeight(unsigned globalDofIdx, unsigned eqIdx OPM_UNUSED) const
Returns the relative weight of an equation.
Definition: blackoilmodel.hh:343