3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/richardsextended/volumevariables.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_RICHARDSEXTENDED_VOLUME_VARIABLES_HH
26#define DUMUX_RICHARDSEXTENDED_VOLUME_VARIABLES_HH
27
28#include <cassert>
29
30#include <dune/common/exceptions.hh>
31
37
39
40namespace Dumux {
41
49template <class Traits>
52, public EnergyVolumeVariables<Traits, ExtendedRichardsVolumeVariables<Traits> >
53{
56 using Scalar = typename Traits::PrimaryVariables::value_type;
57 using PermeabilityType = typename Traits::PermeabilityType;
58 using ModelTraits = typename Traits::ModelTraits;
59
60 static constexpr int numFluidComps = ParentType::numFluidComponents();
61 static constexpr int numPhases = ParentType::numFluidPhases();
62
63 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
64
65 // checks if the fluid system uses the Richards model index convention
66 static constexpr auto fsCheck = ModelTraits::checkFluidSystem(typename Traits::FluidSystem{});
67
68public:
70 using FluidSystem = typename Traits::FluidSystem;
72 using FluidState = typename Traits::FluidState;
75 using SolidState = typename Traits::SolidState;
77 using SolidSystem = typename Traits::SolidSystem;
78 using Indices = typename Traits::ModelTraits::Indices;
80
82 static constexpr auto liquidPhaseIdx = Traits::FluidSystem::phase0Idx;
83 static constexpr auto gasPhaseIdx = Traits::FluidSystem::phase1Idx;
84
94 template<class ElemSol, class Problem, class Element, class Scv>
95 void update(const ElemSol &elemSol,
96 const Problem &problem,
97 const Element &element,
98 const Scv& scv)
99 {
100 ParentType::update(elemSol, problem, element, scv);
101
102 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
103
104 const auto& priVars = elemSol[scv.localDofIndex()];
105 const auto phasePresence = priVars.state();
106
107 // precompute the minimum capillary pressure (entry pressure)
108 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
109 minPc_ = fluidMatrixInteraction.endPointPc();
110
111 //update porosity before calculating the effective properties depending on it
112 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
113
114 typename FluidSystem::ParameterCache paramCache;
115 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
116 {
117 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
118 };
119
120 if (phasePresence == Indices::gasPhaseOnly)
121 {
124 moleFraction_[gasPhaseIdx] = priVars[Indices::switchIdx];
125
126 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
127 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
128
129 //X_w = x_w* M_w/ M_avg
130 massFraction_[gasPhaseIdx] = priVars[Indices::switchIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
131
132 fluidState_.setSaturation(liquidPhaseIdx, 0.0);
133 fluidState_.setSaturation(gasPhaseIdx, 1.0);
134
135 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState_, solidState_);
136
137 // get pc for sw = 0.0
138 const Scalar pc = fluidMatrixInteraction.pc(0.0);
139
140 // set the wetting pressure
141 fluidState_.setPressure(liquidPhaseIdx, problem.nonwettingReferencePressure() - pc);
142 fluidState_.setPressure(gasPhaseIdx, problem.nonwettingReferencePressure());
143
144 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
145 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
146
147 // density and viscosity
148 paramCache.updateAll(fluidState_);
152
153 // compute and set the enthalpy
154 fluidState_.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, liquidPhaseIdx));
155 fluidState_.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, gasPhaseIdx));
156
157 //binary diffusion coefficients
158 paramCache.updateAll(fluidState_);
159 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
160 FluidSystem::comp1Idx,
161 FluidSystem::comp0Idx);
162 }
163 else if (phasePresence == Indices::bothPhases)
164 {
165 completeFluidState_(elemSol, problem, element, scv, fluidState_, solidState_);
166
167 // we want to account for diffusion in the air phase
168 // use Raoult to compute the water mole fraction in air
169 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
170 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
172
173 moleFraction_[gasPhaseIdx] = FluidSystem::H2O::vaporPressure(temperature()) / problem.nonwettingReferencePressure();
174
175 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
176 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
177
178 //X_w = x_w* M_w/ M_avg
179 massFraction_[gasPhaseIdx] = moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
180
181 // binary diffusion coefficients
182 paramCache.updateAll(fluidState_);
183 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
184 FluidSystem::comp1Idx,
185 FluidSystem::comp0Idx);
186 }
187 else if (phasePresence == Indices::liquidPhaseOnly)
188 {
189 completeFluidState_(elemSol, problem, element, scv, fluidState_, solidState_);
190
191 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
192 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
197
198 // binary diffusion coefficients (none required for liquid phase only)
200 }
201
203 // specify the other parameters
205 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(liquidPhaseIdx));
206 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
207 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
208 EnergyVolVars::updateEffectiveThermalConductivity();
209 }
210
215 const FluidState &fluidState() const
216 { return fluidState_; }
217
221 const SolidState &solidState() const
222 { return solidState_; }
223
227 Scalar temperature() const
228 { return fluidState_.temperature(); }
229
236 Scalar porosity() const
237 { return solidState_.porosity(); }
238
242 const PermeabilityType& permeability() const
243 { return permeability_; }
244
255 Scalar saturation(const int phaseIdx = liquidPhaseIdx) const
256 { return fluidState_.saturation(phaseIdx); }
257
264 Scalar density(const int phaseIdx = liquidPhaseIdx) const
265 { return fluidState_.density(phaseIdx); }
266
278 Scalar pressure(const int phaseIdx = liquidPhaseIdx) const
279 { return fluidState_.pressure(phaseIdx); }
280
292 Scalar mobility(const int phaseIdx = liquidPhaseIdx) const
293 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
294
302 Scalar viscosity(const int phaseIdx = liquidPhaseIdx) const
303 { return phaseIdx == liquidPhaseIdx ? fluidState_.viscosity(liquidPhaseIdx) : 0.0; }
304
311 Scalar relativePermeability(const int phaseIdx = liquidPhaseIdx) const
312 { return phaseIdx == liquidPhaseIdx ? relativePermeabilityWetting_ : 1.0; }
313
325 Scalar capillaryPressure() const
326 {
327 using std::max;
329 }
330
345 Scalar pressureHead(const int phaseIdx = liquidPhaseIdx) const
346 { return 100.0 *(pressure(phaseIdx) - pressure(gasPhaseIdx))/density(phaseIdx)/9.81; }
347
358 Scalar waterContent(const int phaseIdx = liquidPhaseIdx) const
359 { return saturation(phaseIdx) * solidState_.porosity(); }
360
368 Scalar moleFraction(const int phaseIdx, const int compIdx) const
369 {
370 if (compIdx != FluidSystem::comp0Idx)
371 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
372 return moleFraction_[phaseIdx];
373 }
374
382 Scalar massFraction(const int phaseIdx, const int compIdx) const
383 {
384 if (compIdx != FluidSystem::comp0Idx)
385 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
386 return massFraction_[phaseIdx];
387 }
388
395 Scalar molarDensity(const int phaseIdx) const
396 {
397 return molarDensity_[phaseIdx];
398 }
399
403 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
404 {
405 assert(phaseIdx == gasPhaseIdx);
406 assert(compIIdx != compJIdx);
407 typename FluidSystem::ParameterCache paramCache;
408 paramCache.updatePhase(fluidState_, phaseIdx);
409 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
410 }
411
415 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
416 {
417 assert(phaseIdx == gasPhaseIdx);
418 assert(compIIdx != compJIdx);
419 return effectiveDiffCoeff_;
420 }
421private:
436 template<class ElemSol, class Problem, class Element, class Scv>
437 void completeFluidState_(const ElemSol& elemSol,
438 const Problem& problem,
439 const Element& element,
440 const Scv& scv,
443 {
444 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
445
446 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
447
448 const auto& priVars = elemSol[scv.localDofIndex()];
449
450 // set the wetting pressure
451 using std::max;
452 Scalar minPc = fluidMatrixInteraction.pc(1.0);
453 fluidState.setPressure(liquidPhaseIdx, priVars[Indices::pressureIdx]);
454 fluidState.setPressure(gasPhaseIdx, max(problem.nonwettingReferencePressure(), fluidState.pressure(liquidPhaseIdx) + minPc));
455
456 // compute the capillary pressure to compute the saturation
457 // make sure that we the capillary pressure is not smaller than the minimum pc
458 // this would possibly return unphysical values from regularized material laws
459 using std::max;
460 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
461 problem.nonwettingReferencePressure() - fluidState.pressure(liquidPhaseIdx));
462 const Scalar sw = fluidMatrixInteraction.sw(pc);
463 fluidState.setSaturation(liquidPhaseIdx, sw);
464 fluidState.setSaturation(gasPhaseIdx, 1.0-sw);
465
466 // density and viscosity
467 typename FluidSystem::ParameterCache paramCache;
468 paramCache.updateAll(fluidState);
469 fluidState.setDensity(liquidPhaseIdx,
471 fluidState.setDensity(gasPhaseIdx,
473
474 fluidState.setViscosity(liquidPhaseIdx,
476
477 // compute and set the enthalpy
478 fluidState.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, liquidPhaseIdx));
479 fluidState.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, gasPhaseIdx));
480 }
481
482protected:
486 PermeabilityType permeability_;
487 Scalar minPc_;
488 Scalar moleFraction_[numPhases];
489 Scalar massFraction_[numPhases];
490 Scalar molarDensity_[numPhases];
491
492 // Effective diffusion coefficients for the phases
494
495};
496} // end namespace Dumux
497
498#endif
Relations valid for an ideal gas.
A central place for various physical constants occurring in some equations.
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
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
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 density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
static constexpr Scalar molarDensity(Scalar temperature, Scalar pressure)
The molar density of the gas , depending on pressure and temperature.
Definition: idealgas.hh:70
Definition: porousmediumflow/nonisothermal/volumevariables.hh:75
The primary variable switch controlling the phase presence state variable.
Definition: richardsextended/primaryvariableswitch.hh:41
Volume averaged quantities required by the extended Richards model.
Definition: porousmediumflow/richardsextended/volumevariables.hh:53
PermeabilityType permeability_
the intrinsic permeability
Definition: porousmediumflow/richardsextended/volumevariables.hh:486
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:221
Scalar massFraction_[numPhases]
The water mass fractions in water and air.
Definition: porousmediumflow/richardsextended/volumevariables.hh:489
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsextended/volumevariables.hh:403
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:236
typename Traits::SolidState SolidState
Definition: porousmediumflow/richardsextended/volumevariables.hh:75
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:95
Scalar molarDensity_[numPhases]
The molar density of water and air.
Definition: porousmediumflow/richardsextended/volumevariables.hh:490
Scalar effectiveDiffCoeff_
Definition: porousmediumflow/richardsextended/volumevariables.hh:493
Scalar relativePermeabilityWetting_
the relative permeability of the wetting phase
Definition: porousmediumflow/richardsextended/volumevariables.hh:485
Scalar pressureHead(const int phaseIdx=liquidPhaseIdx) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:345
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richardsextended/volumevariables.hh:72
Scalar viscosity(const int phaseIdx=liquidPhaseIdx) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:302
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsextended/volumevariables.hh:415
Scalar mobility(const int phaseIdx=liquidPhaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:292
Scalar minPc_
the minimum capillary pressure (entry pressure)
Definition: porousmediumflow/richardsextended/volumevariables.hh:487
Scalar saturation(const int phaseIdx=liquidPhaseIdx) const
Returns the average absolute saturation [] of a given fluid phase within the finite volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:255
Scalar density(const int phaseIdx=liquidPhaseIdx) const
Returns the average mass density of a given fluid phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:264
Scalar relativePermeability(const int phaseIdx=liquidPhaseIdx) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:311
typename Traits::ModelTraits::Indices Indices
Definition: porousmediumflow/richardsextended/volumevariables.hh:78
static constexpr auto gasPhaseIdx
Definition: porousmediumflow/richardsextended/volumevariables.hh:83
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richardsextended/volumevariables.hh:242
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:325
Scalar moleFraction_[numPhases]
The water mole fractions in water and air.
Definition: porousmediumflow/richardsextended/volumevariables.hh:488
Scalar massFraction(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/richardsextended/volumevariables.hh:382
SolidState solidState_
Definition: porousmediumflow/richardsextended/volumevariables.hh:484
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/richardsextended/volumevariables.hh:395
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/richardsextended/volumevariables.hh:368
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richardsextended/volumevariables.hh:70
Scalar pressure(const int phaseIdx=liquidPhaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:278
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richardsextended/volumevariables.hh:215
Scalar waterContent(const int phaseIdx=liquidPhaseIdx) const
Returns the water content of a fluid phase within the finite volume.
Definition: porousmediumflow/richardsextended/volumevariables.hh:358
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richardsextended/volumevariables.hh:227
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richardsextended/volumevariables.hh:483
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richardsextended/volumevariables.hh:77
static constexpr auto liquidPhaseIdx
Export phase indices.
Definition: porousmediumflow/richardsextended/volumevariables.hh:82
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
static constexpr int numFluidPhases()
Return number of phases considered by the model.
Definition: porousmediumflow/volumevariables.hh:50
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.