26#ifndef DUMUX_2PNC_VOLUME_VARIABLES_HH
27#define DUMUX_2PNC_VOLUME_VARIABLES_HH
56template <
class Traits>
63 using Scalar =
typename Traits::PrimaryVariables::value_type;
64 using PermeabilityType =
typename Traits::PermeabilityType;
65 using FS =
typename Traits::FluidSystem;
66 using ModelTraits =
typename Traits::ModelTraits;
70 numMajorComponents = ModelTraits::numFluidPhases(),
73 phase0Idx = FS::phase0Idx,
74 phase1Idx = FS::phase1Idx,
77 comp0Idx = FS::comp0Idx,
78 comp1Idx = FS::comp1Idx,
81 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
82 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
83 bothPhases = ModelTraits::Indices::bothPhases,
86 pressureIdx = ModelTraits::Indices::pressureIdx,
87 switchIdx = ModelTraits::Indices::switchIdx
90 static constexpr auto formulation = ModelTraits::priVarFormulation();
91 static constexpr bool setFirstPhaseMoleFractions = ModelTraits::setMoleFractionsForFirstPhase();
95 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
96 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
104 using Indices =
typename ModelTraits::Indices;
113 static constexpr bool useMoles() {
return Traits::ModelTraits::useMoles(); }
118 static_assert(
useMoles(),
"use moles has to be set true in the 2pnc model");
119 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
131 template<
class ElemSol,
class Problem,
class Element,
class Scv>
133 const Problem &problem,
134 const Element &element,
149 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
152 const int nPhaseIdx = 1 - wPhaseIdx;
155 mobility_[wPhaseIdx] = fluidMatrixInteraction.krw(
saturation(wPhaseIdx))/
fluidState_.viscosity(wPhaseIdx);
156 mobility_[nPhaseIdx] = fluidMatrixInteraction.krn(
saturation(wPhaseIdx))/
fluidState_.viscosity(nPhaseIdx);
161 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
163 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
166 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
169 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
170 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
171 EnergyVolVars::updateEffectiveThermalConductivity();
186 template<
class ElemSol,
class Problem,
class Element,
class Scv>
188 const Problem& problem,
189 const Element& element,
196 const auto&
priVars = elemSol[scv.localDofIndex()];
202 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
204 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
232 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
235 pc_ = fluidMatrixInteraction.pc(
fluidState.saturation(wPhaseIdx));
239 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
245 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
250 typename FluidSystem::ParameterCache paramCache;
262 const int knownPhaseIdx = setFirstPhaseMoleFractions ? phase0Idx : phase1Idx;
263 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
272 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
274 moleFrac[comp0Idx] =
priVars[switchIdx];
275 Scalar sumMoleFracOtherComponents = moleFrac[comp0Idx];
277 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
279 moleFrac[compIdx] =
priVars[compIdx];
280 sumMoleFracOtherComponents += moleFrac[compIdx];
283 moleFrac[comp1Idx] = 1 - sumMoleFracOtherComponents;
286 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
287 fluidState.setMoleFraction(phase1Idx, compIdx, moleFrac[compIdx]);
300 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
302 moleFrac[comp1Idx] =
priVars[switchIdx];
303 Scalar sumMoleFracOtherComponents = moleFrac[comp1Idx];
304 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
306 moleFrac[compIdx] =
priVars[compIdx];
308 sumMoleFracOtherComponents += moleFrac[compIdx];
311 moleFrac[comp0Idx] = 1 - sumMoleFracOtherComponents;
314 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
315 fluidState.setMoleFraction(phase0Idx, compIdx, moleFrac[compIdx]);
325 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
330 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
333 fluidState.setMolarDensity(phaseIdx, rhoMolar);
394 if (phaseIdx < ModelTraits::numFluidPhases())
398 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
427 {
return mobility_[phaseIdx]; }
446 {
return permeability_; }
453 typename FluidSystem::ParameterCache paramCache;
455 return FluidSystem::binaryDiffusionCoefficient(
fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
462 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
471 {
return fluidState_.massFraction(phaseIdx, compIdx); }
480 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
496 PermeabilityType permeability_;
497 Scalar mobility_[ModelTraits::numFluidPhases()];
498 DiffusionCoefficients effectiveDiffCoeff_;
Define some often used mathematical functions.
The available discretization methods in Dumux.
Computes all quantities of a generic fluid state if a reference phase has been specified.
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system assum...
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
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: computefromreferencephase.hh:76
static void solve(FluidState &fluidState, ParameterCache ¶mCache, int refPhaseIdx)
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: computefromreferencephase.hh:111
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:59
static void solve(FluidState &fluidState, ParameterCache ¶mCache, int knownPhaseIdx=0)
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:81
The primary variable switch controlling the phase presence state variable.
Definition: 2pnc/primaryvariableswitch.hh:41
Contains the quantities which are are constant within a finite volume in the two-phase,...
Definition: porousmediumflow/2pnc/volumevariables.hh:60
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:439
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:451
Scalar molarDensity(int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:392
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2pnc/volumevariables.hh:115
Scalar viscosity(int phaseIdx) const
Returns the kinematic viscosity of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:383
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:433
Scalar density(int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:374
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:132
const SolidState & solidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:348
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:479
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/2pnc/volumevariables.hh:104
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:106
Scalar saturation(int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:365
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2pnc/volumevariables.hh:108
const PermeabilityType & permeability() const
Returns the permeability within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:445
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:461
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:417
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:356
SolidState solidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:490
FluidState fluidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:489
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition: porousmediumflow/2pnc/volumevariables.hh:102
typename Traits::FluidState FluidState
Export fluid state type.
Definition: porousmediumflow/2pnc/volumevariables.hh:100
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Sets complete fluid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:187
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2pnc/volumevariables.hh:485
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:470
Scalar pressure(int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:407
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/2pnc/volumevariables.hh:113
Scalar mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:426
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:342
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.