stokes2cvolumevariables.hh 6.21 KB
Newer Older
Andreas Lauser's avatar
Andreas Lauser committed
1
2
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
3
/*****************************************************************************
4
 *   See the file COPYING for full copying permissions.                      *
5
6
7
8
9
10
11
12
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation, either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
14
15
16
17
18
19
20
21
22
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
 *
 * \brief Contains the quantities which are constant within a
Klaus Mosthaf's avatar
Klaus Mosthaf committed
23
 *        finite volume in the compositional Stokes model.
24
25
26
27
28
29
30
31
32
33
34
 */
#ifndef DUMUX_STOKES2C_VOLUME_VARIABLES_HH
#define DUMUX_STOKES2C_VOLUME_VARIABLES_HH

#include <dumux/freeflow/stokes/stokesvolumevariables.hh>
#include "stokes2cproperties.hh"

namespace Dumux
{

/*!
35
36
 * \ingroup BoxStokes2cModel
 * \ingroup BoxVolumeVariables
37
 * \brief Contains the quantities which are are constant within a
Klaus Mosthaf's avatar
Klaus Mosthaf committed
38
 *        finite volume in the two-component Stokes box model.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 */
template <class TypeTag>
class Stokes2cVolumeVariables : public StokesVolumeVariables<TypeTag>
{
    typedef StokesVolumeVariables<TypeTag> ParentType;

    typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
    typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;

    typedef typename GridView::template Codim<0>::Entity Element;
    typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry;
    typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
    typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
    typedef typename GET_PROP_TYPE(TypeTag, FluidState) FluidState;
    typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
54
    typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
55
56

    enum {
Klaus Mosthaf's avatar
Klaus Mosthaf committed
57
58
        transportCompIdx = Indices::transportCompIdx,
        phaseCompIdx = Indices::phaseCompIdx
59
60
    };
    enum { numComponents = GET_PROP_VALUE(TypeTag, NumComponents) };
61
    enum { phaseIdx = GET_PROP_VALUE(TypeTag, PhaseIdx) };
62
    enum { transportEqIdx = Indices::transportEqIdx };
Klaus Mosthaf's avatar
Klaus Mosthaf committed
63
    enum { massOrMoleFracIdx = Indices::massOrMoleFracIdx };
64
65
66

public:
    /*!
Bernd Flemisch's avatar
Bernd Flemisch committed
67
     * \copydoc ImplicitVolumeVariables::update()
68
     */
69
    void update(const PrimaryVariables &priVars,
70
71
                const Problem &problem,
                const Element &element,
72
73
74
                const FVElementGeometry &fvGeometry,
                const int scvIdx,
                const bool isOldSol)
75
76
    {
        // set the mole fractions first
77
        completeFluidState(priVars, problem, element, fvGeometry, scvIdx, this->fluidState(), isOldSol);
78
79

        // update vertex data for the mass and momentum balance
80
        ParentType::update(priVars,
81
82
                           problem,
                           element,
83
                           fvGeometry,
84
                           scvIdx,
85
86
87
88
89
90
91
92
93
94
95
                           isOldSol);

        // Second instance of a parameter cache.
        // Could be avoided if diffusion coefficients also
        // became part of the fluid state.
        typename FluidSystem::ParameterCache paramCache;
        paramCache.updateAll(this->fluidState());

        diffCoeff_ = FluidSystem::binaryDiffusionCoefficient(this->fluidState(),
                                                             paramCache,
                                                             phaseIdx,
Klaus Mosthaf's avatar
Klaus Mosthaf committed
96
97
                                                             transportCompIdx,
                                                             phaseCompIdx);
Klaus Mosthaf's avatar
Klaus Mosthaf committed
98

99
100
101
        Valgrind::CheckDefined(diffCoeff_);
    };

102
    /*!
Bernd Flemisch's avatar
Bernd Flemisch committed
103
     * \copydoc ImplicitModel::completeFluidState()
104
     * \param isOldSol Specifies whether this is the previous solution or the current one
105
     */
106
    static void completeFluidState(const PrimaryVariables& priVars,
107
108
                                   const Problem& problem,
                                   const Element& element,
109
110
                                   const FVElementGeometry& fvGeometry,
                                   const int scvIdx,
111
                                   FluidState& fluidState,
112
                                   const bool isOldSol = false)
113
114
    {
        Scalar massFraction[numComponents];
Klaus Mosthaf's avatar
Klaus Mosthaf committed
115
116
        massFraction[transportCompIdx] = priVars[massOrMoleFracIdx];
        massFraction[phaseCompIdx] = 1 - massFraction[transportCompIdx];
117
118

        // calculate average molar mass of the gas phase
Klaus Mosthaf's avatar
Klaus Mosthaf committed
119
120
121
        Scalar M1 = FluidSystem::molarMass(transportCompIdx);
        Scalar M2 = FluidSystem::molarMass(phaseCompIdx);
        Scalar X2 = massFraction[phaseCompIdx];
122
123
124
        Scalar avgMolarMass = M1*M2/(M2 + X2*(M1 - M2));

        // convert mass to mole fractions and set the fluid state
Klaus Mosthaf's avatar
Klaus Mosthaf committed
125
126
        fluidState.setMoleFraction(phaseIdx, transportCompIdx, massFraction[transportCompIdx]*avgMolarMass/M1);
        fluidState.setMoleFraction(phaseIdx, phaseCompIdx, massFraction[phaseCompIdx]*avgMolarMass/M2);
127
128
    }

Christoph Grueninger's avatar
Christoph Grueninger committed
129
130
131
132
133
134
135
    /*!
     * \brief Returns the molar density \f$\mathrm{[mol/m^3]}\f$ of the fluid within the
     *        sub-control volume.
     */
    Scalar molarDensity() const
    { return this->fluidState_.density(phaseIdx) / this->fluidState_.averageMolarMass(phaseIdx); }

136
    /*!
Klaus Mosthaf's avatar
Klaus Mosthaf committed
137
     * \brief Returns the binary (mass) diffusion coefficient
138
139
140
141
142
143
144
145
146
147
148
     */
    Scalar diffusionCoeff() const
    { return diffCoeff_; }

protected:
    Scalar diffCoeff_; //!< Binary diffusion coefficient
};

} // end namespace

#endif