Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup NavierStokesModel | ||
10 | * \copydoc Dumux::NavierStokesMassOnePNCFluxVariables | ||
11 | */ | ||
12 | #ifndef DUMUX_NAVIERSTOKES_MASS_1PNC_FLUXVARIABLES_HH | ||
13 | #define DUMUX_NAVIERSTOKES_MASS_1PNC_FLUXVARIABLES_HH | ||
14 | |||
15 | #include <dumux/common/typetraits/problem.hh> | ||
16 | #include <dumux/flux/referencesystemformulation.hh> | ||
17 | #include <dumux/flux/upwindscheme.hh> | ||
18 | #include <dumux/freeflow/navierstokes/scalarfluxvariables.hh> | ||
19 | |||
20 | #include "advectiveflux.hh" | ||
21 | |||
22 | namespace Dumux { | ||
23 | |||
24 | /*! | ||
25 | * \ingroup NavierStokesModel | ||
26 | * \brief The flux variables class for the single-phase flow, | ||
27 | * multi-component Navier-Stokes model. | ||
28 | */ | ||
29 | template<class Problem, | ||
30 | class ModelTraits, | ||
31 | class FluxTs, | ||
32 | class ElementVolumeVariables, | ||
33 | class ElementFluxVariablesCache, | ||
34 | class UpwindScheme = UpwindScheme<typename ProblemTraits<Problem>::GridGeometry>> | ||
35 | class NavierStokesMassOnePNCFluxVariables | ||
36 | : public NavierStokesScalarConservationModelFluxVariables<Problem, | ||
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 | |||
54 | using ParentType = NavierStokesScalarConservationModelFluxVariables<Problem, | ||
55 | ModelTraits, | ||
56 | FluxTs, | ||
57 | ElementVolumeVariables, | ||
58 | ElementFluxVariablesCache, | ||
59 | UpwindScheme>; | ||
60 | |||
61 | public: | ||
62 | |||
63 | static constexpr auto numComponents = ModelTraits::numFluidComponents(); | ||
64 | static constexpr bool useMoles = ModelTraits::useMoles(); | ||
65 | using MolecularDiffusionType = typename FluxTs::MolecularDiffusionType; | ||
66 | |||
67 | /*! | ||
68 | * \brief Returns the diffusive fluxes computed by the respective law. | ||
69 | */ | ||
70 | 15445064 | NumEqVector molecularDiffusionFlux(int phaseIdx = 0) const | |
71 | { | ||
72 | 15445064 | NumEqVector result(0.0); | |
73 | if constexpr (enableMolecularDiffusion) | ||
74 | { | ||
75 | 15445064 | 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 |
3/3✓ Branch 0 taken 28997008 times.
✓ Branch 1 taken 17338184 times.
✓ Branch 2 taken 946560 times.
|
47281752 | for (int compIdx = 0; compIdx < numComponents; ++compIdx) |
86 | { | ||
87 | // get equation index | ||
88 | 31836688 | const auto eqIdx = Indices::conti0EqIdx + compIdx; | |
89 |
2/2✓ Branch 0 taken 16391624 times.
✓ Branch 1 taken 15445064 times.
|
31836688 | 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 | 34676368 | 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 |
2/2✓ Branch 0 taken 31836688 times.
✓ Branch 1 taken 15445064 times.
|
47281752 | 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 | 95510064 | 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 | 15445064 | return result; | |
120 | } | ||
121 | |||
122 | /*! | ||
123 | * \brief Returns the flux of enthalpy in J/s carried by diffusing molecules. | ||
124 | */ | ||
125 | 3942400 | Scalar diffusiveEnthalpyFlux(int phaseIdx = 0) const | |
126 | { | ||
127 | 3942400 | 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 | 3942400 | Scalar flux = 0.0; | |
136 | 3942400 | const auto& scvf = this->scvFace(); | |
137 | 3942400 | const auto& elemVolVars = this->elemVolVars(); | |
138 | |||
139 | ✗ | const auto componentEnthalpy = [](const auto& volVars, int compIdx) | |
140 |
2/6✓ Branch 0 taken 3942400 times.
✓ Branch 1 taken 3942400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
7884800 | { return FluidSystem::componentEnthalpy(volVars.fluidState(), 0, compIdx); }; |
141 | |||
142 |
2/2✓ Branch 0 taken 7884800 times.
✓ Branch 1 taken 3942400 times.
|
11827200 | 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 |
4/4✓ Branch 0 taken 4729852 times.
✓ Branch 1 taken 3154948 times.
✓ Branch 2 taken 4729852 times.
✓ Branch 3 taken 3154948 times.
|
15769600 | const bool insideIsUpstream = !signbit(diffusiveFlux[compIdx]); |
147 |
2/2✓ Branch 0 taken 4729852 times.
✓ Branch 1 taken 3154948 times.
|
7884800 | const auto& upstreamVolVars = insideIsUpstream ? elemVolVars[scvf.insideScvIdx()] : elemVolVars[scvf.outsideScvIdx()]; |
148 | |||
149 | if constexpr (referenceSystemFormulation == ReferenceSystemFormulation::massAveraged) | ||
150 |
4/4✓ Branch 0 taken 3942400 times.
✓ Branch 1 taken 3942400 times.
✓ Branch 2 taken 3942400 times.
✓ Branch 3 taken 3942400 times.
|
23654400 | flux += diffusiveFlux[compIdx] * componentEnthalpy(upstreamVolVars, compIdx); |
151 | else | ||
152 | flux += diffusiveFlux[compIdx] * componentEnthalpy(upstreamVolVars, compIdx)* elemVolVars[scvf.insideScvIdx()].molarMass(compIdx); | ||
153 | } | ||
154 | |||
155 | 3942400 | return flux; | |
156 | } | ||
157 | |||
158 | /*! | ||
159 | * \brief Returns the advective mass flux in kg/s | ||
160 | * or the advective mole flux in mole/s. | ||
161 | */ | ||
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 | |||
171 | /*! | ||
172 | * \brief Returns all fluxes for the single-phase flow, multi-component | ||
173 | * Navier-Stokes model: the advective mass flux in kg/s | ||
174 | * or the advective mole flux in mole/s and the energy flux | ||
175 | * in J/s (for nonisothermal models). | ||
176 | */ | ||
177 | 15445064 | NumEqVector flux(int phaseIdx = 0) const | |
178 | { | ||
179 | 15445064 | const auto diffusiveFlux = molecularDiffusionFlux(phaseIdx); | |
180 | 15445064 | NumEqVector flux = diffusiveFlux; | |
181 | // g++ requires to capture 'this' by value | ||
182 | 31836688 | const auto upwinding = [this](const auto& term) { return this->getAdvectiveFlux(term); }; | |
183 | 15445064 | AdvectiveFlux<ModelTraits>::addAdvectiveFlux(flux, upwinding); | |
184 | |||
185 | if constexpr (ModelTraits::enableEnergyBalance()) | ||
186 | { | ||
187 | 3942400 | ParentType::addHeatFlux(flux); | |
188 | 3942400 | flux[ModelTraits::Indices::energyEqIdx] += diffusiveEnthalpyFlux(); | |
189 | } | ||
190 | |||
191 | 15445064 | return flux; | |
192 | } | ||
193 | |||
194 | }; | ||
195 | |||
196 | } // end namespace Dumux | ||
197 | |||
198 | #endif | ||
199 |