version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
14#ifndef DUMUX_RICHARDSNC_VOLUME_VARIABLES_HH
15#define DUMUX_RICHARDSNC_VOLUME_VARIABLES_HH
16
17#include <algorithm>
18#include <array>
19
23
24namespace Dumux {
25
31template <class Traits>
34, public EnergyVolumeVariables<Traits, RichardsNCVolumeVariables<Traits> >
35{
36
39 using Scalar = typename Traits::PrimaryVariables::value_type;
40 using PermeabilityType = typename Traits::PermeabilityType;
41
42 static constexpr int numFluidComps = ParentType::numFluidComponents();
43 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
44
45 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
46 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
47
48public:
50 using FluidSystem = typename Traits::FluidSystem;
52 using FluidState = typename Traits::FluidState;
54 using SolidState = typename Traits::SolidState;
56 using SolidSystem = typename Traits::SolidSystem;
58 using Indices = typename Traits::ModelTraits::Indices;
60 static constexpr int liquidPhaseIdx = 0;
61 static constexpr int gasPhaseIdx = 1;
62
72 template<class ElemSol, class Problem, class Element, class Scv>
73 void update(const ElemSol &elemSol,
74 const Problem &problem,
75 const Element &element,
76 const Scv& scv)
77 {
78 ParentType::update(elemSol, problem, element, scv);
79
80 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
82 // specify the other parameters
84
85 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
86 relativePermeabilityWetting_ = fluidMatrixInteraction.krw(fluidState_.saturation(0));
87
88 // precompute the minimum capillary pressure (entry pressure)
89 // needed to make sure we don't compute unphysical capillary pressures and thus saturations
90 minPc_ = fluidMatrixInteraction.endPointPc();
91 pn_ = problem.nonwettingReferencePressure();
92 //porosity
93 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, ParentType::numFluidComponents());
94 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
95 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
96 EnergyVolVars::updateEffectiveThermalConductivity();
97
98 // Second instance of a parameter cache.
99 // Could be avoided if diffusion coefficients also
100 // became part of the fluid state.
101 typename FluidSystem::ParameterCache paramCache;
102 paramCache.updatePhase(fluidState_, 0);
103
104 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
105 {
106 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
107 };
108
109 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
110
111 // calculate the remaining quantities
112 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
113 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
114 EnergyVolVars::updateEffectiveThermalConductivity();
115 }
116
131 template<class ElemSol, class Problem, class Element, class Scv>
132 void completeFluidState(const ElemSol& elemSol,
133 const Problem& problem,
134 const Element& element,
135 const Scv& scv,
138 {
139 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
140
141 const auto fluidMatrixInteraction = problem.spatialParams().fluidMatrixInteraction(element, scv, elemSol);
142
143 const auto& priVars = elemSol[scv.localDofIndex()];
144
145 // set the wetting pressure
146 fluidState.setPressure(0, priVars[Indices::pressureIdx]);
147
148 // compute the capillary pressure to compute the saturation
149 // make sure that we the capillary pressure is not smaller than the minimum pc
150 // this would possibly return unphysical values from regularized material laws
151 using std::max;
152 const Scalar pc = max(fluidMatrixInteraction.endPointPc(),
153 problem.nonwettingReferencePressure() - fluidState.pressure(0));
154 const Scalar sw = fluidMatrixInteraction.sw(pc);
155 fluidState.setSaturation(0, sw);
156
157 // set the mole/mass fractions
158 if(useMoles)
159 {
160 Scalar sumSecondaryFractions = 0.0;
161 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
162 {
163 fluidState.setMoleFraction(0, compIdx, priVars[compIdx]);
164 sumSecondaryFractions += priVars[compIdx];
165 }
166 fluidState.setMoleFraction(0, 0, 1.0 - sumSecondaryFractions);
167 }
168 else
169 {
170 for (int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
171 fluidState.setMassFraction(0, compIdx, priVars[compIdx]);
172 }
173
174 // density and viscosity
175 typename FluidSystem::ParameterCache paramCache;
176 paramCache.updateAll(fluidState);
177 fluidState.setDensity(0, FluidSystem::density(fluidState, paramCache, 0));
178 fluidState.setMolarDensity(0, FluidSystem::molarDensity(fluidState, paramCache, 0));
179 fluidState.setViscosity(0, FluidSystem::viscosity(fluidState, paramCache, 0));
180
181 // compute and set the enthalpy
182 fluidState.setEnthalpy(0, EnergyVolVars::enthalpy(fluidState, paramCache, 0));
183 }
184
189 const FluidState &fluidState() const
190 { return fluidState_; }
191
195 const SolidState &solidState() const
196 { return solidState_; }
197
203 Scalar averageMolarMass(const int phaseIdx = 0) const
204 { return fluidState_.averageMolarMass(phaseIdx); }
205
209 Scalar temperature() const
210 { return fluidState_.temperature(); }
211
218 Scalar porosity() const
219 { return solidState_.porosity(); }
220
224 const PermeabilityType& permeability() const
225 { return permeability_; }
226
237 Scalar saturation(const int phaseIdx = 0) const
238 { return phaseIdx == 0 ? fluidState_.saturation(0) : 1.0-fluidState_.saturation(0); }
239
246 Scalar density(const int phaseIdx = 0) const
247 { return phaseIdx == 0 ? fluidState_.density(phaseIdx) : 0.0; }
248
260 Scalar pressure(const int phaseIdx = 0) const
261 { return phaseIdx == 0 ? fluidState_.pressure(phaseIdx) : pn_; }
262
274 Scalar mobility(const int phaseIdx = 0) const
275 { return relativePermeability(phaseIdx)/fluidState_.viscosity(phaseIdx); }
276
284 Scalar viscosity(const int phaseIdx = 0) const
285 { return phaseIdx == 0 ? fluidState_.viscosity(0) : 0.0; }
286
293 Scalar relativePermeability(const int phaseIdx = 0) const
294 { return phaseIdx == 0 ? relativePermeabilityWetting_ : 1.0; }
295
307 Scalar capillaryPressure() const
308 {
309 using std::max;
310 return max(minPc_, pn_ - fluidState_.pressure(0));
311 }
312
327 Scalar pressureHead(const int phaseIdx = 0) const
328 { return 100.0 *(pressure(phaseIdx) - pn_)/density(phaseIdx)/9.81; }
329
341 Scalar waterContent(const int phaseIdx = 0) const
342 { return saturation(phaseIdx) * solidState_.porosity(); }
343
349 Scalar molarDensity(const int phaseIdx = 0) const
350 { return phaseIdx == 0 ? this->fluidState_.molarDensity(phaseIdx) : 0.0; }
351
360 Scalar moleFraction(const int phaseIdx, const int compIdx) const
361 { return phaseIdx == 0 ? this->fluidState_.moleFraction(phaseIdx, compIdx) : 0.0; }
362
371 Scalar massFraction(const int phaseIdx, const int compIdx) const
372 { return phaseIdx == 0 ? this->fluidState_.massFraction(phaseIdx, compIdx) : 0.0; }
373
382 Scalar molarity(const int phaseIdx, const int compIdx) const
383 { return phaseIdx == 0 ? this->fluidState_.molarity(phaseIdx, compIdx) : 0.0; }
384
388 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
389 {
390 typename FluidSystem::ParameterCache paramCache;
391 paramCache.updatePhase(fluidState_, phaseIdx);
392 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
393 }
394
398 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
399 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
400
401protected:
403
404private:
405 // Effective diffusion coefficients for the phases
406 DiffusionCoefficients effectiveDiffCoeff_;
407
408 Scalar relativePermeabilityWetting_; // the relative permeability of the wetting phase
409 SolidState solidState_;
410 PermeabilityType permeability_; // the intrinsic permeability
411 Scalar pn_; // the reference nonwetting pressure
412 Scalar minPc_; // the minimum capillary pressure (entry pressure)
413};
414
415} // end namespace Dumux
416
417#endif
Definition: porousmediumflow/nonisothermal/volumevariables.hh:63
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
Returns the vector of primary variables.
Definition: porousmediumflow/volumevariables.hh:64
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
Contains the quantities which are constant within a finite volume in the Richards,...
Definition: porousmediumflow/richardsnc/volumevariables.hh:35
Scalar molarDensity(const int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:349
Scalar relativePermeability(const int phaseIdx=0) const
Returns relative permeability [-] of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:293
Scalar porosity() const
Returns the average porosity [] within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:218
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:371
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:237
typename Traits::ModelTraits::Indices Indices
Export indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:58
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:398
Scalar averageMolarMass(const int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:203
typename Traits::FluidState FluidState
Export type of the fluid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:52
Scalar viscosity(const int phaseIdx=0) const
Returns the dynamic viscosity of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:284
Scalar waterContent(const int phaseIdx=0) const
Returns the water content fluid phase within the finite volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:341
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:307
static constexpr int liquidPhaseIdx
Export phase access indices.
Definition: porousmediumflow/richardsnc/volumevariables.hh:60
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:56
Scalar temperature() const
Returns the temperature.
Definition: porousmediumflow/richardsnc/volumevariables.hh:209
static constexpr int gasPhaseIdx
Definition: porousmediumflow/richardsnc/volumevariables.hh:61
FluidState fluidState_
the fluid state
Definition: porousmediumflow/richardsnc/volumevariables.hh:402
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:73
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:360
Scalar molarity(const int phaseIdx, const int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/richardsnc/volumevariables.hh:382
typename Traits::FluidSystem FluidSystem
Export type of the fluid system.
Definition: porousmediumflow/richardsnc/volumevariables.hh:50
Scalar pressureHead(const int phaseIdx=0) const
Returns the pressureHead of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:327
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:246
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/richardsnc/volumevariables.hh:54
Scalar pressure(const int phaseIdx=0) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:260
const FluidState & fluidState() const
Returns the fluid configuration at the given primary variables.
Definition: porousmediumflow/richardsnc/volumevariables.hh:189
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:195
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:388
Scalar mobility(const int phaseIdx=0) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/richardsnc/volumevariables.hh:274
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:132
const PermeabilityType & permeability() const
Returns the permeability within the control volume in .
Definition: porousmediumflow/richardsnc/volumevariables.hh:224
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
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
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.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.