25#ifndef DUMUX_3P3C_VOLUME_VARIABLES_HH
26#define DUMUX_3P3C_VOLUME_VARIABLES_HH
44template <
class Flu
idMatrixInteraction>
47template<
class Flu
idMatrixInteraction>
49{
return Dune::Std::is_detected<AdsorptionModelDetector, FluidMatrixInteraction>::value; }
58template <
class Traits>
66 using Scalar =
typename Traits::PrimaryVariables::value_type;
67 using PermeabilityType =
typename Traits::PermeabilityType;
69 using FS =
typename Traits::FluidSystem;
73 using ModelTraits =
typename Traits::ModelTraits;
74 using Idx =
typename ModelTraits::Indices;
77 wCompIdx = FS::wCompIdx,
78 gCompIdx = FS::gCompIdx,
79 nCompIdx = FS::nCompIdx,
81 wPhaseIdx = FS::wPhaseIdx,
82 gPhaseIdx = FS::gPhaseIdx,
83 nPhaseIdx = FS::nPhaseIdx,
85 switch1Idx = Idx::switch1Idx,
86 switch2Idx = Idx::switch2Idx,
87 pressureIdx = Idx::pressureIdx
92 threePhases = Idx::threePhases,
93 wPhaseOnly = Idx::wPhaseOnly,
94 gnPhaseOnly = Idx::gnPhaseOnly,
95 wnPhaseOnly = Idx::wnPhaseOnly,
96 gPhaseOnly = Idx::gPhaseOnly,
97 wgPhaseOnly = Idx::wgPhaseOnly
100 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
101 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
109 using Indices =
typename ModelTraits::Indices;
126 template<
class ElemSol,
class Problem,
class Element,
class Scv>
128 const Problem &problem,
129 const Element &element,
133 const auto&
priVars = elemSol[scv.localDofIndex()];
136 constexpr bool useConstraintSolver = ModelTraits::useConstraintSolver();
145 sg_ = 1. - sw_ - sn_;
178 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
189 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
190 Scalar pcgw = fluidMatrixInteraction.pcgw(sw_, sn_);
191 Scalar pcnw = fluidMatrixInteraction.pcnw(sw_, sn_);
192 Scalar pcgn = fluidMatrixInteraction.pcgn(sw_, sn_);
194 const Scalar pcAlpha = fluidMatrixInteraction.pcAlpha(sw_, sn_);
195 const Scalar pcNW1 = 0.0;
197 pn_ = pg_- pcAlpha * pcgn - (1.-pcAlpha)*(pcgw - pcNW1);
198 pw_ = pn_ - pcAlpha * pcnw - (1.-pcAlpha)*pcNW1;
208 typename FluidSystem::ParameterCache paramCache;
210 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++ phaseIdx) {
211 assert(FluidSystem::isIdealMixture(phaseIdx));
213 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++ compIdx) {
214 Scalar phi = FluidSystem::fugacityCoefficient(
fluidState_, paramCache, phaseIdx, compIdx);
215 fluidState_.setFugacityCoefficient(phaseIdx, compIdx, phi);
225 if (useConstraintSolver) {
234 Scalar partPressH2O = FluidSystem::fugacityCoefficient(
fluidState_,
237 if (partPressH2O > pg_) partPressH2O = pg_;
238 Scalar partPressNAPL = FluidSystem::fugacityCoefficient(
fluidState_,
241 if (partPressNAPL > pg_) partPressNAPL = pg_;
242 Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
244 Scalar xgn = partPressNAPL/pg_;
245 Scalar xgw = partPressH2O/pg_;
246 Scalar xgg = partPressAir/pg_;
249 Scalar xwn = partPressNAPL
253 Scalar xwg = partPressAir
257 Scalar xww = 1.-xwg-xwn;
259 Scalar xnn = 1.-2.e-10;
263 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
264 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
265 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
266 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
267 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
268 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
269 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
270 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
271 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
293 Scalar xwg =
priVars[switch1Idx];
294 Scalar xwn =
priVars[switch2Idx];
295 Scalar xww = 1 - xwg - xwn;
298 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
299 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
300 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
305 if (useConstraintSolver)
315 Scalar xgg = xwg * FluidSystem::fugacityCoefficient(
fluidState_,
318 Scalar xgn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
321 Scalar xgw = FluidSystem::fugacityCoefficient(
fluidState_,
328 Scalar xnn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
334 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
335 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
336 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
337 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
338 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
339 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
365 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx, nCompIdx)*pn_;
366 if (partPressNAPL > pg_) partPressNAPL = pg_;
368 Scalar xgw =
priVars[switch1Idx];
369 Scalar xgn = partPressNAPL/pg_;
370 Scalar xgg = 1.-xgw-xgn;
373 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
374 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
375 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
386 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx,nCompIdx)*pn_;
387 if (partPressNAPL > pg_) partPressNAPL = pg_;
388 Scalar henryC =
fluidState_.fugacityCoefficient(wPhaseIdx,nCompIdx)*pw_;
390 Scalar xwg =
priVars[switch1Idx];
391 Scalar xwn = partPressNAPL/henryC;
392 Scalar xww = 1.-xwg-xwn;
395 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
396 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
397 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
410 const Scalar xgw =
priVars[switch1Idx];
411 const Scalar xgn =
priVars[switch2Idx];
412 Scalar xgg = 1 - xgw - xgn;
415 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
416 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
417 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
422 if (useConstraintSolver)
433 Scalar xww = xgw * pg_
442 Scalar xnn = xgn * pg_
449 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
450 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
451 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
452 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
453 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
454 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
473 Scalar xgn =
priVars[switch2Idx];
474 Scalar partPressH2O =
fluidState_.fugacityCoefficient(wPhaseIdx, wCompIdx)*pw_;
475 if (partPressH2O > pg_) partPressH2O = pg_;
477 Scalar xgw = partPressH2O/pg_;
478 Scalar xgg = 1.-xgn-xgw;
481 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
482 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
483 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
488 if (useConstraintSolver)
497 Scalar xwn = xgn * pg_
501 Scalar xwg = xgg * pg_
505 Scalar xww = 1.-xwg-xwn;
509 Scalar xnn = xgn * pg_
516 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
517 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
518 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
519 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
520 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
521 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
539 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
541 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
550 const Scalar kr = fluidMatrixInteraction.kr(phaseIdx,
553 mobility_[phaseIdx] = kr / mu;
558 bulkDensTimesAdsorpCoeff_ = fluidMatrixInteraction.adsorptionModel().bulkDensTimesAdsorpCoeff();
568 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
570 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
576 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
578 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
579 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
580 EnergyVolVars::updateEffectiveThermalConductivity();
583 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
585 Scalar h = EnergyVolVars::enthalpy(
fluidState_, paramCache, phaseIdx);
627 {
return fluidState_.massFraction(phaseIdx, compIdx); }
637 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
683 {
return mobility_[phaseIdx]; }
702 if (bulkDensTimesAdsorpCoeff_)
703 return bulkDensTimesAdsorpCoeff_.
value();
705 DUNE_THROW(Dune::NotImplemented,
"Your spatialParams do not provide an adsorption model");
712 {
return permeability_; }
719 typename FluidSystem::ParameterCache paramCache;
721 return FluidSystem::diffusionCoefficient(
fluidState_, paramCache, phaseIdx, compJIdx);
728 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
736 Scalar sw_, sg_, sn_, pg_, pw_, pn_;
738 Scalar moleFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
739 Scalar massFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
741 PermeabilityType permeability_;
742 Scalar mobility_[ModelTraits::numFluidPhases()];
745 DiffusionCoefficients effectiveDiffCoeff_;
A wrapper that can either contain a valid Scalar or NaN.
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.
A central place for various physical constants occuring in some equations.
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
decltype(std::declval< FluidMatrixInteraction >().adsorptionModel()) AdsorptionModelDetector
Definition: porousmediumflow/3p3c/volumevariables.hh:45
static constexpr bool hasAdsorptionModel()
Definition: porousmediumflow/3p3c/volumevariables.hh:48
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
T value() const
Definition: optionalscalar.hh:48
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: 3p3c/primaryvariableswitch.hh:40
Contains the quantities which are are constant within a finite volume in the three-phase three-compon...
Definition: porousmediumflow/3p3c/volumevariables.hh:62
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/3p3c/volumevariables.hh:626
typename ModelTraits::Indices Indices
export the indices
Definition: porousmediumflow/3p3c/volumevariables.hh:109
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/3p3c/volumevariables.hh:607
FluidState fluidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:731
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Update all quantities for a given control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:127
SolidState solidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:732
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:616
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/3p3c/volumevariables.hh:636
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:654
typename Traits::SolidState SolidState
export type of solid state
Definition: porousmediumflow/3p3c/volumevariables.hh:111
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:663
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:599
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/3p3c/volumevariables.hh:711
typename Traits::FluidState FluidState
export fluid state type
Definition: porousmediumflow/3p3c/volumevariables.hh:105
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:673
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:688
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:682
const FluidState & fluidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:593
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:645
typename Traits::FluidSystem FluidSystem
export fluid system type
Definition: porousmediumflow/3p3c/volumevariables.hh:107
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/3p3c/volumevariables.hh:727
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Definition: porousmediumflow/3p3c/volumevariables.hh:717
Scalar bulkDensTimesAdsorpCoeff() const
Returns the adsorption information.
Definition: porousmediumflow/3p3c/volumevariables.hh:700
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:694
typename Traits::SolidSystem SolidSystem
export type of solid system
Definition: porousmediumflow/3p3c/volumevariables.hh:113
Definition: porousmediumflow/nonisothermal/volumevariables.hh:76
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:42
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition: porousmediumflow/volumevariables.hh:54
const PrimaryVariables & priVars() const
Returns the vector of primary variables.
Definition: porousmediumflow/volumevariables.hh:78
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:66
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.