GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/flux/maxwellstefandiffusioncoefficients.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 16 18 88.9%
Functions: 16 41 39.0%
Branches: 17 22 77.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 Flux
10 * \brief Container storing the diffusion coefficients required by the Maxwell-
11 * Stefan diffusion law. Uses the minimal possible container size and
12 * provides unified access.
13 */
14 #ifndef DUMUX_FLUX_MAXWELLSTEFAN_DIFFUSION_COEFFICIENTS_HH
15 #define DUMUX_FLUX_MAXWELLSTEFAN_DIFFUSION_COEFFICIENTS_HH
16
17 #include <array>
18 #include <cassert>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Flux
24 * \brief Container storing the diffusion coefficients required by the Maxwell-
25 * Stefan diffusion law. Uses the minimal possible container size and
26 * provides unified access.
27 * \tparam Scalar The type used for scalar values
28 * \tparam numPhases Number of phases in the fluid composition
29 * \tparam numComponents Number of components in the fluid composition
30 */
31 template <class Scalar, int numPhases, int numComponents>
32 class MaxwellStefanDiffusionCoefficients
33 {
34 public:
35 template<class DiffCoeffFunc>
36 4939264 void update(const DiffCoeffFunc& computeDiffCoeff)
37 {
38
2/2
✓ Branch 0 taken 3178684 times.
✓ Branch 1 taken 2979184 times.
10078029 for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx)
39
2/2
✓ Branch 0 taken 3577684 times.
✓ Branch 1 taken 8043492 times.
18766936 for (int compIIdx = 0; compIIdx < numComponents; ++compIIdx)
40
2/2
✓ Branch 0 taken 8442492 times.
✓ Branch 1 taken 7348932 times.
25468224 for (int compJIdx = compIIdx+1; compJIdx < numComponents; ++compJIdx)
41 11840052 diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)]
42
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
11840052 = computeDiffCoeff(phaseIdx, compIIdx, compJIdx);
43 4939264 }
44
45 57983736 Scalar operator() (int phaseIdx, int compIIdx, int compJIdx) const
46 {
47 115967472 sortComponentIndices_(compIIdx, compJIdx);
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57983550 times.
57983736 assert(compIIdx != compJIdx);
49 173951208 return diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)];
50 }
51
52 private:
53 /*!
54 * \brief Maxwell Stefan diffusion coefficient container.
55 * This container is sized to hold all required diffusion coefficients.
56 *
57 * For each phase "(numPhases * ("
58 * We have a square coefficient matrix sized by
59 * the number of components "((numComponents * numComponents)".
60 * The diagonal is not used and removed " - numComponents)".
61 * The matrix is symmetrical, but only the upper triangle is required " / 2))".
62 */
63 std::array<Scalar, (numPhases * ((numComponents * (numComponents - 1)) / 2))> diffCoeff_;
64
65 /*!
66 * \brief Index logic for collecting the correct diffusion coefficient from the container.
67 *
68 * First, we advance our index to the correct phase coefficient matrix:
69 * " phaseIdx * ((numComponents * numComponents - numComponents) / 2) ".
70 * The individual index within each phase matrix is then calculated using
71 * " i*n - (i^2+i)/2 + j-(i+1) ".
72 *
73 * This index calculation can be reduced from the following:
74 * https://stackoverflow.com/questions/27086195/
75 */
76 constexpr int getIndex_(int phaseIdx, int compIIdx, int compJIdx) const
77 {
78 168 return phaseIdx * ((numComponents * (numComponents - 1)) / 2)
79 65332482 + compIIdx * numComponents
80 65332482 - ((compIIdx * (compIIdx + 1)) / 2)
81 7348932 + compJIdx - (compIIdx +1);
82 }
83
84 void sortComponentIndices_(int& compIIdx, int& compJIdx) const
85
10/12
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 8477844 times.
✓ Branch 3 taken 49505688 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
57983550 { if (compIIdx > compJIdx) std::swap(compIIdx, compJIdx); }
86 };
87
88 } // end namespace Dumux
89
90 #endif
91