3.4
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
78public:
80 using FluidSystem = typename Traits::FluidSystem;
82 using FluidState = typename Traits::FluidState;
85 using SolidState = typename Traits::SolidState;
87 using SolidSystem = typename Traits::SolidSystem;
88 using Indices = typename Traits::ModelTraits::Indices;
90 static constexpr bool enableWaterDiffusionInAir() { return ModelTraits::enableMolecularDiffusion(); };
91
101 template<class ElemSol, class Problem, class Element, class Scv>
102 void update(const ElemSol &elemSol,
103 const Problem &problem,
104 const Element &element,
105 const Scv& scv)
106 {
107 ParentType::update(elemSol, problem, element, scv);
108
109 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
110
111 const auto& priVars = elemSol[scv.localDofIndex()];
112 const auto phasePresence = priVars.state();
113
114 // precompute the minimum capillary pressure (entry pressure)
115 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
116 minPc_ = fluidMatrixInteraction.endPointPc();
117
118 typename FluidSystem::ParameterCache paramCache;
119 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
120 {
121 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
122 };
123
124 if (phasePresence == Indices::gasPhaseOnly)
125 {
126 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
127 massFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
128 moleFraction_[FluidSystem::gasPhaseIdx] = priVars[Indices::switchIdx];
129
130 const auto averageMolarMassGasPhase = (moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)) +
131 ((1-moleFraction_[FluidSystem::gasPhaseIdx])*FluidSystem::molarMass(FluidSystem::gasPhaseIdx));
132
133 //X_w = x_w* M_w/ M_avg
134 massFraction_[FluidSystem::gasPhaseIdx] = priVars[Indices::switchIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)/averageMolarMassGasPhase;
135
136 fluidState_.setSaturation(FluidSystem::liquidPhaseIdx, 0.0);
137 fluidState_.setSaturation(FluidSystem::gasPhaseIdx, 1.0);
138
139 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState_, solidState_);
140
141 // get pc for sw = 0.0
142 const Scalar pc = fluidMatrixInteraction.pc(0.0);
143
144 // set the wetting pressure
145 fluidState_.setPressure(FluidSystem::liquidPhaseIdx, problem.nonwettingReferencePressure() - pc);
146 fluidState_.setPressure(FluidSystem::gasPhaseIdx, problem.nonwettingReferencePressure());
147
148 // set molar densities
150 {
151 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
152 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
153 }
154
155 // density and viscosity
156 paramCache.updateAll(fluidState_);
157 fluidState_.setDensity(FluidSystem::liquidPhaseIdx, FluidSystem::density(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
158 fluidState_.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fluidState_, paramCache, FluidSystem::gasPhaseIdx));
159 fluidState_.setViscosity(FluidSystem::liquidPhaseIdx, FluidSystem::viscosity(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
160
161 // compute and set the enthalpy
162 fluidState_.setEnthalpy(FluidSystem::liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
163 fluidState_.setEnthalpy(FluidSystem::gasPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, FluidSystem::gasPhaseIdx));
164
165 //binary diffusion coefficients
166 paramCache.updateAll(fluidState_);
167 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(FluidSystem::gasPhaseIdx,
168 FluidSystem::comp1Idx,
169 FluidSystem::comp0Idx);
170 }
171 else if (phasePresence == Indices::bothPhases)
172 {
173 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
174
175 // if we want to account for diffusion in the air phase
176 // use Raoult to compute the water mole fraction in air
178 {
179 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
180 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
181 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
182
183 moleFraction_[FluidSystem::gasPhaseIdx] = FluidSystem::H2O::vaporPressure(temperature()) / problem.nonwettingReferencePressure();
184
185 const auto averageMolarMassGasPhase = (moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)) +
186 ((1-moleFraction_[FluidSystem::gasPhaseIdx])*FluidSystem::molarMass(FluidSystem::gasPhaseIdx));
187
188 //X_w = x_w* M_w/ M_avg
189 massFraction_[FluidSystem::gasPhaseIdx] = moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)/averageMolarMassGasPhase;
190
191 // binary diffusion coefficients
192 paramCache.updateAll(fluidState_);
193 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(FluidSystem::gasPhaseIdx,
194 FluidSystem::comp1Idx,
195 FluidSystem::comp0Idx);
196 }
197 }
198 else if (phasePresence == Indices::liquidPhaseOnly)
199 {
200 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
201
203 {
204 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
205 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
206 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
207 moleFraction_[FluidSystem::gasPhaseIdx] = 0.0;
208 massFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
209 massFraction_[FluidSystem::gasPhaseIdx] = 0.0;
210
211 // binary diffusion coefficients (none required for liquid phase only)
213 }
214 }
215
217 // specify the other parameters
219 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(FluidSystem::liquidPhaseIdx));
220 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
221 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
222 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
223 EnergyVolVars::updateEffectiveThermalConductivity();
224 }
225
240 template<class ElemSol, class Problem, class Element, class Scv>
241 void completeFluidState(const ElemSol& elemSol,
242 const Problem& problem,
243 const Element& element,
244 const Scv& scv,
247 {
248 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
249
250 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
251
252 const auto& priVars = elemSol[scv.localDofIndex()];
253
254 // set the wetting pressure
255 using std::max;
256 Scalar minPc = fluidMatrixInteraction.pc(1.0);
257 fluidState.setPressure(FluidSystem::liquidPhaseIdx, priVars[Indices::pressureIdx]);
258 fluidState.setPressure(FluidSystem::gasPhaseIdx, max(problem.nonwettingReferencePressure(), fluidState.pressure(FluidSystem::liquidPhaseIdx) + minPc));
259
260 // compute the capillary pressure to compute the saturation
261 // make sure that we the capillary pressure is not smaller than the minimum pc
262 // this would possibly return unphysical values from regularized material laws
263 using std::max;
264 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
265 problem.nonwettingReferencePressure() - fluidState.pressure(FluidSystem::liquidPhaseIdx));
266 const Scalar sw = fluidMatrixInteraction.sw(pc);
267 fluidState.setSaturation(FluidSystem::liquidPhaseIdx, sw);
268 fluidState.setSaturation(FluidSystem::gasPhaseIdx, 1.0-sw);
269
270 // density and viscosity
271 typename FluidSystem::ParameterCache paramCache;
272 paramCache.updateAll(fluidState);
273 fluidState.setDensity(FluidSystem::liquidPhaseIdx,
274 FluidSystem::density(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
275 fluidState.setDensity(FluidSystem::gasPhaseIdx,
276 FluidSystem::density(fluidState, paramCache, FluidSystem::gasPhaseIdx));
277
278 fluidState.setViscosity(FluidSystem::liquidPhaseIdx,
279 FluidSystem::viscosity(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
280
281 // compute and set the enthalpy
282 fluidState.setEnthalpy(FluidSystem::liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
283 fluidState.setEnthalpy(FluidSystem::gasPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, FluidSystem::gasPhaseIdx));
284 }
285
290 const FluidState &fluidState() const
291 { return fluidState_; }
292
296 const SolidState &solidState() const
297 { return solidState_; }
298
302 Scalar temperature() const
303 { return fluidState_.temperature(); }
304
311 Scalar porosity() const
312 { return solidState_.porosity(); }
313
317 const PermeabilityType& permeability() const
318 { return permeability_; }
319
330 Scalar saturation(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
331 { return fluidState_.saturation(phaseIdx); }
332
339 Scalar density(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
340 { return fluidState_.density(phaseIdx); }
341
353 Scalar pressure(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
354 { return fluidState_.pressure(phaseIdx); }
355
367 Scalar mobility(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
368 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
369
377 Scalar viscosity(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
378 { return phaseIdx == FluidSystem::liquidPhaseIdx ? fluidState_.viscosity(FluidSystem::liquidPhaseIdx) : 0.0; }
379
386 Scalar relativePermeability(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
387 { return phaseIdx == FluidSystem::liquidPhaseIdx ? relativePermeabilityWetting_ : 1.0; }
388
400 Scalar capillaryPressure() const
401 {
402 using std::max;
403 return max(minPc_, pressure(FluidSystem::gasPhaseIdx) - pressure(FluidSystem::liquidPhaseIdx));
404 }
405
420 Scalar pressureHead(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
421 { return 100.0 *(pressure(phaseIdx) - pressure(FluidSystem::gasPhaseIdx))/density(phaseIdx)/9.81; }
422
433 Scalar waterContent(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
434 { return saturation(phaseIdx) * solidState_.porosity(); }
435
443 Scalar moleFraction(const int phaseIdx, const int compIdx) const
444 {
446 if (compIdx != FluidSystem::comp0Idx)
447 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
448 return moleFraction_[phaseIdx];
449 }
450
458 Scalar massFraction(const int phaseIdx, const int compIdx) const
459 {
461 if (compIdx != FluidSystem::comp0Idx)
462 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
463 return massFraction_[phaseIdx];
464 }
465
472 Scalar molarDensity(const int phaseIdx) const
473 {
475 return molarDensity_[phaseIdx];
476 }
477
481 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
482 {
484 assert(phaseIdx == FluidSystem::gasPhaseIdx);
485 assert(compIIdx != compJIdx);
486 typename FluidSystem::ParameterCache paramCache;
487 paramCache.updatePhase(fluidState_, phaseIdx);
488 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
489 }
490
494 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
495 {
497 assert(phaseIdx == FluidSystem::gasPhaseIdx);
498 assert(compIIdx != compJIdx);
499 return effectiveDiffCoeff_;
500 }
501
502protected:
506 PermeabilityType permeability_;
507 Scalar minPc_;
508 Scalar moleFraction_[numPhases];
509 Scalar massFraction_[numPhases];
510 Scalar molarDensity_[numPhases];
511
512 // Effective diffusion coefficients for the phases
514
515};
516} // end namespace Dumux
517
518#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:75
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 density(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the average mass density of a given fluid phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:339
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richards/volumevariables.hh:503
Scalar relativePermeabilityWetting_
the relative permeability of the wetting phase
Definition: porousmediumflow/richards/volumevariables.hh:505
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:317
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richards/volumevariables.hh:481
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:311
Scalar pressureHead(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:420
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:443
SolidState solidState_
Definition: porousmediumflow/richards/volumevariables.hh:504
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richards/volumevariables.hh:290
static constexpr bool enableWaterDiffusionInAir()
If water diffusion in air is enabled.
Definition: porousmediumflow/richards/volumevariables.hh:90
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:102
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:400
PermeabilityType permeability_
the instrinsic permeability
Definition: porousmediumflow/richards/volumevariables.hh:506
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richards/volumevariables.hh:87
Scalar pressure(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:353
Scalar waterContent(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the water content of a fluid phase within the finite volume.
Definition: porousmediumflow/richards/volumevariables.hh:433
Scalar viscosity(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:377
Scalar massFraction_[numPhases]
The water mass fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:509
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richards/volumevariables.hh:494
Scalar molarDensity_[numPhases]
The molar density of water and air.
Definition: porousmediumflow/richards/volumevariables.hh:510
Scalar mobility(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:367
typename Traits::ModelTraits::Indices Indices
Definition: porousmediumflow/richards/volumevariables.hh:88
Scalar relativePermeability(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:386
Scalar moleFraction_[numPhases]
The water mole fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:508
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:296
typename Traits::SolidState SolidState
Definition: porousmediumflow/richards/volumevariables.hh:85
Scalar effectiveDiffCoeff_
Definition: porousmediumflow/richards/volumevariables.hh:513
Scalar saturation(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the average absolute saturation [] of a given fluid phase within the finite volume.
Definition: porousmediumflow/richards/volumevariables.hh:330
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:241
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:472
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:458
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richards/volumevariables.hh:80
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richards/volumevariables.hh:82
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richards/volumevariables.hh:302
Scalar minPc_
the minimum capillary pressure (entry pressure)
Definition: porousmediumflow/richards/volumevariables.hh:507
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.