3.5-git
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
36namespace Dumux {
37
43template <class Traits>
46, public EnergyVolumeVariables<Traits, RichardsNCVolumeVariables<Traits> >
47{
48
51 using Scalar = typename Traits::PrimaryVariables::value_type;
52 using PermeabilityType = typename Traits::PermeabilityType;
53
54 static constexpr int numFluidComps = ParentType::numFluidComponents();
55 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
56
57 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
58 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
59
60public:
62 using FluidSystem = typename Traits::FluidSystem;
64 using FluidState = typename Traits::FluidState;
66 using SolidState = typename Traits::SolidState;
68 using SolidSystem = typename Traits::SolidSystem;
70 using Indices = typename Traits::ModelTraits::Indices;
72 static constexpr int liquidPhaseIdx = 0;
73 static constexpr int gasPhaseIdx = 1;
74
84 template<class ElemSol, class Problem, class Element, class Scv>
85 void update(const ElemSol &elemSol,
86 const Problem &problem,
87 const Element &element,
88 const Scv& scv)
89 {
90 ParentType::update(elemSol, problem, element, scv);
91
92 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
94 // specify the other parameters
96
97 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
98 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(0));
99
100 // precompute the minimum capillary pressure (entry pressure)
101 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
102 minPc_ = fluidMatrixInteraction.endPointPc();
103 pn_ = problem.nonwettingReferencePressure();
104 //porosity
105 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, ParentType::numFluidComponents());
106 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
107 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
108 EnergyVolVars::updateEffectiveThermalConductivity();
109
110 // Second instance of a parameter cache.
111 // Could be avoided if diffusion coefficients also
112 // became part of the fluid state.
113 typename FluidSystem::ParameterCache paramCache;
114 paramCache.updatePhase(fluidState_, 0);
115
116 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
117 {
118 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
119 };
120
121 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
122
123 // calculate the remaining quantities
124 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
125 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
126 EnergyVolVars::updateEffectiveThermalConductivity();
127 }
128
143 template<class ElemSol, class Problem, class Element, class Scv>
144 void completeFluidState(const ElemSol& elemSol,
145 const Problem& problem,
146 const Element& element,
147 const Scv& scv,
150 {
151 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
152
153 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
154
155 const auto& priVars = elemSol[scv.localDofIndex()];
156
157 // set the wetting pressure
158 fluidState.setPressure(0, priVars[Indices::pressureIdx]);
159
160 // compute the capillary pressure to compute the saturation
161 // make sure that we the capillary pressure is not smaller than the minimum pc
162 // this would possibly return unphysical values from regularized material laws
163 using std::max;
164 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
165 problem.nonwettingReferencePressure() - fluidState.pressure(0));
166 const Scalar sw = fluidMatrixInteraction.sw(pc);
167 fluidState.setSaturation(0, sw);
168
169 // set the mole/mass fractions
170 if(useMoles)
171 {
172 Scalar sumSecondaryFractions = 0.0;
173 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
174 {
175 fluidState.setMoleFraction(0, compIdx, priVars[compIdx]);
176 sumSecondaryFractions += priVars[compIdx];
177 }
178 fluidState.setMoleFraction(0, 0, 1.0 - sumSecondaryFractions);
179 }
180 else
181 {
182 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
183 fluidState.setMassFraction(0, compIdx, priVars[compIdx]);
184 }
185
186 // density and viscosity
187 typename FluidSystem::ParameterCache paramCache;
188 paramCache.updateAll(fluidState);
189 fluidState.setDensity(0, FluidSystem::density(fluidState, paramCache, 0));
190 fluidState.setMolarDensity(0, FluidSystem::molarDensity(fluidState, paramCache, 0));
191 fluidState.setViscosity(0, FluidSystem::viscosity(fluidState, paramCache, 0));
192
193 // compute and set the enthalpy
194 fluidState.setEnthalpy(0, EnergyVolVars::enthalpy(fluidState, paramCache, 0));
195 }
196
201 const FluidState &fluidState() const
202 { return fluidState_; }
203
207 const SolidState &solidState() const
208 { return solidState_; }
209
215 Scalar averageMolarMass(const int phaseIdx = 0) const
216 { return fluidState_.averageMolarMass(phaseIdx); }
217
221 Scalar temperature() const
222 { return fluidState_.temperature(); }
223
230 Scalar porosity() const
231 { return solidState_.porosity(); }
232
236 const PermeabilityType& permeability() const
237 { return permeability_; }
238
249 Scalar saturation(const int phaseIdx = 0) const
250 { return phaseIdx == 0 ? fluidState_.saturation(0) : 1.0-fluidState_.saturation(0); }
251
258 Scalar density(const int phaseIdx = 0) const
259 { return phaseIdx == 0 ? fluidState_.density(phaseIdx) : 0.0; }
260
272 Scalar pressure(const int phaseIdx = 0) const
273 { return phaseIdx == 0 ? fluidState_.pressure(phaseIdx) : pn_; }
274
286 Scalar mobility(const int phaseIdx = 0) const
287 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
288
296 Scalar viscosity(const int phaseIdx = 0) const
297 { return phaseIdx == 0 ? fluidState_.viscosity(0) : 0.0; }
298
305 Scalar relativePermeability(const int phaseIdx = 0) const
306 { return phaseIdx == 0 ? relativePermeabilityWetting_ : 1.0; }
307
319 Scalar capillaryPressure() const
320 {
321 using std::max;
322 return max(minPc_, pn_ - fluidState_.pressure(0));
323 }
324
339 Scalar pressureHead(const int phaseIdx = 0) const
340 { return 100.0 *(pressure(phaseIdx) - pn_)/density(phaseIdx)/9.81; }
341
353 Scalar waterContent(const int phaseIdx = 0) const
354 { return saturation(phaseIdx) * solidState_.porosity(); }
355
361 Scalar molarDensity(const int phaseIdx = 0) const
362 { return phaseIdx == 0 ? this->fluidState_.molarDensity(phaseIdx) : 0.0; }
363
372 Scalar moleFraction(const int phaseIdx, const int compIdx) const
373 { return phaseIdx == 0 ? this->fluidState_.moleFraction(phaseIdx, compIdx) : 0.0; }
374
383 Scalar massFraction(const int phaseIdx, const int compIdx) const
384 { return phaseIdx == 0 ? this->fluidState_.massFraction(phaseIdx, compIdx) : 0.0; }
385
394 Scalar molarity(const int phaseIdx, const int compIdx) const
395 { return phaseIdx == 0 ? this->fluidState_.molarity(phaseIdx, compIdx) : 0.0; }
396
400 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
401 {
402 typename FluidSystem::ParameterCache paramCache;
403 paramCache.updatePhase(fluidState_, phaseIdx);
404 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
405 }
406
410 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
411 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
412
413protected:
415
416private:
417 // Effective diffusion coefficients for the phases
418 DiffusionCoefficients effectiveDiffCoeff_;
419
420 Scalar relativePermeabilityWetting_; // the relative permeability of the wetting phase
421 SolidState solidState_;
422 PermeabilityType permeability_; // the instrinsic permeability
423 Scalar pn_; // the reference nonwetting pressure
424 Scalar minPc_; // the minimum capillary pressure (entry pressure)
425};
426
427} // end namespace Dumux
428
429#endif
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:76
Contains the quantities which are constant within a finite volume in the Richards,...
Definition: porousmediumflow/richardsnc/volumevariables.hh:47
Scalar molarDensity(const int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:361
Scalar relativePermeability(const int phaseIdx=0) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:305
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:230
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:383
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:249
typename Traits::ModelTraits::Indices Indices
Export indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:70
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:410
Scalar averageMolarMass(const int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:215
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:64
Scalar viscosity(const int phaseIdx=0) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:296
Scalar waterContent(const int phaseIdx=0) const
Returns the water content fluid phase within the finite volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:353
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:319
static constexpr int liquidPhaseIdx
Export phase acess indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:72
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:68
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richardsnc/volumevariables.hh:221
static constexpr int gasPhaseIdx
Definition: porousmediumflow/richardsnc/volumevariables.hh:73
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richardsnc/volumevariables.hh:414
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:85
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:372
Scalar molarity(const int phaseIdx, const int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:394
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:62
Scalar pressureHead(const int phaseIdx=0) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:339
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:258
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:66
Scalar pressure(const int phaseIdx=0) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:272
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richardsnc/volumevariables.hh:201
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:207
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:400
Scalar mobility(const int phaseIdx=0) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:286
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:144
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:236
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
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.