3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/richards/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_RICHARDS_VOLUME_VARIABLES_HH
26#define DUMUX_RICHARDS_VOLUME_VARIABLES_HH
27
28#include <cassert>
29
30#include <dune/common/exceptions.hh>
31
37
39
40namespace Dumux {
41
42namespace Detail {
45{
47};
48
50{};
51} // end namespace Detail
52
60template <class Traits>
63, public EnergyVolumeVariables<Traits, RichardsVolumeVariables<Traits> >
64, public std::conditional_t<Traits::ModelTraits::enableMolecularDiffusion(),
65 Detail::VolVarsWithPVSwitch, Detail::VolVarsWithOutPVSwitch>
66{
69 using Scalar = typename Traits::PrimaryVariables::value_type;
70 using PermeabilityType = typename Traits::PermeabilityType;
71 using ModelTraits = typename Traits::ModelTraits;
72
73 static constexpr int numFluidComps = ParentType::numFluidComponents();
74 static constexpr int numPhases = ParentType::numFluidPhases();
75
76 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
77
78 // checks if the fluid system uses the Richards model index convention
79 static constexpr auto fsCheck = ModelTraits::checkFluidSystem(typename Traits::FluidSystem{});
80
81public:
83 using FluidSystem = typename Traits::FluidSystem;
85 using FluidState = typename Traits::FluidState;
88 using SolidState = typename Traits::SolidState;
90 using SolidSystem = typename Traits::SolidSystem;
91 using Indices = typename Traits::ModelTraits::Indices;
93 static constexpr bool enableWaterDiffusionInAir() { return ModelTraits::enableMolecularDiffusion(); };
94
96 static constexpr auto liquidPhaseIdx = Traits::FluidSystem::phase0Idx;
97 static constexpr auto gasPhaseIdx = Traits::FluidSystem::phase1Idx;
98
108 template<class ElemSol, class Problem, class Element, class Scv>
109 void update(const ElemSol &elemSol,
110 const Problem &problem,
111 const Element &element,
112 const Scv& scv)
113 {
114 ParentType::update(elemSol, problem, element, scv);
115
116 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
117
118 const auto& priVars = elemSol[scv.localDofIndex()];
119 const auto phasePresence = priVars.state();
120
121 // precompute the minimum capillary pressure (entry pressure)
122 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
123 minPc_ = fluidMatrixInteraction.endPointPc();
124
125 //update porosity before calculating the effective properties depending on it
126 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
127
128 typename FluidSystem::ParameterCache paramCache;
129 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
130 {
131 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
132 };
133
134 if (phasePresence == Indices::gasPhaseOnly)
135 {
138 moleFraction_[gasPhaseIdx] = priVars[Indices::switchIdx];
139
140 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
141 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
142
143 //X_w = x_w* M_w/ M_avg
144 massFraction_[gasPhaseIdx] = priVars[Indices::switchIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
145
146 fluidState_.setSaturation(liquidPhaseIdx, 0.0);
147 fluidState_.setSaturation(gasPhaseIdx, 1.0);
148
149 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState_, solidState_);
150
151 // get pc for sw = 0.0
152 const Scalar pc = fluidMatrixInteraction.pc(0.0);
153
154 // set the wetting pressure
155 fluidState_.setPressure(liquidPhaseIdx, problem.nonwettingReferencePressure() - pc);
156 fluidState_.setPressure(gasPhaseIdx, problem.nonwettingReferencePressure());
157
158 // set molar densities
159 if constexpr (enableWaterDiffusionInAir())
160 {
161 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
162 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
163 }
164
165 // density and viscosity
166 paramCache.updateAll(fluidState_);
170
171 // compute and set the enthalpy
172 fluidState_.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, liquidPhaseIdx));
173 fluidState_.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, gasPhaseIdx));
174
175 //binary diffusion coefficients
176 paramCache.updateAll(fluidState_);
177 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
178 FluidSystem::comp1Idx,
179 FluidSystem::comp0Idx);
180 }
181 else if (phasePresence == Indices::bothPhases)
182 {
183 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
184
185 // if we want to account for diffusion in the air phase
186 // use Raoult to compute the water mole fraction in air
187 if constexpr (enableWaterDiffusionInAir())
188 {
189 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
190 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
192
193 moleFraction_[gasPhaseIdx] = FluidSystem::H2O::vaporPressure(temperature()) / problem.nonwettingReferencePressure();
194
195 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
196 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
197
198 //X_w = x_w* M_w/ M_avg
199 massFraction_[gasPhaseIdx] = moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
200
201 // binary diffusion coefficients
202 paramCache.updateAll(fluidState_);
203 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
204 FluidSystem::comp1Idx,
205 FluidSystem::comp0Idx);
206 }
207 }
208 else if (phasePresence == Indices::liquidPhaseOnly)
209 {
210 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
211
212 if constexpr (enableWaterDiffusionInAir())
213 {
214 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
215 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
220
221 // binary diffusion coefficients (none required for liquid phase only)
223 }
224 }
225
227 // specify the other parameters
229 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(liquidPhaseIdx));
230 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
231 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
232 EnergyVolVars::updateEffectiveThermalConductivity();
233 }
234
249 template<class ElemSol, class Problem, class Element, class Scv>
250 void completeFluidState(const ElemSol& elemSol,
251 const Problem& problem,
252 const Element& element,
253 const Scv& scv,
256 {
257 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
258
259 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
260
261 const auto& priVars = elemSol[scv.localDofIndex()];
262
263 // set the wetting pressure
264 using std::max;
265 Scalar minPc = fluidMatrixInteraction.pc(1.0);
266 fluidState.setPressure(liquidPhaseIdx, priVars[Indices::pressureIdx]);
267 fluidState.setPressure(gasPhaseIdx, max(problem.nonwettingReferencePressure(), fluidState.pressure(liquidPhaseIdx) + minPc));
268
269 // compute the capillary pressure to compute the saturation
270 // make sure that we the capillary pressure is not smaller than the minimum pc
271 // this would possibly return unphysical values from regularized material laws
272 using std::max;
273 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
274 problem.nonwettingReferencePressure() - fluidState.pressure(liquidPhaseIdx));
275 const Scalar sw = fluidMatrixInteraction.sw(pc);
276 fluidState.setSaturation(liquidPhaseIdx, sw);
277 fluidState.setSaturation(gasPhaseIdx, 1.0-sw);
278
279 // density and viscosity
280 typename FluidSystem::ParameterCache paramCache;
281 paramCache.updateAll(fluidState);
282 fluidState.setDensity(liquidPhaseIdx,
284 fluidState.setDensity(gasPhaseIdx,
286
287 fluidState.setViscosity(liquidPhaseIdx,
289
290 // compute and set the enthalpy
291 fluidState.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, liquidPhaseIdx));
292 fluidState.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, gasPhaseIdx));
293 }
294
299 const FluidState &fluidState() const
300 { return fluidState_; }
301
305 const SolidState &solidState() const
306 { return solidState_; }
307
311 Scalar temperature() const
312 { return fluidState_.temperature(); }
313
320 Scalar porosity() const
321 { return solidState_.porosity(); }
322
326 const PermeabilityType& permeability() const
327 { return permeability_; }
328
339 Scalar saturation(const int phaseIdx = liquidPhaseIdx) const
340 { return fluidState_.saturation(phaseIdx); }
341
348 Scalar density(const int phaseIdx = liquidPhaseIdx) const
349 { return fluidState_.density(phaseIdx); }
350
362 Scalar pressure(const int phaseIdx = liquidPhaseIdx) const
363 { return fluidState_.pressure(phaseIdx); }
364
376 Scalar mobility(const int phaseIdx = liquidPhaseIdx) const
377 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
378
386 Scalar viscosity(const int phaseIdx = liquidPhaseIdx) const
387 { return phaseIdx == liquidPhaseIdx ? fluidState_.viscosity(liquidPhaseIdx) : 0.0; }
388
395 Scalar relativePermeability(const int phaseIdx = liquidPhaseIdx) const
396 { return phaseIdx == liquidPhaseIdx ? relativePermeabilityWetting_ : 1.0; }
397
409 Scalar capillaryPressure() const
410 {
411 using std::max;
413 }
414
429 Scalar pressureHead(const int phaseIdx = liquidPhaseIdx) const
430 { return 100.0 *(pressure(phaseIdx) - pressure(gasPhaseIdx))/density(phaseIdx)/9.81; }
431
442 Scalar waterContent(const int phaseIdx = liquidPhaseIdx) const
443 { return saturation(phaseIdx) * solidState_.porosity(); }
444
452 Scalar moleFraction(const int phaseIdx, const int compIdx) const
453 {
454 static_assert(enableWaterDiffusionInAir());
455 if (compIdx != FluidSystem::comp0Idx)
456 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
457 return moleFraction_[phaseIdx];
458 }
459
467 Scalar massFraction(const int phaseIdx, const int compIdx) const
468 {
469 static_assert(enableWaterDiffusionInAir());
470 if (compIdx != FluidSystem::comp0Idx)
471 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
472 return massFraction_[phaseIdx];
473 }
474
481 Scalar molarDensity(const int phaseIdx) const
482 {
483 static_assert(enableWaterDiffusionInAir());
484 return molarDensity_[phaseIdx];
485 }
486
490 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
491 {
493 assert(phaseIdx == gasPhaseIdx);
494 assert(compIIdx != compJIdx);
495 typename FluidSystem::ParameterCache paramCache;
496 paramCache.updatePhase(fluidState_, phaseIdx);
497 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
498 }
499
503 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
504 {
506 assert(phaseIdx == gasPhaseIdx);
507 assert(compIIdx != compJIdx);
508 return effectiveDiffCoeff_;
509 }
510
511protected:
515 PermeabilityType permeability_;
516 Scalar minPc_;
517 Scalar moleFraction_[numPhases];
518 Scalar massFraction_[numPhases];
519 Scalar molarDensity_[numPhases];
520
521 // Effective diffusion coefficients for the phases
523
524};
525} // end namespace Dumux
526
527#endif
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.
Relations valid for an ideal gas.
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
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:76
The primary variable switch controlling the phase presence state variable.
Definition: richards/primaryvariableswitch.hh:41
Helper structs to conditionally use a primary variable switch or not.
Definition: porousmediumflow/richards/volumevariables.hh:45
Definition: porousmediumflow/richards/volumevariables.hh:50
Volume averaged quantities required by the Richards model.
Definition: porousmediumflow/richards/volumevariables.hh:66
Scalar saturation(const int phaseIdx=liquidPhaseIdx) const
Returns the average absolute saturation [] of a given fluid phase within the finite volume.
Definition: porousmediumflow/richards/volumevariables.hh:339
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richards/volumevariables.hh:512
Scalar relativePermeabilityWetting_
the relative permeability of the wetting phase
Definition: porousmediumflow/richards/volumevariables.hh:514
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:326
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richards/volumevariables.hh:490
Scalar waterContent(const int phaseIdx=liquidPhaseIdx) const
Returns the water content of a fluid phase within the finite volume.
Definition: porousmediumflow/richards/volumevariables.hh:442
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:320
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/richards/volumevariables.hh:452
SolidState solidState_
Definition: porousmediumflow/richards/volumevariables.hh:513
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richards/volumevariables.hh:299
Scalar viscosity(const int phaseIdx=liquidPhaseIdx) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:386
static constexpr auto liquidPhaseIdx
Export phase indices.
Definition: porousmediumflow/richards/volumevariables.hh:96
static constexpr auto gasPhaseIdx
Definition: porousmediumflow/richards/volumevariables.hh:97
Scalar pressureHead(const int phaseIdx=liquidPhaseIdx) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:429
static constexpr bool enableWaterDiffusionInAir()
If water diffusion in air is enabled.
Definition: porousmediumflow/richards/volumevariables.hh:93
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/richards/volumevariables.hh:109
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:409
PermeabilityType permeability_
the intrinsic permeability
Definition: porousmediumflow/richards/volumevariables.hh:515
Scalar density(const int phaseIdx=liquidPhaseIdx) const
Returns the average mass density of a given fluid phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:348
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richards/volumevariables.hh:90
Scalar massFraction_[numPhases]
The water mass fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:518
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richards/volumevariables.hh:503
Scalar molarDensity_[numPhases]
The molar density of water and air.
Definition: porousmediumflow/richards/volumevariables.hh:519
typename Traits::ModelTraits::Indices Indices
Definition: porousmediumflow/richards/volumevariables.hh:91
Scalar relativePermeability(const int phaseIdx=liquidPhaseIdx) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:395
Scalar moleFraction_[numPhases]
The water mole fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:517
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:305
typename Traits::SolidState SolidState
Definition: porousmediumflow/richards/volumevariables.hh:88
Scalar effectiveDiffCoeff_
Definition: porousmediumflow/richards/volumevariables.hh:522
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Fills the fluid state according to the primary variables.
Definition: porousmediumflow/richards/volumevariables.hh:250
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:481
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/richards/volumevariables.hh:467
Scalar mobility(const int phaseIdx=liquidPhaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:376
Scalar pressure(const int phaseIdx=liquidPhaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:362
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richards/volumevariables.hh:83
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richards/volumevariables.hh:85
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richards/volumevariables.hh:311
Scalar minPc_
the minimum capillary pressure (entry pressure)
Definition: porousmediumflow/richards/volumevariables.hh:516
The isothermal base class.
Definition: porousmediumflow/volumevariables.hh:42
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition: porousmediumflow/volumevariables.hh:54
const PrimaryVariables & priVars() const
Returns the vector of primary variables.
Definition: porousmediumflow/volumevariables.hh:78
static constexpr int numFluidPhases()
Return number of phases considered by the model.
Definition: porousmediumflow/volumevariables.hh:52
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:66
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.