GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/flux/porenetwork/fickslaw.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 4 4 100.0%
Branches: 5 6 83.3%

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 PoreNetworkFlux
10 * \brief This file contains the data which is required to calculate
11 * diffusive mass fluxes due to molecular diffusion with Fick's law.
12 */
13 #ifndef DUMUX_FLUX_PNM_FICKS_LAW_HH
14 #define DUMUX_FLUX_PNM_FICKS_LAW_HH
15
16 #include <dune/common/fvector.hh>
17 #include <dumux/common/math.hh>
18 #include <dumux/flux/referencesystemformulation.hh>
19 #include <dumux/flux/fickiandiffusioncoefficients.hh>
20
21 namespace Dumux::PoreNetwork {
22
23 /*!
24 * \ingroup PoreNetworkFlux
25 * \brief Specialization of Fick's Law for the pore-network model.
26 */
27 template<class Scalar, int numPhases, int numComponents,
28 ReferenceSystemFormulation referenceSystem = ReferenceSystemFormulation::massAveraged>
29 class PNMFicksLaw
30 {
31 public:
32 using DiffusionCoefficientsContainer = FickianDiffusionCoefficients<Scalar, numPhases, numComponents>;
33
34 //return the reference system
35 static constexpr ReferenceSystemFormulation referenceSystemFormulation()
36 { return referenceSystem; }
37
38 template<class Problem, class Element, class FVElementGeometry,
39 class ElementVolumeVariables, class ElementFluxVariablesCache>
40 static Dune::FieldVector<Scalar, numComponents>
41 324821 flux(const Problem& problem,
42 const Element& element,
43 const FVElementGeometry& fvGeometry,
44 const ElementVolumeVariables& elemVolVars,
45 const typename FVElementGeometry::SubControlVolumeFace& scvf,
46 const int phaseIdx,
47 const ElementFluxVariablesCache& elemFluxVarsCache)
48 {
49 324821 Dune::FieldVector<Scalar, numComponents> componentFlux(0.0);
50
51 // get inside and outside diffusion tensors and calculate the harmonic mean
52 649642 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
53 649642 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
54
55 324821 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
56
57 649642 const Scalar density = 0.5 * (massOrMolarDensity(insideVolVars, referenceSystem, phaseIdx) + massOrMolarDensity(outsideVolVars, referenceSystem, phaseIdx));
58 324821 const Scalar throatLength = fluxVarsCache.throatLength();
59 324821 const Scalar phaseCrossSectionalArea = fluxVarsCache.throatCrossSectionalArea(phaseIdx);
60
61
2/2
✓ Branch 0 taken 649642 times.
✓ Branch 1 taken 324821 times.
974463 for (int compIdx = 0; compIdx < numComponents; compIdx++)
62 {
63
2/2
✓ Branch 0 taken 324821 times.
✓ Branch 1 taken 324821 times.
649642 if(compIdx == phaseIdx)
64 continue;
65
66 649642 auto insideDiffCoeff = getDiffusionCoefficient_(phaseIdx, compIdx, insideVolVars);
67 649642 auto outsideDiffCoeff = getDiffusionCoefficient_(phaseIdx, compIdx, outsideVolVars);
68
69 // scale by extrusion factor
70 324821 insideDiffCoeff *= insideVolVars.extrusionFactor();
71 324821 outsideDiffCoeff *= outsideVolVars.extrusionFactor();
72
73 // the resulting averaged diffusion coefficient
74 649642 const auto diffCoeff = harmonicMean(insideDiffCoeff, outsideDiffCoeff);
75
76 324821 const Scalar insideMoleFraction = massOrMoleFraction(insideVolVars, referenceSystem, phaseIdx, compIdx);
77 324821 const Scalar outsideMoleFraction = massOrMoleFraction(outsideVolVars, referenceSystem, phaseIdx, compIdx);
78
79 324821 componentFlux[compIdx] = density * (insideMoleFraction - outsideMoleFraction) / throatLength * diffCoeff * phaseCrossSectionalArea;
80 974463 componentFlux[phaseIdx] -= componentFlux[compIdx];
81 }
82 324821 return componentFlux;
83 }
84 private:
85
86 template<class VolumeVariables>
87 static Scalar getDiffusionCoefficient_(const int phaseIdx, const int compIdx,
88 const VolumeVariables& volVars)
89 {
90 using FluidSystem = typename VolumeVariables::FluidSystem;
91
92 if constexpr (!FluidSystem::isTracerFluidSystem())
93 {
94 649642 const auto mainCompIdx = FluidSystem::getMainComponent(phaseIdx);
95
1/2
✓ Branch 2 taken 324821 times.
✗ Branch 3 not taken.
324821 return volVars.diffusionCoefficient(phaseIdx, mainCompIdx, compIdx);
96 }
97 else
98 return volVars.diffusionCoefficient(0, 0, compIdx);
99 }
100 };
101 } // end namespace Dumux::PoreNetwork
102
103 #endif
104