3.4
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
39namespace Dumux {
40
45template <class Traits>
48, public EnergyVolumeVariables<Traits, TwoPOneCVolumeVariables<Traits> >
49{
52 using Scalar = typename Traits::PrimaryVariables::value_type;
53 using PermeabilityType = typename Traits::PermeabilityType;
54 using FS = typename Traits::FluidSystem;
55 using Idx = typename Traits::ModelTraits::Indices;
56 static constexpr int numFluidComps = ParentType::numFluidComponents();
57
58 // primary variable indices
59 enum
60 {
61 numFluidPhases = Traits::ModelTraits::numFluidPhases(),
62 switchIdx = Idx::switchIdx,
63 pressureIdx = Idx::pressureIdx
64 };
65
66 // component indices
67 enum
68 {
69 comp0Idx = FS::comp0Idx,
70 liquidPhaseIdx = FS::liquidPhaseIdx,
71 gasPhaseIdx = FS::gasPhaseIdx
72 };
73
74 // phase presence indices
75 enum
76 {
77 twoPhases = Idx::twoPhases,
78 liquidPhaseOnly = Idx::liquidPhaseOnly,
79 gasPhaseOnly = Idx::gasPhaseOnly,
80 };
81
82 // formulations
83 static constexpr auto formulation = Traits::ModelTraits::priVarFormulation();
84
85public:
87 using FluidState = typename Traits::FluidState;
89 using FluidSystem = typename Traits::FluidSystem;
91 using Indices = typename Traits::ModelTraits::Indices;
93 using SolidState = typename Traits::SolidState;
95 using SolidSystem = typename Traits::SolidSystem;
98
100 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
101
102 // check for permissive combinations
103 static_assert(Traits::ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
104 static_assert(Traits::ModelTraits::numFluidComponents() == 1, "NumComponents set in the model is not one!");
105 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
106
116 template<class ElemSol, class Problem, class Element, class Scv>
117 void update(const ElemSol &elemSol,
118 const Problem &problem,
119 const Element &element,
120 const Scv& scv)
121 {
122 ParentType::update(elemSol, problem, element, scv);
123
124 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
125
127 // calculate the remaining quantities
129
130 const auto& spatialParams = problem.spatialParams();
131 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
132
133 // Second instance of a parameter cache.
134 // Could be avoided if diffusion coefficients also
135 // became part of the fluid state.
136 typename FluidSystem::ParameterCache paramCache;
137 paramCache.updateAll(fluidState_);
138 const int wPhaseIdx = fluidState_.wettingPhase();
139 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
140 {
141 // relative permeabilities
142 Scalar kr;
143 if (phaseIdx == wPhaseIdx)
144 kr = fluidMatrixInteraction.krw(saturation(wPhaseIdx));
145 else // ATTENTION: krn requires the wetting phase saturation
146 // as parameter!
147 kr = fluidMatrixInteraction.krn(saturation(wPhaseIdx));
148 relativePermeability_[phaseIdx] = kr;
149 }
150
151 // porosity & permeability
152 // porosity calculation over inert volumefraction
153 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
154 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
155 permeability_ = spatialParams.permeability(element, scv, elemSol);
156 EnergyVolVars::updateEffectiveThermalConductivity();
157 }
158
170 template<class ElemSol, class Problem, class Element, class Scv>
171 void completeFluidState(const ElemSol& elemSol,
172 const Problem& problem,
173 const Element& element,
174 const Scv& scv,
177 {
178
179 // capillary pressure parameters
180 const auto& spatialParams = problem.spatialParams();
181 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
182 fluidState.setWettingPhase(wPhaseIdx);
183
184 const auto& priVars = elemSol[scv.localDofIndex()];
185 const auto phasePresence = priVars.state();
186
187 // set the saturations
188 if (phasePresence == twoPhases)
189 {
190 if (formulation == TwoPFormulation::p0s1)
191 {
192 fluidState.setSaturation(gasPhaseIdx, priVars[switchIdx]);
193 fluidState.setSaturation(liquidPhaseIdx, 1.0 - priVars[switchIdx]);
194 }
195 else
196 {
197 fluidState.setSaturation(liquidPhaseIdx, priVars[switchIdx]);
198 fluidState.setSaturation(gasPhaseIdx, 1.0 - priVars[switchIdx]);
199 }
200 }
201 else if (phasePresence == liquidPhaseOnly)
202 {
203 fluidState.setSaturation(liquidPhaseIdx, 1.0);
204 fluidState.setSaturation(gasPhaseIdx, 0.0);
205 }
206 else if (phasePresence == gasPhaseOnly)
207 {
208 fluidState.setSaturation(liquidPhaseIdx, 0.0);
209 fluidState.setSaturation(gasPhaseIdx, 1.0);
210 }
211 else
212 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
213
214 // set pressures of the fluid phases
215 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
216 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
217 if (formulation == TwoPFormulation::p0s1)
218 {
219 fluidState.setPressure(liquidPhaseIdx, priVars[pressureIdx]);
220 fluidState.setPressure(gasPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] + pc_
221 : priVars[pressureIdx] - pc_);
222 }
223 else
224 {
225 fluidState.setPressure(gasPhaseIdx, priVars[pressureIdx]);
226 fluidState.setPressure(liquidPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] - pc_
227 : priVars[pressureIdx] + pc_);
228 }
229
230 // set the temperature
231 updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
232
233 // set the densities
234 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
235 {
236 Scalar rho = FluidSystem::density(fluidState, phaseIdx);
237 Scalar rhoMolar = FluidSystem::molarDensity(fluidState, phaseIdx);
238
239 fluidState.setDensity(phaseIdx, rho);
240 fluidState.setMolarDensity(phaseIdx, rhoMolar);
241 }
242
243 //get the viscosity and mobility
244 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
245 {
246 // Mobilities
247 const Scalar mu =
249 phaseIdx);
250 fluidState.setViscosity(phaseIdx,mu);
251 }
252
253 // the enthalpies (internal energies are directly calculated in the fluidstate
254 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
255 {
256 const Scalar h = FluidSystem::enthalpy(fluidState, phaseIdx);
257 fluidState.setEnthalpy(phaseIdx, h);
258 }
259 }
260
263 template<class ElemSol, class Problem, class Element, class Scv>
264 void updateTemperature(const ElemSol& elemSol,
265 const Problem& problem,
266 const Element& element,
267 const Scv& scv,
270 {
271 const auto& priVars = elemSol[scv.localDofIndex()];
272 const auto phasePresence = priVars.state();
273
274 // get temperature
275 Scalar fluidTemperature;
276 if (phasePresence == liquidPhaseOnly || phasePresence == gasPhaseOnly)
277 fluidTemperature = priVars[switchIdx];
278 else if (phasePresence == twoPhases)
279 fluidTemperature = FluidSystem::vaporTemperature(fluidState, fluidState_.wettingPhase());
280 else
281 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
282
283 // the model assumes that all fluid phases have the same temperature
284 for (int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
285 fluidState.setTemperature(phaseIdx, fluidTemperature);
286
287 // the solid phase could have a different temperature
288 if (Traits::ModelTraits::numEnergyEq() == 1)
289 solidState.setTemperature(fluidTemperature);
290 else
291 {
292 const Scalar solidTemperature = elemSol[scv.localDofIndex()][Traits::ModelTraits::numEq()-1];
293 solidState.setTemperature(solidTemperature);
294 }
295 }
296
300 const FluidState &fluidState() const
301 { return fluidState_; }
302
306 const SolidState &solidState() const
307 { return solidState_; }
308
314 Scalar averageMolarMass(int phaseIdx) const
315 { return fluidState_.averageMolarMass(phaseIdx); }
316
323 Scalar saturation(const int phaseIdx) const
324 { return fluidState_.saturation(phaseIdx); }
325
332 Scalar density(const int phaseIdx) const
333 { return fluidState_.density(phaseIdx); }
334
341 Scalar molarDensity(const int phaseIdx) const
342 { return fluidState_.molarDensity(phaseIdx); }
343
350 Scalar pressure(const int phaseIdx) const
351 { return fluidState_.pressure(phaseIdx); }
352
360 Scalar temperature(const int phaseIdx = 0) const
361 { return fluidState_.temperature(phaseIdx); }
362
369 Scalar mobility(const int phaseIdx) const
370 {
371 return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx);
372 }
373
378 Scalar capillaryPressure() const
379 { return pc_; }
380
384 Scalar porosity() const
385 { return solidState_.porosity(); }
386
390 const PermeabilityType& permeability() const
391 { return permeability_; }
392
396 Scalar vaporTemperature() const
397 { return FluidSystem::vaporTemperature(fluidState_, liquidPhaseIdx);}
398
402 int wettingPhase() const
403 { return fluidState_.wettingPhase(); }
404
405protected:
408
409private:
410 Scalar pc_; // The capillary pressure
411 PermeabilityType permeability_; // Effective permeability within the control volume
412
413 // Relative permeability within the control volume
414 std::array<Scalar, numFluidPhases> relativePermeability_;
415};
416
417} // end namespace Dumux
418
419#endif
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:49
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:323
typename Traits::FluidSystem FluidSystem
The type of the fluid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:89
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:390
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:332
Scalar temperature(const int phaseIdx=0) const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:360
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/2p1c/volumevariables.hh:87
const FluidState & fluidState() const
Returns the fluid state for the control-volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:300
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2p1c/volumevariables.hh:314
Scalar vaporTemperature() const
Returns the vapor temperature of the fluid within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:396
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:171
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:341
FluidState fluidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:406
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:95
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:378
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Definition: porousmediumflow/2p1c/volumevariables.hh:264
typename Traits::ModelTraits::Indices Indices
The type of the indices.
Definition: porousmediumflow/2p1c/volumevariables.hh:91
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:117
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:384
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2p1c/volumevariables.hh:93
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:369
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:306
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2p1c/volumevariables.hh:402
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2p1c/volumevariables.hh:100
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:350
SolidState solidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:407
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.