26#ifndef DUMUX_2PNC_VOLUME_VARIABLES_HH
27#define DUMUX_2PNC_VOLUME_VARIABLES_HH
54template <
class Traits>
61 using Scalar =
typename Traits::PrimaryVariables::value_type;
62 using PermeabilityType =
typename Traits::PermeabilityType;
63 using FS =
typename Traits::FluidSystem;
64 using ModelTraits =
typename Traits::ModelTraits;
68 numMajorComponents = ModelTraits::numFluidPhases(),
71 phase0Idx = FS::phase0Idx,
72 phase1Idx = FS::phase1Idx,
75 comp0Idx = FS::comp0Idx,
76 comp1Idx = FS::comp1Idx,
79 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
80 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
81 bothPhases = ModelTraits::Indices::bothPhases,
84 pressureIdx = ModelTraits::Indices::pressureIdx,
85 switchIdx = ModelTraits::Indices::switchIdx
88 static constexpr auto formulation = ModelTraits::priVarFormulation();
89 static constexpr bool setFirstPhaseMoleFractions = ModelTraits::setMoleFractionsForFirstPhase();
108 static constexpr bool useMoles() {
return Traits::ModelTraits::useMoles(); }
113 static_assert(
useMoles(),
"use moles has to be set true in the 2pnc model");
114 static_assert(ModelTraits::numFluidPhases() == 2,
"NumPhases set in the model is not two!");
126 template<
class ElemSol,
class Problem,
class Element,
class Scv>
128 const Problem &problem,
129 const Element &element,
142 typename FluidSystem::ParameterCache paramCache;
145 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
146 const auto& matParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
148 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
149 const int nPhaseIdx = 1 - wPhaseIdx;
152 mobility_[wPhaseIdx] = MaterialLaw::krw(matParams,
saturation(wPhaseIdx))/
fluidState_.viscosity(wPhaseIdx);
153 mobility_[nPhaseIdx] = MaterialLaw::krn(matParams,
saturation(wPhaseIdx))/
fluidState_.viscosity(nPhaseIdx);
156 for (
unsigned int compJIdx = 0; compJIdx < ModelTraits::numFluidComponents(); ++compJIdx)
158 if(compJIdx != comp0Idx)
159 setDiffusionCoefficient_( phase0Idx, compJIdx,
160 FluidSystem::binaryDiffusionCoefficient(
fluidState_,
165 if(compJIdx != comp1Idx)
166 setDiffusionCoefficient_( phase1Idx, compJIdx,
167 FluidSystem::binaryDiffusionCoefficient(
fluidState_,
176 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
177 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
192 template<
class ElemSol,
class Problem,
class Element,
class Scv>
194 const Problem& problem,
195 const Element& element,
202 const auto&
priVars = elemSol[scv.localDofIndex()];
205 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
206 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
207 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
235 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
238 pc_ = MaterialLaw::pc(materialParams,
fluidState.saturation(wPhaseIdx));
242 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] + pc_
248 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ?
priVars[pressureIdx] - pc_
253 typename FluidSystem::ParameterCache paramCache;
265 const int knownPhaseIdx = setFirstPhaseMoleFractions ? phase0Idx : phase1Idx;
266 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
276 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
278 moleFrac[comp0Idx] =
priVars[switchIdx];
279 Scalar sumMoleFracOtherComponents = moleFrac[comp0Idx];
281 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
283 moleFrac[compIdx] =
priVars[compIdx];
284 sumMoleFracOtherComponents += moleFrac[compIdx];
287 moleFrac[comp1Idx] = 1 - sumMoleFracOtherComponents;
290 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
291 fluidState.setMoleFraction(phase1Idx, compIdx, moleFrac[compIdx]);
304 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
306 moleFrac[comp1Idx] =
priVars[switchIdx];
307 Scalar sumMoleFracOtherComponents = moleFrac[comp1Idx];
308 for (
int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
310 moleFrac[compIdx] =
priVars[compIdx];
312 sumMoleFracOtherComponents += moleFrac[compIdx];
315 moleFrac[comp0Idx] = 1 - sumMoleFracOtherComponents;
318 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
319 fluidState.setMoleFraction(phase0Idx, compIdx, moleFrac[compIdx]);
329 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
334 Scalar h = EnergyVolVars::enthalpy(
fluidState, paramCache, phaseIdx);
337 fluidState.setMolarDensity(phaseIdx, rhoMolar);
398 if (phaseIdx < ModelTraits::numFluidPhases())
402 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
431 {
return mobility_[phaseIdx]; }
450 {
return permeability_; }
458 if (compIdx < phaseIdx)
459 return diffCoefficient_[phaseIdx][compIdx];
460 else if (compIdx > phaseIdx)
461 return diffCoefficient_[phaseIdx][compIdx-1];
463 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient called for phaseIdx = compIdx");
473 {
return fluidState_.massFraction(phaseIdx, compIdx); }
482 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
489 void setDiffusionCoefficient_(
int phaseIdx,
int compIdx, Scalar d)
491 if (compIdx < phaseIdx)
492 diffCoefficient_[phaseIdx][compIdx] = std::move(d);
493 else if (compIdx > phaseIdx)
494 diffCoefficient_[phaseIdx][compIdx-1] = std::move(d);
496 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient for phaseIdx = compIdx doesn't exist");
501 PermeabilityType permeability_;
502 Scalar mobility_[ModelTraits::numFluidPhases()];
503 std::array<std::array<Scalar, ModelTraits::numFluidComponents()-1>, ModelTraits::numFluidPhases()> diffCoefficient_;
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
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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:77
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:112
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:60
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:82
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:58
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:443
Scalar molarDensity(int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:396
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2pnc/volumevariables.hh:110
Scalar viscosity(int phaseIdx) const
Returns the kinematic viscosity of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:387
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:437
Scalar density(int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:378
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:127
const SolidState & solidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:352
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:481
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:101
Scalar saturation(int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:369
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2pnc/volumevariables.hh:103
const PermeabilityType & permeability() const
Returns the permeability within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:449
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:421
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:360
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the diffusion coefficient.
Definition: porousmediumflow/2pnc/volumevariables.hh:456
SolidState solidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:486
FluidState fluidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:485
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition: porousmediumflow/2pnc/volumevariables.hh:99
typename Traits::FluidState FluidState
Export fluid state type.
Definition: porousmediumflow/2pnc/volumevariables.hh:97
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:193
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:472
Scalar pressure(int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:411
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/2pnc/volumevariables.hh:108
Scalar mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:430
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:346
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.