3.2-git
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
47namespace Dumux {
48
54template <class Traits>
57, public EnergyVolumeVariables<Traits, TwoPNCVolumeVariables<Traits> >
58{
61 using Scalar = typename Traits::PrimaryVariables::value_type;
62 using PermeabilityType = typename Traits::PermeabilityType;
63 using FS = typename Traits::FluidSystem;
64 using ModelTraits = typename Traits::ModelTraits;
65 static constexpr int numFluidComps = ParentType::numFluidComponents();
66 enum
67 {
68 numMajorComponents = ModelTraits::numFluidPhases(),
69
70 // phase indices
71 phase0Idx = FS::phase0Idx,
72 phase1Idx = FS::phase1Idx,
73
74 // component indices
75 comp0Idx = FS::comp0Idx,
76 comp1Idx = FS::comp1Idx,
77
78 // phase presence enums
79 secondPhaseOnly = ModelTraits::Indices::secondPhaseOnly,
80 firstPhaseOnly = ModelTraits::Indices::firstPhaseOnly,
81 bothPhases = ModelTraits::Indices::bothPhases,
82
83 // primary variable indices
84 pressureIdx = ModelTraits::Indices::pressureIdx,
85 switchIdx = ModelTraits::Indices::switchIdx
86 };
87
88 static constexpr auto formulation = ModelTraits::priVarFormulation();
89 static constexpr bool setFirstPhaseMoleFractions = ModelTraits::setMoleFractionsForFirstPhase();
90
93 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
94 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
95
96public:
98 using FluidState = typename Traits::FluidState;
100 using FluidSystem = typename Traits::FluidSystem;
102 using SolidState = typename Traits::SolidState;
104 using SolidSystem = typename Traits::SolidSystem;
107
109 static constexpr bool useMoles() { return Traits::ModelTraits::useMoles(); }
111 static constexpr TwoPFormulation priVarFormulation() { return formulation; }
112
113 // check for permissive specifications
114 static_assert(useMoles(), "use moles has to be set true in the 2pnc model");
115 static_assert(ModelTraits::numFluidPhases() == 2, "NumPhases set in the model is not two!");
116 static_assert((formulation == TwoPFormulation::p0s1 || formulation == TwoPFormulation::p1s0), "Chosen TwoPFormulation not supported!");
117
127 template<class ElemSol, class Problem, class Element, class Scv>
128 void update(const ElemSol &elemSol,
129 const Problem &problem,
130 const Element &element,
131 const Scv& scv)
132 {
133 ParentType::update(elemSol, problem, element, scv);
134
135 completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
136
138 // calculate the remaining quantities
140
141 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
142 const auto& matParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
143 const int wPhaseIdx = fluidState_.wettingPhase();
144 const int nPhaseIdx = 1 - wPhaseIdx;
145
146 // mobilities -> require wetting phase saturation as parameter!
147 mobility_[wPhaseIdx] = MaterialLaw::krw(matParams, saturation(wPhaseIdx))/fluidState_.viscosity(wPhaseIdx);
148 mobility_[nPhaseIdx] = MaterialLaw::krn(matParams, saturation(wPhaseIdx))/fluidState_.viscosity(nPhaseIdx);
149
150 //update porosity before calculating the effective properties depending on it
151 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
152
153 auto getEffectiveDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
154 {
155 return EffDiffModel::effectiveDiffusionCoefficient(*this, phaseIdx, compIIdx, compJIdx);
156 };
157
158 effectiveDiffCoeff_.update(getEffectiveDiffusionCoefficient);
159
160 // calculate the remaining quantities
161 EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
162 permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
163 EnergyVolVars::updateEffectiveThermalConductivity();
164 }
165
178 template<class ElemSol, class Problem, class Element, class Scv>
179 void completeFluidState(const ElemSol& elemSol,
180 const Problem& problem,
181 const Element& element,
182 const Scv& scv,
185 {
186 EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
187
188 const auto& priVars = elemSol[scv.localDofIndex()];
189 const auto phasePresence = priVars.state();
190
191 using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
192 const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
193 const auto wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
194 fluidState.setWettingPhase(wPhaseIdx);
195
196 // set the saturations
197 if (phasePresence == secondPhaseOnly)
198 {
199 fluidState.setSaturation(phase0Idx, 0.0);
200 fluidState.setSaturation(phase1Idx, 1.0);
201 }
202 else if (phasePresence == firstPhaseOnly)
203 {
204 fluidState.setSaturation(phase0Idx, 1.0);
205 fluidState.setSaturation(phase1Idx, 0.0);
206 }
207 else if (phasePresence == bothPhases)
208 {
209 if (formulation == TwoPFormulation::p0s1)
210 {
211 fluidState.setSaturation(phase1Idx, priVars[switchIdx]);
212 fluidState.setSaturation(phase0Idx, 1 - priVars[switchIdx]);
213 }
214 else
215 {
216 fluidState.setSaturation(phase0Idx, priVars[switchIdx]);
217 fluidState.setSaturation(phase1Idx, 1 - priVars[switchIdx]);
218 }
219 }
220 else
221 DUNE_THROW(Dune::InvalidStateException, "phasePresence: " << phasePresence << " is invalid.");
222
223 // set pressures of the fluid phases
224 pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
225 if (formulation == TwoPFormulation::p0s1)
226 {
227 fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
228 fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] + pc_
229 : priVars[pressureIdx] - pc_);
230 }
231 else
232 {
233 fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
234 fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] - pc_
235 : priVars[pressureIdx] + pc_);
236 }
237
238 // calculate the phase compositions
239 typename FluidSystem::ParameterCache paramCache;
240
241 // now comes the tricky part: calculate phase composition
242 if (phasePresence == bothPhases)
243 {
244 // both phases are present, phase composition results from
245 // the first <-> second phase equilibrium. This is the job
246 // of the "MiscibleMultiPhaseComposition" constraint solver
247
248 // set the known mole fractions in the fluidState so that they
249 // can be used by the MiscibleMultiPhaseComposition constraint solver
250
251 const int knownPhaseIdx = setFirstPhaseMoleFractions ? phase0Idx : phase1Idx;
252 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
253 fluidState.setMoleFraction(knownPhaseIdx, compIdx, priVars[compIdx]);
254
256 paramCache,
257 knownPhaseIdx);
258 }
259 else if (phasePresence == secondPhaseOnly)
260 {
261
262 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
263
264 moleFrac[comp0Idx] = priVars[switchIdx];
265 Scalar sumMoleFracOtherComponents = moleFrac[comp0Idx];
266
267 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
268 {
269 moleFrac[compIdx] = priVars[compIdx];
270 sumMoleFracOtherComponents += moleFrac[compIdx];
271 }
272
273 moleFrac[comp1Idx] = 1 - sumMoleFracOtherComponents;
274
275 // Set fluid state mole fractions
276 for (int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
277 fluidState.setMoleFraction(phase1Idx, compIdx, moleFrac[compIdx]);
278
279 // calculate the composition of the remaining phases (as
280 // well as the densities of all phases). this is the job
281 // of the "ComputeFromReferencePhase" constraint solver
283 paramCache,
284 phase1Idx);
285 }
286 else if (phasePresence == firstPhaseOnly)
287 {
288 // only the first phase is present, i.e. first phase composition
289 // is stored explicitly. extract _mass_ fractions in the second phase
290 Dune::FieldVector<Scalar, ModelTraits::numFluidComponents()> moleFrac;
291
292 moleFrac[comp1Idx] = priVars[switchIdx];
293 Scalar sumMoleFracOtherComponents = moleFrac[comp1Idx];
294 for (int compIdx = numMajorComponents; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
295 {
296 moleFrac[compIdx] = priVars[compIdx];
297
298 sumMoleFracOtherComponents += moleFrac[compIdx];
299 }
300
301 moleFrac[comp0Idx] = 1 - sumMoleFracOtherComponents;
302
303 // convert mass to mole fractions and set the fluid state
304 for (int compIdx = 0; compIdx < ModelTraits::numFluidComponents(); ++compIdx)
305 fluidState.setMoleFraction(phase0Idx, compIdx, moleFrac[compIdx]);
306
307 // calculate the composition of the remaining phases (as
308 // well as the densities of all phases). this is the job
309 // of the "ComputeFromReferencePhase" constraint solver
311 paramCache,
312 phase0Idx);
313 }
314 paramCache.updateAll(fluidState);
315 for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx)
316 {
317 Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
318 Scalar rhoMolar = FluidSystem::molarDensity(fluidState, paramCache, phaseIdx);
319 Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
320 Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
321
322 fluidState.setDensity(phaseIdx, rho);
323 fluidState.setMolarDensity(phaseIdx, rhoMolar);
324 fluidState.setViscosity(phaseIdx, mu);
325 fluidState.setEnthalpy(phaseIdx, h);
326 }
327 }
328
332 const FluidState &fluidState() const
333 { return fluidState_; }
334
338 const SolidState &solidState() const
339 { return solidState_; }
340
346 Scalar averageMolarMass(int phaseIdx) const
347 { return fluidState_.averageMolarMass(phaseIdx); }
348
355 Scalar saturation(int phaseIdx) const
356 { return fluidState_.saturation(phaseIdx); }
357
364 Scalar density(int phaseIdx) const
365 { return fluidState_.density(phaseIdx); }
366
373 Scalar viscosity(int phaseIdx) const
374 { return fluidState_.viscosity(phaseIdx); }
375
382 Scalar molarDensity(int phaseIdx) const
383 {
384 if (phaseIdx < ModelTraits::numFluidPhases())
385 return fluidState_.molarDensity(phaseIdx);
386
387 else
388 DUNE_THROW(Dune::InvalidStateException, "Invalid phase index " << phaseIdx);
389 }
390
397 Scalar pressure(int phaseIdx) const
398 { return fluidState_.pressure(phaseIdx); }
399
407 Scalar temperature() const
408 { return fluidState_.temperature(/*phaseIdx=*/0); }
409
416 Scalar mobility(int phaseIdx) const
417 { return mobility_[phaseIdx]; }
418
423 Scalar capillaryPressure() const
424 { return pc_; }
425
429 Scalar porosity() const
430 { return solidState_.porosity(); }
431
435 const PermeabilityType& permeability() const
436 { return permeability_; }
437
438
442 [[deprecated("Will be removed after release 3.2. Use diffusionCoefficient(phaseIdx, compIIdx, compJIdx)!")]]
443 Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
444 {
445 if (compIdx != phaseIdx)
446 return diffusionCoefficient(phaseIdx, FluidSystem::getMainComponent(phaseIdx), compIdx);
447 else
448 DUNE_THROW(Dune::InvalidStateException, "Diffusion coefficient called for phaseIdx = compIdx");
449 }
450
454 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
455 {
456 typename FluidSystem::ParameterCache paramCache;
457 paramCache.updatePhase(fluidState_, phaseIdx);
458 return FluidSystem::binaryDiffusionCoefficient(fluidState_, paramCache, phaseIdx, compIIdx, compJIdx);
459 }
460
464 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
465 { return effectiveDiffCoeff_(phaseIdx, compIIdx, compJIdx); }
466
473 Scalar massFraction(int phaseIdx, int compIdx) const
474 { return fluidState_.massFraction(phaseIdx, compIdx); }
475
482 Scalar moleFraction(int phaseIdx, int compIdx) const
483 { return fluidState_.moleFraction(phaseIdx, compIdx); }
484
488 int wettingPhase() const
489 { return fluidState_.wettingPhase(); }
490
491protected:
494
495private:
496
497 Scalar pc_; // The capillary pressure
498 Scalar porosity_; // Effective porosity within the control volume
499 PermeabilityType permeability_; // Effective permeability within the control volume
500 Scalar mobility_[ModelTraits::numFluidPhases()]; // Effective mobility within the control volume
501 DiffusionCoefficients effectiveDiffCoeff_;
502
503};
504
505} // end namespace Dumux
506
507#endif
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:77
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:112
Computes the composition of all phases of a N-phase, N-component fluid system assuming that all N pha...
Definition: misciblemultiphasecomposition.hh:60
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:82
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:58
Scalar porosity() const
Returns the average porosity within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:429
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:454
Scalar molarDensity(int phaseIdx) const
Returns the molar density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:382
static constexpr TwoPFormulation priVarFormulation()
Return the two-phase formulation used here.
Definition: porousmediumflow/2pnc/volumevariables.hh:111
Scalar viscosity(int phaseIdx) const
Returns the kinematic viscosity of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:373
Scalar capillaryPressure() const
Returns the effective capillary pressure within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:423
Scalar density(int phaseIdx) const
Returns the mass density of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:364
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:128
const SolidState & solidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:338
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:482
typename Traits::SolidState SolidState
Export type of solid state.
Definition: porousmediumflow/2pnc/volumevariables.hh:102
Scalar saturation(int phaseIdx) const
Returns the saturation of a given phase within the control volume in .
Definition: porousmediumflow/2pnc/volumevariables.hh:355
typename Traits::SolidSystem SolidSystem
Export type of solid system.
Definition: porousmediumflow/2pnc/volumevariables.hh:104
const PermeabilityType & permeability() const
Returns the permeability within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:435
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/2pnc/volumevariables.hh:464
Scalar temperature() const
Returns temperature inside the sub-control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:407
Scalar averageMolarMass(int phaseIdx) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:346
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the diffusion coefficient.
Definition: porousmediumflow/2pnc/volumevariables.hh:443
SolidState solidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:493
FluidState fluidState_
Definition: porousmediumflow/2pnc/volumevariables.hh:492
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition: porousmediumflow/2pnc/volumevariables.hh:100
typename Traits::FluidState FluidState
Export fluid state type.
Definition: porousmediumflow/2pnc/volumevariables.hh:98
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:179
int wettingPhase() const
Returns the wetting phase index.
Definition: porousmediumflow/2pnc/volumevariables.hh:488
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/2pnc/volumevariables.hh:473
Scalar pressure(int phaseIdx) const
Returns the effective pressure of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:397
static constexpr bool useMoles()
Return whether moles or masses are balanced.
Definition: porousmediumflow/2pnc/volumevariables.hh:109
Scalar mobility(int phaseIdx) const
Returns the effective mobility of a given phase within the control volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:416
const FluidState & fluidState() const
Returns the phase state for the control-volume.
Definition: porousmediumflow/2pnc/volumevariables.hh:332
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.