25#ifndef DUMUX_3P3C_VOLUME_VARIABLES_HH
26#define DUMUX_3P3C_VOLUME_VARIABLES_HH
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();
127 const auto &materialParams =
128 problem.spatialParams().materialLawParams(element, scv, elemSol);
138 sg_ = 1. - sw_ - sn_;
171 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
182 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
183 Scalar pcgw = MaterialLaw::pcgw(materialParams, sw_);
184 Scalar pcnw = MaterialLaw::pcnw(materialParams, sw_);
185 Scalar pcgn = MaterialLaw::pcgn(materialParams, sw_ + sn_);
187 Scalar pcAlpha = MaterialLaw::pcAlpha(materialParams, sn_);
190 pn_ = pg_- pcAlpha * pcgn - (1.-pcAlpha)*(pcgw - pcNW1);
191 pw_ = pn_ - pcAlpha * pcnw - (1.-pcAlpha)*pcNW1;
201 typename FluidSystem::ParameterCache paramCache;
203 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++ phaseIdx) {
204 assert(FluidSystem::isIdealMixture(phaseIdx));
206 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++ compIdx) {
207 Scalar phi = FluidSystem::fugacityCoefficient(
fluidState_, paramCache, phaseIdx, compIdx);
208 fluidState_.setFugacityCoefficient(phaseIdx, compIdx, phi);
218 if (useConstraintSolver) {
227 Scalar partPressH2O = FluidSystem::fugacityCoefficient(
fluidState_,
230 if (partPressH2O > pg_) partPressH2O = pg_;
231 Scalar partPressNAPL = FluidSystem::fugacityCoefficient(
fluidState_,
234 if (partPressNAPL > pg_) partPressNAPL = pg_;
235 Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
237 Scalar xgn = partPressNAPL/pg_;
238 Scalar xgw = partPressH2O/pg_;
239 Scalar xgg = partPressAir/pg_;
242 Scalar xwn = partPressNAPL
246 Scalar xwg = partPressAir
250 Scalar xww = 1.-xwg-xwn;
252 Scalar xnn = 1.-2.e-10;
256 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
257 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
258 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
259 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
260 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
261 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
262 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
263 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
264 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
286 Scalar xwg =
priVars[switch1Idx];
287 Scalar xwn =
priVars[switch2Idx];
288 Scalar xww = 1 - xwg - xwn;
291 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
292 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
293 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
298 if (useConstraintSolver)
308 Scalar xgg = xwg * FluidSystem::fugacityCoefficient(
fluidState_,
311 Scalar xgn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
314 Scalar xgw = FluidSystem::fugacityCoefficient(
fluidState_,
321 Scalar xnn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
327 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
328 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
329 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
330 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
331 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
332 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
358 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx, nCompIdx)*pn_;
359 if (partPressNAPL > pg_) partPressNAPL = pg_;
361 Scalar xgw =
priVars[switch1Idx];
362 Scalar xgn = partPressNAPL/pg_;
363 Scalar xgg = 1.-xgw-xgn;
366 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
367 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
368 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
379 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx,nCompIdx)*pn_;
380 if (partPressNAPL > pg_) partPressNAPL = pg_;
381 Scalar henryC =
fluidState_.fugacityCoefficient(wPhaseIdx,nCompIdx)*pw_;
383 Scalar xwg =
priVars[switch1Idx];
384 Scalar xwn = partPressNAPL/henryC;
385 Scalar xww = 1.-xwg-xwn;
388 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
389 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
390 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
403 const Scalar xgw =
priVars[switch1Idx];
404 const Scalar xgn =
priVars[switch2Idx];
405 Scalar xgg = 1 - xgw - xgn;
408 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
409 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
410 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
415 if (useConstraintSolver)
426 Scalar xww = xgw * pg_
435 Scalar xnn = xgn * pg_
442 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
443 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
444 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
445 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
446 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
447 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
466 Scalar xgn =
priVars[switch2Idx];
467 Scalar partPressH2O =
fluidState_.fugacityCoefficient(wPhaseIdx, wCompIdx)*pw_;
468 if (partPressH2O > pg_) partPressH2O = pg_;
470 Scalar xgw = partPressH2O/pg_;
471 Scalar xgg = 1.-xgn-xgw;
474 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
475 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
476 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
481 if (useConstraintSolver)
490 Scalar xwn = xgn * pg_
494 Scalar xwg = xgg * pg_
498 Scalar xww = 1.-xwg-xwn;
502 Scalar xnn = xgn * pg_
509 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
510 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
511 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
512 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
513 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
514 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
533 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
536 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx) {
545 kr = MaterialLaw::kr(materialParams, phaseIdx,
549 mobility_[phaseIdx] = kr / mu;
554 bulkDensTimesAdsorpCoeff_ =
555 MaterialLaw::bulkDensTimesAdsorpCoeff(materialParams);
565 auto getEffectiveDiffusionCoefficient = [&](
int phaseIdx,
int compIIdx,
int compJIdx)
567 return EffDiffModel::effectiveDiffusionCoefficient(*
this, phaseIdx, compIIdx, compJIdx);
573 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
575 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
576 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
577 EnergyVolVars::updateEffectiveThermalConductivity();
580 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
582 Scalar h = EnergyVolVars::enthalpy(
fluidState_, paramCache, phaseIdx);
624 {
return fluidState_.massFraction(phaseIdx, compIdx); }
634 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
681 return mobility_[phaseIdx];
700 {
return bulkDensTimesAdsorpCoeff_; }
706 {
return permeability_; }
711 [[deprecated(
"Will be removed after release 3.2. Use diffusionCoefficient(phaseIdx, compIIdx, compJIdx)!")]]
714 if (compIdx != phaseIdx)
717 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient called for phaseIdx = compIdx");
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()];
749 Scalar bulkDensTimesAdsorpCoeff_;
751 DiffusionCoefficients effectiveDiffCoeff_;
A central place for various physical constants occuring in some equations.
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.
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.
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
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
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: 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: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:623
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:604
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:115
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:613
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:633
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:651
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:660
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:596
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/3p3c/volumevariables.hh:705
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:670
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:687
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the diffusion coefficient.
Definition: porousmediumflow/3p3c/volumevariables.hh:712
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:679
const FluidState & fluidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:590
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:642
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: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:699
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:693
typename Traits::SolidSystem SolidSystem
export type of solid system
Definition: porousmediumflow/3p3c/volumevariables.hh:101
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.