3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
porousmediumflow/tracer/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 *****************************************************************************/
24#ifndef DUMUX_TRACER_VOLUME_VARIABLES_HH
25#define DUMUX_TRACER_VOLUME_VARIABLES_HH
26
27#include <cassert>
28#include <array>
29#include <type_traits>
30
31#include <dune/common/std/type_traits.hh>
32
35
36namespace Dumux {
37
38namespace Detail {
39// helper structs and functions detecting if the user-defined spatial params class
40// has user-specified functions saturation() for multi-phase tracer.
41template <typename T, typename ...Ts>
42using SaturationDetector = decltype(std::declval<T>().spatialParams().saturation(std::declval<Ts>()...));
43
44template<class T, typename ...Args>
45static constexpr bool hasSaturation()
46{ return Dune::Std::is_detected<SaturationDetector, T, Args...>::value; }
47
48} // end namespace Detail
49
55template <class Traits>
58{
60 using Scalar = typename Traits::PrimaryVariables::value_type;
61 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
62 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
63 static constexpr int numFluidComps = ParentType::numFluidComponents();
64
65public:
67 using FluidSystem = typename Traits::FluidSystem;
68 using SolidState = typename Traits::SolidState;
69
79 template<class ElemSol, class Problem, class Element, class Scv>
80 void update(const ElemSol &elemSol,
81 const Problem &problem,
82 const Element &element,
83 const Scv &scv)
84 {
85 // update parent type sets primary variables
86 ParentType::update(elemSol, problem, element, scv);
87
88 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
89
90 // the spatial params special to the tracer model
91 fluidDensity_ = problem.spatialParams().fluidDensity(element, scv);
92 fluidMolarMass_ = problem.spatialParams().fluidMolarMass(element, scv);
93
94 if constexpr (Detail::hasSaturation<Problem, Element, Scv>())
95 fluidSaturation_ = problem.spatialParams().saturation(element, scv);
96
97 for (int compIdx = 0; compIdx < ParentType::numFluidComponents(); ++compIdx)
98 {
99 moleOrMassFraction_[compIdx] = this->priVars()[compIdx];
100 diffCoeff_[compIdx] = FluidSystem::binaryDiffusionCoefficient(compIdx, problem, element, scv);
101 effectiveDiffCoeff_[compIdx] = EffDiffModel::effectiveDiffusionCoefficient(*this, 0, 0, compIdx);
102 }
103 }
104
112 Scalar density(int phaseIdx = 0) const
113 { return fluidDensity_; }
114
120 Scalar averageMolarMass(int phaseIdx = 0) const
121 { return fluidMolarMass_; }
122
126 const SolidState &solidState() const
127 { return solidState_; }
128
139 Scalar saturation(int phaseIdx = 0) const
140 { return fluidSaturation_ ; }
141
150 Scalar mobility(int phaseIdx = 0) const
151 { return 1.0; }
152
158 Scalar molarDensity(int phaseIdx = 0) const
160
167 Scalar moleFraction(int phaseIdx, int compIdx) const
168 { return useMoles ? moleOrMassFraction_[compIdx] : moleOrMassFraction_[compIdx]/FluidSystem::molarMass(compIdx)*fluidMolarMass_; }
169
176 Scalar massFraction(int phaseIdx, int compIdx) const
177 { return useMoles ? moleOrMassFraction_[compIdx]*FluidSystem::molarMass(compIdx)/fluidMolarMass_ : moleOrMassFraction_[compIdx]; }
178
185 Scalar molarity(int phaseIdx, int compIdx) const
186 { return moleFraction(phaseIdx, compIdx)*molarDensity(); }
187
191 [[deprecated("Will be removed after release 3.2. Use diffusionCoefficient(phaseIdx, compIIdx, compJIdx)!")]]
192 Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
193 { return diffCoeff_[compIdx]; }
194
198 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
199 {
200 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
201 assert(phaseIdx == 0);
202 assert(phaseIdx == compIIdx);
203 return diffCoeff_[compJIdx]; }
204
208 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
209 {
210 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
211 assert(phaseIdx == 0);
212 assert(phaseIdx == compIIdx);
213 return effectiveDiffCoeff_[compJIdx];
214 }
215
219 Scalar porosity() const
220 { return solidState_.porosity(); }
221
222protected:
225 Scalar fluidSaturation_ = 1.0;
226
227 std::array<Scalar, numFluidComps> diffCoeff_;
228 std::array<Scalar, numFluidComps> effectiveDiffCoeff_;
229 std::array<Scalar, numFluidComps> moleOrMassFraction_;
230};
231
232} // end namespace Dumux
233
234#endif
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.
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
decltype(std::declval< T >().spatialParams().saturation(std::declval< Ts >()...)) SaturationDetector
Definition: porousmediumflow/tracer/volumevariables.hh:42
static constexpr bool hasSaturation()
Definition: porousmediumflow/tracer/volumevariables.hh:45
Contains the quantities which are constant within a finite volume for the tracer model.
Definition: porousmediumflow/tracer/volumevariables.hh:58
Scalar averageMolarMass(int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:120
Scalar diffusionCoefficient(int phaseIdx, int compIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/tracer/volumevariables.hh:192
typename Traits::FluidSystem FluidSystem
Export fluid system type.
Definition: porousmediumflow/tracer/volumevariables.hh:67
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:167
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:176
std::array< Scalar, numFluidComps > effectiveDiffCoeff_
Definition: porousmediumflow/tracer/volumevariables.hh:228
Scalar molarDensity(int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:158
std::array< Scalar, numFluidComps > moleOrMassFraction_
Definition: porousmediumflow/tracer/volumevariables.hh:229
typename Traits::SolidState SolidState
Definition: porousmediumflow/tracer/volumevariables.hh:68
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/tracer/volumevariables.hh:208
Scalar fluidDensity_
Definition: porousmediumflow/tracer/volumevariables.hh:224
SolidState solidState_
Definition: porousmediumflow/tracer/volumevariables.hh:223
Scalar density(int phaseIdx=0) const
Returns the density the of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:112
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/tracer/volumevariables.hh:126
Scalar mobility(int phaseIdx=0) const
Returns the mobility.
Definition: porousmediumflow/tracer/volumevariables.hh:150
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/tracer/volumevariables.hh:198
Scalar saturation(int phaseIdx=0) const
Returns the saturation.
Definition: porousmediumflow/tracer/volumevariables.hh:139
void update(const ElemSol &elemSol, const Problem &problem, const Element &element, const Scv &scv)
Updates all quantities for a given control volume.
Definition: porousmediumflow/tracer/volumevariables.hh:80
Scalar porosity() const
Return the average porosity within the control volume.
Definition: porousmediumflow/tracer/volumevariables.hh:219
Scalar fluidSaturation_
Definition: porousmediumflow/tracer/volumevariables.hh:225
Scalar fluidMolarMass_
Definition: porousmediumflow/tracer/volumevariables.hh:224
Scalar molarity(int phaseIdx, int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:185
std::array< Scalar, numFluidComps > diffCoeff_
Definition: porousmediumflow/tracer/volumevariables.hh:227
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.