GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/flux/fickiandiffusioncoefficients.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 12 14 85.7%
Functions: 146 170 85.9%
Branches: 31 36 86.1%

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 Fick's law.
11 * Uses the minimal possible container size and provides unified access.
12 */
13 #ifndef DUMUX_FLUX_FICKIAN_DIFFUSION_COEFFICIENTS_HH
14 #define DUMUX_FLUX_FICKIAN_DIFFUSION_COEFFICIENTS_HH
15
16 #include <array>
17 #include <cassert>
18 #include <algorithm>
19
20 namespace Dumux {
21
22 /*!
23 * \ingroup Flux
24 * \brief Container storing the diffusion coefficients required by Fick's law.
25 * Uses the minimal possible container size and provides unified access.
26 * \tparam Scalar The type used for scalar values
27 * \tparam numPhases Number of phases in the fluid composition
28 * \tparam numComponents Number of components in the fluid composition
29 */
30 template <class Scalar, int numPhases, int numComponents>
31 class FickianDiffusionCoefficients
32 {
33 public:
34 template<class DiffCoeffFunc>
35 198916994 void update(const DiffCoeffFunc& computeDiffCoeff)
36 {
37 // fill the diffusion coefficient, only compute the ones we need, see getIndex_ doc
38 // the first component index "compIIdx" is always the main component index (phaseIdx)
39 // if we have less components than phases we need to limit the index
40 // this last case only occurs for 3p2c, there are no other special cases (2p1c doesn't have diffusion, max. number of phases is 3)
41 static_assert(numPhases <= numComponents || (numPhases == 3 && numComponents == 2),
42 "This combination of numPhases and numComponents is not supported!");
43
2/2
✓ Branch 0 taken 305652384 times.
✓ Branch 1 taken 186486864 times.
517233692 for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx)
44
4/4
✓ Branch 0 taken 666172398 times.
✓ Branch 1 taken 301797437 times.
✓ Branch 2 taken 23129682 times.
✓ Branch 3 taken 11564841 times.
1032947433 for (int compIIdx = std::min(phaseIdx, numComponents-1), compJIdx = 0; compJIdx < numComponents; ++compJIdx)
45
2/2
✓ Branch 0 taken 379794749 times.
✓ Branch 1 taken 305652384 times.
710775787 if (compIIdx != compJIdx)
46
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10 times.
428736117 diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)] = computeDiffCoeff(phaseIdx, compIIdx, compJIdx);
47 198916994 }
48
49 1777514132 Scalar operator() (int phaseIdx, int compIIdx, int compJIdx) const
50 {
51 3555028264 sortComponentIndices_(phaseIdx, compIIdx, compJIdx);
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1766275826 times.
1777514132 assert(compIIdx != compJIdx);
53 5332542396 return diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)];
54 }
55
56
57 private:
58 /*
59 * \brief For the mpnc case, we do not track a diffusion coefficient for the component of a phase.
60 * Hence, we have a matrix of dimensions (numPhases * (numComponents - 1))
61 * We store this matrix in a one-dimensional array
62 */
63 std::array<Scalar, numPhases * (numComponents - 1)> diffCoeff_;
64
65 /*
66 * \brief This calculates the array index to a corresponding matrix entry.
67 * An example with a 3p5c model:
68 * compJIdx
69 * [ x 0 1 2 3 ]
70 * phaseIdx [ 4 x 5 6 7 ]
71 * [ 8 9 x 10 11 ]
72 * -- "(phaseIdx * (numComponents-1))" advances to the phaseIdx row (numComp-1 per phase)
73 * -- "+ compJIdx" advances to the component index
74 * -- "- static_cast<int>(phaseIdx < compJIdx)" if the index is after the diagonal, -1.
75 */
76 constexpr int getIndex_(int phaseIdx, int compIIdx, int compJIdx) const
77 379794749 { return (phaseIdx * (numComponents-1)) + compJIdx - static_cast<int>(phaseIdx < compJIdx); }
78
79 void sortComponentIndices_(int phaseIdx, int& compIIdx, int& compJIdx) const
80
20/24
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3274800 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3274799 times.
✓ Branch 4 taken 15974400 times.
✓ Branch 5 taken 1747026592 times.
✓ Branch 6 taken 15974421 times.
✓ Branch 7 taken 1747026571 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 12 times.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 8 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4 times.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 8 times.
✓ Branch 22 taken 4 times.
✓ Branch 23 taken 4 times.
1782250228 { if (compIIdx != std::min(phaseIdx, numComponents-1)) std::swap(compIIdx, compJIdx); }
81 };
82
83 } // end namespace Dumux
84
85 #endif
86