28#ifndef OPM_FLASH_INTENSIVE_QUANTITIES_HH
29#define OPM_FLASH_INTENSIVE_QUANTITIES_HH
31#include <dune/common/fmatrix.hh>
32#include <dune/common/fvector.hh>
34#include <opm/material/Constants.hpp>
35#include <opm/material/common/Valgrind.hpp>
36#include <opm/material/fluidstates/CompositionalFluidState.hpp>
54template <
class TypeTag>
55class FlashIntensiveQuantities
56 :
public GetPropType<TypeTag, Properties::DiscIntensiveQuantities>
57 ,
public DiffusionIntensiveQuantities<TypeTag, getPropValue<TypeTag, Properties::EnableDiffusion>() >
58 ,
public EnergyIntensiveQuantities<TypeTag, getPropValue<TypeTag, Properties::EnableEnergy>() >
59 ,
public GetPropType<TypeTag, Properties::FluxModule>::FluxIntensiveQuantities
61 using ParentType = GetPropType<TypeTag, Properties::DiscIntensiveQuantities>;
63 using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
64 using MaterialLaw = GetPropType<TypeTag, Properties::MaterialLaw>;
65 using MaterialLawParams = GetPropType<TypeTag, Properties::MaterialLawParams>;
66 using Indices = GetPropType<TypeTag, Properties::Indices>;
67 using FluxModule = GetPropType<TypeTag, Properties::FluxModule>;
68 using GridView = GetPropType<TypeTag, Properties::GridView>;
69 using ThreadManager = GetPropType<TypeTag, Properties::ThreadManager>;
72 enum { z0Idx = Indices::z0Idx };
73 enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
74 enum { numComponents = getPropValue<TypeTag, Properties::NumComponents>() };
75 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
76 enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
77 enum { dimWorld = GridView::dimensionworld };
78 enum { pressure0Idx = Indices::pressure0Idx };
80 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
81 using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
82 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
83 using FlashSolver = GetPropType<TypeTag, Properties::FlashSolver>;
85 using ComponentVector = Dune::FieldVector<Evaluation, numComponents>;
86 using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
88 using FluxIntensiveQuantities =
typename FluxModule::FluxIntensiveQuantities;
94 using FluidState = Opm::CompositionalFluidState<Evaluation, FluidSystem, enableEnergy>;
105 void update(
const ElementContext& elemCtx,
unsigned dofIdx,
unsigned timeIdx)
107 ParentType::update(elemCtx, dofIdx, timeIdx);
108 EnergyIntensiveQuantities::updateTemperatures_(fluidState_, elemCtx, dofIdx, timeIdx);
110 const auto& priVars = elemCtx.primaryVars(dofIdx, timeIdx);
111 const auto& problem = elemCtx.problem();
113 const Scalar flashTolerance = Parameters::Get<Parameters::FlashTolerance<Scalar>>();
114 const int flashVerbosity = Parameters::Get<Parameters::FlashVerbosity>();
115 const std::string flashTwoPhaseMethod = Parameters::Get<Parameters::FlashTwoPhaseMethod>();
118 ComponentVector z(0.);
120 Evaluation lastZ = 1.0;
121 for (
unsigned compIdx = 0; compIdx < numComponents - 1; ++compIdx) {
122 z[compIdx] = priVars.makeEvaluation(z0Idx + compIdx, timeIdx);
125 z[numComponents - 1] = lastZ;
127 Evaluation sumz = 0.0;
128 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
129 z[compIdx] = Opm::max(z[compIdx], 1e-8);
135 Evaluation p = priVars.makeEvaluation(pressure0Idx, timeIdx);
136 for (
int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
137 fluidState_.setPressure(phaseIdx, p);
140 const auto *hint = elemCtx.thermodynamicHint(dofIdx, timeIdx);
142 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
143 const Evaluation& Ktmp = hint->fluidState().K(compIdx);
144 fluidState_.setKvalue(compIdx, Ktmp);
146 const Evaluation& Ltmp = hint->fluidState().L();
147 fluidState_.setLvalue(Ltmp);
149 else if (timeIdx == 0 && elemCtx.thermodynamicHint(dofIdx, 1)) {
151 const auto& hint2 = elemCtx.thermodynamicHint(dofIdx, 1);
152 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
153 const Evaluation& Ktmp = hint2->fluidState().K(compIdx);
154 fluidState_.setKvalue(compIdx, Ktmp);
156 const Evaluation& Ltmp = hint2->fluidState().L();
157 fluidState_.setLvalue(Ltmp);
160 for (
unsigned compIdx = 0; compIdx < numComponents; ++compIdx) {
161 const Evaluation Ktmp = fluidState_.wilsonK_(compIdx);
162 fluidState_.setKvalue(compIdx, Ktmp);
164 const Evaluation& Ltmp = -1.0;
165 fluidState_.setLvalue(Ltmp);
171 if (flashVerbosity >= 1) {
172 const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
173 std::cout <<
" updating the intensive quantities for Cell " << spatialIdx << std::endl;
175 FlashSolver::solve(fluidState_, z, flashTwoPhaseMethod, flashTolerance, flashVerbosity);
177 if (flashVerbosity >= 5) {
179 const int spatialIdx = elemCtx.globalSpaceIndex(dofIdx, timeIdx);
180 std::cout <<
" \n After flash solve for cell " << spatialIdx << std::endl;
181 ComponentVector x, y;
182 for (
unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
183 x[comp_idx] = fluidState_.moleFraction(FluidSystem::oilPhaseIdx, comp_idx);
184 y[comp_idx] = fluidState_.moleFraction(FluidSystem::gasPhaseIdx, comp_idx);
186 for (
unsigned comp_idx = 0; comp_idx < numComponents; ++comp_idx) {
187 std::cout <<
" x for component: " << comp_idx <<
" is:" << std::endl;
188 std::cout << x[comp_idx] << std::endl;
190 std::cout <<
" y for component: " << comp_idx <<
"is:" << std::endl;
191 std::cout << y[comp_idx] << std::endl;
193 const Evaluation& L = fluidState_.L();
194 std::cout <<
" L is:" << std::endl;
195 std::cout << L << std::endl;
200 typename FluidSystem::template ParameterCache<Evaluation> paramCache;
201 paramCache.updatePhase(fluidState_, FluidSystem::oilPhaseIdx);
203 const Scalar R = Opm::Constants<Scalar>::R;
204 Evaluation Z_L = (paramCache.molarVolume(FluidSystem::oilPhaseIdx) * fluidState_.pressure(FluidSystem::oilPhaseIdx) )/
205 (R * fluidState_.temperature(FluidSystem::oilPhaseIdx));
206 paramCache.updatePhase(fluidState_, FluidSystem::gasPhaseIdx);
207 Evaluation Z_V = (paramCache.molarVolume(FluidSystem::gasPhaseIdx) * fluidState_.pressure(FluidSystem::gasPhaseIdx) )/
208 (R * fluidState_.temperature(FluidSystem::gasPhaseIdx));
213 Evaluation L = fluidState_.L();
214 Evaluation So = Opm::max((L * Z_L / ( L * Z_L + (1 - L) * Z_V)), 0.0);
215 Evaluation Sg = Opm::max(1 - So, 0.0);
216 Scalar sumS = Opm::getValue(So) + Opm::getValue(Sg);
220 fluidState_.setSaturation(0, So);
221 fluidState_.setSaturation(1, Sg);
223 fluidState_.setCompressFactor(0, Z_L);
224 fluidState_.setCompressFactor(1, Z_V);
227 if (flashVerbosity >= 5) {
228 std::cout <<
"So = " << So <<std::endl;
229 std::cout <<
"Sg = " << Sg <<std::endl;
233 if (flashVerbosity >= 5) {
234 std::cout <<
"So = " << So <<std::endl;
235 std::cout <<
"Sg = " << Sg <<std::endl;
236 std::cout <<
"Z_L = " << Z_L <<std::endl;
237 std::cout <<
"Z_V = " << Z_V <<std::endl;
243 const MaterialLawParams& materialParams = problem.materialLawParams(elemCtx, dofIdx, timeIdx);
246 MaterialLaw::relativePermeabilities(relativePermeability_,
247 materialParams, fluidState_);
248 Opm::Valgrind::CheckDefined(relativePermeability_);
251 for (
unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
252 paramCache.updatePhase(fluidState_, phaseIdx);
254 const Evaluation& mu = FluidSystem::viscosity(fluidState_, paramCache, phaseIdx);
256 fluidState_.setViscosity(phaseIdx, mu);
258 mobility_[phaseIdx] = relativePermeability_[phaseIdx] / mu;
259 Opm::Valgrind::CheckDefined(mobility_[phaseIdx]);
261 const Evaluation& rho = FluidSystem::density(fluidState_, paramCache, phaseIdx);
262 fluidState_.setDensity(phaseIdx, rho);
270 porosity_ = problem.porosity(elemCtx, dofIdx, timeIdx);
271 Opm::Valgrind::CheckDefined(porosity_);
274 intrinsicPerm_ = problem.intrinsicPermeability(elemCtx, dofIdx, timeIdx);
277 FluxIntensiveQuantities::update_(elemCtx, dofIdx, timeIdx);
280 EnergyIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
283 DiffusionIntensiveQuantities::update_(fluidState_, paramCache, elemCtx, dofIdx, timeIdx);
290 {
return fluidState_; }
296 {
return intrinsicPerm_; }
302 {
return relativePermeability_[phaseIdx]; }
307 const Evaluation&
mobility(
unsigned phaseIdx)
const
309 return mobility_[phaseIdx];
316 {
return porosity_; }
319 DimMatrix intrinsicPerm_;
321 Evaluation porosity_;
322 std::array<Evaluation,numPhases> relativePermeability_;
323 std::array<Evaluation,numPhases> mobility_;
Provides the volumetric quantities required for the calculation of molecular diffusive fluxes.
Definition: diffusionmodule.hh:141
Provides the volumetric quantities required for the energy equation.
Definition: energymodule.hh:532
Contains the intensive quantities of the flash-based compositional multi-phase model.
Definition: flash/flashintensivequantities.hh:58
Opm::CompositionalFluidState< Evaluation, FluidSystem, enableEnergy > FluidState
The type of the object returned by the fluidState() method.
Definition: flash/flashintensivequantities.hh:91
const Evaluation & mobility(unsigned phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: ptflash/flashintensivequantities.hh:307
const DimMatrix & intrinsicPermeability() const
Returns the intrinsic permeability tensor a degree of freedom.
Definition: ptflash/flashintensivequantities.hh:295
FlashIntensiveQuantities(const FlashIntensiveQuantities &other)=default
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: ptflash/flashintensivequantities.hh:289
const Evaluation & porosity() const
Returns the average porosity within the control volume.
Definition: ptflash/flashintensivequantities.hh:315
const Evaluation & relativePermeability(unsigned phaseIdx) const
Returns the relative permeability of a given phase within the control volume.
Definition: ptflash/flashintensivequantities.hh:301
FlashIntensiveQuantities()=default
void update(const ElementContext &elemCtx, unsigned dofIdx, unsigned timeIdx)
Definition: ptflash/flashintensivequantities.hh:105
FlashIntensiveQuantities & operator=(const FlashIntensiveQuantities &other)=default
Classes required for molecular diffusion.
Contains the classes required to consider energy as a conservation quantity in a multi-phase module.
Declares the properties required by the compositional multi-phase model based on flash calculations.
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
Declares the parameters for the compositional multi-phase model based on flash calculations.