version 3.8
freeflow/compositional/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//
13#ifndef DUMUX_FREEFLOW_NC_VOLUMEVARIABLES_HH
14#define DUMUX_FREEFLOW_NC_VOLUMEVARIABLES_HH
15
16#include <array>
17#include <dune/common/exceptions.hh>
19
20namespace Dumux {
21
26template <class Traits>
27class FreeflowNCVolumeVariables : public FreeFlowVolumeVariables< Traits, FreeflowNCVolumeVariables<Traits> >
28{
31
32 using Scalar = typename Traits::PrimaryVariables::value_type;
33
34 static constexpr bool useMoles = Traits::ModelTraits::useMoles();
35 static constexpr int numFluidComps = ParentType::numFluidComponents();
36 using DiffusionCoefficients = typename Traits::DiffusionType::DiffusionCoefficientsContainer;
37
38public:
40 using FluidSystem = typename Traits::FluidSystem;
42 using FluidState = typename Traits::FluidState;
44 using Indices = typename Traits::ModelTraits::Indices;
45
55 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
56 void update(const ElementSolution &elemSol,
57 const Problem &problem,
58 const Element &element,
59 const SubControlVolume& scv)
60 {
61 ParentType::update(elemSol, problem, element, scv);
62
63 completeFluidState(elemSol, problem, element, scv, fluidState_);
64
65 typename FluidSystem::ParameterCache paramCache;
66 paramCache.updateAll(fluidState_);
67
68 auto getDiffusionCoefficient = [&](int phaseIdx, int compIIdx, int compJIdx)
69 {
70 return FluidSystem::binaryDiffusionCoefficient(this->fluidState_,
71 paramCache,
72 0,
73 compIIdx,
74 compJIdx);
75 };
76
77 diffCoefficient_.update(getDiffusionCoefficient);
78 }
79
83 template<class ElementSolution, class Problem, class Element, class SubControlVolume>
84 static void completeFluidState(const ElementSolution& elemSol,
85 const Problem& problem,
86 const Element& element,
87 const SubControlVolume& scv,
89 {
90 fluidState.setTemperature(ParentType::temperature(elemSol, problem, element, scv));
91 fluidState.setPressure(0, elemSol[0][Indices::pressureIdx]);
92
93 // saturation in a single phase is always 1 and thus redundant
94 // to set. But since we use the fluid state shared by the
95 // immiscible multi-phase models, so we have to set it here...
96 fluidState.setSaturation(0, 1.0);
97
98 Scalar sumFracMinorComp = 0.0;
99
100 for(int compIdx = 1; compIdx < ParentType::numFluidComponents(); ++compIdx)
101 {
102 // temporary add 1.0 to remove spurious differences in mole fractions
103 // which are below the numerical accuracy
104 Scalar moleOrMassFraction = elemSol[0][Indices::conti0EqIdx+compIdx] + 1.0;
105 moleOrMassFraction = moleOrMassFraction - 1.0;
106 if(useMoles)
107 fluidState.setMoleFraction(0, compIdx, moleOrMassFraction);
108 else
109 fluidState.setMassFraction(0, compIdx, moleOrMassFraction);
110 sumFracMinorComp += moleOrMassFraction;
111 }
112 if(useMoles)
113 fluidState.setMoleFraction(0, 0, 1.0 - sumFracMinorComp);
114 else
115 fluidState.setMassFraction(0, 0, 1.0 - sumFracMinorComp);
116
117 typename FluidSystem::ParameterCache paramCache;
118 paramCache.updateAll(fluidState);
119
120 Scalar value = FluidSystem::density(fluidState, paramCache, 0);
121 fluidState.setDensity(0, value);
122
123 value = FluidSystem::molarDensity(fluidState, paramCache, 0);
124 fluidState.setMolarDensity(0, value);
125
126 value = FluidSystem::viscosity(fluidState, paramCache, 0);
127 fluidState.setViscosity(0, value);
128
129 // compute and set the enthalpy
130 const Scalar h = ParentType::enthalpy(fluidState, paramCache);
131 fluidState.setEnthalpy(0, h);
132 }
133
138 Scalar pressure(int phaseIdx = 0) const
139 { return fluidState_.pressure(0); }
140
145 Scalar density(int phaseIdx = 0) const
146 { return fluidState_.density(0); }
147
155 Scalar temperature() const
156 { return fluidState_.temperature(); }
157
162 Scalar effectiveViscosity() const
163 { return viscosity(); }
164
169 Scalar viscosity(int phaseIdx = 0) const
170 { return fluidState_.viscosity(0); }
171
178 Scalar massFraction(int phaseIdx, int compIdx) const
179 { return fluidState_.massFraction(0, compIdx); }
180
186 Scalar massFraction(int compIdx) const
187 { return fluidState_.massFraction(0, compIdx); }
188
195 Scalar moleFraction(int phaseIdx, int compIdx) const
196 { return fluidState_.moleFraction(0, compIdx); }
197
203 Scalar moleFraction(int compIdx) const
204 { return fluidState_.moleFraction(0, compIdx); }
205
209 Scalar molarDensity(int phaseIdx = 0) const
210 { return fluidState_.molarDensity(0); }
211
217 Scalar molarMass(int compIdx) const
218 { return FluidSystem::molarMass(compIdx); }
219
225 Scalar averageMolarMass(const int phaseIdx = 0) const
226 { return fluidState_.averageMolarMass(phaseIdx); }
227
231 Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
232 { return diffCoefficient_(0, compIIdx, compJIdx); }
233
237 Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
238 { return diffusionCoefficient(0, compIIdx, compJIdx); }
239
243 const FluidState& fluidState() const
244 { return fluidState_; }
245
246protected:
248 // Binary diffusion coefficient
249 DiffusionCoefficients diffCoefficient_;
250};
251
252} // end namespace Dumux
253
254#endif
Definition: freeflow/volumevariables.hh:22
Volume variables for the single-phase, multi-component free-flow model.
Definition: freeflow/compositional/volumevariables.hh:28
Scalar moleFraction(int phaseIdx, int compIdx) const
Returns the mole fraction of a component in the phase .
Definition: freeflow/compositional/volumevariables.hh:195
const FluidState & fluidState() const
Return the fluid state of the control volume.
Definition: freeflow/compositional/volumevariables.hh:243
Scalar massFraction(int phaseIdx, int compIdx) const
Returns the mass fraction of a component in the phase .
Definition: freeflow/compositional/volumevariables.hh:178
Scalar diffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the binary diffusion coefficients for a phase in .
Definition: freeflow/compositional/volumevariables.hh:231
Scalar effectiveViscosity() const
Return the effective dynamic viscosity of the fluid within the control volume.
Definition: freeflow/compositional/volumevariables.hh:162
FluidState fluidState_
Definition: freeflow/compositional/volumevariables.hh:247
typename Traits::ModelTraits::Indices Indices
export the indices type
Definition: freeflow/compositional/volumevariables.hh:44
Scalar temperature() const
Return temperature inside the sub-control volume.
Definition: freeflow/compositional/volumevariables.hh:155
static void completeFluidState(const ElementSolution &elemSol, const Problem &problem, const Element &element, const SubControlVolume &scv, FluidState &fluidState)
Update the fluid state.
Definition: freeflow/compositional/volumevariables.hh:84
typename Traits::FluidState FluidState
export the fluid state type
Definition: freeflow/compositional/volumevariables.hh:42
void update(const ElementSolution &elemSol, const Problem &problem, const Element &element, const SubControlVolume &scv)
Update all quantities for a given control volume.
Definition: freeflow/compositional/volumevariables.hh:56
Scalar viscosity(int phaseIdx=0) const
Return the dynamic viscosity of the fluid within the control volume.
Definition: freeflow/compositional/volumevariables.hh:169
Scalar pressure(int phaseIdx=0) const
Return the effective pressure of a given phase within the control volume.
Definition: freeflow/compositional/volumevariables.hh:138
Scalar molarMass(int compIdx) const
Returns the molar mass of a given component.
Definition: freeflow/compositional/volumevariables.hh:217
Scalar moleFraction(int compIdx) const
Returns the mole fraction of a component in the phase .
Definition: freeflow/compositional/volumevariables.hh:203
Scalar density(int phaseIdx=0) const
Return the mass density of a given phase within the control volume.
Definition: freeflow/compositional/volumevariables.hh:145
Scalar massFraction(int compIdx) const
Returns the mass fraction of a component in the phase .
Definition: freeflow/compositional/volumevariables.hh:186
DiffusionCoefficients diffCoefficient_
Definition: freeflow/compositional/volumevariables.hh:249
Scalar molarDensity(int phaseIdx=0) const
Returns the mass density of a given phase .
Definition: freeflow/compositional/volumevariables.hh:209
Scalar effectiveDiffusionCoefficient(int phaseIdx, int compIIdx, int compJIdx) const
Returns the effective diffusion coefficients for a phase in .
Definition: freeflow/compositional/volumevariables.hh:237
typename Traits::FluidSystem FluidSystem
export the underlying fluid system
Definition: freeflow/compositional/volumevariables.hh:40
Scalar averageMolarMass(const int phaseIdx=0) const
Returns the average molar mass of the fluid phase.
Definition: freeflow/compositional/volumevariables.hh:225
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53
Definition: adapt.hh:17