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;
99 using Indices =
typename ModelTraits::Indices;
109 static constexpr bool useMoles() {
return ModelTraits::useMoles(); }
114 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
115 static_assert(ModelTraits::numFluidComponents() == 2,
"NumComponents set in the model is not two!");
127 template<
class ElemSol,
class Problem,
class Element,
class Scv>
128 void update(
const ElemSol& elemSol,
const Problem& problem,
const Element& element,
const Scv& scv)
135 typename FluidSystem::ParameterCache paramCache;
136 paramCache.updateAll(fluidState_);
138 const auto& spatialParams = problem.spatialParams();
139 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
141 const int wPhaseIdx = fluidState_.wettingPhase();
142 const int nPhaseIdx = 1 - wPhaseIdx;
145 relativePermeability_[wPhaseIdx] = fluidMatrixInteraction.krw(
saturation(wPhaseIdx));
146 relativePermeability_[nPhaseIdx] = fluidMatrixInteraction.krn(
saturation(wPhaseIdx));
150 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
151 permeability_ = spatialParams.permeability(element, scv, elemSol);
153 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
155 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
158 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
160 EnergyVolVars::updateEffectiveThermalConductivity();
177 template<
class ElemSol,
class Problem,
class Element,
class Scv>
179 const Problem& problem,
180 const Element& element,
187 const auto&
priVars = elemSol[scv.localDofIndex()];
190 const auto& spatialParams = problem.spatialParams();
191 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
194 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
221 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase presence.");
224 pc_ = fluidMatrixInteraction.pc(
fluidState.saturation(wPhaseIdx));
228 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
234 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
239 typename FluidSystem::ParameterCache paramCache;
246 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
247 const auto xgH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
248 const auto xwH2O = 1 - xwCO2;
249 const auto xgCO2 = 1 - xgH2O;
250 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
251 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
252 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
253 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
266 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
267 const auto xwH2O = 1 - xwCO2;
268 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
269 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
276 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
277 const auto xwH2O = 1 - xwCO2;
278 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
279 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
293 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
294 Scalar xnCO2 = 1 - xnH2O;
295 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
296 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
303 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
304 Scalar xnCO2 = 1 - xnH2O;
305 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
306 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
310 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
313 paramCache.updateComposition(
fluidState, phaseIdx);
317 fluidState.setMolarDensity(phaseIdx, rhoMolar);
322 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
331 {
return fluidState_; }
337 {
return solidState_; }
345 {
return fluidState_.averageMolarMass(phaseIdx); }
354 {
return fluidState_.saturation(phaseIdx); }
364 {
return fluidState_.massFraction(phaseIdx, compIdx); }
374 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
383 {
return fluidState_.density(phaseIdx); }
392 {
return fluidState_.viscosity(phaseIdx); }
401 {
return fluidState_.molarDensity(phaseIdx) ; }
410 {
return fluidState_.pressure(phaseIdx); }
420 {
return fluidState_.temperature(0); }
429 {
return relativePermeability_[phaseIdx]; }
438 {
return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
445 {
return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
451 {
return solidState_.porosity(); }
457 {
return permeability_; }
464 typename FluidSystem::ParameterCache paramCache;
465 paramCache.updatePhase(fluidState_, phaseIdx);
466 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
473 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
480 {
return fluidState_.wettingPhase(); }
486 PermeabilityType permeability_;
489 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
492 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
@ p0s1
first phase pressure and second phase saturation as primary variables
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
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:147
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:83
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
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:363
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:336
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
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:353
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:178
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:437
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:472
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:450
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/co2/volumevariables.hh:99
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:382
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:391
typename Traits::FluidSystem FluidSystem
The fluid system used here.
Definition: porousmediumflow/co2/volumevariables.hh:97
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/co2/volumevariables.hh:479
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/co2/volumevariables.hh:101
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/co2/volumevariables.hh:103
Scalar temperature() const
Returns temperature within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:419
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:409
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/co2/volumevariables.hh:109
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:456
const FluidState & fluidState() const
Returns the phase state within the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:330
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:128
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:400
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/co2/volumevariables.hh:344
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:373
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/co2/volumevariables.hh:111
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:462
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:444
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:428
Definition: porousmediumflow/nonisothermal/volumevariables.hh:76
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:42
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition: porousmediumflow/volumevariables.hh:54
const PrimaryVariables & priVars() const
Returns the vector of primary variables.
Definition: porousmediumflow/volumevariables.hh:78
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:66
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 extended Richards model.