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 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 | 208949287 | 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 310811536 times.
✓ Branch 1 taken 191897273 times.
|
537047709 | for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx) |
44 |
4/4✓ Branch 0 taken 676490006 times.
✓ Branch 1 taken 306956589 times.
✓ Branch 2 taken 23129682 times.
✓ Branch 3 taken 11564841 times.
|
1062291909 | for (int compIIdx = std::min(phaseIdx, numComponents-1), compJIdx = 0; compJIdx < numComponents; ++compJIdx) |
45 |
2/2✓ Branch 0 taken 384953205 times.
✓ Branch 1 taken 310811536 times.
|
730338539 | if (compIIdx != compJIdx) |
46 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10 times.
|
402240117 | diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)] = computeDiffCoeff(phaseIdx, compIIdx, compJIdx); |
47 | 208949287 | } | |
48 | |||
49 | 1795850211 | Scalar operator() (int phaseIdx, int compIIdx, int compJIdx) const | |
50 | { | ||
51 | 1795850211 | sortComponentIndices_(phaseIdx, compIIdx, compJIdx); | |
52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1784588066 times.
|
1795850211 | assert(compIIdx != compJIdx); |
53 | 1795850211 | 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 | 2169541271 | constexpr int getIndex_(int phaseIdx, int compIIdx, int compJIdx) const | |
77 | 384953205 | { return (phaseIdx * (numComponents-1)) + compJIdx - static_cast<int>(phaseIdx < compJIdx); } | |
78 | |||
79 | 1784588066 | void sortComponentIndices_(int phaseIdx, int& compIIdx, int& compJIdx) const | |
80 |
19/24✓ Branch 0 taken 15974402 times.
✓ Branch 1 taken 1760635911 times.
✓ Branch 2 taken 15974403 times.
✓ Branch 3 taken 1760635910 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 7977721 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 7977700 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.
|
1800562468 | { if (compIIdx != std::min(phaseIdx, numComponents-1)) std::swap(compIIdx, compJIdx); } |
81 | }; | ||
82 | |||
83 | } // end namespace Dumux | ||
84 | |||
85 | #endif | ||
86 |