version 3.10-dev
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_2P1C_VOLUME_VARIABLES_HH
14#define DUMUX_2P1C_VOLUME_VARIABLES_HH
15
16#include <array>
17
18#include <dune/common/exceptions.hh>
19
24
26
27namespace Dumux {
28
33template <class Traits>
36, public EnergyVolumeVariables<Traits, TwoPOneCVolumeVariables<Traits> >
37{
40 using Scalar = typename Traits::PrimaryVariables::value_type;
41 using PermeabilityType = typename Traits::PermeabilityType;
42 using FS = typename Traits::FluidSystem;
43 using Idx = typename Traits::ModelTraits::Indices;
44 static constexpr int numFluidComps = ParentType::numFluidComponents();
45
46 // primary variable indices
47 enum
48 {
49 numFluidPhases = Traits::ModelTraits::numFluidPhases(),
50 switchIdx = Idx::switchIdx,
51 pressureIdx = Idx::pressureIdx
52 };
53
54 // component indices
55 enum
56 {
57 comp0Idx = FS::comp0Idx,
58 liquidPhaseIdx = FS::liquidPhaseIdx,
59 gasPhaseIdx = FS::gasPhaseIdx
60 };
61
62 // phase presence indices
63 enum
64 {
65 twoPhases = Idx::twoPhases,
66 liquidPhaseOnly = Idx::liquidPhaseOnly,
67 gasPhaseOnly = Idx::gasPhaseOnly,
68 };
69
70 // formulations
71 static constexpr auto formulation = Traits::ModelTraits::priVarFormulation();
72
73public:
75 using FluidState = typename Traits::FluidState;
77 using FluidSystem = typename Traits::FluidSystem;
79 using Indices = typename Traits::ModelTraits::Indices;
81 using SolidState = typename Traits::SolidState;
83 using SolidSystem = typename Traits::SolidSystem;
86
88 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
89
90 // check for permissive combinations
91 static_assert(Traits::ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
92 static_assert(Traits::ModelTraits::numFluidComponents() == 1, "NumComponents set in the model is not one!");
93 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
94
104 template<class ElemSol, class Problem, class Element, class Scv>
105 void update(const ElemSol &elemSol,
106 const Problem &problem,
107 const Element &element,
108 const Scv& scv)
109 {
110 ParentType::update(elemSol, problem, element, scv);
111
112 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
113
115 // calculate the remaining quantities
117
118 const auto& spatialParams = problem.spatialParams();
119 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
120
121 // Second instance of a parameter cache.
122 // Could be avoided if diffusion coefficients also
123 // became part of the fluid state.
124 typename FluidSystem::ParameterCache paramCache;
125 paramCache.updateAll(fluidState_);
126 const int wPhaseIdx = fluidState_.wettingPhase();
127 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
128 {
129 // relative permeabilities
130 Scalar kr;
131 if (phaseIdx == wPhaseIdx)
132 kr = fluidMatrixInteraction.krw(saturation(wPhaseIdx));
133 else // ATTENTION: krn requires the wetting phase saturation
134 // as parameter!
135 kr = fluidMatrixInteraction.krn(saturation(wPhaseIdx));
136 relativePermeability_[phaseIdx] = kr;
137 }
138
139 // porosity & permeability
140 // porosity calculation over inert volumefraction
141 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
142 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
143 permeability_ = spatialParams.permeability(element, scv, elemSol);
144 EnergyVolVars::updateEffectiveThermalConductivity();
145 }
146
158 template<class ElemSol, class Problem, class Element, class Scv>
159 void completeFluidState(const ElemSol& elemSol,
160 const Problem& problem,
161 const Element& element,
162 const Scv& scv,
165 {
166
167 // capillary pressure parameters
168 const auto& spatialParams = problem.spatialParams();
169 const auto wPhaseIdx = spatialParams.template wettingPhase<FluidSystem>(element, scv, elemSol);
170 fluidState.setWettingPhase(wPhaseIdx);
171
172 const auto& priVars = elemSol[scv.localDofIndex()];
173 const auto phasePresence = priVars.state();
174
175 // set the saturations
176 if (phasePresence == twoPhases)
177 {
178 if (formulation == TwoPFormulation::p0s1)
179 {
180 fluidState.setSaturation(gasPhaseIdx, priVars[switchIdx]);
181 fluidState.setSaturation(liquidPhaseIdx, 1.0 - priVars[switchIdx]);
182 }
183 else
184 {
185 fluidState.setSaturation(liquidPhaseIdx, priVars[switchIdx]);
186 fluidState.setSaturation(gasPhaseIdx, 1.0 - priVars[switchIdx]);
187 }
188 }
189 else if (phasePresence == liquidPhaseOnly)
190 {
191 fluidState.setSaturation(liquidPhaseIdx, 1.0);
192 fluidState.setSaturation(gasPhaseIdx, 0.0);
193 }
194 else if (phasePresence == gasPhaseOnly)
195 {
196 fluidState.setSaturation(liquidPhaseIdx, 0.0);
197 fluidState.setSaturation(gasPhaseIdx, 1.0);
198 }
199 else
200 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
201
202 // set pressures of the fluid phases
203 const auto fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
204 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
205 if (formulation == TwoPFormulation::p0s1)
206 {
207 fluidState.setPressure(liquidPhaseIdx, priVars[pressureIdx]);
208 fluidState.setPressure(gasPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] + pc_
209 : priVars[pressureIdx] - pc_);
210 }
211 else
212 {
213 fluidState.setPressure(gasPhaseIdx, priVars[pressureIdx]);
214 fluidState.setPressure(liquidPhaseIdx, (wPhaseIdx == liquidPhaseIdx) ? priVars[pressureIdx] - pc_
215 : priVars[pressureIdx] + pc_);
216 }
217
218 // set the temperature
219 updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
220
221 // set the densities
222 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
223 {
224 Scalar rho = FluidSystem::density(fluidState, phaseIdx);
225 Scalar rhoMolar = FluidSystem::molarDensity(fluidState, phaseIdx);
226
227 fluidState.setDensity(phaseIdx, rho);
228 fluidState.setMolarDensity(phaseIdx, rhoMolar);
229 }
230
231 //get the viscosity and mobility
232 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
233 {
234 // Mobilities
235 const Scalar mu =
237 phaseIdx);
238 fluidState.setViscosity(phaseIdx,mu);
239 }
240
241 // the enthalpies (internal energies are directly calculated in the fluidstate
242 for (int phaseIdx = 0; phaseIdx < numFluidPhases; ++phaseIdx)
243 {
244 const Scalar h = FluidSystem::enthalpy(fluidState, phaseIdx);
245 fluidState.setEnthalpy(phaseIdx, h);
246 }
247 }
248
251 template<class ElemSol, class Problem, class Element, class Scv>
252 void updateTemperature(const ElemSol& elemSol,
253 const Problem& problem,
254 const Element& element,
255 const Scv& scv,
258 {
259 const auto& priVars = elemSol[scv.localDofIndex()];
260 const auto phasePresence = priVars.state();
261
262 // get temperature
263 Scalar fluidTemperature;
264 if (phasePresence == liquidPhaseOnly || phasePresence == gasPhaseOnly)
265 fluidTemperature = priVars[switchIdx];
266 else if (phasePresence == twoPhases)
267 fluidTemperature = FluidSystem::vaporTemperature(fluidState, fluidState_.wettingPhase());
268 else
269 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
270
271 // the model assumes that all fluid phases have the same temperature
272 for (int phaseIdx=0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
273 fluidState.setTemperature(phaseIdx, fluidTemperature);
274
275 // the solid phase could have a different temperature
276 if (Traits::ModelTraits::numEnergyEq() == 1)
277 solidState.setTemperature(fluidTemperature);
278 else
279 {
280 const Scalar solidTemperature = elemSol[scv.localDofIndex()][Traits::ModelTraits::numEq()-1];
281 solidState.setTemperature(solidTemperature);
282 }
283 }
284
288 const FluidState &fluidState() const
289 { return fluidState_; }
290
294 const SolidState &solidState() const
295 { return solidState_; }
296
302 Scalar averageMolarMass(int phaseIdx) const
303 { return fluidState_.averageMolarMass(phaseIdx); }
304
311 Scalar saturation(const int phaseIdx) const
312 { return fluidState_.saturation(phaseIdx); }
313
320 Scalar density(const int phaseIdx) const
321 { return fluidState_.density(phaseIdx); }
322
329 Scalar molarDensity(const int phaseIdx) const
330 { return fluidState_.molarDensity(phaseIdx); }
331
338 Scalar pressure(const int phaseIdx) const
339 { return fluidState_.pressure(phaseIdx); }
340
348 Scalar temperature(const int phaseIdx = 0) const
349 { return fluidState_.temperature(phaseIdx); }
350
357 Scalar mobility(const int phaseIdx) const
358 {
359 return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx);
360 }
361
366 Scalar capillaryPressure() const
367 { return pc_; }
368
372 Scalar porosity() const
373 { return solidState_.porosity(); }
374
378 const PermeabilityType& permeability() const
379 { return permeability_; }
380
384 Scalar vaporTemperature() const
385 { return FluidSystem::vaporTemperature(fluidState_, liquidPhaseIdx);}
386
390 int wettingPhase() const
391 { return fluidState_.wettingPhase(); }
392
393protected:
396
397private:
398 Scalar pc_; // The capillary pressure
399 PermeabilityType permeability_; // Effective permeability within the control volume
400
401 // Relative permeability within the control volume
402 std::array<Scalar, numFluidPhases> relativePermeability_;
403};
404
405} // end namespace Dumux
406
407#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
The primary variable switch for the two-phase one-component model.
Definition: 2p1c/primaryvariableswitch.hh:29
The volume variables (i.e. secondary variables) for the two-phase one-component model.
Definition: porousmediumflow/2p1c/volumevariables.hh:37
Scalar saturation(const int phaseIdx) const
Returns the effective saturation of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:311
typename Traits::FluidSystem FluidSystem
The type of the fluid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:77
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:378
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:320
Scalar temperature(const int phaseIdx=0) const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:348
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/2p1c/volumevariables.hh:75
const FluidState & fluidState() const
Returns the fluid state for the control-volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:288
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2p1c/volumevariables.hh:302
Scalar vaporTemperature() const
Returns the vapor temperature of the fluid within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:384
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:159
Scalar molarDensity(const int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:329
FluidState fluidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:394
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2p1c/volumevariables.hh:83
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2p1c/volumevariables.hh:366
void updateTemperature(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Definition: porousmediumflow/2p1c/volumevariables.hh:252
typename Traits::ModelTraits::Indices Indices
The type of the indices.
Definition: porousmediumflow/2p1c/volumevariables.hh:79
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:105
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:372
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2p1c/volumevariables.hh:81
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:357
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:294
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2p1c/volumevariables.hh:390
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2p1c/volumevariables.hh:88
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2p1c/volumevariables.hh:338
SolidState solidState_
Definition: porousmediumflow/2p1c/volumevariables.hh:395
Defines an enumeration for the formulations accepted by the two-phase model.
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
TwoPFormulation
Enumerates the formulations which the two-phase model accepts.
Definition: formulation.hh:23
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
std::string solidTemperature() noexcept
I/O name of solid temperature for non-equilibrium models.
Definition: name.hh:48
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135
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
std::string fluidTemperature(int phaseIdx) noexcept
I/O name of temperature for non-equilibrium models.
Definition: name.hh:44
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.
The primary variable switch for the extended Richards model.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.