14#ifndef DUMUX_2PNC_VOLUME_VARIABLES_HH
15#define DUMUX_2PNC_VOLUME_VARIABLES_HH
42template <
class Traits>
49 using Scalar =
typename Traits::PrimaryVariables::value_type;
50 using PermeabilityType =
typename Traits::PermeabilityType;
51 using FS =
typename Traits::FluidSystem;
52 using ModelTraits =
typename Traits::ModelTraits;
56 numMajorComponents = ModelTraits::numFluidPhases(),
59 phase0Idx = FS::phase0Idx,
60 phase1Idx = FS::phase1Idx,
63 comp0Idx = FS::comp0Idx,
64 comp1Idx = FS::comp1Idx,
67 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
68 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
69 bothPhases = ModelTraits::Indices::bothPhases,
72 pressureIdx = ModelTraits::Indices::pressureIdx,
73 switchIdx = ModelTraits::Indices::switchIdx
76 static constexpr auto formulation = ModelTraits::priVarFormulation();
77 static constexpr bool setFirstPhaseMoleFractions = ModelTraits::setMoleFractionsForFirstPhase();
81 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
82 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
90 using Indices =
typename ModelTraits::Indices;
99 static constexpr bool useMoles() {
return Traits::ModelTraits::useMoles(); }
104 static_assert(
useMoles(),
"use moles has to be set true in the 2pnc model");
105 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
117 template<
class ElemSol,
class Problem,
class Element,
class Scv>
119 const Problem &problem,
120 const Element &element,
131 const auto& spatialParams = problem.spatialParams();
132 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
135 const int nPhaseIdx = 1 - wPhaseIdx;
138 mobility_[wPhaseIdx] = fluidMatrixInteraction.krw(
saturation(wPhaseIdx))/
fluidState_.viscosity(wPhaseIdx);
139 mobility_[nPhaseIdx] = fluidMatrixInteraction.krn(
saturation(wPhaseIdx))/
fluidState_.viscosity(nPhaseIdx);
144 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
146 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
149 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
152 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
153 permeability_ = spatialParams.permeability(element, scv, elemSol);
154 EnergyVolVars::updateEffectiveThermalConductivity();
169 template<
class ElemSol,
class Problem,
class Element,
class Scv>
171 const Problem& problem,
172 const Element& element,
179 const auto&
priVars = elemSol[scv.localDofIndex()];
180 const auto phasePresence =
priVars.state();
182 const auto& spatialParams = problem.spatialParams();
183 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
184 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
188 if (phasePresence == secondPhaseOnly)
193 else if (phasePresence == firstPhaseOnly)
198 else if (phasePresence == bothPhases)
212 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " << phasePresence <<
" is invalid.");
215 pc_ = fluidMatrixInteraction.pc(
fluidState.saturation(wPhaseIdx));
219 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
225 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
230 typename FluidSystem::ParameterCache paramCache;
233 if (phasePresence == bothPhases)
242 const int knownPhaseIdx = setFirstPhaseMoleFractions ? phase0Idx : phase1Idx;
243 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
250 else if (phasePresence == secondPhaseOnly)
252 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
254 moleFrac[comp0Idx] =
priVars[switchIdx];
255 Scalar sumMoleFracOtherComponents = moleFrac[comp0Idx];
257 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
259 moleFrac[compIdx] =
priVars[compIdx];
260 sumMoleFracOtherComponents += moleFrac[compIdx];
263 moleFrac[comp1Idx] = 1 - sumMoleFracOtherComponents;
266 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
267 fluidState.setMoleFraction(phase1Idx, compIdx, moleFrac[compIdx]);
276 else if (phasePresence == firstPhaseOnly)
280 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
282 moleFrac[comp1Idx] =
priVars[switchIdx];
283 Scalar sumMoleFracOtherComponents = moleFrac[comp1Idx];
284 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
286 moleFrac[compIdx] =
priVars[compIdx];
288 sumMoleFracOtherComponents += moleFrac[compIdx];
291 moleFrac[comp0Idx] = 1 - sumMoleFracOtherComponents;
294 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
295 fluidState.setMoleFraction(phase0Idx, compIdx, moleFrac[compIdx]);
305 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
307 Scalar mu = FluidSystem::viscosity(
fluidState, paramCache, phaseIdx);
308 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
369 if (phaseIdx < ModelTraits::numFluidPhases())
373 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
402 {
return mobility_[phaseIdx]; }
421 {
return permeability_; }
428 typename FluidSystem::ParameterCache paramCache;
430 return FluidSystem::binaryDiffusionCoefficient(
fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
437 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
446 {
return fluidState_.massFraction(phaseIdx, compIdx); }
455 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
471 PermeabilityType permeability_;
472 Scalar mobility_[ModelTraits::numFluidPhases()];
473 DiffusionCoefficients effectiveDiffCoeff_;
The primary variable switch for the 2pnc model.
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition computefromreferencephase.hh:64
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:99
Definition porousmediumflow/nonisothermal/volumevariables.hh:63
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition misciblemultiphasecomposition.hh:47
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:69
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 controlling the phase presence state variable.
Definition 2pnc/primaryvariableswitch.hh:29
Contains the quantities which are are constant within a finite volume in the two-phase,...
Definition porousmediumflow/2pnc/volumevariables.hh:46
Scalar porosity() const
Returns the average porosity within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:414
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition porousmediumflow/2pnc/volumevariables.hh:426
Scalar molarDensity(int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:367
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition porousmediumflow/2pnc/volumevariables.hh:101
Scalar viscosity(int phaseIdx) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:358
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition porousmediumflow/2pnc/volumevariables.hh:408
Scalar density(int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:349
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:118
const SolidState & solidState() const
Returns the phase state for the control-volume.
Definition porousmediumflow/2pnc/volumevariables.hh:323
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition porousmediumflow/2pnc/volumevariables.hh:454
typename ModelTraits::Indices Indices
Export the indices.
Definition porousmediumflow/2pnc/volumevariables.hh:90
typename Traits::SolidState SolidState
Export type of solid state.
Definition porousmediumflow/2pnc/volumevariables.hh:92
Scalar saturation(int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition porousmediumflow/2pnc/volumevariables.hh:340
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition porousmediumflow/2pnc/volumevariables.hh:94
const PermeabilityType & permeability() const
Returns the permeability within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:420
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition porousmediumflow/2pnc/volumevariables.hh:436
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:392
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition porousmediumflow/2pnc/volumevariables.hh:331
SolidState solidState_
Definition porousmediumflow/2pnc/volumevariables.hh:465
FluidState fluidState_
Definition porousmediumflow/2pnc/volumevariables.hh:464
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition porousmediumflow/2pnc/volumevariables.hh:88
typename Traits::FluidState FluidState
Export fluid state type.
Definition porousmediumflow/2pnc/volumevariables.hh:86
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:170
int wettingPhase() const
Returns the wetting phase index.
Definition porousmediumflow/2pnc/volumevariables.hh:460
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition porousmediumflow/2pnc/volumevariables.hh:445
Scalar pressure(int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:382
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition porousmediumflow/2pnc/volumevariables.hh:99
Scalar mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition porousmediumflow/2pnc/volumevariables.hh:401
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition porousmediumflow/2pnc/volumevariables.hh:317
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system assum...
Computes all quantities of a generic fluid state if a reference phase has been specified.
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
Define some often used mathematical functions.
The available discretization methods in Dumux.
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
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.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.