3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_FLUX_FICKIAN_DIFFUSION_COEFFICIENTS_HH
26#define DUMUX_FLUX_FICKIAN_DIFFUSION_COEFFICIENTS_HH
27
28#include <array>
29#include <cassert>
30#include <algorithm>
31
32namespace Dumux {
33
42template <class Scalar, int numPhases, int numComponents>
44{
45public:
46 template<class DiffCoeffFunc>
47 void update(const DiffCoeffFunc& computeDiffCoeff)
48 {
49 // fill the diffusion coefficient, only compute the ones we need, see getIndex_ doc
50 // the first component index "compIIdx" is always the main compnent index (phaseIdx)
51 // if we have less components than phases we need to limit the index
52 // this last case only occurs for 3p2c, there are no other special cases (2p1c doesn't have diffusion, max. number of phases is 3)
53 static_assert(numPhases <= numComponents || (numPhases == 3 && numComponents == 2),
54 "This combination of numPhases and numComponents is not supported!");
55 for (int phaseIdx = 0; phaseIdx < numPhases; ++ phaseIdx)
56 for (int compIIdx = std::min(phaseIdx, numComponents-1), compJIdx = 0; compJIdx < numComponents; ++compJIdx)
57 if (compIIdx != compJIdx)
58 diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)] = computeDiffCoeff(phaseIdx, compIIdx, compJIdx);
59 }
60
61 Scalar operator() (int phaseIdx, int compIIdx, int compJIdx) const
62 {
63 sortComponentIndices_(phaseIdx, compIIdx, compJIdx);
64 assert(compIIdx != compJIdx);
65 return diffCoeff_[getIndex_(phaseIdx, compIIdx, compJIdx)];
66 }
67
68
69private:
70 /*
71 * \brief For the mpnc case, we do not track a diffusion coefficient for the component of a phase.
72 * Hence, we have a matrix of dimensions (numPhases * (numComponents - 1))
73 * We store this matrix in a one-dimensional array
74 */
75 std::array<Scalar, numPhases * (numComponents - 1)> diffCoeff_;
76
77 /*
78 * \brief This calculates the array index to a corresponding matrix entry.
79 * An example with a 3p5c model:
80 * compJIdx
81 * [ x 0 1 2 3 ]
82 * phaseIdx [ 4 x 5 6 7 ]
83 * [ 8 9 x 10 11 ]
84 * -- "(phaseIdx * (numComponents-1))" advances to the phaseIdx row (numComp-1 per phase)
85 * -- "+ compJIdx" advances to the component index
86 * -- "- static_cast<int>(phaseIdx < compJIdx)" if the index is after the diagonal, -1.
87 */
88 constexpr int getIndex_(int phaseIdx, int compIIdx, int compJIdx) const
89 { return (phaseIdx * (numComponents-1)) + compJIdx - static_cast<int>(phaseIdx < compJIdx); }
90
91 void sortComponentIndices_(int phaseIdx, int& compIIdx, int& compJIdx) const
92 { if (compIIdx != std::min(phaseIdx, numComponents-1)) std::swap(compIIdx, compJIdx); }
93};
94
95} // end namespace Dumux
96
97#endif
Definition: adapt.hh:29
Container storing the diffusion coefficients required by Fick's law. Uses the minimal possible contai...
Definition: fickiandiffusioncoefficients.hh:44
Scalar operator()(int phaseIdx, int compIIdx, int compJIdx) const
Definition: fickiandiffusioncoefficients.hh:61
void update(const DiffCoeffFunc &computeDiffCoeff)
Definition: fickiandiffusioncoefficients.hh:47