3.1-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{
50 using Scalar = typename Traits::PrimaryVariables::value_type;
51 using PermeabilityType = typename Traits::PermeabilityType;
52
53 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
54
55public:
57 using FluidSystem = typename Traits::FluidSystem;
59 using FluidState = typename Traits::FluidState;
61 using SolidState = typename Traits::SolidState;
63 using SolidSystem = typename Traits::SolidSystem;
67 static constexpr int liquidPhaseIdx = 0;
68 static constexpr int gasPhaseIdx = 1;
69
79 template<class ElemSol, class Problem, class Element, class Scv>
80 void update(const ElemSol &elemSol,
81 const Problem &problem,
82 const Element &element,
83 const Scv& scv)
84 {
85 ParentType::update(elemSol, problem, element, scv);
86
87 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
89 // specify the other parameters
91 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
92 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
93 relativePermeabilityWetting_ = MaterialLaw::krw(materialParams, fluidState_.saturation(0));
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_ = MaterialLaw::endPointPc(materialParams);
98 pn_ = problem.nonWettingReferencePressure();
99 //porosity
100 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, ParentType::numFluidComponents());
101 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
102 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
103
104 // Second instance of a parameter cache.
105 // Could be avoided if diffusion coefficients also
106 // became part of the fluid state.
107 typename FluidSystem::ParameterCache paramCache;
108 paramCache.updatePhase(fluidState_, 0);
109
110 const int compIIdx = 0;
111 for (unsigned int compJIdx = 0; compJIdx < ParentType::numFluidComponents(); ++compJIdx)
112 if(compIIdx != compJIdx)
113 setDiffusionCoefficient_(compJIdx,
114 FluidSystem::binaryDiffusionCoefficient(fluidState_,
115 paramCache,
116 0,
117 compIIdx,
118 compJIdx));
119 }
120
135 template<class ElemSol, class Problem, class Element, class Scv>
136 void completeFluidState(const ElemSol& elemSol,
137 const Problem& problem,
138 const Element& element,
139 const Scv& scv,
142 {
143 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
144
145 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
146 const auto& priVars = elemSol[scv.localDofIndex()];
147
148 // set the wetting pressure
149 fluidState.setPressure(0, priVars[Indices::pressureIdx]);
150
151 // compute the capillary pressure to compute the saturation
152 // make sure that we the capillary pressure is not smaller than the minimum pc
153 // this would possibly return unphysical values from regularized material laws
154 using std::max;
155 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
156 const Scalar pc = max(MaterialLaw::endPointPc(materialParams),
157 problem.nonWettingReferencePressure() - fluidState.pressure(0));
158 const Scalar sw = MaterialLaw::sw(materialParams, pc);
159 fluidState.setSaturation(0, sw);
160
161 // set the mole/mass fractions
162 if(useMoles)
163 {
164 Scalar sumSecondaryFractions = 0.0;
165 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
166 {
167 fluidState.setMoleFraction(0, compIdx, priVars[compIdx]);
168 sumSecondaryFractions += priVars[compIdx];
169 }
170 fluidState.setMoleFraction(0, 0, 1.0 - sumSecondaryFractions);
171 }
172 else
173 {
174 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
175 fluidState.setMassFraction(0, compIdx, priVars[compIdx]);
176 }
177
178 // density and viscosity
179 typename FluidSystem::ParameterCache paramCache;
180 paramCache.updateAll(fluidState);
181 fluidState.setDensity(0, FluidSystem::density(fluidState, paramCache, 0));
182 fluidState.setMolarDensity(0, FluidSystem::molarDensity(fluidState, paramCache, 0));
183 fluidState.setViscosity(0, FluidSystem::viscosity(fluidState, paramCache, 0));
184
185 // compute and set the enthalpy
186 fluidState.setEnthalpy(0, EnergyVolVars::enthalpy(fluidState, paramCache, 0));
187 }
188
193 const FluidState &fluidState() const
194 { return fluidState_; }
195
199 const SolidState &solidState() const
200 { return solidState_; }
201
207 Scalar averageMolarMass(const int phaseIdx = 0) const
208 { return fluidState_.averageMolarMass(phaseIdx); }
209
213 Scalar temperature() const
214 { return fluidState_.temperature(); }
215
222 Scalar porosity() const
223 { return solidState_.porosity(); }
224
228 const PermeabilityType& permeability() const
229 { return permeability_; }
230
241 Scalar saturation(const int phaseIdx = 0) const
242 { return phaseIdx == 0 ? fluidState_.saturation(0) : 1.0-fluidState_.saturation(0); }
243
250 Scalar density(const int phaseIdx = 0) const
251 { return phaseIdx == 0 ? fluidState_.density(phaseIdx) : 0.0; }
252
264 Scalar pressure(const int phaseIdx = 0) const
265 { return phaseIdx == 0 ? fluidState_.pressure(phaseIdx) : pn_; }
266
278 Scalar mobility(const int phaseIdx = 0) const
279 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
280
288 Scalar viscosity(const int phaseIdx = 0) const
289 { return phaseIdx == 0 ? fluidState_.viscosity(0) : 0.0; }
290
297 Scalar relativePermeability(const int phaseIdx = 0) const
298 { return phaseIdx == 0 ? relativePermeabilityWetting_ : 1.0; }
299
311 Scalar capillaryPressure() const
312 {
313 using std::max;
314 return max(minPc_, pn_ - fluidState_.pressure(0));
315 }
316
331 Scalar pressureHead(const int phaseIdx = 0) const
332 { return 100.0 *(pressure(phaseIdx) - pn_)/density(phaseIdx)/9.81; }
333
345 Scalar waterContent(const int phaseIdx = 0) const
346 { return saturation(phaseIdx) * solidState_.porosity(); }
347
353 Scalar molarDensity(const int phaseIdx = 0) const
354 { return phaseIdx == 0 ? this->fluidState_.molarDensity(phaseIdx) : 0.0; }
355
364 Scalar moleFraction(const int phaseIdx, const int compIdx) const
365 { return phaseIdx == 0 ? this->fluidState_.moleFraction(phaseIdx, compIdx) : 0.0; }
366
375 Scalar massFraction(const int phaseIdx, const int compIdx) const
376 { return phaseIdx == 0 ? this->fluidState_.massFraction(phaseIdx, compIdx) : 0.0; }
377
386 Scalar molarity(const int phaseIdx, const int compIdx) const
387 { return phaseIdx == 0 ? this->fluidState_.molarity(phaseIdx, compIdx) : 0.0; }
388
395 Scalar diffusionCoefficient(const int phaseIdx, const int compIdx) const
396 { return diffCoefficient_[compIdx-1]; }
397
398protected:
400
401private:
402 void setDiffusionCoefficient_(int compIdx, Scalar d)
403 { diffCoefficient_[compIdx-1] = d; }
404
405 std::array<Scalar, ParentType::numFluidComponents()-1> diffCoefficient_;
406
407 Scalar relativePermeabilityWetting_; // the relative permeability of the wetting phase
408 SolidState solidState_;
409 PermeabilityType permeability_; // the instrinsic permeability
410 Scalar pn_; // the reference non-wetting pressure
411 Scalar minPc_; // the minimum capillary pressure (entry pressure)
412};
413
414} // end namespace Dumux
415
416#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
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 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:47
Scalar molarDensity(const int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:353
Scalar relativePermeability(const int phaseIdx=0) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:297
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:222
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:375
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:241
typename Traits::ModelTraits::Indices Indices
Export indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:65
Scalar averageMolarMass(const int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:207
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:59
Scalar viscosity(const int phaseIdx=0) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:288
Scalar waterContent(const int phaseIdx=0) const
Returns the water content fluid phase within the finite volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:345
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:311
static constexpr int liquidPhaseIdx
Export phase acess indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:67
Scalar diffusionCoefficient(const int phaseIdx, const int compIdx) const
Returns the binary diffusion coefficient in the fluid.
Definition: porousmediumflow/richardsnc/volumevariables.hh:395
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:63
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richardsnc/volumevariables.hh:213
static constexpr int gasPhaseIdx
Definition: porousmediumflow/richardsnc/volumevariables.hh:68
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richardsnc/volumevariables.hh:399
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:80
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:364
Scalar molarity(const int phaseIdx, const int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:386
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:57
Scalar pressureHead(const int phaseIdx=0) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:331
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:250
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:61
Scalar pressure(const int phaseIdx=0) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:264
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richardsnc/volumevariables.hh:193
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:199
Scalar mobility(const int phaseIdx=0) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:278
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:136
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:228
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.