GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/dumux/flux/porenetwork/fickslaw.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 6 6 100.0%
Branches: 6 8 75.0%

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-FileCopyrightText: 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 327716 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 327716 Dune::FieldVector<Scalar, numComponents> componentFlux(0.0);
50
51 // get inside and outside diffusion tensors and calculate the harmonic mean
52 327716 const auto& insideVolVars = elemVolVars[scvf.insideScvIdx()];
53 327716 const auto& outsideVolVars = elemVolVars[scvf.outsideScvIdx()];
54
55 327716 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
56
57 327716 const Scalar density = 0.5 * (massOrMolarDensity(insideVolVars, referenceSystem, phaseIdx) + massOrMolarDensity(outsideVolVars, referenceSystem, phaseIdx));
58 327716 const Scalar throatLength = fluxVarsCache.throatLength();
59 327716 const Scalar phaseCrossSectionalArea = fluxVarsCache.throatCrossSectionalArea(phaseIdx);
60
61
2/2
✓ Branch 0 taken 655432 times.
✓ Branch 1 taken 327716 times.
983148 for (int compIdx = 0; compIdx < numComponents; compIdx++)
62 {
63
2/2
✓ Branch 0 taken 327716 times.
✓ Branch 1 taken 327716 times.
655432 if(compIdx == phaseIdx)
64 327716 continue;
65
66 327716 auto insideDiffCoeff = getDiffusionCoefficient_(phaseIdx, compIdx, insideVolVars);
67 327716 auto outsideDiffCoeff = getDiffusionCoefficient_(phaseIdx, compIdx, outsideVolVars);
68
69 // scale by extrusion factor
70 327716 insideDiffCoeff *= insideVolVars.extrusionFactor();
71
1/2
✓ Branch 0 taken 327716 times.
✗ Branch 1 not taken.
327716 outsideDiffCoeff *= outsideVolVars.extrusionFactor();
72
73 // the resulting averaged diffusion coefficient
74 327716 const auto diffCoeff = harmonicMean(insideDiffCoeff, outsideDiffCoeff);
75
76 327716 const Scalar insideMoleFraction = massOrMoleFraction(insideVolVars, referenceSystem, phaseIdx, compIdx);
77 327716 const Scalar outsideMoleFraction = massOrMoleFraction(outsideVolVars, referenceSystem, phaseIdx, compIdx);
78
79 327716 componentFlux[compIdx] = density * (insideMoleFraction - outsideMoleFraction) / throatLength * diffCoeff * phaseCrossSectionalArea;
80 327716 componentFlux[phaseIdx] -= componentFlux[compIdx];
81 }
82 327716 return componentFlux;
83 }
84 private:
85
86 template<class VolumeVariables>
87 655432 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 655432 const auto mainCompIdx = FluidSystem::getMainComponent(phaseIdx);
95
1/2
✓ Branch 2 taken 327716 times.
✗ Branch 3 not taken.
327716 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