26#ifndef DUMUX_CO2_VOLUME_VARIABLES_HH
27#define DUMUX_CO2_VOLUME_VARIABLES_HH
31#include <dune/common/exceptions.hh>
47template <
class Traits>
55 using Scalar =
typename Traits::PrimaryVariables::value_type;
56 using ModelTraits =
typename Traits::ModelTraits;
62 comp0Idx = Traits::FluidSystem::comp0Idx,
63 comp1Idx = Traits::FluidSystem::comp1Idx,
64 phase0Idx = Traits::FluidSystem::phase0Idx,
65 phase1Idx = Traits::FluidSystem::phase1Idx
71 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
72 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
73 bothPhases = ModelTraits::Indices::bothPhases
79 switchIdx = ModelTraits::Indices::switchIdx,
80 pressureIdx = ModelTraits::Indices::pressureIdx
84 static constexpr auto formulation = ModelTraits::priVarFormulation();
87 using PermeabilityType =
typename Traits::PermeabilityType;
90 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
91 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
107 static constexpr bool useMoles() {
return ModelTraits::useMoles(); }
112 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
113 static_assert(ModelTraits::numFluidComponents() == 2,
"NumComponents set in the model is not two!");
125 template<
class ElemSol,
class Problem,
class Element,
class Scv>
126 void update(
const ElemSol& elemSol,
const Problem& problem,
const Element& element,
const Scv& scv)
133 typename FluidSystem::ParameterCache paramCache;
134 paramCache.updateAll(fluidState_);
136 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
137 const auto& matParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
139 const int wPhaseIdx = fluidState_.wettingPhase();
140 const int nPhaseIdx = 1 - wPhaseIdx;
143 relativePermeability_[wPhaseIdx] = MaterialLaw::krw(matParams,
saturation(wPhaseIdx));
144 relativePermeability_[nPhaseIdx] = MaterialLaw::krn(matParams,
saturation(wPhaseIdx));
148 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
149 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
151 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
153 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
156 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
158 EnergyVolVars::updateEffectiveThermalConductivity();
175 template<
class ElemSol,
class Problem,
class Element,
class Scv>
177 const Problem& problem,
178 const Element& element,
185 const auto&
priVars = elemSol[scv.localDofIndex()];
186 const auto phasePresence =
priVars.state();
188 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
189 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
194 if (phasePresence == secondPhaseOnly)
199 else if (phasePresence == firstPhaseOnly)
204 else if (phasePresence == bothPhases)
218 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase presence.");
221 pc_ = MaterialLaw::pc(materialParams,
fluidState.saturation(wPhaseIdx));
225 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
231 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
236 typename FluidSystem::ParameterCache paramCache;
238 if (phasePresence == bothPhases)
243 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
244 const auto xgH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
245 const auto xwH2O = 1 - xwCO2;
246 const auto xgCO2 = 1 - xgH2O;
247 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
248 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
249 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
250 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
255 else if (phasePresence == secondPhaseOnly)
263 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
264 const auto xwH2O = 1 - xwCO2;
265 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
266 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
273 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
274 const auto xwH2O = 1 - xwCO2;
275 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
276 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
282 else if (phasePresence == firstPhaseOnly)
290 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
291 Scalar xnCO2 = 1 - xnH2O;
292 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
293 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
300 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
301 Scalar xnCO2 = 1 - xnH2O;
302 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
303 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
307 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
310 paramCache.updateComposition(
fluidState, phaseIdx);
311 const Scalar rho = FluidSystem::density(
fluidState, paramCache, phaseIdx);
313 const Scalar rhoMolar = FluidSystem::molarDensity(
fluidState, phaseIdx);
314 fluidState.setMolarDensity(phaseIdx, rhoMolar);
315 const Scalar mu = FluidSystem::viscosity(
fluidState, paramCache, phaseIdx);
319 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
328 {
return fluidState_; }
334 {
return solidState_; }
342 {
return fluidState_.averageMolarMass(phaseIdx); }
351 {
return fluidState_.saturation(phaseIdx); }
361 {
return fluidState_.massFraction(phaseIdx, compIdx); }
371 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
380 {
return fluidState_.density(phaseIdx); }
389 {
return fluidState_.viscosity(phaseIdx); }
398 {
return fluidState_.molarDensity(phaseIdx) ; }
407 {
return fluidState_.pressure(phaseIdx); }
417 {
return fluidState_.temperature(0); }
426 {
return relativePermeability_[phaseIdx]; }
435 {
return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
442 {
return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
448 {
return solidState_.porosity(); }
454 {
return permeability_; }
459 [[deprecated(
"Will be removed after release 3.2. Use diffusionCoefficient(phaseIdx, compIIdx, compJIdx)!")]]
462 if (phaseIdx == compIdx)
463 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient called for phaseIdx = compIdx");
473 typename FluidSystem::ParameterCache paramCache;
474 paramCache.updatePhase(fluidState_, phaseIdx);
475 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
482 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
489 {
return fluidState_.wettingPhase(); }
495 PermeabilityType permeability_;
498 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
501 DiffusionCoefficients effectiveDiffCoeff_;
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.
Defines an enumeration for the formulations accepted by the two-phase model.
TwoPFormulation
Enumerates the formulations which the two-phase model accepts.
Definition formulation.hh:35
@ p1s0
first phase saturation and second phase pressure as primary variables
Definition formulation.hh:37
@ p0s1
first phase pressure and second phase saturation as primary variables
Definition formulation.hh:36
EnergyVolumeVariablesImplementation< IsothermalTraits, Impl, IsothermalTraits::ModelTraits::enableEnergyBalance()> EnergyVolumeVariables
Base class for the model specific class which provides access to all volume averaged quantities.
Definition porousmediumflow/nonisothermal/volumevariables.hh:85
void updateSolidVolumeFractions(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, SolidState &solidState, const int solidVolFracOffset)
update the solid volume fractions (inert and reacitve) and set them in the solidstate
Definition updatesolidvolumefractions.hh:36
The primary variable switch for the 2p2c-CO2 model controlling the phase presence state variable.
Definition co2/primaryvariableswitch.hh:45
Contains the quantities which are are constant within a finite volume in the CO2 model.
Definition porousmediumflow/co2/volumevariables.hh:51
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a given component in a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:360
const SolidState & solidState() const
Definition porousmediumflow/co2/volumevariables.hh:333
typename NCTraits< BaseTraits, DT, EDM >::FluidState FluidState
Definition porousmediumflow/co2/volumevariables.hh:95
Scalar saturation(const int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:350
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Completes the fluid state.
Definition porousmediumflow/co2/volumevariables.hh:176
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:434
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition porousmediumflow/co2/volumevariables.hh:481
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:447
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:379
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:388
typename NCTraits< BaseTraits, DT, EDM >::FluidSystem FluidSystem
Definition porousmediumflow/co2/volumevariables.hh:97
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition porousmediumflow/co2/volumevariables.hh:460
int wettingPhase() const
Returns the wetting phase index.
Definition porousmediumflow/co2/volumevariables.hh:488
TwoPTwoCCO2PrimaryVariableSwitch PrimaryVariableSwitch
Definition porousmediumflow/co2/volumevariables.hh:103
typename NCTraits< BaseTraits, DT, EDM >::SolidState SolidState
Definition porousmediumflow/co2/volumevariables.hh:99
typename NCTraits< BaseTraits, DT, EDM >::SolidSystem SolidSystem
Definition porousmediumflow/co2/volumevariables.hh:101
Scalar temperature() const
Returns temperature within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:416
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:406
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition porousmediumflow/co2/volumevariables.hh:107
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:453
const FluidState & fluidState() const
Definition porousmediumflow/co2/volumevariables.hh:327
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition porousmediumflow/co2/volumevariables.hh:126
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:397
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition porousmediumflow/co2/volumevariables.hh:341
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a given component in a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:370
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition porousmediumflow/co2/volumevariables.hh:109
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition porousmediumflow/co2/volumevariables.hh:471
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:441
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:425
The isothermal base class.
Definition porousmediumflow/volumevariables.hh:40
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition porousmediumflow/volumevariables.hh:52
const PrimaryVariables & priVars() const
Definition porousmediumflow/volumevariables.hh:76
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition porousmediumflow/volumevariables.hh:64
Base class for the model specific class which provides access to all volume averaged quantities.
Base class for the model specific class which provides access to all volume averaged quantities.
The primary variable switch for the 2p2c-CO2 model.