14#ifndef DUMUX_CO2_VOLUME_VARIABLES_HH
15#define DUMUX_CO2_VOLUME_VARIABLES_HH
19#include <dune/common/exceptions.hh>
35template <
class Traits>
43 using Scalar =
typename Traits::PrimaryVariables::value_type;
44 using ModelTraits =
typename Traits::ModelTraits;
50 comp0Idx = Traits::FluidSystem::comp0Idx,
51 comp1Idx = Traits::FluidSystem::comp1Idx,
52 phase0Idx = Traits::FluidSystem::phase0Idx,
53 phase1Idx = Traits::FluidSystem::phase1Idx
59 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
60 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
61 bothPhases = ModelTraits::Indices::bothPhases
67 switchIdx = ModelTraits::Indices::switchIdx,
68 pressureIdx = ModelTraits::Indices::pressureIdx
72 static constexpr auto formulation = ModelTraits::priVarFormulation();
75 using PermeabilityType =
typename Traits::PermeabilityType;
78 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
79 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
87 using Indices =
typename ModelTraits::Indices;
97 static constexpr bool useMoles() {
return ModelTraits::useMoles(); }
102 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
103 static_assert(ModelTraits::numFluidComponents() == 2,
"NumComponents set in the model is not two!");
115 template<
class ElemSol,
class Problem,
class Element,
class Scv>
116 void update(
const ElemSol& elemSol,
const Problem& problem,
const Element& element,
const Scv& scv)
123 typename FluidSystem::ParameterCache paramCache;
124 paramCache.updateAll(fluidState_);
126 const auto& spatialParams = problem.spatialParams();
127 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
129 const int wPhaseIdx = fluidState_.wettingPhase();
130 const int nPhaseIdx = 1 - wPhaseIdx;
133 relativePermeability_[wPhaseIdx] = fluidMatrixInteraction.krw(
saturation(wPhaseIdx));
134 relativePermeability_[nPhaseIdx] = fluidMatrixInteraction.krn(
saturation(wPhaseIdx));
138 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
139 permeability_ = spatialParams.permeability(element, scv, elemSol);
141 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
143 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
146 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
148 EnergyVolVars::updateEffectiveThermalConductivity();
165 template<
class ElemSol,
class Problem,
class Element,
class Scv>
167 const Problem& problem,
168 const Element& element,
175 const auto&
priVars = elemSol[scv.localDofIndex()];
178 const auto& spatialParams = problem.spatialParams();
179 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
182 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
209 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase presence.");
212 pc_ = fluidMatrixInteraction.pc(
fluidState.saturation(wPhaseIdx));
216 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
222 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
227 typename FluidSystem::ParameterCache paramCache;
234 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
235 const auto xgH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
236 const auto xwH2O = 1 - xwCO2;
237 const auto xgCO2 = 1 - xgH2O;
238 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
239 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
240 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
241 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
254 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
255 const auto xwH2O = 1 - xwCO2;
256 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
257 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
264 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
265 const auto xwH2O = 1 - xwCO2;
266 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
267 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
281 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
282 Scalar xnCO2 = 1 - xnH2O;
283 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
284 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
291 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
292 Scalar xnCO2 = 1 - xnH2O;
293 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
294 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
298 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
301 paramCache.updateComposition(
fluidState, phaseIdx);
305 fluidState.setMolarDensity(phaseIdx, rhoMolar);
310 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
319 {
return fluidState_; }
325 {
return solidState_; }
333 {
return fluidState_.averageMolarMass(phaseIdx); }
342 {
return fluidState_.saturation(phaseIdx); }
352 {
return fluidState_.massFraction(phaseIdx, compIdx); }
362 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
371 {
return fluidState_.density(phaseIdx); }
380 {
return fluidState_.viscosity(phaseIdx); }
389 {
return fluidState_.molarDensity(phaseIdx) ; }
398 {
return fluidState_.pressure(phaseIdx); }
408 {
return fluidState_.temperature(0); }
417 {
return relativePermeability_[phaseIdx]; }
426 {
return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
433 {
return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
439 {
return solidState_.porosity(); }
445 {
return permeability_; }
452 typename FluidSystem::ParameterCache paramCache;
453 paramCache.updatePhase(fluidState_, phaseIdx);
454 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
461 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
468 {
return fluidState_.wettingPhase(); }
474 PermeabilityType permeability_;
477 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
480 DiffusionCoefficients effectiveDiffCoeff_;
Definition: porousmediumflow/nonisothermal/volumevariables.hh:63
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:28
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition: porousmediumflow/volumevariables.hh:40
const PrimaryVariables & priVars() const
Returns the vector of primary variables.
Definition: porousmediumflow/volumevariables.hh:64
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:52
The primary variable switch for the 2p2c-CO2 model controlling the phase presence state variable.
Definition: co2/primaryvariableswitch.hh:33
Contains the quantities which are are constant within a finite volume in the CO2 model.
Definition: porousmediumflow/co2/volumevariables.hh:39
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:351
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:324
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/co2/volumevariables.hh:83
Scalar saturation(const int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:341
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:166
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:425
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:460
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:438
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/co2/volumevariables.hh:87
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:370
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:379
typename Traits::FluidSystem FluidSystem
The fluid system used here.
Definition: porousmediumflow/co2/volumevariables.hh:85
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/co2/volumevariables.hh:467
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/co2/volumevariables.hh:89
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/co2/volumevariables.hh:91
Scalar temperature() const
Returns temperature within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:407
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:397
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/co2/volumevariables.hh:97
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:444
const FluidState & fluidState() const
Returns the phase state within the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:318
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:116
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:388
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/co2/volumevariables.hh:332
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:361
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/co2/volumevariables.hh:99
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:450
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:432
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:416
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:24
TwoPFormulation
Enumerates the formulations which the two-phase model accepts.
Definition: formulation.hh:23
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
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.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.