3.1-git
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
37
39
40namespace Dumux {
41
46template <class Traits>
49, public EnergyVolumeVariables<Traits, TwoPOneCVolumeVariables<Traits> >
50{
53 using Scalar = typename Traits::PrimaryVariables::value_type;
54 using PermeabilityType = typename Traits::PermeabilityType;
55 using FS = typename Traits::FluidSystem;
56 using Idx = typename Traits::ModelTraits::Indices;
57 static constexpr int numFluidComps = ParentType::numFluidComponents();
58
59 // primary variable indices
60 enum
61 {
62 numFluidPhases = Traits::ModelTraits::numFluidPhases(),
63 switchIdx = Idx::switchIdx,
64 pressureIdx = Idx::pressureIdx
65 };
66
67 // component indices
68 enum
69 {
70 comp0Idx = FS::comp0Idx,
71 liquidPhaseIdx = FS::liquidPhaseIdx,
72 gasPhaseIdx = FS::gasPhaseIdx
73 };
74
75 // phase presence indices
76 enum
77 {
78 twoPhases = Idx::twoPhases,
79 liquidPhaseOnly = Idx::liquidPhaseOnly,
80 gasPhaseOnly = Idx::gasPhaseOnly,
81 };
82
83 // formulations
84 static constexpr auto formulation = Traits::ModelTraits::priVarFormulation();
85
86public:
88 using FluidState = typename Traits::FluidState;
90 using FluidSystem = typename Traits::FluidSystem;
94 using SolidState = typename Traits::SolidState;
96 using SolidSystem = typename Traits::SolidSystem;
99
101 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
102
103 // check for permissive combinations
104 static_assert(Traits::ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
105 static_assert(Traits::ModelTraits::numFluidComponents() == 1, "NumComponents set in the model is not one!");
106 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
107
117 template<class ElemSol, class Problem, class Element, class Scv>
118 void update(const ElemSol &elemSol,
119 const Problem &problem,
120 const Element &element,
121 const Scv& scv)
122 {
123 ParentType::update(elemSol, problem, element, scv);
124
125 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
126
128 // calculate the remaining quantities
130 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
131 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
132 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
133
134 // Second instance of a parameter cache.
135 // Could be avoided if diffusion coefficients also
136 // became part of the fluid state.
137 typename FluidSystem::ParameterCache paramCache;
138 paramCache.updateAll(fluidState_);
139 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
140 {
141 // relative permeabilities
142 Scalar kr;
143 if (phaseIdx == wPhaseIdx)
144 kr = MaterialLaw::krw(materialParams, saturation(wPhaseIdx));
145 else // ATTENTION: krn requires the wetting phase saturation
146 // as parameter!
147 kr = MaterialLaw::krn(materialParams, saturation(wPhaseIdx));
148 relativePermeability_[phaseIdx] = kr;
149 Valgrind::CheckDefined(relativePermeability_[phaseIdx]);
150 }
151
152 // porosity & permeability
153 // porosity calculation over inert volumefraction
154 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
155 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
156 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
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& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
181 const int wPhaseIdx = problem.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 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
216 pc_ = MaterialLaw::pc(materialParams, 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 const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
274
275 // get temperature
276 Scalar fluidTemperature;
277 if (phasePresence == liquidPhaseOnly || phasePresence == gasPhaseOnly)
278 fluidTemperature = priVars[switchIdx];
279 else if (phasePresence == twoPhases)
280 fluidTemperature = FluidSystem::vaporTemperature(fluidState, wPhaseIdx);
281 else
282 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
283
285
286 // the model assumes that all fluid phases have the same temperature
287 for (int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
288 fluidState.setTemperature(phaseIdx, fluidTemperature);
289
290 // the solid phase could have a different temperature
291 if (Traits::ModelTraits::numEnergyEq() == 1)
292 solidState.setTemperature(fluidTemperature);
293 else
294 {
295 const Scalar solidTemperature = elemSol[scv.localDofIndex()][Traits::ModelTraits::numEq()-1];
296 solidState.setTemperature(solidTemperature);
297 }
298 }
299
303 const FluidState &fluidState() const
304 { return fluidState_; }
305
309 const SolidState &solidState() const
310 { return solidState_; }
311
317 Scalar averageMolarMass(int phaseIdx) const
318 { return fluidState_.averageMolarMass(phaseIdx); }
319
326 Scalar saturation(const int phaseIdx) const
327 { return fluidState_.saturation(phaseIdx); }
328
335 Scalar density(const int phaseIdx) const
336 { return fluidState_.density(phaseIdx); }
337
344 Scalar molarDensity(const int phaseIdx) const
345 { return fluidState_.molarDensity(phaseIdx); }
346
353 Scalar pressure(const int phaseIdx) const
354 { return fluidState_.pressure(phaseIdx); }
355
363 Scalar temperature(const int phaseIdx = 0) const
364 { return fluidState_.temperature(phaseIdx); }
365
372 Scalar mobility(const int phaseIdx) const
373 {
374 return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx);
375 }
376
381 Scalar capillaryPressure() const
382 { return pc_; }
383
387 Scalar porosity() const
388 { return solidState_.porosity(); }
389
393 const PermeabilityType& permeability() const
394 { return permeability_; }
395
399 Scalar vaporTemperature() const
400 { return FluidSystem::vaporTemperature(fluidState_, liquidPhaseIdx);}
401
402protected:
405
406private:
407 Scalar pc_; // The capillary pressure
408 PermeabilityType permeability_; // Effective permeability within the control volume
409
410 // Relative permeability within the control volume
411 std::array<Scalar, numFluidPhases> relativePermeability_;
412};
413
414} // end namespace Dumux
415
416#endif
Some templates to wrap the valgrind macros.
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
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
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 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:50
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:326
typename Traits::FluidSystem FluidSystem
The type of the fluid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:90
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:393
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:335
Scalar temperature(const int phaseIdx=0) const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:363
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/2p1c/volumevariables.hh:88
const FluidState & fluidState() const
Returns the fluid state for the control-volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:303
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2p1c/volumevariables.hh:317
Scalar vaporTemperature() const
Returns the vapor temperature of the fluid within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:399
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:344
FluidState fluidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:403
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:96
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:381
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:92
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:118
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:387
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2p1c/volumevariables.hh:94
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:372
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:309
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2p1c/volumevariables.hh:101
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:353
SolidState solidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:404
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.