version 3.11-dev
Loading...
Searching...
No Matches
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// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12
13#ifndef DUMUX_RICHARDSEXTENDED_VOLUME_VARIABLES_HH
14#define DUMUX_RICHARDSEXTENDED_VOLUME_VARIABLES_HH
15
16#include <cassert>
17
18#include <dune/common/exceptions.hh>
19
25
27
28namespace Dumux {
29
37template <class Traits>
40, public EnergyVolumeVariables<Traits, ExtendedRichardsVolumeVariables<Traits> >
41{
44 using Scalar = typename Traits::PrimaryVariables::value_type;
45 using PermeabilityType = typename Traits::PermeabilityType;
46 using ModelTraits = typename Traits::ModelTraits;
47
48 static constexpr int numFluidComps = ParentType::numFluidComponents();
49 static constexpr int numPhases = ParentType::numFluidPhases();
50
51 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
52
53 // checks if the fluid system uses the Richards model index convention
54 static constexpr auto fsCheck = ModelTraits::checkFluidSystem(typename Traits::FluidSystem{});
55
56public:
58 using FluidSystem = typename Traits::FluidSystem;
60 using FluidState = typename Traits::FluidState;
63 using SolidState = typename Traits::SolidState;
65 using SolidSystem = typename Traits::SolidSystem;
66 using Indices = typename Traits::ModelTraits::Indices;
68
70 static constexpr auto liquidPhaseIdx = Traits::FluidSystem::phase0Idx;
71 static constexpr auto gasPhaseIdx = Traits::FluidSystem::phase1Idx;
72
82 template<class ElemSol, class Problem, class Element, class Scv>
83 void update(const ElemSol &elemSol,
84 const Problem &problem,
85 const Element &element,
86 const Scv& scv)
87 {
88 ParentType::update(elemSol, problem, element, scv);
89
90 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
91
92 const auto& priVars = elemSol[scv.localDofIndex()];
93 const auto phasePresence = priVars.state();
94
95 // precompute the minimum capillary pressure (entry pressure)
96 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
97 minPc_ = fluidMatrixInteraction.endPointPc();
98
99 //update porosity before calculating the effective properties depending on it
100 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
101
102 typename FluidSystem::ParameterCache paramCache;
103 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
104 {
105 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
106 };
107
108 if (phasePresence == Indices::gasPhaseOnly)
109 {
112 moleFraction_[gasPhaseIdx] = priVars[Indices::switchIdx];
113
114 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
115 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
116
117 //X_w = x_w* M_w/ M_avg
118 massFraction_[gasPhaseIdx] = priVars[Indices::switchIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
119
120 fluidState_.setSaturation(liquidPhaseIdx, 0.0);
121 fluidState_.setSaturation(gasPhaseIdx, 1.0);
122
123 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState_, solidState_);
124
125 // get pc for sw = 0.0
126 const Scalar pc = fluidMatrixInteraction.pc(0.0);
127
128 // set the wetting pressure
129 fluidState_.setPressure(liquidPhaseIdx, problem.nonwettingReferencePressure() - pc);
130 fluidState_.setPressure(gasPhaseIdx, problem.nonwettingReferencePressure());
131
132 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
133 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
134
135 // density and viscosity
136 paramCache.updateAll(fluidState_);
137 fluidState_.setDensity(liquidPhaseIdx, FluidSystem::density(fluidState_, paramCache, liquidPhaseIdx));
138 fluidState_.setDensity(gasPhaseIdx, FluidSystem::density(fluidState_, paramCache, gasPhaseIdx));
139 fluidState_.setViscosity(liquidPhaseIdx, FluidSystem::viscosity(fluidState_, paramCache, liquidPhaseIdx));
140
141 // compute and set the enthalpy
142 fluidState_.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, liquidPhaseIdx));
143 fluidState_.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState_, paramCache, gasPhaseIdx));
144
145 //binary diffusion coefficients
146 paramCache.updateAll(fluidState_);
147 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
148 FluidSystem::comp1Idx,
149 FluidSystem::comp0Idx);
150 }
151 else if (phasePresence == Indices::bothPhases)
152 {
153 completeFluidState_(elemSol, problem, element, scv, fluidState_, solidState_);
154
155 // we want to account for diffusion in the air phase
156 // the water vapor in the air is in equilibrium with the liquid phase
157 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
158 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
160
162 / problem.nonwettingReferencePressure();
163
164 const auto averageMolarMassGasPhase = (moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)) +
165 ((1-moleFraction_[gasPhaseIdx])*FluidSystem::molarMass(gasPhaseIdx));
166
167 //X_w = x_w* M_w/ M_avg
168 massFraction_[gasPhaseIdx] = moleFraction_[gasPhaseIdx]*FluidSystem::molarMass(liquidPhaseIdx)/averageMolarMassGasPhase;
169
170 // binary diffusion coefficients
171 paramCache.updateAll(fluidState_);
172 effectiveDiffCoeff_ = getEffectiveDiffusionCoefficient(gasPhaseIdx,
173 FluidSystem::comp1Idx,
174 FluidSystem::comp0Idx);
175 }
176 else if (phasePresence == Indices::liquidPhaseOnly)
177 {
178 completeFluidState_(elemSol, problem, element, scv, fluidState_, solidState_);
179
180 molarDensity_[liquidPhaseIdx] = FluidSystem::H2O::liquidDensity(temperature(), pressure(liquidPhaseIdx))/FluidSystem::H2O::molarMass();
181 molarDensity_[gasPhaseIdx] = IdealGas<Scalar>::molarDensity(temperature(), problem.nonwettingReferencePressure());
186
187 // binary diffusion coefficients (none required for liquid phase only)
189 }
190
192 // specify the other parameters
194 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(liquidPhaseIdx));
195 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
196 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
197 EnergyVolVars::updateEffectiveThermalConductivity();
198 }
199
204 const FluidState &fluidState() const
205 { return fluidState_; }
206
210 const SolidState &solidState() const
211 { return solidState_; }
212
216 Scalar temperature() const
217 { return fluidState_.temperature(); }
218
225 Scalar porosity() const
226 { return solidState_.porosity(); }
227
231 const PermeabilityType& permeability() const
232 { return permeability_; }
233
244 Scalar saturation(const int phaseIdx = liquidPhaseIdx) const
245 { return fluidState_.saturation(phaseIdx); }
246
253 Scalar density(const int phaseIdx = liquidPhaseIdx) const
254 { return fluidState_.density(phaseIdx); }
255
267 Scalar pressure(const int phaseIdx = liquidPhaseIdx) const
268 { return fluidState_.pressure(phaseIdx); }
269
281 Scalar mobility(const int phaseIdx = liquidPhaseIdx) const
282 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
283
291 Scalar viscosity(const int phaseIdx = liquidPhaseIdx) const
292 { return phaseIdx == liquidPhaseIdx ? fluidState_.viscosity(liquidPhaseIdx) : 0.0; }
293
300 Scalar relativePermeability(const int phaseIdx = liquidPhaseIdx) const
301 { return phaseIdx == liquidPhaseIdx ? relativePermeabilityWetting_ : 1.0; }
302
314 Scalar capillaryPressure() const
315 {
316 using std::max;
318 }
319
334 Scalar pressureHead(const int phaseIdx = liquidPhaseIdx) const
335 { return 100.0 *(pressure(phaseIdx) - pressure(gasPhaseIdx))/density(phaseIdx)/9.81; }
336
347 Scalar waterContent(const int phaseIdx = liquidPhaseIdx) const
348 { return saturation(phaseIdx) * solidState_.porosity(); }
349
357 Scalar moleFraction(const int phaseIdx, const int compIdx) const
358 {
359 if (compIdx != FluidSystem::comp0Idx)
360 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
361 return moleFraction_[phaseIdx];
362 }
363
371 Scalar massFraction(const int phaseIdx, const int compIdx) const
372 {
373 if (compIdx != FluidSystem::comp0Idx)
374 DUNE_THROW(Dune::InvalidStateException, "There is only one component for Richards!");
375 return massFraction_[phaseIdx];
376 }
377
384 Scalar molarDensity(const int phaseIdx) const
385 {
386 return molarDensity_[phaseIdx];
387 }
388
392 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
393 {
394 assert(phaseIdx == gasPhaseIdx);
395 assert(compIIdx != compJIdx);
396 typename FluidSystem::ParameterCache paramCache;
397 paramCache.updatePhase(fluidState_, phaseIdx);
398 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
399 }
400
404 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
405 {
406 assert(phaseIdx == gasPhaseIdx);
407 assert(compIIdx != compJIdx);
408 return effectiveDiffCoeff_;
409 }
410private:
425 template<class ElemSol, class Problem, class Element, class Scv>
426 void completeFluidState_(const ElemSol& elemSol,
427 const Problem& problem,
428 const Element& element,
429 const Scv& scv,
432 {
433 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
434
435 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
436
437 const auto& priVars = elemSol[scv.localDofIndex()];
438
439 // set the wetting pressure
440 using std::max;
441 Scalar minPc = fluidMatrixInteraction.pc(1.0);
442 fluidState.setPressure(liquidPhaseIdx, priVars[Indices::pressureIdx]);
443 fluidState.setPressure(gasPhaseIdx, max(problem.nonwettingReferencePressure(), fluidState.pressure(liquidPhaseIdx) + minPc));
444
445 // compute the capillary pressure to compute the saturation
446 // make sure that we the capillary pressure is not smaller than the minimum pc
447 // this would possibly return unphysical values from regularized material laws
448 using std::max;
449 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
450 problem.nonwettingReferencePressure() - fluidState.pressure(liquidPhaseIdx));
451 const Scalar sw = fluidMatrixInteraction.sw(pc);
452 fluidState.setSaturation(liquidPhaseIdx, sw);
453 fluidState.setSaturation(gasPhaseIdx, 1.0-sw);
454
455 // density and viscosity
456 typename FluidSystem::ParameterCache paramCache;
457 paramCache.updateAll(fluidState);
458 fluidState.setDensity(liquidPhaseIdx,
459 FluidSystem::density(fluidState, paramCache, liquidPhaseIdx));
460 fluidState.setDensity(gasPhaseIdx,
461 FluidSystem::density(fluidState, paramCache, gasPhaseIdx));
462
463 fluidState.setViscosity(liquidPhaseIdx,
464 FluidSystem::viscosity(fluidState, paramCache, liquidPhaseIdx));
465
466 // compute and set the enthalpy
467 fluidState.setEnthalpy(liquidPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, liquidPhaseIdx));
468 fluidState.setEnthalpy(gasPhaseIdx, EnergyVolVars::enthalpy(fluidState, paramCache, gasPhaseIdx));
469 }
470
471protected:
475 PermeabilityType permeability_;
476 Scalar minPc_;
477 Scalar moleFraction_[numPhases];
478 Scalar massFraction_[numPhases];
479 Scalar molarDensity_[numPhases];
480
481 // Effective diffusion coefficients for the phases
483
484};
485} // end namespace Dumux
486
487#endif
The primary variable switch controlling the phase presence state variable.
Definition richardsextended/primaryvariableswitch.hh:55
Volume averaged quantities required by the extended Richards model.
Definition porousmediumflow/richardsextended/volumevariables.hh:41
PermeabilityType permeability_
Definition porousmediumflow/richardsextended/volumevariables.hh:475
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:210
Scalar massFraction_[numPhases]
Definition porousmediumflow/richardsextended/volumevariables.hh:478
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition porousmediumflow/richardsextended/volumevariables.hh:392
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:225
typename NITraits< BaseTraits, ETCM >::SolidState SolidState
Definition porousmediumflow/richardsextended/volumevariables.hh:63
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:83
Scalar molarDensity_[numPhases]
Definition porousmediumflow/richardsextended/volumevariables.hh:479
Scalar effectiveDiffCoeff_
Definition porousmediumflow/richardsextended/volumevariables.hh:482
Scalar relativePermeabilityWetting_
Definition porousmediumflow/richardsextended/volumevariables.hh:474
Scalar pressureHead(const int phaseIdx=liquidPhaseIdx) const
Returns the pressureHead of a given phase within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:334
typename NITraits< BaseTraits, ETCM >::FluidState FluidState
Definition porousmediumflow/richardsextended/volumevariables.hh:60
Scalar viscosity(const int phaseIdx=liquidPhaseIdx) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:291
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition porousmediumflow/richardsextended/volumevariables.hh:404
Scalar mobility(const int phaseIdx=liquidPhaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:281
Scalar minPc_
Definition porousmediumflow/richardsextended/volumevariables.hh:476
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:244
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:253
Scalar relativePermeability(const int phaseIdx=liquidPhaseIdx) const
Returns relative permeability [-] of a given phase within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:300
typename NITraits< BaseTraits, ETCM >::ModelTraits::Indices Indices
Definition porousmediumflow/richardsextended/volumevariables.hh:66
static constexpr auto gasPhaseIdx
Definition porousmediumflow/richardsextended/volumevariables.hh:71
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition porousmediumflow/richardsextended/volumevariables.hh:231
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:314
Scalar moleFraction_[numPhases]
Definition porousmediumflow/richardsextended/volumevariables.hh:477
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:371
SolidState solidState_
Definition porousmediumflow/richardsextended/volumevariables.hh:473
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition porousmediumflow/richardsextended/volumevariables.hh:384
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:357
typename NITraits< BaseTraits, ETCM >::FluidSystem FluidSystem
Definition porousmediumflow/richardsextended/volumevariables.hh:58
Scalar pressure(const int phaseIdx=liquidPhaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:267
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition porousmediumflow/richardsextended/volumevariables.hh:204
Scalar waterContent(const int phaseIdx=liquidPhaseIdx) const
Returns the water content of a fluid phase within the finite volume.
Definition porousmediumflow/richardsextended/volumevariables.hh:347
Scalar temperature() const
Returns the temperature.
Definition porousmediumflow/richardsextended/volumevariables.hh:216
FluidState fluidState_
Definition porousmediumflow/richardsextended/volumevariables.hh:472
typename NITraits< BaseTraits, ETCM >::SolidSystem SolidSystem
Definition porousmediumflow/richardsextended/volumevariables.hh:65
ExtendedRichardsPrimaryVariableSwitch PrimaryVariableSwitch
Definition porousmediumflow/richardsextended/volumevariables.hh:67
static constexpr auto liquidPhaseIdx
Definition porousmediumflow/richardsextended/volumevariables.hh:70
static constexpr Scalar molarDensity(Scalar temperature, Scalar pressure)
The molar density of the gas , depending on pressure and temperature.
Definition idealgas.hh:58
The isothermal base class.
Definition porousmediumflow/volumevariables.hh:28
static constexpr int numFluidComponents()
Return number of components considered by the model.
Definition porousmediumflow/volumevariables.hh:40
const PrimaryVariables & priVars() const
Definition porousmediumflow/volumevariables.hh:64
static constexpr int numFluidPhases()
Return number of phases considered by the model.
Definition porousmediumflow/volumevariables.hh:38
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:52
A central place for various physical constants occurring in some equations.
auto equilibriumVaporPressure(const FluidState &fluidState)
The vapor pressure of water in equilibrium with the liquid phase.
Definition richardsextended/primaryvariableswitch.hh:39
EnergyVolumeVariablesImplementation< IsothermalTraits, Impl, IsothermalTraits::ModelTraits::enableEnergyBalance()> EnergyVolumeVariables
Base class for the model specific class which provides access to all volume averaged quantities.
Definition porousmediumflow/nonisothermal/volumevariables.hh:73
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:24
Relations valid for an ideal gas.
Definition adapt.hh:17
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.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.