3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/2p1c/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 *****************************************************************************/
25#ifndef DUMUX_2P1C_VOLUME_VARIABLES_HH
26#define DUMUX_2P1C_VOLUME_VARIABLES_HH
27
28#include <array>
29
30#include <dune/common/exceptions.hh>
31
36
38
40
41namespace Dumux {
42
47template <class Traits>
50, public EnergyVolumeVariables<Traits, TwoPOneCVolumeVariables<Traits> >
51{
54 using Scalar = typename Traits::PrimaryVariables::value_type;
55 using PermeabilityType = typename Traits::PermeabilityType;
56 using FS = typename Traits::FluidSystem;
57 using Idx = typename Traits::ModelTraits::Indices;
58 static constexpr int numFluidComps = ParentType::numFluidComponents();
59
60 // primary variable indices
61 enum
62 {
63 numFluidPhases = Traits::ModelTraits::numFluidPhases(),
64 switchIdx = Idx::switchIdx,
65 pressureIdx = Idx::pressureIdx
66 };
67
68 // component indices
69 enum
70 {
71 comp0Idx = FS::comp0Idx,
72 liquidPhaseIdx = FS::liquidPhaseIdx,
73 gasPhaseIdx = FS::gasPhaseIdx
74 };
75
76 // phase presence indices
77 enum
78 {
79 twoPhases = Idx::twoPhases,
80 liquidPhaseOnly = Idx::liquidPhaseOnly,
81 gasPhaseOnly = Idx::gasPhaseOnly,
82 };
83
84 // formulations
85 static constexpr auto formulation = Traits::ModelTraits::priVarFormulation();
86
87public:
89 using FluidState = typename Traits::FluidState;
91 using FluidSystem = typename Traits::FluidSystem;
93 using Indices = typename Traits::ModelTraits::Indices;
95 using SolidState = typename Traits::SolidState;
97 using SolidSystem = typename Traits::SolidSystem;
100
102 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
103
104 // check for permissive combinations
105 static_assert(Traits::ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
106 static_assert(Traits::ModelTraits::numFluidComponents() == 1, "NumComponents set in the model is not one!");
107 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
108
118 template<class ElemSol, class Problem, class Element, class Scv>
119 void update(const ElemSol &elemSol,
120 const Problem &problem,
121 const Element &element,
122 const Scv& scv)
123 {
124 ParentType::update(elemSol, problem, element, scv);
125
126 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
127
129 // calculate the remaining quantities
131
132 // old material law interface is deprecated: Replace this by
133 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
134 // after the release of 3.3, when the deprecated interface is no longer supported
135 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
136
137 // Second instance of a parameter cache.
138 // Could be avoided if diffusion coefficients also
139 // became part of the fluid state.
140 typename FluidSystem::ParameterCache paramCache;
141 paramCache.updateAll(fluidState_);
142 const int wPhaseIdx = fluidState_.wettingPhase();
143 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
144 {
145 // relative permeabilities
146 Scalar kr;
147 if (phaseIdx == wPhaseIdx)
148 kr = fluidMatrixInteraction.krw(saturation(wPhaseIdx));
149 else // ATTENTION: krn requires the wetting phase saturation
150 // as parameter!
151 kr = fluidMatrixInteraction.krn(saturation(wPhaseIdx));
152 relativePermeability_[phaseIdx] = kr;
153 }
154
155 // porosity & permeability
156 // porosity calculation over inert volumefraction
157 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
158 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
159 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
160 EnergyVolVars::updateEffectiveThermalConductivity();
161 }
162
174 template<class ElemSol, class Problem, class Element, class Scv>
175 void completeFluidState(const ElemSol& elemSol,
176 const Problem& problem,
177 const Element& element,
178 const Scv& scv,
181 {
182
183 // capillary pressure parameters
184 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
185 fluidState.setWettingPhase(wPhaseIdx);
186
187 const auto& priVars = elemSol[scv.localDofIndex()];
188 const auto phasePresence = priVars.state();
189
190 // set the saturations
191 if (phasePresence == twoPhases)
192 {
193 if (formulation == TwoPFormulation::p0s1)
194 {
195 fluidState.setSaturation(gasPhaseIdx, priVars[switchIdx]);
196 fluidState.setSaturation(liquidPhaseIdx, 1.0 - priVars[switchIdx]);
197 }
198 else
199 {
200 fluidState.setSaturation(liquidPhaseIdx, priVars[switchIdx]);
201 fluidState.setSaturation(gasPhaseIdx, 1.0 - priVars[switchIdx]);
202 }
203 }
204 else if (phasePresence == liquidPhaseOnly)
205 {
206 fluidState.setSaturation(liquidPhaseIdx, 1.0);
207 fluidState.setSaturation(gasPhaseIdx, 0.0);
208 }
209 else if (phasePresence == gasPhaseOnly)
210 {
211 fluidState.setSaturation(liquidPhaseIdx, 0.0);
212 fluidState.setSaturation(gasPhaseIdx, 1.0);
213 }
214 else
215 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
216
217 // set pressures of the fluid phases
218 // old material law interface is deprecated: Replace this by
219 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
220 // after the release of 3.3, when the deprecated interface is no longer supported
221 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
222
223 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
224 if (formulation == TwoPFormulation::p0s1)
225 {
226 fluidState.setPressure(liquidPhaseIdx, priVars[pressureIdx]);
227 fluidState.setPressure(gasPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] + pc_
228 : priVars[pressureIdx] - pc_);
229 }
230 else
231 {
232 fluidState.setPressure(gasPhaseIdx, priVars[pressureIdx]);
233 fluidState.setPressure(liquidPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] - pc_
234 : priVars[pressureIdx] + pc_);
235 }
236
237 // set the temperature
238 updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
239
240 // set the densities
241 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
242 {
243 Scalar rho = FluidSystem::density(fluidState, phaseIdx);
244 Scalar rhoMolar = FluidSystem::molarDensity(fluidState, phaseIdx);
245
246 fluidState.setDensity(phaseIdx, rho);
247 fluidState.setMolarDensity(phaseIdx, rhoMolar);
248 }
249
250 //get the viscosity and mobility
251 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
252 {
253 // Mobilities
254 const Scalar mu =
256 phaseIdx);
257 fluidState.setViscosity(phaseIdx,mu);
258 }
259
260 // the enthalpies (internal energies are directly calculated in the fluidstate
261 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
262 {
263 const Scalar h = FluidSystem::enthalpy(fluidState, phaseIdx);
264 fluidState.setEnthalpy(phaseIdx, h);
265 }
266 }
267
270 template<class ElemSol, class Problem, class Element, class Scv>
271 void updateTemperature(const ElemSol& elemSol,
272 const Problem& problem,
273 const Element& element,
274 const Scv& scv,
277 {
278 const auto& priVars = elemSol[scv.localDofIndex()];
279 const auto phasePresence = priVars.state();
280
281 // get temperature
282 Scalar fluidTemperature;
283 if (phasePresence == liquidPhaseOnly || phasePresence == gasPhaseOnly)
284 fluidTemperature = priVars[switchIdx];
285 else if (phasePresence == twoPhases)
286 fluidTemperature = FluidSystem::vaporTemperature(fluidState, fluidState_.wettingPhase());
287 else
288 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
289
290 // the model assumes that all fluid phases have the same temperature
291 for (int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
292 fluidState.setTemperature(phaseIdx, fluidTemperature);
293
294 // the solid phase could have a different temperature
295 if (Traits::ModelTraits::numEnergyEq() == 1)
296 solidState.setTemperature(fluidTemperature);
297 else
298 {
299 const Scalar solidTemperature = elemSol[scv.localDofIndex()][Traits::ModelTraits::numEq()-1];
300 solidState.setTemperature(solidTemperature);
301 }
302 }
303
307 const FluidState &fluidState() const
308 { return fluidState_; }
309
313 const SolidState &solidState() const
314 { return solidState_; }
315
321 Scalar averageMolarMass(int phaseIdx) const
322 { return fluidState_.averageMolarMass(phaseIdx); }
323
330 Scalar saturation(const int phaseIdx) const
331 { return fluidState_.saturation(phaseIdx); }
332
339 Scalar density(const int phaseIdx) const
340 { return fluidState_.density(phaseIdx); }
341
348 Scalar molarDensity(const int phaseIdx) const
349 { return fluidState_.molarDensity(phaseIdx); }
350
357 Scalar pressure(const int phaseIdx) const
358 { return fluidState_.pressure(phaseIdx); }
359
367 Scalar temperature(const int phaseIdx = 0) const
368 { return fluidState_.temperature(phaseIdx); }
369
376 Scalar mobility(const int phaseIdx) const
377 {
378 return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx);
379 }
380
385 Scalar capillaryPressure() const
386 { return pc_; }
387
391 Scalar porosity() const
392 { return solidState_.porosity(); }
393
397 const PermeabilityType& permeability() const
398 { return permeability_; }
399
403 Scalar vaporTemperature() const
404 { return FluidSystem::vaporTemperature(fluidState_, liquidPhaseIdx);}
405
409 int wettingPhase() const
410 { return fluidState_.wettingPhase(); }
411
412protected:
415
416private:
417 Scalar pc_; // The capillary pressure
418 PermeabilityType permeability_; // Effective permeability within the control volume
419
420 // Relative permeability within the control volume
421 std::array<Scalar, numFluidPhases> relativePermeability_;
422};
423
424} // end namespace Dumux
425
426#endif
Helpers for deprecation.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.
Defines an enumeration for the formulations accepted by the two-phase model.
TwoPFormulation
Enumerates the formulations which the two-phase model accepts.
Definition: formulation.hh:35
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
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 solidTemperature() noexcept
I/O name of solid temperature for non-equilibrium models.
Definition: name.hh:60
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:147
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
std::string fluidTemperature(int phaseIdx) noexcept
I/O name of temperature for non-equilibrium models.
Definition: name.hh:56
The primary variable switch for the two-phase one-component model.
Definition: 2p1c/primaryvariableswitch.hh:41
The volume variables (i.e. secondary variables) for the two-phase one-component model.
Definition: porousmediumflow/2p1c/volumevariables.hh:51
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:330
typename Traits::FluidSystem FluidSystem
The type of the fluid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:91
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:397
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:339
Scalar temperature(const int phaseIdx=0) const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:367
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/2p1c/volumevariables.hh:89
const FluidState & fluidState() const
Returns the fluid state for the control-volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:307
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2p1c/volumevariables.hh:321
Scalar vaporTemperature() const
Returns the vapor temperature of the fluid within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:403
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Sets complete fluid state.
Definition: porousmediumflow/2p1c/volumevariables.hh:175
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:348
FluidState fluidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:413
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:97
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:385
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Definition: porousmediumflow/2p1c/volumevariables.hh:271
typename Traits::ModelTraits::Indices Indices
The type of the indices.
Definition: porousmediumflow/2p1c/volumevariables.hh:93
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:119
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:391
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2p1c/volumevariables.hh:95
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:376
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:313
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2p1c/volumevariables.hh:409
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2p1c/volumevariables.hh:102
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:357
SolidState solidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:414
Definition: porousmediumflow/nonisothermal/volumevariables.hh:75
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.
The primary variable switch for the extended Richards model.