3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/richardsnc/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 *****************************************************************************/
26#ifndef DUMUX_RICHARDSNC_VOLUME_VARIABLES_HH
27#define DUMUX_RICHARDSNC_VOLUME_VARIABLES_HH
28
29#include <algorithm>
30#include <array>
31
35
37
38namespace Dumux {
39
45template <class Traits>
48, public EnergyVolumeVariables<Traits, RichardsNCVolumeVariables<Traits> >
49{
50
53 using Scalar = typename Traits::PrimaryVariables::value_type;
54 using PermeabilityType = typename Traits::PermeabilityType;
55
56 static constexpr int numFluidComps = ParentType::numFluidComponents();
57 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
58
59 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
60 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
61
62public:
64 using FluidSystem = typename Traits::FluidSystem;
66 using FluidState = typename Traits::FluidState;
68 using SolidState = typename Traits::SolidState;
70 using SolidSystem = typename Traits::SolidSystem;
72 using Indices = typename Traits::ModelTraits::Indices;
74 static constexpr int liquidPhaseIdx = 0;
75 static constexpr int gasPhaseIdx = 1;
76
86 template<class ElemSol, class Problem, class Element, class Scv>
87 void update(const ElemSol &elemSol,
88 const Problem &problem,
89 const Element &element,
90 const Scv& scv)
91 {
92 ParentType::update(elemSol, problem, element, scv);
93
94 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
96 // specify the other parameters
98
99 // old material law interface is deprecated: Replace this by
100 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
101 // after the release of 3.3, when the deprecated interface is no longer supported
102 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
103
104 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(0));
105
106 // precompute the minimum capillary pressure (entry pressure)
107 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
108 minPc_ = fluidMatrixInteraction.endPointPc();
109 pn_ = problem.nonwettingReferencePressure();
110 //porosity
111 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, ParentType::numFluidComponents());
112 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
113 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
114 EnergyVolVars::updateEffectiveThermalConductivity();
115
116 // Second instance of a parameter cache.
117 // Could be avoided if diffusion coefficients also
118 // became part of the fluid state.
119 typename FluidSystem::ParameterCache paramCache;
120 paramCache.updatePhase(fluidState_, 0);
121
122 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
123 {
124 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
125 };
126
127 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
128
129 // calculate the remaining quantities
130 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
131 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
132 EnergyVolVars::updateEffectiveThermalConductivity();
133 }
134
149 template<class ElemSol, class Problem, class Element, class Scv>
150 void completeFluidState(const ElemSol& elemSol,
151 const Problem& problem,
152 const Element& element,
153 const Scv& scv,
156 {
157 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
158
159 // old material law interface is deprecated: Replace this by
160 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
161 // after the release of 3.3, when the deprecated interface is no longer supported
162 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
163
164 const auto& priVars = elemSol[scv.localDofIndex()];
165
166 // set the wetting pressure
167 fluidState.setPressure(0, priVars[Indices::pressureIdx]);
168
169 // compute the capillary pressure to compute the saturation
170 // make sure that we the capillary pressure is not smaller than the minimum pc
171 // this would possibly return unphysical values from regularized material laws
172 using std::max;
173 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
174 problem.nonwettingReferencePressure() - fluidState.pressure(0));
175 const Scalar sw = fluidMatrixInteraction.sw(pc);
176 fluidState.setSaturation(0, sw);
177
178 // set the mole/mass fractions
179 if(useMoles)
180 {
181 Scalar sumSecondaryFractions = 0.0;
182 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
183 {
184 fluidState.setMoleFraction(0, compIdx, priVars[compIdx]);
185 sumSecondaryFractions += priVars[compIdx];
186 }
187 fluidState.setMoleFraction(0, 0, 1.0 - sumSecondaryFractions);
188 }
189 else
190 {
191 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
192 fluidState.setMassFraction(0, compIdx, priVars[compIdx]);
193 }
194
195 // density and viscosity
196 typename FluidSystem::ParameterCache paramCache;
197 paramCache.updateAll(fluidState);
198 fluidState.setDensity(0, FluidSystem::density(fluidState, paramCache, 0));
199 fluidState.setMolarDensity(0, FluidSystem::molarDensity(fluidState, paramCache, 0));
200 fluidState.setViscosity(0, FluidSystem::viscosity(fluidState, paramCache, 0));
201
202 // compute and set the enthalpy
203 fluidState.setEnthalpy(0, EnergyVolVars::enthalpy(fluidState, paramCache, 0));
204 }
205
210 const FluidState &fluidState() const
211 { return fluidState_; }
212
216 const SolidState &solidState() const
217 { return solidState_; }
218
224 Scalar averageMolarMass(const int phaseIdx = 0) const
225 { return fluidState_.averageMolarMass(phaseIdx); }
226
230 Scalar temperature() const
231 { return fluidState_.temperature(); }
232
239 Scalar porosity() const
240 { return solidState_.porosity(); }
241
245 const PermeabilityType& permeability() const
246 { return permeability_; }
247
258 Scalar saturation(const int phaseIdx = 0) const
259 { return phaseIdx == 0 ? fluidState_.saturation(0) : 1.0-fluidState_.saturation(0); }
260
267 Scalar density(const int phaseIdx = 0) const
268 { return phaseIdx == 0 ? fluidState_.density(phaseIdx) : 0.0; }
269
281 Scalar pressure(const int phaseIdx = 0) const
282 { return phaseIdx == 0 ? fluidState_.pressure(phaseIdx) : pn_; }
283
295 Scalar mobility(const int phaseIdx = 0) const
296 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
297
305 Scalar viscosity(const int phaseIdx = 0) const
306 { return phaseIdx == 0 ? fluidState_.viscosity(0) : 0.0; }
307
314 Scalar relativePermeability(const int phaseIdx = 0) const
315 { return phaseIdx == 0 ? relativePermeabilityWetting_ : 1.0; }
316
328 Scalar capillaryPressure() const
329 {
330 using std::max;
331 return max(minPc_, pn_ - fluidState_.pressure(0));
332 }
333
348 Scalar pressureHead(const int phaseIdx = 0) const
349 { return 100.0 *(pressure(phaseIdx) - pn_)/density(phaseIdx)/9.81; }
350
362 Scalar waterContent(const int phaseIdx = 0) const
363 { return saturation(phaseIdx) * solidState_.porosity(); }
364
370 Scalar molarDensity(const int phaseIdx = 0) const
371 { return phaseIdx == 0 ? this->fluidState_.molarDensity(phaseIdx) : 0.0; }
372
381 Scalar moleFraction(const int phaseIdx, const int compIdx) const
382 { return phaseIdx == 0 ? this->fluidState_.moleFraction(phaseIdx, compIdx) : 0.0; }
383
392 Scalar massFraction(const int phaseIdx, const int compIdx) const
393 { return phaseIdx == 0 ? this->fluidState_.massFraction(phaseIdx, compIdx) : 0.0; }
394
403 Scalar molarity(const int phaseIdx, const int compIdx) const
404 { return phaseIdx == 0 ? this->fluidState_.molarity(phaseIdx, compIdx) : 0.0; }
405
409 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
410 {
411 typename FluidSystem::ParameterCache paramCache;
412 paramCache.updatePhase(fluidState_, phaseIdx);
413 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
414 }
415
419 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
420 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
421
422protected:
424
425private:
426 // Effective diffusion coefficients for the phases
427 DiffusionCoefficients effectiveDiffCoeff_;
428
429 Scalar relativePermeabilityWetting_; // the relative permeability of the wetting phase
430 SolidState solidState_;
431 PermeabilityType permeability_; // the instrinsic permeability
432 Scalar pn_; // the reference nonwetting pressure
433 Scalar minPc_; // the minimum capillary pressure (entry pressure)
434};
435
436} // end namespace Dumux
437
438#endif
Helpers for deprecation.
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
Definition: adapt.hh:29
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:74
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:83
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:65
Definition: porousmediumflow/nonisothermal/volumevariables.hh:75
Contains the quantities which are constant within a finite volume in the Richards,...
Definition: porousmediumflow/richardsnc/volumevariables.hh:49
Scalar molarDensity(const int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:370
Scalar relativePermeability(const int phaseIdx=0) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:314
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:239
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:392
Scalar saturation(const int phaseIdx=0) const
Returns the average absolute saturation [] of a given fluid phase within the finite volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:258
typename Traits::ModelTraits::Indices Indices
Export indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:72
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:419
Scalar averageMolarMass(const int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:224
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:66
Scalar viscosity(const int phaseIdx=0) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:305
Scalar waterContent(const int phaseIdx=0) const
Returns the water content fluid phase within the finite volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:362
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:328
static constexpr int liquidPhaseIdx
Export phase acess indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:74
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:70
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richardsnc/volumevariables.hh:230
static constexpr int gasPhaseIdx
Definition: porousmediumflow/richardsnc/volumevariables.hh:75
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richardsnc/volumevariables.hh:423
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:87
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:381
Scalar molarity(const int phaseIdx, const int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:403
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:64
Scalar pressureHead(const int phaseIdx=0) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:348
Scalar density(const int phaseIdx=0) const
Returns the average mass density of a given fluid phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:267
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:68
Scalar pressure(const int phaseIdx=0) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:281
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richardsnc/volumevariables.hh:210
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:216
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:409
Scalar mobility(const int phaseIdx=0) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:295
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/richardsnc/volumevariables.hh:150
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:245
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
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.