13#ifndef DUMUX_3P3C_VOLUME_VARIABLES_HH
14#define DUMUX_3P3C_VOLUME_VARIABLES_HH
32template <
class Flu
idMatrixInteraction>
35template<
class Flu
idMatrixInteraction>
37{
return Dune::Std::is_detected<AdsorptionModelDetector, FluidMatrixInteraction>::value; }
46template <
class Traits>
54 using Scalar =
typename Traits::PrimaryVariables::value_type;
55 using PermeabilityType =
typename Traits::PermeabilityType;
57 using FS =
typename Traits::FluidSystem;
61 using ModelTraits =
typename Traits::ModelTraits;
62 using Idx =
typename ModelTraits::Indices;
65 wCompIdx = FS::wCompIdx,
66 gCompIdx = FS::gCompIdx,
67 nCompIdx = FS::nCompIdx,
69 wPhaseIdx = FS::wPhaseIdx,
70 gPhaseIdx = FS::gPhaseIdx,
71 nPhaseIdx = FS::nPhaseIdx,
73 switch1Idx = Idx::switch1Idx,
74 switch2Idx = Idx::switch2Idx,
75 pressureIdx = Idx::pressureIdx
80 threePhases = Idx::threePhases,
81 wPhaseOnly = Idx::wPhaseOnly,
82 gnPhaseOnly = Idx::gnPhaseOnly,
83 wnPhaseOnly = Idx::wnPhaseOnly,
84 gPhaseOnly = Idx::gPhaseOnly,
85 wgPhaseOnly = Idx::wgPhaseOnly
88 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
89 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
97 using Indices =
typename ModelTraits::Indices;
114 template<
class ElemSol,
class Problem,
class Element,
class Scv>
116 const Problem &problem,
117 const Element &element,
121 const auto&
priVars = elemSol[scv.localDofIndex()];
124 constexpr bool useConstraintSolver = ModelTraits::useConstraintSolver();
133 sg_ = 1. - sw_ - sn_;
166 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
177 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
178 Scalar pcgw = fluidMatrixInteraction.pcgw(sw_, sn_);
179 Scalar pcnw = fluidMatrixInteraction.pcnw(sw_, sn_);
180 Scalar pcgn = fluidMatrixInteraction.pcgn(sw_, sn_);
182 const Scalar pcAlpha = fluidMatrixInteraction.pcAlpha(sw_, sn_);
183 const Scalar pcNW1 = 0.0;
185 pn_ = pg_- pcAlpha * pcgn - (1.-pcAlpha)*(pcgw - pcNW1);
186 pw_ = pn_ - pcAlpha * pcnw - (1.-pcAlpha)*pcNW1;
196 typename FluidSystem::ParameterCache paramCache;
198 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++ phaseIdx) {
199 assert(FluidSystem::isIdealMixture(phaseIdx));
201 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++ compIdx) {
202 Scalar phi = FluidSystem::fugacityCoefficient(
fluidState_, paramCache, phaseIdx, compIdx);
203 fluidState_.setFugacityCoefficient(phaseIdx, compIdx, phi);
213 if (useConstraintSolver) {
222 Scalar partPressH2O = FluidSystem::fugacityCoefficient(
fluidState_,
225 if (partPressH2O > pg_) partPressH2O = pg_;
226 Scalar partPressNAPL = FluidSystem::fugacityCoefficient(
fluidState_,
229 if (partPressNAPL > pg_) partPressNAPL = pg_;
230 Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
232 Scalar xgn = partPressNAPL/pg_;
233 Scalar xgw = partPressH2O/pg_;
234 Scalar xgg = partPressAir/pg_;
237 Scalar xwn = partPressNAPL
241 Scalar xwg = partPressAir
245 Scalar xww = 1.-xwg-xwn;
247 Scalar xnn = 1.-2.e-10;
251 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
252 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
253 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
254 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
255 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
256 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
257 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
258 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
259 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
281 Scalar xwg =
priVars[switch1Idx];
282 Scalar xwn =
priVars[switch2Idx];
283 Scalar xww = 1 - xwg - xwn;
286 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
287 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
288 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
293 if (useConstraintSolver)
303 Scalar xgg = xwg * FluidSystem::fugacityCoefficient(
fluidState_,
306 Scalar xgn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
309 Scalar xgw = FluidSystem::fugacityCoefficient(
fluidState_,
316 Scalar xnn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
322 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
323 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
324 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
325 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
326 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
327 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
353 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx, nCompIdx)*pn_;
354 if (partPressNAPL > pg_) partPressNAPL = pg_;
356 Scalar xgw =
priVars[switch1Idx];
357 Scalar xgn = partPressNAPL/pg_;
358 Scalar xgg = 1.-xgw-xgn;
361 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
362 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
363 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
374 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx,nCompIdx)*pn_;
375 if (partPressNAPL > pg_) partPressNAPL = pg_;
376 Scalar henryC =
fluidState_.fugacityCoefficient(wPhaseIdx,nCompIdx)*pw_;
378 Scalar xwg =
priVars[switch1Idx];
379 Scalar xwn = partPressNAPL/henryC;
380 Scalar xww = 1.-xwg-xwn;
383 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
384 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
385 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
398 const Scalar xgw =
priVars[switch1Idx];
399 const Scalar xgn =
priVars[switch2Idx];
400 Scalar xgg = 1 - xgw - xgn;
403 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
404 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
405 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
410 if (useConstraintSolver)
421 Scalar xww = xgw * pg_
430 Scalar xnn = xgn * pg_
437 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
438 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
439 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
440 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
441 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
442 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
461 Scalar xgn =
priVars[switch2Idx];
462 Scalar partPressH2O =
fluidState_.fugacityCoefficient(wPhaseIdx, wCompIdx)*pw_;
463 if (partPressH2O > pg_) partPressH2O = pg_;
465 Scalar xgw = partPressH2O/pg_;
466 Scalar xgg = 1.-xgn-xgw;
469 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
470 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
471 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
476 if (useConstraintSolver)
485 Scalar xwn = xgn * pg_
489 Scalar xwg = xgg * pg_
493 Scalar xww = 1.-xwg-xwn;
497 Scalar xnn = xgn * pg_
504 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
505 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
506 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
507 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
508 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
509 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
527 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
529 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
538 const Scalar kr = fluidMatrixInteraction.kr(phaseIdx,
541 mobility_[phaseIdx] = kr / mu;
546 bulkDensTimesAdsorpCoeff_ = fluidMatrixInteraction.adsorptionModel().bulkDensTimesAdsorpCoeff();
556 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
558 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
564 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
566 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
567 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
568 EnergyVolVars::updateEffectiveThermalConductivity();
571 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
573 Scalar h = EnergyVolVars::enthalpy(
fluidState_, paramCache, phaseIdx);
615 {
return fluidState_.massFraction(phaseIdx, compIdx); }
625 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
671 {
return mobility_[phaseIdx]; }
690 if (bulkDensTimesAdsorpCoeff_)
691 return bulkDensTimesAdsorpCoeff_.
value();
693 DUNE_THROW(Dune::NotImplemented,
"Your spatialParams do not provide an adsorption model");
700 {
return permeability_; }
707 typename FluidSystem::ParameterCache paramCache;
709 return FluidSystem::diffusionCoefficient(
fluidState_, paramCache, phaseIdx, compJIdx);
716 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
724 Scalar sw_, sg_, sn_, pg_, pw_, pn_;
726 Scalar moleFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
727 Scalar massFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
729 PermeabilityType permeability_;
730 Scalar mobility_[ModelTraits::numFluidPhases()];
733 DiffusionCoefficients effectiveDiffCoeff_;
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: 3p3c/primaryvariableswitch.hh:28
Contains the quantities which are are constant within a finite volume in the three-phase three-compon...
Definition: porousmediumflow/3p3c/volumevariables.hh:50
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:614
typename ModelTraits::Indices Indices
export the indices
Definition: porousmediumflow/3p3c/volumevariables.hh:97
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/3p3c/volumevariables.hh:595
FluidState fluidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:719
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:115
SolidState solidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:720
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:604
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:624
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:642
typename Traits::SolidState SolidState
export type of solid state
Definition: porousmediumflow/3p3c/volumevariables.hh:99
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:651
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:587
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/3p3c/volumevariables.hh:699
typename Traits::FluidState FluidState
export fluid state type
Definition: porousmediumflow/3p3c/volumevariables.hh:93
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:661
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:676
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:670
const FluidState & fluidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:581
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:633
typename Traits::FluidSystem FluidSystem
export fluid system type
Definition: porousmediumflow/3p3c/volumevariables.hh:95
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/3p3c/volumevariables.hh:715
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Definition: porousmediumflow/3p3c/volumevariables.hh:705
Scalar bulkDensTimesAdsorpCoeff() const
Returns the adsorption information.
Definition: porousmediumflow/3p3c/volumevariables.hh:688
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:682
typename Traits::SolidSystem SolidSystem
export type of solid system
Definition: porousmediumflow/3p3c/volumevariables.hh:101
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.
A central place for various physical constants occurring 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:24
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
decltype(std::declval< FluidMatrixInteraction >().adsorptionModel()) AdsorptionModelDetector
Definition: porousmediumflow/3p3c/volumevariables.hh:33
static constexpr bool hasAdsorptionModel()
Definition: porousmediumflow/3p3c/volumevariables.hh:36
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
A wrapper that can either contain a valid Scalar or NaN.
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.
T value() const
Definition: optionalscalar.hh:36
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.