25#ifndef DUMUX_3P3C_VOLUME_VARIABLES_HH
26#define DUMUX_3P3C_VOLUME_VARIABLES_HH
46template <
class Flu
idMatrixInteraction>
49template<
class Flu
idMatrixInteraction>
51{
return Dune::Std::is_detected<AdsorptionModelDetector, FluidMatrixInteraction>::value; }
60template <
class Traits>
68 using Scalar =
typename Traits::PrimaryVariables::value_type;
69 using PermeabilityType =
typename Traits::PermeabilityType;
71 using FS =
typename Traits::FluidSystem;
75 using ModelTraits =
typename Traits::ModelTraits;
76 using Idx =
typename ModelTraits::Indices;
79 wCompIdx = FS::wCompIdx,
80 gCompIdx = FS::gCompIdx,
81 nCompIdx = FS::nCompIdx,
83 wPhaseIdx = FS::wPhaseIdx,
84 gPhaseIdx = FS::gPhaseIdx,
85 nPhaseIdx = FS::nPhaseIdx,
87 switch1Idx = Idx::switch1Idx,
88 switch2Idx = Idx::switch2Idx,
89 pressureIdx = Idx::pressureIdx
94 threePhases = Idx::threePhases,
95 wPhaseOnly = Idx::wPhaseOnly,
96 gnPhaseOnly = Idx::gnPhaseOnly,
97 wnPhaseOnly = Idx::wnPhaseOnly,
98 gPhaseOnly = Idx::gPhaseOnly,
99 wgPhaseOnly = Idx::wgPhaseOnly
102 using EffDiffModel =
typename Traits::EffectiveDiffusivityModel;
103 using DiffusionCoefficients =
typename Traits::DiffusionType::DiffusionCoefficientsContainer;
111 using Indices =
typename ModelTraits::Indices;
128 template<
class ElemSol,
class Problem,
class Element,
class Scv>
130 const Problem &problem,
131 const Element &element,
135 const auto&
priVars = elemSol[scv.localDofIndex()];
138 constexpr bool useConstraintSolver = ModelTraits::useConstraintSolver();
147 sg_ = 1. - sw_ - sn_;
180 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
194 const auto fluidMatrixInteraction = Deprecated::makePcKrSw<3>(Scalar{}, problem.spatialParams(), element, scv, elemSol);
196 Scalar pcgw = fluidMatrixInteraction.pcgw(sw_, sn_);
197 Scalar pcnw = fluidMatrixInteraction.pcnw(sw_, sn_);
198 Scalar pcgn = fluidMatrixInteraction.pcgn(sw_, sn_);
200 const Scalar pcAlpha = fluidMatrixInteraction.pcAlpha(sw_, sn_);
201 const Scalar pcNW1 = 0.0;
203 pn_ = pg_- pcAlpha * pcgn - (1.-pcAlpha)*(pcgw - pcNW1);
204 pw_ = pn_ - pcAlpha * pcnw - (1.-pcAlpha)*pcNW1;
214 typename FluidSystem::ParameterCache paramCache;
216 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++ phaseIdx) {
217 assert(FluidSystem::isIdealMixture(phaseIdx));
219 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++ compIdx) {
220 Scalar phi = FluidSystem::fugacityCoefficient(
fluidState_, paramCache, phaseIdx, compIdx);
221 fluidState_.setFugacityCoefficient(phaseIdx, compIdx, phi);
231 if (useConstraintSolver) {
240 Scalar partPressH2O = FluidSystem::fugacityCoefficient(
fluidState_,
243 if (partPressH2O > pg_) partPressH2O = pg_;
244 Scalar partPressNAPL = FluidSystem::fugacityCoefficient(
fluidState_,
247 if (partPressNAPL > pg_) partPressNAPL = pg_;
248 Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
250 Scalar xgn = partPressNAPL/pg_;
251 Scalar xgw = partPressH2O/pg_;
252 Scalar xgg = partPressAir/pg_;
255 Scalar xwn = partPressNAPL
259 Scalar xwg = partPressAir
263 Scalar xww = 1.-xwg-xwn;
265 Scalar xnn = 1.-2.e-10;
269 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
270 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
271 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
272 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
273 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
274 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
275 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
276 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
277 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
299 Scalar xwg =
priVars[switch1Idx];
300 Scalar xwn =
priVars[switch2Idx];
301 Scalar xww = 1 - xwg - xwn;
304 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
305 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
306 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
311 if (useConstraintSolver)
321 Scalar xgg = xwg * FluidSystem::fugacityCoefficient(
fluidState_,
324 Scalar xgn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
327 Scalar xgw = FluidSystem::fugacityCoefficient(
fluidState_,
334 Scalar xnn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
340 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
341 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
342 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
343 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
344 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
345 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
371 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx, nCompIdx)*pn_;
372 if (partPressNAPL > pg_) partPressNAPL = pg_;
374 Scalar xgw =
priVars[switch1Idx];
375 Scalar xgn = partPressNAPL/pg_;
376 Scalar xgg = 1.-xgw-xgn;
379 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
380 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
381 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
392 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx,nCompIdx)*pn_;
393 if (partPressNAPL > pg_) partPressNAPL = pg_;
394 Scalar henryC =
fluidState_.fugacityCoefficient(wPhaseIdx,nCompIdx)*pw_;
396 Scalar xwg =
priVars[switch1Idx];
397 Scalar xwn = partPressNAPL/henryC;
398 Scalar xww = 1.-xwg-xwn;
401 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
402 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
403 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
416 const Scalar xgw =
priVars[switch1Idx];
417 const Scalar xgn =
priVars[switch2Idx];
418 Scalar xgg = 1 - xgw - xgn;
421 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
422 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
423 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
428 if (useConstraintSolver)
439 Scalar xww = xgw * pg_
448 Scalar xnn = xgn * pg_
455 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
456 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
457 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
458 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
459 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
460 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
479 Scalar xgn =
priVars[switch2Idx];
480 Scalar partPressH2O =
fluidState_.fugacityCoefficient(wPhaseIdx, wCompIdx)*pw_;
481 if (partPressH2O > pg_) partPressH2O = pg_;
483 Scalar xgw = partPressH2O/pg_;
484 Scalar xgg = 1.-xgn-xgw;
487 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
488 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
489 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
494 if (useConstraintSolver)
503 Scalar xwn = xgn * pg_
507 Scalar xwg = xgg * pg_
511 Scalar xww = 1.-xwg-xwn;
515 Scalar xnn = xgn * pg_
522 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
523 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
524 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
525 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
526 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
527 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
545 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
547 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
556 const Scalar kr = fluidMatrixInteraction.kr(phaseIdx,
559 mobility_[phaseIdx] = kr / mu;
564 bulkDensTimesAdsorpCoeff_ = fluidMatrixInteraction.adsorptionModel().bulkDensTimesAdsorpCoeff();
574 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
576 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
582 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
584 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
585 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
586 EnergyVolVars::updateEffectiveThermalConductivity();
589 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
591 Scalar h = EnergyVolVars::enthalpy(
fluidState_, paramCache, phaseIdx);
633 {
return fluidState_.massFraction(phaseIdx, compIdx); }
643 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
689 {
return mobility_[phaseIdx]; }
708 if (bulkDensTimesAdsorpCoeff_)
709 return bulkDensTimesAdsorpCoeff_.
value();
711 DUNE_THROW(Dune::NotImplemented,
"Your spatialParams do not provide an adsorption model");
718 {
return permeability_; }
725 typename FluidSystem::ParameterCache paramCache;
727 return FluidSystem::diffusionCoefficient(
fluidState_, paramCache, phaseIdx, compJIdx);
734 {
return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
742 Scalar sw_, sg_, sn_, pg_, pw_, pn_;
744 Scalar moleFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
745 Scalar massFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
747 PermeabilityType permeability_;
748 Scalar mobility_[ModelTraits::numFluidPhases()];
751 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:47
static constexpr bool hasAdsorptionModel()
Definition: porousmediumflow/3p3c/volumevariables.hh:50
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:64
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:632
typename ModelTraits::Indices Indices
export the indices
Definition: porousmediumflow/3p3c/volumevariables.hh:111
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/3p3c/volumevariables.hh:613
FluidState fluidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:737
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:129
SolidState solidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:738
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:622
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:642
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:660
typename Traits::SolidState SolidState
export type of solid state
Definition: porousmediumflow/3p3c/volumevariables.hh:113
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:669
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:605
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/3p3c/volumevariables.hh:717
typename Traits::FluidState FluidState
export fluid state type
Definition: porousmediumflow/3p3c/volumevariables.hh:107
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:679
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:694
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:688
const FluidState & fluidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:599
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:651
typename Traits::FluidSystem FluidSystem
export fluid system type
Definition: porousmediumflow/3p3c/volumevariables.hh:109
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/3p3c/volumevariables.hh:733
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Definition: porousmediumflow/3p3c/volumevariables.hh:723
Scalar bulkDensTimesAdsorpCoeff() const
Returns the adsorption information.
Definition: porousmediumflow/3p3c/volumevariables.hh:706
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:700
typename Traits::SolidSystem SolidSystem
export type of solid system
Definition: porousmediumflow/3p3c/volumevariables.hh:115
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.