version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_TRACER_VOLUME_VARIABLES_HH
13#define DUMUX_TRACER_VOLUME_VARIABLES_HH
14
15#include <cassert>
16#include <array>
17#include <type_traits>
18
19#include <dune/common/std/type_traits.hh>
20
23
24namespace Dumux {
25
26namespace Detail {
27// helper structs and functions detecting if the user-defined spatial params class
28// has user-specified functions saturation() for multi-phase tracer.
29template <typename T, typename ...Ts>
30using SaturationDetector = decltype(std::declval<T>().spatialParams().saturation(std::declval<Ts>()...));
31
32template<class T, typename ...Args>
33static constexpr bool hasSaturation()
34{ return Dune::Std::is_detected<SaturationDetector, T, Args...>::value; }
35
36} // end namespace Detail
37
43template <class Traits>
46{
48 using Scalar = typename Traits::PrimaryVariables::value_type;
49 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
50 using EffDiffModel = typename Traits::EffectiveDiffusivityModel;
51 static constexpr int numFluidComps = ParentType::numFluidComponents();
52
53public:
55 using FluidSystem = typename Traits::FluidSystem;
57 using SolidState = typename Traits::SolidState;
59 using Indices = typename Traits::ModelTraits::Indices;
60
70 template<class ElemSol, class Problem, class Element, class Scv>
71 void update(const ElemSol &elemSol,
72 const Problem &problem,
73 const Element &element,
74 const Scv &scv)
75 {
76 // update parent type sets primary variables
77 ParentType::update(elemSol, problem, element, scv);
78
79 updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
80
81 // the spatial params special to the tracer model
82 fluidDensity_ = problem.spatialParams().fluidDensity(element, scv);
83 fluidMolarMass_ = problem.spatialParams().fluidMolarMass(element, scv);
84
85 if constexpr (Detail::hasSaturation<Problem, Element, Scv>())
86 fluidSaturation_ = problem.spatialParams().saturation(element, scv);
87
88 for (int compIdx = 0; compIdx < ParentType::numFluidComponents(); ++compIdx)
89 {
90 moleOrMassFraction_[compIdx] = this->priVars()[compIdx];
91 diffCoeff_[compIdx] = FluidSystem::binaryDiffusionCoefficient(compIdx, problem, element, scv);
92 effectiveDiffCoeff_[compIdx] = EffDiffModel::effectiveDiffusionCoefficient(*this, 0, 0, compIdx);
93 }
94 }
95
103 Scalar density(int phaseIdx = 0) const
104 { return fluidDensity_; }
105
111 Scalar averageMolarMass(int phaseIdx = 0) const
112 { return fluidMolarMass_; }
113
117 const SolidState &solidState() const
118 { return solidState_; }
119
130 Scalar saturation(int phaseIdx = 0) const
131 { return fluidSaturation_ ; }
132
141 Scalar mobility(int phaseIdx = 0) const
142 { return 1.0; }
143
149 Scalar molarDensity(int phaseIdx = 0) const
151
158 Scalar moleFraction(int phaseIdx, int compIdx) const
159 { return useMoles ? moleOrMassFraction_[compIdx] : moleOrMassFraction_[compIdx]/FluidSystem::molarMass(compIdx)*fluidMolarMass_; }
160
167 Scalar massFraction(int phaseIdx, int compIdx) const
168 { return useMoles ? moleOrMassFraction_[compIdx]*FluidSystem::molarMass(compIdx)/fluidMolarMass_ : moleOrMassFraction_[compIdx]; }
169
176 Scalar molarity(int phaseIdx, int compIdx) const
177 { return moleFraction(phaseIdx, compIdx)*molarDensity(); }
178
182 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
183 {
184 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
185 assert(phaseIdx == 0);
186 assert(phaseIdx == compIIdx);
187 return diffCoeff_[compJIdx]; }
188
192 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
193 {
194 if (phaseIdx != compIIdx) std::swap(compIIdx, compJIdx);
195 assert(phaseIdx == 0);
196 assert(phaseIdx == compIIdx);
197 return effectiveDiffCoeff_[compJIdx];
198 }
199
203 Scalar porosity() const
204 { return solidState_.porosity(); }
205
206protected:
209 Scalar fluidSaturation_ = 1.0;
210
211 std::array<Scalar, numFluidComps> diffCoeff_;
212 std::array<Scalar, numFluidComps> effectiveDiffCoeff_;
213 std::array<Scalar, numFluidComps> moleOrMassFraction_;
214};
215
216} // end namespace Dumux
217
218#endif
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
Contains the quantities which are constant within a finite volume for the tracer model.
Definition: porousmediumflow/tracer/volumevariables.hh:46
Scalar averageMolarMass(int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:111
typename Traits::FluidSystem FluidSystem
Export the fluid system type.
Definition: porousmediumflow/tracer/volumevariables.hh:55
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:158
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:167
std::array< Scalar, numFluidComps > effectiveDiffCoeff_
Definition: porousmediumflow/tracer/volumevariables.hh:212
Scalar molarDensity(int phaseIdx=0) const
Returns the molar density the of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:149
std::array< Scalar, numFluidComps > moleOrMassFraction_
Definition: porousmediumflow/tracer/volumevariables.hh:213
typename Traits::SolidState SolidState
Export the solid state type.
Definition: porousmediumflow/tracer/volumevariables.hh:57
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: porousmediumflow/tracer/volumevariables.hh:192
Scalar fluidDensity_
Definition: porousmediumflow/tracer/volumevariables.hh:208
SolidState solidState_
Definition: porousmediumflow/tracer/volumevariables.hh:207
Scalar density(int phaseIdx=0) const
Returns the density the of the fluid phase.
Definition: porousmediumflow/tracer/volumevariables.hh:103
const SolidState & solidState() const
Returns the phase state for the control volume.
Definition: porousmediumflow/tracer/volumevariables.hh:117
Scalar mobility(int phaseIdx=0) const
Returns the mobility.
Definition: porousmediumflow/tracer/volumevariables.hh:141
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: porousmediumflow/tracer/volumevariables.hh:182
Scalar saturation(int phaseIdx=0) const
Returns the saturation.
Definition: porousmediumflow/tracer/volumevariables.hh:130
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:71
Scalar porosity() const
Return the average porosity within the control volume.
Definition: porousmediumflow/tracer/volumevariables.hh:203
typename Traits::ModelTraits::Indices Indices
Export the indices.
Definition: porousmediumflow/tracer/volumevariables.hh:59
Scalar fluidSaturation_
Definition: porousmediumflow/tracer/volumevariables.hh:209
Scalar fluidMolarMass_
Definition: porousmediumflow/tracer/volumevariables.hh:208
Scalar molarity(int phaseIdx, int compIdx) const
Returns the concentration of a component in the phase.
Definition: porousmediumflow/tracer/volumevariables.hh:176
std::array< Scalar, numFluidComps > diffCoeff_
Definition: porousmediumflow/tracer/volumevariables.hh:211
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
decltype(std::declval< T >().spatialParams().saturation(std::declval< Ts >()...)) SaturationDetector
Definition: porousmediumflow/tracer/volumevariables.hh:30
static constexpr bool hasSaturation()
Definition: porousmediumflow/tracer/volumevariables.hh:33
Definition: adapt.hh:17
Base class for the model specific class which provides access to all volume averaged quantities.
Update the solid volume fractions (inert and reacitve) and set them in the solidstate.