version 3.10-dev
freeflow/navierstokes/mass/1pnc/fluxvariables.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_NAVIERSTOKES_MASS_1PNC_FLUXVARIABLES_HH
13#define DUMUX_NAVIERSTOKES_MASS_1PNC_FLUXVARIABLES_HH
14
19
20#include "advectiveflux.hh"
21
22namespace Dumux {
23
29template<class Problem,
30 class ModelTraits,
31 class FluxTs,
32 class ElementVolumeVariables,
33 class ElementFluxVariablesCache,
34 class UpwindScheme = UpwindScheme<typename ProblemTraits<Problem>::GridGeometry>>
37 ModelTraits,
38 FluxTs,
39 ElementVolumeVariables,
40 ElementFluxVariablesCache,
41 UpwindScheme>
42{
43 using VolumeVariables = typename ElementVolumeVariables::VolumeVariables;
44 using NumEqVector = typename VolumeVariables::PrimaryVariables;
45 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
46 using Indices = typename ModelTraits::Indices;
47
48 static constexpr bool enableMolecularDiffusion = ModelTraits::enableMolecularDiffusion();
49 static constexpr auto replaceCompEqIdx = ModelTraits::replaceCompEqIdx();
50 static constexpr bool useTotalMassBalance = replaceCompEqIdx < ModelTraits::numFluidComponents();
51
52 using FluidSystem = typename VolumeVariables::FluidSystem;
53
55 ModelTraits,
56 FluxTs,
57 ElementVolumeVariables,
58 ElementFluxVariablesCache,
60
61public:
62
63 static constexpr auto numComponents = ModelTraits::numFluidComponents();
64 static constexpr bool useMoles = ModelTraits::useMoles();
65 using MolecularDiffusionType = typename FluxTs::MolecularDiffusionType;
66
70 NumEqVector molecularDiffusionFlux(int phaseIdx = 0) const
71 {
72 NumEqVector result(0.0);
73 if constexpr (enableMolecularDiffusion)
74 {
75 const auto diffusiveFluxes = MolecularDiffusionType::flux(this->problem(),
76 this->element(),
77 this->fvGeometry(),
78 this->elemVolVars(),
79 this->scvFace(),
80 phaseIdx,
81 this->elemFluxVarsCache());
82
83 static constexpr auto referenceSystemFormulation = MolecularDiffusionType::referenceSystemFormulation();
84
85 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
86 {
87 // get equation index
88 const auto eqIdx = Indices::conti0EqIdx + compIdx;
89 if (eqIdx == replaceCompEqIdx)
90 continue;
91
92 //check for the reference system and adapt units of the diffusive flux accordingly.
93 if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
94 result[eqIdx] += useMoles ? diffusiveFluxes[compIdx]/FluidSystem::molarMass(compIdx)
95 : diffusiveFluxes[compIdx];
96 else if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::molarAveraged)
97 result[eqIdx] += useMoles ? diffusiveFluxes[compIdx]
98 : diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx);
99 else
100 DUNE_THROW(Dune::NotImplemented, "other reference systems than mass and molar averaged are not implemented");
101 }
102
103 // in case one balance is substituted by the total mass balance
104 if constexpr(useTotalMassBalance)
105 {
106 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
107 {
108 //check for the reference system and adapt units of the diffusive flux accordingly.
109 if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
110 result[replaceCompEqIdx] += diffusiveFluxes[compIdx];
111 else if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::molarAveraged)
112 result[replaceCompEqIdx] += diffusiveFluxes[compIdx]*FluidSystem::molarMass(compIdx);
113 else
114 DUNE_THROW(Dune::NotImplemented, "other reference systems than mass and molar averaged are not implemented");
115 }
116 }
117 }
118
119 return result;
120 }
121
125 Scalar diffusiveEnthalpyFlux(int phaseIdx = 0) const
126 {
127 const auto diffusiveFlux = MolecularDiffusionType::flux(this->problem(),
128 this->element(),
129 this->fvGeometry(),
130 this->elemVolVars(),
131 this->scvFace(),
132 phaseIdx,
133 this->elemFluxVarsCache());
134 static constexpr auto referenceSystemFormulation = MolecularDiffusionType::referenceSystemFormulation();
135 Scalar flux = 0.0;
136 const auto& scvf = this->scvFace();
137 const auto& elemVolVars = this->elemVolVars();
138
139 const auto componentEnthalpy = [](const auto& volVars, int compIdx)
140 { return FluidSystem::componentEnthalpy(volVars.fluidState(), 0, compIdx); };
141
142 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
143 {
144 // do a simple upwinding of enthalpy based on the direction of the diffusive flux
145 using std::signbit;
146 const bool insideIsUpstream = !signbit(diffusiveFlux[compIdx]);
147 const auto& upstreamVolVars = insideIsUpstream ? elemVolVars[scvf.insideScvIdx()] : elemVolVars[scvf.outsideScvIdx()];
148
149 if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged)
150 flux += diffusiveFlux[compIdx] * componentEnthalpy(upstreamVolVars, compIdx);
151 else
152 flux += diffusiveFlux[compIdx] * componentEnthalpy(upstreamVolVars, compIdx)* elemVolVars[scvf.insideScvIdx()].molarMass(compIdx);
153 }
154
155 return flux;
156 }
157
162 NumEqVector advectiveFlux(int phaseIdx = 0) const
163 {
164 NumEqVector result(0.0);
165 // g++ requires to capture 'this' by value
166 const auto upwinding = [this](const auto& term) { return this->getAdvectiveFlux(term); };
167 AdvectiveFlux<ModelTraits>::addAdvectiveFlux(result, upwinding);
168 return result;
169 }
170
177 NumEqVector flux(int phaseIdx = 0) const
178 {
179 const auto diffusiveFlux = molecularDiffusionFlux(phaseIdx);
180 NumEqVector flux = diffusiveFlux;
181 // g++ requires to capture 'this' by value
182 const auto upwinding = [this](const auto& term) { return this->getAdvectiveFlux(term); };
183 AdvectiveFlux<ModelTraits>::addAdvectiveFlux(flux, upwinding);
184
185 if constexpr (ModelTraits::enableEnergyBalance())
186 {
188 flux[ModelTraits::Indices::energyEqIdx] += diffusiveEnthalpyFlux();
189 }
190
191 return flux;
192 }
193
194};
195
196} // end namespace Dumux
197
198#endif
Helper struct defining the advective fluxes of the single-phase flow multicomponent Navier-Stokes mas...
const ProblemTraits< Problem >::GridGeometry::LocalView & fvGeometry() const
Definition: fluxvariablesbase.hh:66
The flux variables class for the single-phase flow, multi-component Navier-Stokes model.
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:42
static constexpr auto numComponents
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:63
NumEqVector molecularDiffusionFlux(int phaseIdx=0) const
Returns the diffusive fluxes computed by the respective law.
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:70
NumEqVector advectiveFlux(int phaseIdx=0) const
Returns the advective mass flux in kg/s or the advective mole flux in mole/s.
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:162
typename FluxTs::MolecularDiffusionType MolecularDiffusionType
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:65
static constexpr bool useMoles
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:64
NumEqVector flux(int phaseIdx=0) const
Returns all fluxes for the single-phase flow, multi-component Navier-Stokes model: the advective mass...
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:177
Scalar diffusiveEnthalpyFlux(int phaseIdx=0) const
Returns the flux of enthalpy in J/s carried by diffusing molecules.
Definition: freeflow/navierstokes/mass/1pnc/fluxvariables.hh:125
The flux variables base class for scalar quantities balanced in the Navier-Stokes model.
Definition: scalarfluxvariables.hh:39
void addHeatFlux(NumEqVector &flux) const
Adds the energy flux to a given flux vector.
Definition: scalarfluxvariables.hh:127
Scalar getAdvectiveFlux(const FunctionType &upwindTerm) const
Returns the advective flux computed by the respective law.
Definition: scalarfluxvariables.hh:69
Forward declaration of the upwind scheme implementation.
Definition: flux/upwindscheme.hh:22
Type traits for problem classes.
Base class for the upwind scheme.
UpwindSchemeImpl< GridGeometry, typename GridGeometry::DiscretizationMethod > UpwindScheme
The upwind scheme used for the advective fluxes. This depends on the chosen discretization method.
Definition: flux/upwindscheme.hh:30
Definition: adapt.hh:17
The reference frameworks and formulations available for splitting total fluxes into a advective and d...