3.1-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}
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 static constexpr int numFluidComps = ParentType::numFluidComponents();
73public:
75 using FluidSystem = typename Traits::FluidSystem;
77 using FluidState = typename Traits::FluidState;
80 using SolidState = typename Traits::SolidState;
82 using SolidSystem = typename Traits::SolidSystem;
85 static constexpr bool enableWaterDiffusionInAir() { return ModelTraits::enableMolecularDiffusion(); };
86
96 template<class ElemSol, class Problem, class Element, class Scv>
97 void update(const ElemSol &elemSol,
98 const Problem &problem,
99 const Element &element,
100 const Scv& scv)
101 {
102 ParentType::update(elemSol, problem, element, scv);
103 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
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 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
110 minPc_ = MaterialLaw::endPointPc(materialParams);
111
112 if (phasePresence == Indices::gasPhaseOnly)
113 {
114 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
115 massFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
116
117
118 moleFraction_[FluidSystem::gasPhaseIdx] = priVars[Indices::switchIdx];
119
120 const auto averageMolarMassGasPhase = (moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)) +
121 ((1-moleFraction_[FluidSystem::gasPhaseIdx])*FluidSystem::molarMass(FluidSystem::gasPhaseIdx));
122
123 //X_w = x_w* M_w/ M_avg
124 massFraction_[FluidSystem::gasPhaseIdx] = priVars[Indices::switchIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)/averageMolarMassGasPhase;
125
126 fluidState_.setSaturation(FluidSystem::liquidPhaseIdx, 0.0);
127 fluidState_.setSaturation(FluidSystem::gasPhaseIdx, 1.0);
128
129 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState_, solidState_);
130
131 // get pc for sw = 0.0
132 const Scalar pc = MaterialLaw::pc(materialParams, 0.0);
133
134 // set the wetting pressure
135 fluidState_.setPressure(FluidSystem::liquidPhaseIdx, problem.nonWettingReferencePressure() - pc);
136 fluidState_.setPressure(FluidSystem::gasPhaseIdx, problem.nonWettingReferencePressure());
137
138 // set molar densities
140 {
141 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
142 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonWettingReferencePressure());
143 }
144
145 // density and viscosity
146 typename FluidSystem::ParameterCache paramCache;
147 paramCache.updateAll(fluidState_);
148 fluidState_.setDensity(FluidSystem::liquidPhaseIdx, FluidSystem::density(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
149 fluidState_.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fluidState_, paramCache, FluidSystem::gasPhaseIdx));
150 fluidState_.setViscosity(FluidSystem::liquidPhaseIdx, FluidSystem::viscosity(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
151
152 // compute and set the enthalpy
153 fluidState_.setEnthalpy(FluidSystem::liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, FluidSystem::liquidPhaseIdx));
154 fluidState_.setEnthalpy(FluidSystem::gasPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, FluidSystem::gasPhaseIdx));
155 }
156 else if (phasePresence == Indices::bothPhases)
157 {
158 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
159
160 // if we want to account for diffusion in the air phase
161 // use Raoult to compute the water mole fraction in air
163 {
164 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
165 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonWettingReferencePressure());
166 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
167
168 moleFraction_[FluidSystem::gasPhaseIdx] = FluidSystem::H2O::vaporPressure(temperature()) / problem.nonWettingReferencePressure();
169
170 const auto averageMolarMassGasPhase = (moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)) +
171 ((1-moleFraction_[FluidSystem::gasPhaseIdx])*FluidSystem::molarMass(FluidSystem::gasPhaseIdx));
172
173 //X_w = x_w* M_w/ M_avg
174 massFraction_[FluidSystem::gasPhaseIdx] = moleFraction_[FluidSystem::gasPhaseIdx]*FluidSystem::molarMass(FluidSystem::liquidPhaseIdx)/averageMolarMassGasPhase;
175
176 // binary diffusion coefficients
177 typename FluidSystem::ParameterCache paramCache;
178 paramCache.updateAll(fluidState_);
179 diffCoeff_ = FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, FluidSystem::gasPhaseIdx, FluidSystem::comp0Idx, FluidSystem::comp1Idx);
180 }
181 }
182 else if (phasePresence == Indices::liquidPhaseOnly)
183 {
184 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
185
187 {
188 molarDensity_[FluidSystem::liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(FluidSystem::liquidPhaseIdx))/FluidSystem::H2O::molarMass();
189 molarDensity_[FluidSystem::gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonWettingReferencePressure());
190 moleFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
191 moleFraction_[FluidSystem::gasPhaseIdx] = 0.0;
192 massFraction_[FluidSystem::liquidPhaseIdx] = 1.0;
193 massFraction_[FluidSystem::gasPhaseIdx] = 0.0;
194
195 // binary diffusion coefficients
196 typename FluidSystem::ParameterCache paramCache;
197 paramCache.updateAll(fluidState_);
198 diffCoeff_ = FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, FluidSystem::gasPhaseIdx, FluidSystem::comp0Idx, FluidSystem::comp1Idx);
199 }
200 }
201
203 // specify the other parameters
205 relativePermeabilityWetting_ = MaterialLaw::krw(materialParams, fluidState_.saturation(FluidSystem::liquidPhaseIdx));
206 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
207 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
208 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
209 }
210
225 template<class ElemSol, class Problem, class Element, class Scv>
226 void completeFluidState(const ElemSol& elemSol,
227 const Problem& problem,
228 const Element& element,
229 const Scv& scv,
232 {
233 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
234
235 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
236 const auto& priVars = elemSol[scv.localDofIndex()];
237
238 // set the wetting pressure
239 using std::max;
240 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
241 Scalar minPc = MaterialLaw::pc(materialParams, 1.0);
242 fluidState.setPressure(FluidSystem::liquidPhaseIdx, priVars[Indices::pressureIdx]);
243 fluidState.setPressure(FluidSystem::gasPhaseIdx, max(problem.nonWettingReferencePressure(), fluidState.pressure(FluidSystem::liquidPhaseIdx) + minPc));
244
245 // compute the capillary pressure to compute the saturation
246 // make sure that we the capillary pressure is not smaller than the minimum pc
247 // this would possibly return unphysical values from regularized material laws
248 using std::max;
249 const Scalar pc = max(MaterialLaw::endPointPc(materialParams),
250 problem.nonWettingReferencePressure() - fluidState.pressure(FluidSystem::liquidPhaseIdx));
251 const Scalar sw = MaterialLaw::sw(materialParams, pc);
252 fluidState.setSaturation(FluidSystem::liquidPhaseIdx, sw);
253 fluidState.setSaturation(FluidSystem::gasPhaseIdx, 1.0-sw);
254
255 // density and viscosity
256 typename FluidSystem::ParameterCache paramCache;
257 paramCache.updateAll(fluidState);
258 fluidState.setDensity(FluidSystem::liquidPhaseIdx,
259 FluidSystem::density(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
260 fluidState.setDensity(FluidSystem::gasPhaseIdx,
261 FluidSystem::density(fluidState, paramCache, FluidSystem::gasPhaseIdx));
262
263 fluidState.setViscosity(FluidSystem::liquidPhaseIdx,
264 FluidSystem::viscosity(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
265
266 // compute and set the enthalpy
267 fluidState.setEnthalpy(FluidSystem::liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, FluidSystem::liquidPhaseIdx));
268 fluidState.setEnthalpy(FluidSystem::gasPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, FluidSystem::gasPhaseIdx));
269 }
270
275 const FluidState &fluidState() const
276 { return fluidState_; }
277
281 const SolidState &solidState() const
282 { return solidState_; }
283
287 Scalar temperature() const
288 { return fluidState_.temperature(); }
289
296 Scalar porosity() const
297 { return solidState_.porosity(); }
298
302 const PermeabilityType& permeability() const
303 { return permeability_; }
304
315 Scalar saturation(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
316 { return fluidState_.saturation(phaseIdx); }
317
324 Scalar density(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
325 { return fluidState_.density(phaseIdx); }
326
338 Scalar pressure(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
339 { return fluidState_.pressure(phaseIdx); }
340
352 Scalar mobility(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
353 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
354
362 Scalar viscosity(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
363 { return phaseIdx == FluidSystem::liquidPhaseIdx ? fluidState_.viscosity(FluidSystem::liquidPhaseIdx) : 0.0; }
364
371 Scalar relativePermeability(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
372 { return phaseIdx == FluidSystem::liquidPhaseIdx ? relativePermeabilityWetting_ : 1.0; }
373
385 Scalar capillaryPressure() const
386 {
387 using std::max;
388 return max(minPc_, pressure(FluidSystem::gasPhaseIdx) - pressure(FluidSystem::liquidPhaseIdx));
389 }
390
405 Scalar pressureHead(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
406 { return 100.0 *(pressure(phaseIdx) - pressure(FluidSystem::gasPhaseIdx))/density(phaseIdx)/9.81; }
407
418 Scalar waterContent(const int phaseIdx = FluidSystem::liquidPhaseIdx) const
419 { return saturation(phaseIdx) * solidState_.porosity(); }
420
428 Scalar moleFraction(const int phaseIdx, const int compIdx) const
429 {
431 if (compIdx != FluidSystem::comp0Idx)
432 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
433 return moleFraction_[phaseIdx];
434 }
435
443 Scalar massFraction(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 massFraction_[phaseIdx];
449 }
450
457 Scalar molarDensity(const int phaseIdx) const
458 {
460 return molarDensity_[phaseIdx];
461 }
462
469 Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
470 {
471 assert(enableWaterDiffusionInAir() && phaseIdx == FluidSystem::gasPhaseIdx && compIdx == FluidSystem::comp0Idx);
472 return diffCoeff_;
473 }
474
475protected:
479 PermeabilityType permeability_;
480 Scalar minPc_;
484 Scalar diffCoeff_;
485};
486
487} // end namespace Dumux
488
489#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
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 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:324
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richards/volumevariables.hh:476
Scalar relativePermeabilityWetting_
the relative permeability of the wetting phase
Definition: porousmediumflow/richards/volumevariables.hh:478
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:302
Scalar molarDensity_[ParentType::numFluidPhases()]
The molar density of water and air.
Definition: porousmediumflow/richards/volumevariables.hh:483
Scalar massFraction_[ParentType::numFluidPhases()]
The water mass fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:482
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:296
Scalar pressureHead(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:405
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:428
SolidState solidState_
Definition: porousmediumflow/richards/volumevariables.hh:477
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richards/volumevariables.hh:469
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richards/volumevariables.hh:275
static constexpr bool enableWaterDiffusionInAir()
If water diffusion in air is enabled.
Definition: porousmediumflow/richards/volumevariables.hh:85
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:97
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:385
PermeabilityType permeability_
the instrinsic permeability
Definition: porousmediumflow/richards/volumevariables.hh:479
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richards/volumevariables.hh:82
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:338
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:418
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:362
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:352
typename Traits::ModelTraits::Indices Indices
Definition: porousmediumflow/richards/volumevariables.hh:83
Scalar relativePermeability(const int phaseIdx=FluidSystem::liquidPhaseIdx) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:371
Scalar diffCoeff_
The binary diffusion coefficient of water in air.
Definition: porousmediumflow/richards/volumevariables.hh:484
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richards/volumevariables.hh:281
typename Traits::SolidState SolidState
Definition: porousmediumflow/richards/volumevariables.hh:80
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:315
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:226
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/richards/volumevariables.hh:457
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:443
Scalar moleFraction_[ParentType::numFluidPhases()]
The water mole fractions in water and air.
Definition: porousmediumflow/richards/volumevariables.hh:481
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richards/volumevariables.hh:75
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richards/volumevariables.hh:77
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richards/volumevariables.hh:287
Scalar minPc_
the minimum capillary pressure (entry pressure)
Definition: porousmediumflow/richards/volumevariables.hh:480
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.