25#ifndef DUMUX_3P3C_VOLUME_VARIABLES_HH
26#define DUMUX_3P3C_VOLUME_VARIABLES_HH
45template <
class Traits>
53 using Scalar =
typename Traits::PrimaryVariables::value_type;
54 using PermeabilityType =
typename Traits::PermeabilityType;
56 using FS =
typename Traits::FluidSystem;
60 using ModelTraits =
typename Traits::ModelTraits;
64 wCompIdx = FS::wCompIdx,
65 gCompIdx = FS::gCompIdx,
66 nCompIdx = FS::nCompIdx,
68 wPhaseIdx = FS::wPhaseIdx,
69 gPhaseIdx = FS::gPhaseIdx,
70 nPhaseIdx = FS::nPhaseIdx,
72 switch1Idx = Idx::switch1Idx,
73 switch2Idx = Idx::switch2Idx,
74 pressureIdx = Idx::pressureIdx
79 threePhases = Idx::threePhases,
80 wPhaseOnly = Idx::wPhaseOnly,
81 gnPhaseOnly = Idx::gnPhaseOnly,
82 wnPhaseOnly = Idx::wnPhaseOnly,
83 gPhaseOnly = Idx::gPhaseOnly,
84 wgPhaseOnly = Idx::wgPhaseOnly
110 template<
class ElemSol,
class Problem,
class Element,
class Scv>
112 const Problem &problem,
113 const Element &element,
117 const auto&
priVars = elemSol[scv.localDofIndex()];
120 constexpr bool useConstraintSolver = ModelTraits::useConstraintSolver();
123 const auto &materialParams =
124 problem.spatialParams().materialLawParams(element, scv, elemSol);
134 sg_ = 1. - sw_ - sn_;
167 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
178 using MaterialLaw =
typename Problem::SpatialParams::MaterialLaw;
179 Scalar pcgw = MaterialLaw::pcgw(materialParams, sw_);
180 Scalar pcnw = MaterialLaw::pcnw(materialParams, sw_);
181 Scalar pcgn = MaterialLaw::pcgn(materialParams, sw_ + sn_);
183 Scalar pcAlpha = MaterialLaw::pcAlpha(materialParams, sn_);
186 pn_ = pg_- pcAlpha * pcgn - (1.-pcAlpha)*(pcgw - pcNW1);
187 pw_ = pn_ - pcAlpha * pcnw - (1.-pcAlpha)*pcNW1;
197 typename FluidSystem::ParameterCache paramCache;
199 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++ phaseIdx) {
200 assert(FluidSystem::isIdealMixture(phaseIdx));
202 for (
int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++ compIdx) {
203 Scalar phi = FluidSystem::fugacityCoefficient(
fluidState_, paramCache, phaseIdx, compIdx);
204 fluidState_.setFugacityCoefficient(phaseIdx, compIdx, phi);
214 if (useConstraintSolver) {
223 Scalar partPressH2O = FluidSystem::fugacityCoefficient(
fluidState_,
226 if (partPressH2O > pg_) partPressH2O = pg_;
227 Scalar partPressNAPL = FluidSystem::fugacityCoefficient(
fluidState_,
230 if (partPressNAPL > pg_) partPressNAPL = pg_;
231 Scalar partPressAir = pg_ - partPressH2O - partPressNAPL;
233 Scalar xgn = partPressNAPL/pg_;
234 Scalar xgw = partPressH2O/pg_;
235 Scalar xgg = partPressAir/pg_;
238 Scalar xwn = partPressNAPL
242 Scalar xwg = partPressAir
246 Scalar xww = 1.-xwg-xwn;
248 Scalar xnn = 1.-2.e-10;
252 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
253 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
254 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
255 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
256 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
257 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
258 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
259 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
260 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
282 Scalar xwg =
priVars[switch1Idx];
283 Scalar xwn =
priVars[switch2Idx];
284 Scalar xww = 1 - xwg - xwn;
287 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
288 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
289 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
294 if (useConstraintSolver)
304 Scalar xgg = xwg * FluidSystem::fugacityCoefficient(
fluidState_,
307 Scalar xgn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
310 Scalar xgw = FluidSystem::fugacityCoefficient(
fluidState_,
317 Scalar xnn = xwn * FluidSystem::fugacityCoefficient(
fluidState_,
323 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
324 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
325 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
326 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
327 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
328 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
354 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx, nCompIdx)*pn_;
355 if (partPressNAPL > pg_) partPressNAPL = pg_;
357 Scalar xgw =
priVars[switch1Idx];
358 Scalar xgn = partPressNAPL/pg_;
359 Scalar xgg = 1.-xgw-xgn;
362 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
363 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
364 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
375 Scalar partPressNAPL =
fluidState_.fugacityCoefficient(nPhaseIdx,nCompIdx)*pn_;
376 if (partPressNAPL > pg_) partPressNAPL = pg_;
377 Scalar henryC =
fluidState_.fugacityCoefficient(wPhaseIdx,nCompIdx)*pw_;
379 Scalar xwg =
priVars[switch1Idx];
380 Scalar xwn = partPressNAPL/henryC;
381 Scalar xww = 1.-xwg-xwn;
384 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
385 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
386 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
399 const Scalar xgw =
priVars[switch1Idx];
400 const Scalar xgn =
priVars[switch2Idx];
401 Scalar xgg = 1 - xgw - xgn;
404 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
405 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
406 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
411 if (useConstraintSolver)
422 Scalar xww = xgw * pg_
431 Scalar xnn = xgn * pg_
438 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
439 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
440 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
441 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
442 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
443 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
462 Scalar xgn =
priVars[switch2Idx];
463 Scalar partPressH2O =
fluidState_.fugacityCoefficient(wPhaseIdx, wCompIdx)*pw_;
464 if (partPressH2O > pg_) partPressH2O = pg_;
466 Scalar xgw = partPressH2O/pg_;
467 Scalar xgg = 1.-xgn-xgw;
470 fluidState_.setMoleFraction(gPhaseIdx, wCompIdx, xgw);
471 fluidState_.setMoleFraction(gPhaseIdx, gCompIdx, xgg);
472 fluidState_.setMoleFraction(gPhaseIdx, nCompIdx, xgn);
477 if (useConstraintSolver)
486 Scalar xwn = xgn * pg_
490 Scalar xwg = xgg * pg_
494 Scalar xww = 1.-xwg-xwn;
498 Scalar xnn = xgn * pg_
505 fluidState_.setMoleFraction(wPhaseIdx, wCompIdx, xww);
506 fluidState_.setMoleFraction(wPhaseIdx, gCompIdx, xwg);
507 fluidState_.setMoleFraction(wPhaseIdx, nCompIdx, xwn);
508 fluidState_.setMoleFraction(nPhaseIdx, wCompIdx, xnw);
509 fluidState_.setMoleFraction(nPhaseIdx, gCompIdx, xna);
510 fluidState_.setMoleFraction(nPhaseIdx, nCompIdx, xnn);
529 DUNE_THROW(Dune::InvalidStateException,
"phasePresence: " <<
phasePresence <<
" is invalid.");
532 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx) {
541 kr = MaterialLaw::kr(materialParams, phaseIdx,
545 mobility_[phaseIdx] = kr / mu;
550 bulkDensTimesAdsorpCoeff_ =
551 MaterialLaw::bulkDensTimesAdsorpCoeff(materialParams);
560 setDiffusionCoefficient_(gPhaseIdx, wCompIdx, FluidSystem::diffusionCoefficient(
fluidState_, paramCache, gPhaseIdx, wCompIdx));
561 setDiffusionCoefficient_(gPhaseIdx, nCompIdx, FluidSystem::diffusionCoefficient(
fluidState_, paramCache, gPhaseIdx, nCompIdx));
562 setDiffusionCoefficient_(wPhaseIdx, gCompIdx, FluidSystem::diffusionCoefficient(
fluidState_, paramCache, wPhaseIdx, gCompIdx));
563 setDiffusionCoefficient_(wPhaseIdx, nCompIdx, FluidSystem::diffusionCoefficient(
fluidState_, paramCache, wPhaseIdx, nCompIdx));
565 setDiffusionCoefficient_(nPhaseIdx, wCompIdx, 0.0);
566 setDiffusionCoefficient_(nPhaseIdx, gCompIdx, 0.0);
570 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv,
solidState_);
571 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
574 for (
int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
576 Scalar h = EnergyVolVars::enthalpy(
fluidState_, paramCache, phaseIdx);
618 {
return fluidState_.massFraction(phaseIdx, compIdx); }
628 {
return fluidState_.moleFraction(phaseIdx, compIdx); }
675 return mobility_[phaseIdx];
694 {
return bulkDensTimesAdsorpCoeff_; }
700 {
return permeability_; }
707 if (compIdx < phaseIdx)
708 return diffCoefficient_[phaseIdx][compIdx];
709 else if (compIdx > phaseIdx)
710 return diffCoefficient_[phaseIdx][compIdx-1];
712 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient called for phaseIdx = compIdx");
721 Scalar sw_, sg_, sn_, pg_, pw_, pn_;
723 Scalar moleFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
724 Scalar massFrac_[ModelTraits::numFluidPhases()][ModelTraits::numFluidComponents()];
726 PermeabilityType permeability_;
727 Scalar mobility_[ModelTraits::numFluidPhases()];
728 Scalar bulkDensTimesAdsorpCoeff_;
730 void setDiffusionCoefficient_(
int phaseIdx,
int compIdx, Scalar d)
732 if (compIdx < phaseIdx)
733 diffCoefficient_[phaseIdx][compIdx] = std::move(d);
734 else if (compIdx > phaseIdx)
735 diffCoefficient_[phaseIdx][compIdx-1] = std::move(d);
736 else if (phaseIdx == nPhaseIdx)
737 diffCoefficient_[phaseIdx][compIdx-1] = 0;
739 DUNE_THROW(Dune::InvalidStateException,
"Diffusion coefficient for phaseIdx = compIdx doesn't exist");
742 std::array<std::array<Scalar, ModelTraits::numFluidComponents()-1>, ModelTraits::numFluidPhases()> diffCoefficient_;
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
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Property tag Indices
Definition: porousmediumflow/sequential/properties.hh:59
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:49
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:617
typename ModelTraits::Indices Indices
export the indices
Definition: porousmediumflow/3p3c/volumevariables.hh:93
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/3p3c/volumevariables.hh:598
FluidState fluidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:716
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:111
SolidState solidState_
Definition: porousmediumflow/3p3c/volumevariables.hh:717
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:607
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:627
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:645
typename Traits::SolidState SolidState
export type of solid state
Definition: porousmediumflow/3p3c/volumevariables.hh:95
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:654
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:590
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:89
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:664
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:681
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the diffusion coefficient.
Definition: porousmediumflow/3p3c/volumevariables.hh:705
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:673
const FluidState & fluidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:584
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:636
typename Traits::FluidSystem FluidSystem
export fluid system type
Definition: porousmediumflow/3p3c/volumevariables.hh:91
Scalar bulkDensTimesAdsorpCoeff() const
Returns the adsorption information.
Definition: porousmediumflow/3p3c/volumevariables.hh:693
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/3p3c/volumevariables.hh:687
typename Traits::SolidSystem SolidSystem
export type of solid system
Definition: porousmediumflow/3p3c/volumevariables.hh:97
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.