28 #ifndef EWOMS_NCP_MODEL_HH 29 #define EWOMS_NCP_MODEL_HH 31 #include <dune/common/fvector.hh> 33 #include <opm/common/Exceptions.hpp> 35 #include <opm/material/common/Valgrind.hpp> 36 #include <opm/material/densead/Math.hpp> 66 template <
class TypeTag>
78 struct NcpModel {
using InheritsFrom = std::tuple<MultiPhaseBaseModel>; };
83 template<
class TypeTag>
88 template<
class TypeTag>
93 template<
class TypeTag>
98 template<
class TypeTag>
103 template<
class TypeTag>
105 {
static constexpr
bool value =
false; };
108 template<
class TypeTag>
110 {
static constexpr
bool value =
false; };
113 template<
class TypeTag>
118 template<
class TypeTag>
123 template<
class TypeTag>
128 template<
class TypeTag>
133 template<
class TypeTag>
138 template<
class TypeTag>
143 template<
class TypeTag>
147 static constexpr type value = 1.0;
151 template<
class TypeTag>
155 static constexpr type value = 1.0;
159 template<
class TypeTag>
163 static constexpr type value = 1.0e-6;
244 template <
class TypeTag>
257 static constexpr
int numPhases = FluidSystem::numPhases;
258 static constexpr
int numComponents = FluidSystem::numComponents;
259 static constexpr
int fugacity0Idx = Indices::fugacity0Idx;
260 enum { pressure0Idx = Indices::pressure0Idx };
261 enum { saturation0Idx = Indices::saturation0Idx };
262 static constexpr
int conti0EqIdx = Indices::conti0EqIdx;
263 static constexpr
int ncp0EqIdx = Indices::ncp0EqIdx;
264 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
265 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
267 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
269 using Toolbox = MathToolbox<Evaluation>;
275 explicit NcpModel(Simulator& simulator)
276 : ParentType(simulator)
286 DiffusionModule::registerParameters();
287 EnergyModule::registerParameters();
292 if constexpr (enableDiffusion) {
296 if constexpr (enableEnergy) {
306 ParentType::finishInit();
308 minActivityCoeff_.resize(this->numGridDof());
309 std::ranges::fill(minActivityCoeff_, 1.0);
314 ParentType::adaptGrid();
315 minActivityCoeff_.resize(this->numGridDof());
329 const std::string s = EnergyModule::primaryVarName(pvIdx);
334 std::ostringstream oss;
335 if (pvIdx == pressure0Idx) {
336 oss <<
"pressure_" << FluidSystem::phaseName(0);
338 else if (saturation0Idx <= pvIdx && pvIdx < saturation0Idx + (numPhases - 1)) {
339 oss <<
"saturation_" << FluidSystem::phaseName(pvIdx - saturation0Idx);
341 else if (fugacity0Idx <= pvIdx && pvIdx < fugacity0Idx + numComponents) {
342 oss <<
"fugacity^" << FluidSystem::componentName(pvIdx - fugacity0Idx);
356 const std::string s = EnergyModule::eqName(eqIdx);
361 std::ostringstream oss;
362 if (conti0EqIdx <= eqIdx && eqIdx < conti0EqIdx + numComponents) {
363 oss <<
"continuity^" << FluidSystem::componentName(eqIdx - conti0EqIdx);
365 else if (ncp0EqIdx <= eqIdx && eqIdx < ncp0EqIdx + numPhases) {
366 oss <<
"ncp_" << FluidSystem::phaseName(eqIdx - ncp0EqIdx);
380 ParentType::updateBegin();
385 for (
unsigned dofIdx = 0; dofIdx < this->numGridDof(); ++dofIdx) {
386 if (this->isLocalDof(dofIdx)) {
388 this->solution(0)[dofIdx][Indices::pressure0Idx];
399 for (
unsigned dofIdx = 0; dofIdx < elemCtx.numDof(0); ++dofIdx) {
400 const unsigned globalIdx = elemCtx.globalSpaceIndex(dofIdx, 0);
402 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
403 minActivityCoeff_[globalIdx][compIdx] = 1e100;
404 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
405 const auto& fs = elemCtx.intensiveQuantities(dofIdx, 0).fluidState();
407 minActivityCoeff_[globalIdx][compIdx] =
408 std::min(minActivityCoeff_[globalIdx][compIdx],
409 Toolbox::value(fs.fugacityCoefficient(phaseIdx, compIdx)) *
410 Toolbox::value(fs.pressure(phaseIdx)));
411 Valgrind::CheckDefined(minActivityCoeff_[globalIdx][compIdx]);
413 if (minActivityCoeff_[globalIdx][compIdx] <= 0) {
414 throw NumericalProblem(
"The minimum activity coefficient for component " +
415 std::to_string(compIdx) +
" on DOF " +
416 std::to_string(globalIdx) +
" is negative or zero!");
427 const Scalar tmp = EnergyModule::primaryVarWeight(*
this, globalDofIdx, pvIdx);
433 else if (fugacity0Idx <= pvIdx && pvIdx < fugacity0Idx + numComponents) {
435 const unsigned compIdx = pvIdx - fugacity0Idx;
436 assert(compIdx <= numComponents);
438 Valgrind::CheckDefined(minActivityCoeff_[globalDofIdx][compIdx]);
439 constexpr Scalar fugacityBaseWeight =
440 getPropValue<TypeTag, Properties::NcpFugacitiesBaseWeight>();
441 result = fugacityBaseWeight / minActivityCoeff_[globalDofIdx][compIdx];
443 else if (Indices::pressure0Idx == pvIdx) {
444 constexpr Scalar pressureBaseWeight =
445 getPropValue<TypeTag, Properties::NcpPressureBaseWeight>();
446 result = pressureBaseWeight / referencePressure_;
450 const unsigned phaseIdx = pvIdx - saturation0Idx;
451 assert(phaseIdx < numPhases - 1);
455 constexpr Scalar saturationsBaseWeight =
456 getPropValue<TypeTag, Properties::NcpSaturationsBaseWeight>();
457 result = saturationsBaseWeight;
460 assert(std::isfinite(result));
472 Scalar
eqWeight(
unsigned globalDofIdx,
unsigned eqIdx)
const 474 const Scalar tmp = EnergyModule::eqWeight(*
this, globalDofIdx, eqIdx);
480 else if (ncp0EqIdx <= eqIdx && eqIdx < Indices::ncp0EqIdx + numPhases) {
485 const unsigned compIdx = eqIdx - Indices::conti0EqIdx;
486 assert(compIdx <= numComponents);
489 return FluidSystem::molarMass(compIdx);
500 {
return minActivityCoeff_[globalDofIdx][compIdx]; }
505 void registerOutputModules_()
507 ParentType::registerOutputModules_();
510 if constexpr (enableDiffusion) {
513 if constexpr (enableEnergy) {
514 this->addOutputModule(std::make_unique<VtkEnergyModule<TypeTag>>(this->simulator_));
518 mutable Scalar referencePressure_;
519 mutable std::vector<ComponentVector> minActivityCoeff_;
Provides the auxiliary methods required for consideration of the diffusion equation.
Definition: diffusionmodule.hh:51
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
Scalar eqWeight(unsigned globalDofIdx, unsigned eqIdx) const
Returns the relative weight of an equation.
Definition: ncpmodel.hh:472
The type of the base class for all problems which use this model.
Definition: fvbaseproperties.hh:84
Implements a boundary vector for the fully implicit compositional multi-phase NCP model...
The type of the local residual function.
Definition: fvbaseproperties.hh:94
The unmodified weight for the fugacity primary variables.
Definition: ncpproperties.hh:47
Specifies the type of the actual Newton method.
Definition: fvbaseproblem.hh:54
VTK output module for quantities which make sense for models which assume thermal equilibrium...
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkcompositionmodule.hpp:87
Enumerations used by the model.
Definition: multiphasebaseproperties.hh:51
Details needed to calculate the local residual in the compositional multi-phase NCP-model ...
Definition: ncplocalresidual.hh:52
Implements a vector representing mass, molar or volumetric rates.
Definition: ncpratevector.hh:51
Represents the primary variables used by the compositional multi-phase NCP model. ...
Definition: ncpprimaryvariables.hh:55
The base class for the problems of ECFV discretizations which deal with a multi-phase flow through a ...
Definition: multiphasebaseproblem.hh:62
A Newton solver specific to the NCP model.
Definition: ncpnewtonmethod.hh:55
Contains the classes required to consider energy as a conservation quantity in a multi-phase module...
This template class represents the extensive quantities of the compositional NCP model.
Definition: ncpextensivequantities.hh:45
Define the type tag for the compositional NCP model.
Definition: ncpmodel.hh:78
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: ncpmodel.hh:282
The primary variable and equation indices for the compositional multi-phase NCP model.
Definition: ncpindices.hh:42
Vector containing volumetric or areal rates of quantities.
Definition: fvbaseproperties.hh:116
Type of object for specifying boundary conditions.
Definition: fvbaseproperties.hh:119
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkdiffusionmodule.hpp:88
static void registerParameters()
Register all run-time parameters for the immiscible model.
Definition: multiphasebasemodel.hh:197
Declares the properties required for the NCP compositional multi-phase model.
Data required to calculate a flux over a face.
Definition: fvbaseproperties.hh:153
Implements a boundary vector for the fully implicit compositional multi-phase NCP model...
Definition: ncpboundaryratevector.hh:49
Represents the primary variables used by the compositional multi-phase NCP model. ...
Scalar primaryVarWeight(unsigned globalDofIdx, unsigned pvIdx) const
Returns the relative weight of a primary variable for calculating relative errors.
Definition: ncpmodel.hh:425
Specify whether energy should be considered as a conservation quantity or not.
Definition: multiphasebaseproperties.hh:87
Contains the quantities which are are constant within a finite volume in the compositional multi-phas...
Definition: ncpintensivequantities.hh:56
The secondary variables within a sub-control volume.
Definition: fvbaseproperties.hh:133
void updatePVWeights(const ElementContext &elemCtx) const
Update the weights of all primary variables within an element given the complete set of intensive qua...
Definition: ncpmodel.hh:397
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: vtkenergymodule.hpp:87
VTK output module for the fluid composition.
Definition: vtkcompositionmodule.hpp:56
std::string eqName(unsigned eqIdx) const
Given an equation index, return a human readable name.
Definition: ncpmodel.hh:354
void updateBegin()
Called by the update() method before it tries to apply the newton method.
Definition: ncpmodel.hh:378
The type of the model.
Definition: basicproperties.hh:92
static std::string name()
Definition: ncpmodel.hh:321
void finishInit()
Apply the initial conditions to the model.
Definition: ncpmodel.hh:304
Provides the auxiliary methods required for consideration of the energy equation. ...
Definition: energymodule.hh:54
Scalar minActivityCoeff(unsigned globalDofIdx, unsigned compIdx) const
Returns the smallest activity coefficient of a component for the most current solution at a vertex...
Definition: ncpmodel.hh:499
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Implements a vector representing mass, molar or volumetric rates.
The unmodified weight for the pressure primary variable.
Definition: ncpproperties.hh:39
The weight for the saturation primary variables.
Definition: ncpproperties.hh:43
Details needed to calculate the local residual in the compositional multi-phase NCP-model ...
Contains the quantities which are are constant within a finite volume in the compositional multi-phas...
A Newton solver specific to the NCP model.
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:83
Definition: blackoilmodel.hh:80
VTK output module for quantities which make sense for models which incorperate molecular diffusion...
Classes required for molecular diffusion.
std::string primaryVarName(unsigned pvIdx) const
Given an primary variable index, return a human readable name.
Definition: ncpmodel.hh:327
A vector of primary variables within a sub-control volume.
Definition: fvbaseproperties.hh:130
This template class represents the extensive quantities of the compositional NCP model.
A compositional multi-phase model based on non-linear complementarity functions.
Definition: ncpmodel.hh:67
Enable diffusive fluxes?
Definition: multiphasebaseproperties.hh:91
VTK output module for quantities which make sense for models which incorperate molecular diffusion...
Definition: vtkdiffusionmodule.hpp:57
VTK output module for the fluid composition.
The primary variable and equation indices for the compositional multi-phase NCP model.
A base class for fully-implicit multi-phase porous-media flow models which assume multiple fluid phas...
Definition: multiphasebasemodel.hh:57