26#ifndef DUMUX_CO2_VOLUME_VARIABLES_HH
27#define DUMUX_CO2_VOLUME_VARIABLES_HH
31#include <dune/common/exceptions.hh>
49template <
class Traits>
57 using Scalar =
typename Traits::PrimaryVariables::value_type;
58 using ModelTraits =
typename Traits::ModelTraits;
64 comp0Idx = Traits::FluidSystem::comp0Idx,
65 comp1Idx = Traits::FluidSystem::comp1Idx,
66 phase0Idx = Traits::FluidSystem::phase0Idx,
67 phase1Idx = Traits::FluidSystem::phase1Idx
73 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
74 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
75 bothPhases = ModelTraits::Indices::bothPhases
81 switchIdx = ModelTraits::Indices::switchIdx,
82 pressureIdx = ModelTraits::Indices::pressureIdx
86 static constexpr auto formulation = ModelTraits::priVarFormulation();
89 using PermeabilityType =
typename Traits::PermeabilityType;
92 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
93 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
101 using Indices =
typename ModelTraits::Indices;
111 static constexpr bool useMoles() {
return ModelTraits::useMoles(); }
116 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
117 static_assert(ModelTraits::numFluidComponents() == 2,
"NumComponents set in the model is not two!");
129 template<
class ElemSol,
class Problem,
class Element,
class Scv>
130 void update(
const ElemSol& elemSol,
const Problem& problem,
const Element& element,
const Scv& scv)
137 typename FluidSystem::ParameterCache paramCache;
138 paramCache.updateAll(fluidState_);
143 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
145 const int wPhaseIdx = fluidState_.wettingPhase();
146 const int nPhaseIdx = 1 - wPhaseIdx;
149 relativePermeability_[wPhaseIdx] = fluidMatrixInteraction.krw(
saturation(wPhaseIdx));
150 relativePermeability_[nPhaseIdx] = fluidMatrixInteraction.krn(
saturation(wPhaseIdx));
154 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
155 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
157 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
159 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
162 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
164 EnergyVolVars::updateEffectiveThermalConductivity();
181 template<
class ElemSol,
class Problem,
class Element,
class Scv>
183 const Problem& problem,
184 const Element& element,
191 const auto&
priVars = elemSol[scv.localDofIndex()];
194 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
200 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
227 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase presence.");
230 pc_ = fluidMatrixInteraction.pc(
fluidState.saturation(wPhaseIdx));
234 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
240 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
245 typename FluidSystem::ParameterCache paramCache;
252 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
253 const auto xgH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
254 const auto xwH2O = 1 - xwCO2;
255 const auto xgCO2 = 1 - xgH2O;
256 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
257 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
258 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
259 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
272 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
273 const auto xwH2O = 1 - xwCO2;
274 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
275 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
282 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
283 const auto xwH2O = 1 - xwCO2;
284 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
285 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
299 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
300 Scalar xnCO2 = 1 - xnH2O;
301 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
302 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
309 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
310 Scalar xnCO2 = 1 - xnH2O;
311 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
312 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
316 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
319 paramCache.updateComposition(
fluidState, phaseIdx);
323 fluidState.setMolarDensity(phaseIdx, rhoMolar);
328 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
337 {
return fluidState_; }
343 {
return solidState_; }
351 {
return fluidState_.averageMolarMass(phaseIdx); }
360 {
return fluidState_.saturation(phaseIdx); }
370 {
return fluidState_.massFraction(phaseIdx, compIdx); }
380 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
389 {
return fluidState_.density(phaseIdx); }
398 {
return fluidState_.viscosity(phaseIdx); }
407 {
return fluidState_.molarDensity(phaseIdx) ; }
416 {
return fluidState_.pressure(phaseIdx); }
426 {
return fluidState_.temperature(0); }
435 {
return relativePermeability_[phaseIdx]; }
444 {
return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
451 {
return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
457 {
return solidState_.porosity(); }
463 {
return permeability_; }
470 typename FluidSystem::ParameterCache paramCache;
471 paramCache.updatePhase(fluidState_, phaseIdx);
472 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
479 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
486 {
return fluidState_.wettingPhase(); }
492 PermeabilityType permeability_;
495 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
498 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:53
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:369
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:342
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/co2/volumevariables.hh:97
Scalar saturation(const int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:359
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:182
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:443
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:478
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:456
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/co2/volumevariables.hh:101
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:388
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:397
typename Traits::FluidSystem FluidSystem
The fluid system used here.
Definition: porousmediumflow/co2/volumevariables.hh:99
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/co2/volumevariables.hh:485
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/co2/volumevariables.hh:103
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/co2/volumevariables.hh:105
Scalar temperature() const
Returns temperature within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:425
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:415
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/co2/volumevariables.hh:111
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:462
const FluidState & fluidState() const
Returns the phase state within the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:336
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:130
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:406
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/co2/volumevariables.hh:350
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:379
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/co2/volumevariables.hh:113
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:468
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:450
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:434
Definition: porousmediumflow/nonisothermal/volumevariables.hh:75
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
Returns the vector of primary variables.
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 extended Richards model.