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;
102 static constexpr bool useMoles() {
return ModelTraits::useMoles(); }
107 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
108 static_assert(ModelTraits::numFluidComponents() == 2,
"NumComponents set in the model is not two!");
120 template<
class ElemSol,
class Problem,
class Element,
class Scv>
121 void update(
const ElemSol& elemSol,
const Problem& problem,
const Element& element,
const Scv& scv)
128 typename FluidSystem::ParameterCache paramCache;
129 paramCache.updateAll(fluidState_);
131 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
132 const auto& matParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
134 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
135 const int nPhaseIdx = 1 - wPhaseIdx;
138 relativePermeability_[wPhaseIdx] = MaterialLaw::krw(matParams,
saturation(wPhaseIdx));
139 relativePermeability_[nPhaseIdx] = MaterialLaw::krn(matParams,
saturation(wPhaseIdx));
142 diffCoeff_[phase0Idx] = FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phase0Idx, comp0Idx, comp1Idx);
143 diffCoeff_[phase1Idx] = FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phase1Idx, comp0Idx, comp1Idx);
147 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
148 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
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()];
176 const auto phasePresence =
priVars.state();
178 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
179 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
180 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
184 if (phasePresence == secondPhaseOnly)
189 else if (phasePresence == firstPhaseOnly)
194 else if (phasePresence == bothPhases)
208 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase presence.");
211 pc_ = MaterialLaw::pc(materialParams,
fluidState.saturation(wPhaseIdx));
215 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
221 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
226 typename FluidSystem::ParameterCache paramCache;
228 if (phasePresence == bothPhases)
233 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
234 const auto xgH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
235 const auto xwH2O = 1 - xwCO2;
236 const auto xgCO2 = 1 - xgH2O;
237 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
238 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
239 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
240 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
245 else if (phasePresence == secondPhaseOnly)
253 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase0Idx);
254 const auto xwH2O = 1 - xwCO2;
255 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
256 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
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);
272 else if (phasePresence == firstPhaseOnly)
280 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(
fluidState, paramCache, phase1Idx);
281 Scalar xnCO2 = 1 - xnH2O;
282 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
283 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
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);
297 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
300 paramCache.updateComposition(
fluidState, phaseIdx);
301 const Scalar rho = FluidSystem::density(
fluidState, paramCache, phaseIdx);
303 const Scalar rhoMolar = FluidSystem::molarDensity(
fluidState, phaseIdx);
304 fluidState.setMolarDensity(phaseIdx, rhoMolar);
305 const Scalar mu = FluidSystem::viscosity(
fluidState, paramCache, phaseIdx);
309 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
318 {
return fluidState_; }
324 {
return solidState_; }
332 {
return fluidState_.averageMolarMass(phaseIdx); }
341 {
return fluidState_.saturation(phaseIdx); }
351 {
return fluidState_.massFraction(phaseIdx, compIdx); }
361 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
370 {
return fluidState_.density(phaseIdx); }
379 {
return fluidState_.viscosity(phaseIdx); }
388 {
return fluidState_.molarDensity(phaseIdx) ; }
397 {
return fluidState_.pressure(phaseIdx); }
407 {
return fluidState_.temperature(0); }
416 {
return relativePermeability_[phaseIdx]; }
425 {
return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
432 {
return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
438 {
return solidState_.porosity(); }
444 {
return permeability_; }
451 if(phaseIdx == compIdx)
452 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient called for phaseIdx = compIdx");
454 return diffCoeff_[phaseIdx];
461 PermeabilityType permeability_;
464 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
467 std::array<Scalar, ModelTraits::numFluidPhases()> diffCoeff_;
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
make the local view function available whenever we use the grid geometry
Definition adapt.hh:29
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:350
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition porousmediumflow/co2/volumevariables.hh:323
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition porousmediumflow/co2/volumevariables.hh:90
Scalar saturation(const int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:340
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:424
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:437
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:369
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:378
typename Traits::FluidSystem FluidSystem
The fluid system used here.
Definition porousmediumflow/co2/volumevariables.hh:92
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition porousmediumflow/co2/volumevariables.hh:449
TwoPTwoCCO2PrimaryVariableSwitch PrimaryVariableSwitch
Export the type of the primary variable switch.
Definition porousmediumflow/co2/volumevariables.hh:98
typename Traits::SolidState SolidState
Export type of solid state.
Definition porousmediumflow/co2/volumevariables.hh:94
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition porousmediumflow/co2/volumevariables.hh:96
Scalar temperature() const
Returns temperature within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:406
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:396
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition porousmediumflow/co2/volumevariables.hh:102
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:443
const FluidState & fluidState() const
Returns the phase state within the control volume.
Definition porousmediumflow/co2/volumevariables.hh:317
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:121
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:387
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition porousmediumflow/co2/volumevariables.hh:331
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:360
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition porousmediumflow/co2/volumevariables.hh:104
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:431
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition porousmediumflow/co2/volumevariables.hh:415
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 2p2c-CO2 model.