3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/co2/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 *****************************************************************************/
26#ifndef DUMUX_CO2_VOLUME_VARIABLES_HH
27#define DUMUX_CO2_VOLUME_VARIABLES_HH
28
29#include <array>
30
31#include <dune/common/exceptions.hh>
32
37
39
41
42namespace Dumux {
43
49template <class Traits>
52, public EnergyVolumeVariables<Traits, TwoPTwoCCO2VolumeVariables<Traits> >
53{
56
57 using Scalar = typename Traits::PrimaryVariables::value_type;
58 using ModelTraits = typename Traits::ModelTraits;
59 static constexpr int numFluidComps = ParentType::numFluidComponents();
60
61 // component indices
62 enum
63 {
64 comp0Idx = Traits::FluidSystem::comp0Idx,
65 comp1Idx = Traits::FluidSystem::comp1Idx,
66 phase0Idx = Traits::FluidSystem::phase0Idx,
67 phase1Idx = Traits::FluidSystem::phase1Idx
68 };
69
70 // phase presence indices
71 enum
72 {
73 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
74 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
75 bothPhases = ModelTraits::Indices::bothPhases
76 };
77
78 // primary variable indices
79 enum
80 {
81 switchIdx = ModelTraits::Indices::switchIdx,
82 pressureIdx = ModelTraits::Indices::pressureIdx
83 };
84
85 // formulation
86 static constexpr auto formulation = ModelTraits::priVarFormulation();
87
88 // type used for the permeability
89 using PermeabilityType = typename Traits::PermeabilityType;
90
91 // type used for the diffusion coefficients
92 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
93 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
94
95public:
97 using FluidState = typename Traits::FluidState;
99 using FluidSystem = typename Traits::FluidSystem;
101 using Indices = typename ModelTraits::Indices;
103 using SolidState = typename Traits::SolidState;
105 using SolidSystem = typename Traits::SolidSystem;
108
109
111 static constexpr bool useMoles() { return ModelTraits::useMoles(); }
113 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
114
115 // check for permissive combinations
116 static_assert(ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
117 static_assert(ModelTraits::numFluidComponents() == 2, "NumComponents set in the model is not two!");
118 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
119
129 template<class ElemSol, class Problem, class Element, class Scv>
130 void update(const ElemSol& elemSol, const Problem& problem, const Element& element, const Scv& scv)
131 {
132 ParentType::update(elemSol, problem, element, scv);
133 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
134
135 // Second instance of a parameter cache. Could be avoided if
136 // diffusion coefficients also became part of the fluid state.
137 typename FluidSystem::ParameterCache paramCache;
138 paramCache.updateAll(fluidState_);
139
140 // old material law interface is deprecated: Replace this by
141 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
142 // after the release of 3.3, when the deprecated interface is no longer supported
143 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
144
145 const int wPhaseIdx = fluidState_.wettingPhase();
146 const int nPhaseIdx = 1 - wPhaseIdx;
147
148 // relative permeabilities -> require wetting phase saturation as parameter!
149 relativePermeability_[wPhaseIdx] = fluidMatrixInteraction.krw(saturation(wPhaseIdx));
150 relativePermeability_[nPhaseIdx] = fluidMatrixInteraction.krn(saturation(wPhaseIdx));
151
152 // porosity & permeabilty
153 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
154 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
155 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
156
157 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
158 {
159 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
160 };
161
162 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
163
164 EnergyVolVars::updateEffectiveThermalConductivity();
165 }
166
181 template<class ElemSol, class Problem, class Element, class Scv>
182 void completeFluidState(const ElemSol& elemSol,
183 const Problem& problem,
184 const Element& element,
185 const Scv& scv,
188 {
189 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
190
191 const auto& priVars = elemSol[scv.localDofIndex()];
192 const auto phasePresence = priVars.state();
193
194 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
195 fluidState.setWettingPhase(wPhaseIdx);
196
197 // old material law interface is deprecated: Replace this by
198 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
199 // after the release of 3.3, when the deprecated interface is no longer supported
200 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
201
202 // set the saturations
203 if (phasePresence == secondPhaseOnly)
204 {
205 fluidState.setSaturation(phase0Idx, 0.0);
206 fluidState.setSaturation(phase1Idx, 1.0);
207 }
208 else if (phasePresence == firstPhaseOnly)
209 {
210 fluidState.setSaturation(phase0Idx, 1.0);
211 fluidState.setSaturation(phase1Idx, 0.0);
212 }
213 else if (phasePresence == bothPhases)
214 {
215 if (formulation == TwoPFormulation::p0s1)
216 {
217 fluidState.setSaturation(phase1Idx, priVars[switchIdx]);
218 fluidState.setSaturation(phase0Idx, 1 - priVars[switchIdx]);
219 }
220 else
221 {
222 fluidState.setSaturation(phase0Idx, priVars[switchIdx]);
223 fluidState.setSaturation(phase1Idx, 1 - priVars[switchIdx]);
224 }
225 }
226 else
227 DUNE_THROW(Dune::InvalidStateException, "Invalid phase presence.");
228
229 // set pressures of the fluid phases
230 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
231 if (formulation == TwoPFormulation::p0s1)
232 {
233 fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
234 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] + pc_
235 : priVars[pressureIdx] - pc_);
236 }
237 else
238 {
239 fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
240 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] - pc_
241 : priVars[pressureIdx] + pc_);
242 }
243
244 // calculate the phase compositions
245 typename FluidSystem::ParameterCache paramCache;
246 // both phases are present
247 if (phasePresence == bothPhases)
248 {
249 //Get the equilibrium mole fractions from the FluidSystem and set them in the fluidState
250 //xCO2 = equilibrium mole fraction of CO2 in the liquid phase
251 //yH2O = equilibrium mole fraction of H2O in the gas phase
252 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase0Idx);
253 const auto xgH2O = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase1Idx);
254 const auto xwH2O = 1 - xwCO2;
255 const auto xgCO2 = 1 - xgH2O;
256 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
257 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
258 fluidState.setMoleFraction(phase1Idx, comp0Idx, xgH2O);
259 fluidState.setMoleFraction(phase1Idx, comp1Idx, xgCO2);
260 }
261
262 // only the nonwetting phase is present, i.e. nonwetting phase
263 // composition is stored explicitly.
264 else if (phasePresence == secondPhaseOnly)
265 {
266 if( useMoles() ) // mole-fraction formulation
267 {
268 // set the fluid state
269 fluidState.setMoleFraction(phase1Idx, comp0Idx, priVars[switchIdx]);
270 fluidState.setMoleFraction(phase1Idx, comp1Idx, 1-priVars[switchIdx]);
271 // TODO give values for non-existing wetting phase
272 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase0Idx);
273 const auto xwH2O = 1 - xwCO2;
274 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
275 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
276 }
277 else // mass-fraction formulation
278 {
279 // setMassFraction() has only to be called 1-numComponents times
280 fluidState.setMassFraction(phase1Idx, comp0Idx, priVars[switchIdx]);
281 // TODO give values for non-existing wetting phase
282 const auto xwCO2 = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase0Idx);
283 const auto xwH2O = 1 - xwCO2;
284 fluidState.setMoleFraction(phase0Idx, comp1Idx, xwCO2);
285 fluidState.setMoleFraction(phase0Idx, comp0Idx, xwH2O);
286 }
287 }
288
289 // only the wetting phase is present, i.e. wetting phase
290 // composition is stored explicitly.
291 else if (phasePresence == firstPhaseOnly)
292 {
293 if( useMoles() ) // mole-fraction formulation
294 {
295 // convert mass to mole fractions and set the fluid state
296 fluidState.setMoleFraction(phase0Idx, comp0Idx, 1-priVars[switchIdx]);
297 fluidState.setMoleFraction(phase0Idx, comp1Idx, priVars[switchIdx]);
298 // TODO give values for non-existing nonwetting phase
299 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase1Idx);
300 Scalar xnCO2 = 1 - xnH2O;
301 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
302 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
303 }
304 else // mass-fraction formulation
305 {
306 // setMassFraction() has only to be called 1-numComponents times
307 fluidState.setMassFraction(phase0Idx, comp1Idx, priVars[switchIdx]);
308 // TODO give values for non-existing nonwetting phase
309 Scalar xnH2O = FluidSystem::equilibriumMoleFraction(fluidState, paramCache, phase1Idx);
310 Scalar xnCO2 = 1 - xnH2O;
311 fluidState.setMoleFraction(phase1Idx, comp1Idx, xnCO2);
312 fluidState.setMoleFraction(phase1Idx, comp0Idx, xnH2O);
313 }
314 }
315
316 for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
317 {
318 // set the viscosity and desity here if constraintsolver is not used
319 paramCache.updateComposition(fluidState, phaseIdx);
320 const Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
321 fluidState.setDensity(phaseIdx, rho);
322 const Scalar rhoMolar = FluidSystem::molarDensity(fluidState, phaseIdx);
323 fluidState.setMolarDensity(phaseIdx, rhoMolar);
324 const Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
325 fluidState.setViscosity(phaseIdx,mu);
326
327 // compute and set the enthalpy
328 Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
329 fluidState.setEnthalpy(phaseIdx, h);
330 }
331 }
332
336 const FluidState &fluidState() const
337 { return fluidState_; }
338
342 const SolidState &solidState() const
343 { return solidState_; }
344
350 Scalar averageMolarMass(int phaseIdx) const
351 { return fluidState_.averageMolarMass(phaseIdx); }
352
359 Scalar saturation(const int phaseIdx) const
360 { return fluidState_.saturation(phaseIdx); }
361
369 Scalar massFraction(const int phaseIdx, const int compIdx) const
370 { return fluidState_.massFraction(phaseIdx, compIdx); }
371
379 Scalar moleFraction(const int phaseIdx, const int compIdx) const
380 { return fluidState_.moleFraction(phaseIdx, compIdx); }
381
388 Scalar density(const int phaseIdx) const
389 { return fluidState_.density(phaseIdx); }
390
397 Scalar viscosity(const int phaseIdx) const
398 { return fluidState_.viscosity(phaseIdx); }
399
406 Scalar molarDensity(const int phaseIdx) const
407 { return fluidState_.molarDensity(phaseIdx) ; }
408
415 Scalar pressure(const int phaseIdx) const
416 { return fluidState_.pressure(phaseIdx); }
417
425 Scalar temperature() const
426 { return fluidState_.temperature(/*phaseIdx=*/0); }
427
434 Scalar relativePermeability(const int phaseIdx) const
435 { return relativePermeability_[phaseIdx]; }
436
443 Scalar mobility(const int phaseIdx) const
444 { return relativePermeability_[phaseIdx]/fluidState_.viscosity(phaseIdx); }
445
450 Scalar capillaryPressure() const
451 { return fluidState_.pressure(phase1Idx) - fluidState_.pressure(phase0Idx); }
452
456 Scalar porosity() const
457 { return solidState_.porosity(); }
458
462 const PermeabilityType& permeability() const
463 { return permeability_; }
464
468 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
469 {
470 typename FluidSystem::ParameterCache paramCache;
471 paramCache.updatePhase(fluidState_, phaseIdx);
472 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
473 }
474
478 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
479 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
480
481
485 int wettingPhase() const
486 { return fluidState_.wettingPhase(); }
487
488private:
489 FluidState fluidState_;
490 SolidState solidState_;
491 Scalar pc_; // The capillary pressure
492 PermeabilityType permeability_; // Effective permeability within the control volume
493
494 // Relative permeability within the control volume
495 std::array<Scalar, ModelTraits::numFluidPhases()> relativePermeability_;
496
497 // Effective diffusion coefficients for the phases
498 DiffusionCoefficients effectiveDiffCoeff_;
499};
500
501} // end namespace Dumux
502
503#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 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
The primary variable switch for the 2p2c-CO2 model controlling the phase presence state variable.
Definition: co2/primaryvariableswitch.hh:45
Contains the quantities which are are constant within a finite volume in the CO2 model.
Definition: porousmediumflow/co2/volumevariables.hh:53
Scalar massFraction(const int phaseIdx, const int compIdx) const
Returns the mass fraction of a given component in a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:369
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:342
typename Traits::FluidState FluidState
The type of the object returned by the fluidState() method.
Definition: porousmediumflow/co2/volumevariables.hh:97
Scalar saturation(const int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:359
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Completes the fluid state.
Definition: porousmediumflow/co2/volumevariables.hh:182
Scalar mobility(const int phaseIdx) const
Returns the effective mobility of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:443
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:478
Scalar porosity() const
Returns the average porosity within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:456
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/co2/volumevariables.hh:101
Scalar density(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:388
Scalar viscosity(const int phaseIdx) const
Returns the dynamic viscosity of the fluid within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:397
typename Traits::FluidSystem FluidSystem
The fluid system used here.
Definition: porousmediumflow/co2/volumevariables.hh:99
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/co2/volumevariables.hh:485
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/co2/volumevariables.hh:103
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/co2/volumevariables.hh:105
Scalar temperature() const
Returns temperature within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:425
Scalar pressure(const int phaseIdx) const
Returns the effective pressure of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:415
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/co2/volumevariables.hh:111
const PermeabilityType & permeability() const
Returns the average permeability within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:462
const FluidState & fluidState() const
Returns the phase state within the control volume.
Definition: porousmediumflow/co2/volumevariables.hh:336
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/co2/volumevariables.hh:130
Scalar molarDensity(const int phaseIdx) const
Returns the mass density of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:406
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/co2/volumevariables.hh:350
Scalar moleFraction(const int phaseIdx, const int compIdx) const
Returns the mole fraction of a given component in a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:379
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/co2/volumevariables.hh:113
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/co2/volumevariables.hh:468
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:450
Scalar relativePermeability(const int phaseIdx) const
Returns the relative permeability of a given phase within the control volume in .
Definition: porousmediumflow/co2/volumevariables.hh:434
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.