3.3.0
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/2pnc/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_2PNC_VOLUME_VARIABLES_HH
27#define DUMUX_2PNC_VOLUME_VARIABLES_HH
28
29#include <iostream>
30#include <vector>
31
32#include <dumux/common/math.hh>
34
37
42
44
46
48
49namespace Dumux {
50
56template <class Traits>
59, public EnergyVolumeVariables<Traits, TwoPNCVolumeVariables<Traits> >
60{
63 using Scalar = typename Traits::PrimaryVariables::value_type;
64 using PermeabilityType = typename Traits::PermeabilityType;
65 using FS = typename Traits::FluidSystem;
66 using ModelTraits = typename Traits::ModelTraits;
67 static constexpr int numFluidComps = ParentType::numFluidComponents();
68 enum
69 {
70 numMajorComponents = ModelTraits::numFluidPhases(),
71
72 // phase indices
73 phase0Idx = FS::phase0Idx,
74 phase1Idx = FS::phase1Idx,
75
76 // component indices
77 comp0Idx = FS::comp0Idx,
78 comp1Idx = FS::comp1Idx,
79
80 // phase presence enums
81 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
82 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
83 bothPhases = ModelTraits::Indices::bothPhases,
84
85 // primary variable indices
86 pressureIdx = ModelTraits::Indices::pressureIdx,
87 switchIdx = ModelTraits::Indices::switchIdx
88 };
89
90 static constexpr auto formulation = ModelTraits::priVarFormulation();
91 static constexpr bool setFirstPhaseMoleFractions = ModelTraits::setMoleFractionsForFirstPhase();
92
95 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
96 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
97
98public:
100 using FluidState = typename Traits::FluidState;
102 using FluidSystem = typename Traits::FluidSystem;
104 using Indices = typename ModelTraits::Indices;
106 using SolidState = typename Traits::SolidState;
108 using SolidSystem = typename Traits::SolidSystem;
111
113 static constexpr bool useMoles() { return Traits::ModelTraits::useMoles(); }
115 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
116
117 // check for permissive specifications
118 static_assert(useMoles(), "use moles has to be set true in the 2pnc model");
119 static_assert(ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
120 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
121
131 template<class ElemSol, class Problem, class Element, class Scv>
132 void update(const ElemSol &elemSol,
133 const Problem &problem,
134 const Element &element,
135 const Scv& scv)
136 {
137 ParentType::update(elemSol, problem, element, scv);
138
139 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
140
142 // calculate the remaining quantities
144
145
146 // old material law interface is deprecated: Replace this by
147 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
148 // after the release of 3.3, when the deprecated interface is no longer supported
149 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
150
151 const int wPhaseIdx = fluidState_.wettingPhase();
152 const int nPhaseIdx = 1 - wPhaseIdx;
153
154 // mobilities -> require wetting phase saturation as parameter!
155 mobility_[wPhaseIdx] = fluidMatrixInteraction.krw(saturation(wPhaseIdx))/fluidState_.viscosity(wPhaseIdx);
156 mobility_[nPhaseIdx] = fluidMatrixInteraction.krn(saturation(wPhaseIdx))/fluidState_.viscosity(nPhaseIdx);
157
158 //update porosity before calculating the effective properties depending on it
159 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
160
161 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
162 {
163 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
164 };
165
166 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
167
168 // calculate the remaining quantities
169 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
170 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
171 EnergyVolVars::updateEffectiveThermalConductivity();
172 }
173
186 template<class ElemSol, class Problem, class Element, class Scv>
187 void completeFluidState(const ElemSol& elemSol,
188 const Problem& problem,
189 const Element& element,
190 const Scv& scv,
193 {
194 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
195
196 const auto& priVars = elemSol[scv.localDofIndex()];
197 const auto phasePresence = priVars.state();
198
199 // old material law interface is deprecated: Replace this by
200 // const auto& fluidMatrixInteraction = spatialParams.fluidMatrixInteraction(element, scv, elemSol);
201 // after the release of 3.3, when the deprecated interface is no longer supported
202 const auto fluidMatrixInteraction = Deprecated::makePcKrSw(Scalar{}, problem.spatialParams(), element, scv, elemSol);
203
204 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
205 fluidState.setWettingPhase(wPhaseIdx);
206
207 // set the saturations
208 if (phasePresence == secondPhaseOnly)
209 {
210 fluidState.setSaturation(phase0Idx, 0.0);
211 fluidState.setSaturation(phase1Idx, 1.0);
212 }
213 else if (phasePresence == firstPhaseOnly)
214 {
215 fluidState.setSaturation(phase0Idx, 1.0);
216 fluidState.setSaturation(phase1Idx, 0.0);
217 }
218 else if (phasePresence == bothPhases)
219 {
220 if (formulation == TwoPFormulation::p0s1)
221 {
222 fluidState.setSaturation(phase1Idx, priVars[switchIdx]);
223 fluidState.setSaturation(phase0Idx, 1 - priVars[switchIdx]);
224 }
225 else
226 {
227 fluidState.setSaturation(phase0Idx, priVars[switchIdx]);
228 fluidState.setSaturation(phase1Idx, 1 - priVars[switchIdx]);
229 }
230 }
231 else
232 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
233
234 // set pressures of the fluid phases
235 pc_ = fluidMatrixInteraction.pc(fluidState.saturation(wPhaseIdx));
236 if (formulation == TwoPFormulation::p0s1)
237 {
238 fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
239 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] + pc_
240 : priVars[pressureIdx] - pc_);
241 }
242 else
243 {
244 fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
245 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] - pc_
246 : priVars[pressureIdx] + pc_);
247 }
248
249 // calculate the phase compositions
250 typename FluidSystem::ParameterCache paramCache;
251
252 // now comes the tricky part: calculate phase composition
253 if (phasePresence == bothPhases)
254 {
255 // both phases are present, phase composition results from
256 // the first <-> second phase equilibrium. This is the job
257 // of the "MiscibleMultiPhaseComposition" constraint solver
258
259 // set the known mole fractions in the fluidState so that they
260 // can be used by the MiscibleMultiPhaseComposition constraint solver
261
262 const int knownPhaseIdx = setFirstPhaseMoleFractions ? phase0Idx : phase1Idx;
263 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
264 fluidState.setMoleFraction(knownPhaseIdx, compIdx, priVars[compIdx]);
265
267 paramCache,
268 knownPhaseIdx);
269 }
270 else if (phasePresence == secondPhaseOnly)
271 {
272 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
273
274 moleFrac[comp0Idx] = priVars[switchIdx];
275 Scalar sumMoleFracOtherComponents = moleFrac[comp0Idx];
276
277 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
278 {
279 moleFrac[compIdx] = priVars[compIdx];
280 sumMoleFracOtherComponents += moleFrac[compIdx];
281 }
282
283 moleFrac[comp1Idx] = 1 - sumMoleFracOtherComponents;
284
285 // Set fluid state mole fractions
286 for (int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
287 fluidState.setMoleFraction(phase1Idx, compIdx, moleFrac[compIdx]);
288
289 // calculate the composition of the remaining phases (as
290 // well as the densities of all phases). this is the job
291 // of the "ComputeFromReferencePhase" constraint solver
293 paramCache,
294 phase1Idx);
295 }
296 else if (phasePresence == firstPhaseOnly)
297 {
298 // only the first phase is present, i.e. first phase composition
299 // is stored explicitly. extract _mass_ fractions in the second phase
300 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
301
302 moleFrac[comp1Idx] = priVars[switchIdx];
303 Scalar sumMoleFracOtherComponents = moleFrac[comp1Idx];
304 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
305 {
306 moleFrac[compIdx] = priVars[compIdx];
307
308 sumMoleFracOtherComponents += moleFrac[compIdx];
309 }
310
311 moleFrac[comp0Idx] = 1 - sumMoleFracOtherComponents;
312
313 // convert mass to mole fractions and set the fluid state
314 for (int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
315 fluidState.setMoleFraction(phase0Idx, compIdx, moleFrac[compIdx]);
316
317 // calculate the composition of the remaining phases (as
318 // well as the densities of all phases). this is the job
319 // of the "ComputeFromReferencePhase" constraint solver
321 paramCache,
322 phase0Idx);
323 }
324 paramCache.updateAll(fluidState);
325 for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
326 {
327 Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
328 Scalar rhoMolar = FluidSystem::molarDensity(fluidState, paramCache, phaseIdx);
329 Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
330 Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
331
332 fluidState.setDensity(phaseIdx, rho);
333 fluidState.setMolarDensity(phaseIdx, rhoMolar);
334 fluidState.setViscosity(phaseIdx, mu);
335 fluidState.setEnthalpy(phaseIdx, h);
336 }
337 }
338
342 const FluidState &fluidState() const
343 { return fluidState_; }
344
348 const SolidState &solidState() const
349 { return solidState_; }
350
356 Scalar averageMolarMass(int phaseIdx) const
357 { return fluidState_.averageMolarMass(phaseIdx); }
358
365 Scalar saturation(int phaseIdx) const
366 { return fluidState_.saturation(phaseIdx); }
367
374 Scalar density(int phaseIdx) const
375 { return fluidState_.density(phaseIdx); }
376
383 Scalar viscosity(int phaseIdx) const
384 { return fluidState_.viscosity(phaseIdx); }
385
392 Scalar molarDensity(int phaseIdx) const
393 {
394 if (phaseIdx < ModelTraits::numFluidPhases())
395 return fluidState_.molarDensity(phaseIdx);
396
397 else
398 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
399 }
400
407 Scalar pressure(int phaseIdx) const
408 { return fluidState_.pressure(phaseIdx); }
409
417 Scalar temperature() const
418 { return fluidState_.temperature(/*phaseIdx=*/0); }
419
426 Scalar mobility(int phaseIdx) const
427 { return mobility_[phaseIdx]; }
428
433 Scalar capillaryPressure() const
434 { return pc_; }
435
439 Scalar porosity() const
440 { return solidState_.porosity(); }
441
445 const PermeabilityType& permeability() const
446 { return permeability_; }
447
451 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
452 {
453 typename FluidSystem::ParameterCache paramCache;
454 paramCache.updatePhase(fluidState_, phaseIdx);
455 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
456 }
457
461 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
462 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
463
470 Scalar massFraction(int phaseIdx, int compIdx) const
471 { return fluidState_.massFraction(phaseIdx, compIdx); }
472
479 Scalar moleFraction(int phaseIdx, int compIdx) const
480 { return fluidState_.moleFraction(phaseIdx, compIdx); }
481
485 int wettingPhase() const
486 { return fluidState_.wettingPhase(); }
487
488protected:
491
492private:
493
494 Scalar pc_; // The capillary pressure
495 Scalar porosity_; // Effective porosity within the control volume
496 PermeabilityType permeability_; // Effective permeability within the control volume
497 Scalar mobility_[ModelTraits::numFluidPhases()]; // Effective mobility within the control volume
498 DiffusionCoefficients effectiveDiffCoeff_;
499
500};
501
502} // end namespace Dumux
503
504#endif
Helpers for deprecation.
Define some often used mathematical functions.
The available discretization methods in Dumux.
Computes all quantities of a generic fluid state if a reference phase has been specified.
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Represents all relevant thermodynamic quantities of a multi-phase, multi-component fluid system assum...
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
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: computefromreferencephase.hh:76
static void solve(FluidState &fluidState, ParameterCache &paramCache, int refPhaseIdx)
Computes all quantities of a generic fluid state if a reference phase has been specified.
Definition: computefromreferencephase.hh:111
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:59
static void solve(FluidState &fluidState, ParameterCache &paramCache, int knownPhaseIdx=0)
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:81
The primary variable switch controlling the phase presence state variable.
Definition: 2pnc/primaryvariableswitch.hh:41
Contains the quantities which are are constant within a finite volume in the two-phase,...
Definition: porousmediumflow/2pnc/volumevariables.hh:60
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:439
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:451
Scalar molarDensity(int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:392
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2pnc/volumevariables.hh:115
Scalar viscosity(int phaseIdx) const
Returns the kinematic viscosity of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:383
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:433
Scalar density(int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:374
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:132
const SolidState & solidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:348
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:479
typename ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/2pnc/volumevariables.hh:104
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:106
Scalar saturation(int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:365
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2pnc/volumevariables.hh:108
const PermeabilityType & permeability() const
Returns the permeability within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:445
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:461
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:417
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:356
SolidState solidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:490
FluidState fluidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:489
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition: porousmediumflow/2pnc/volumevariables.hh:102
typename Traits::FluidState FluidState
Export fluid state type.
Definition: porousmediumflow/2pnc/volumevariables.hh:100
void completeFluidState(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv, FluidState &fluidState, SolidState &solidState)
Sets complete fluid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:187
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2pnc/volumevariables.hh:485
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:470
Scalar pressure(int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:407
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/2pnc/volumevariables.hh:113
Scalar mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:426
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:342
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.