version 3.8
fickiandiffusioncoefficients.hh
Go to the documentation of this file.
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//
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
20namespace Dumux {
21
30template <class Scalar, int numPhases, int numComponents>
32{
33public:
34 template<class DiffCoeffFunc>
35 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 for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx)
44 for (int compIIdx = std::min(phaseIdx, numComponents-1), compJIdx = 0; compJIdx < numComponents; ++compJIdx)
45 if (compIIdx != compJIdx)
46 diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)] = computeDiffCoeff(phaseIdx, compIIdx, compJIdx);
47 }
48
49 Scalar operator() (int phaseIdx, int compIIdx, int compJIdx) const
50 {
51 sortComponentIndices_(phaseIdx, compIIdx, compJIdx);
52 assert(compIIdx != compJIdx);
53 return diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)];
54 }
55
56
57private:
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 { return (phaseIdx * (numComponents-1)) + compJIdx - static_cast<int>(phaseIdx < compJIdx); }
78
79 void sortComponentIndices_(int phaseIdx, int& compIIdx, int& compJIdx) const
80 { if (compIIdx != std::min(phaseIdx, numComponents-1)) std::swap(compIIdx, compJIdx); }
81};
82
83} // end namespace Dumux
84
85#endif
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
Definition: fickiandiffusioncoefficients.hh:32
Scalar operator()(int phaseIdx, int compIIdx, int compJIdx) const
Definition: fickiandiffusioncoefficients.hh:49
void update(const DiffCoeffFunc &computeDiffCoeff)
Definition: fickiandiffusioncoefficients.hh:35
Definition: adapt.hh:17