volumevariables.hh 9.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   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          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   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
21
 * \ingroup TwoPModel
22
23
24
25
26
27
 * \brief Contains the quantities which are constant within a
 *        finite volume in the two-phase model.
 */
#ifndef DUMUX_2P_VOLUME_VARIABLES_HH
#define DUMUX_2P_VOLUME_VARIABLES_HH

28
#include <dumux/porousmediumflow/volumevariables.hh>
29
#include "indices.hh"
30

31
32
namespace Dumux {

33
34
35
36
37
/*!
 * \ingroup TwoPModel
 * \brief Contains the quantities which are are constant within a
 *        finite volume in the two-phase model.
 */
38
39
40
template <class Traits>
class TwoPVolumeVariables
: public PorousMediumFlowVolumeVariables<Traits, TwoPVolumeVariables<Traits> >
41
{
42
43
44
45
46
47
48
    using ParentType = PorousMediumFlowVolumeVariables<Traits, TwoPVolumeVariables<Traits> >;

    using PermeabilityType = typename Traits::PermeabilityType;
    using ModelTraits = typename Traits::ModelTraits;
    using Indices = typename ModelTraits::Indices;
    static constexpr auto formulation = ModelTraits::priVarFormulation();
    using Scalar = typename Traits::PrimaryVariables::value_type;
49
    using FS = typename Traits::FluidSystem;
50
51
52

    enum
    {
53
54
        pressureIdx = Indices::pressureIdx,
        saturationIdx = Indices::saturationIdx,
55
56
57

        phase0Idx = FS::phase0Idx,
        phase1Idx = FS::phase1Idx
58
59
    };

60

61
public:
62
63
64
65
    //! export type of fluid system
    using FluidSystem = typename Traits::FluidSystem;
    //! export type of fluid state
    using FluidState = typename Traits::FluidState;
66
67

    /*!
68
69
70
71
72
73
74
75
     * \brief Update all quantities for a given control volume
     *
     * \param elemSol A vector containing all primary variables connected to the element
     * \param problem The object specifying the problem which ought to
     *                be simulated
     * \param element An element which contains part of the control volume
     * \param scv The sub control volume
    */
76
77
    template<class ElemSol, class Problem, class Element, class Scv>
    void update(const ElemSol &elemSol,
78
79
                const Problem &problem,
                const Element &element,
80
                const Scv& scv)
81
    {
82
        ParentType::update(elemSol, problem, element, scv);
83

84
        completeFluidState(elemSol, problem, element, scv, fluidState_);
85

86
        using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
87
        const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
88

89
90
91
        const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
        const int nPhaseIdx = 1 - wPhaseIdx;

92
93
94
95
96
97
98
99
100
        mobility_[wPhaseIdx] =
            MaterialLaw::krw(materialParams, fluidState_.saturation(wPhaseIdx))
            / fluidState_.viscosity(wPhaseIdx);

        mobility_[nPhaseIdx] =
            MaterialLaw::krn(materialParams, fluidState_.saturation(wPhaseIdx))
            / fluidState_.viscosity(nPhaseIdx);

        // porosity
101
102
        porosity_ = problem.spatialParams().porosity(element, scv, elemSol);
        permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
103
104
105
106

    }

    /*!
107
108
109
110
111
112
113
114
115
     * \brief Complete the fluid state
     *
     * \param elemSol A vector containing all primary variables connected to the element
     * \param problem The problem
     * \param element The element
     * \param scv The sub control volume
     * \param fluidState The fluid state
     *
     * Set temperature, saturations, capillary pressures, viscosities, densities and enthalpies.
116
     */
117
    template<class ElemSol, class Problem, class Element, class Scv>
118
119
120
121
122
    void completeFluidState(const ElemSol& elemSol,
                            const Problem& problem,
                            const Element& element,
                            const Scv& scv,
                            FluidState& fluidState)
123
    {
124
        Scalar t =  ParentType::temperature(elemSol, problem, element, scv);
125
126
        fluidState.setTemperature(t);

127
        using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
128
        const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
129
        const auto& priVars = ParentType::extractDofPriVars(elemSol, scv);
130

131
132
133
134
135
136
137
138
139
140
141
        const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
        if (formulation == TwoPFormulation::p0s1)
        {
            fluidState.setSaturation(phase1Idx, priVars[saturationIdx]);
            fluidState.setSaturation(phase0Idx, 1 - priVars[saturationIdx]);
        }
        else if (formulation == TwoPFormulation::p1s0)
        {
            fluidState.setSaturation(phase0Idx, priVars[saturationIdx]);
            fluidState.setSaturation(phase1Idx, 1 - priVars[saturationIdx]);
        }
142

143
144
145
146
147
148
        pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
        if (formulation == TwoPFormulation::p0s1)
        {
            fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
            fluidState.setPressure(phase1Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] + pc_
                                                                       : priVars[pressureIdx] - pc_);
149
        }
150
151
152
153
154
        else if (formulation == TwoPFormulation::p1s0)
        {
            fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
            fluidState.setPressure(phase0Idx, (wPhaseIdx == phase0Idx) ? priVars[pressureIdx] - pc_
                                                                       : priVars[pressureIdx] + pc_);
155
156
157
158
159
        }

        typename FluidSystem::ParameterCache paramCache;
        paramCache.updateAll(fluidState);

160
        for (int phaseIdx = 0; phaseIdx < ModelTraits::numPhases(); ++phaseIdx) {
161
162
163
164
165
166
167
168
169
            // compute and set the viscosity
            Scalar mu = FluidSystem::viscosity(fluidState, paramCache, phaseIdx);
            fluidState.setViscosity(phaseIdx, mu);

            // compute and set the density
            Scalar rho = FluidSystem::density(fluidState, paramCache, phaseIdx);
            fluidState.setDensity(phaseIdx, rho);

            // compute and set the enthalpy
170
            Scalar h = ParentType::enthalpy(fluidState, paramCache, phaseIdx);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
            fluidState.setEnthalpy(phaseIdx, h);
        }
    }

    /*!
     * \brief Returns the phase state for the control volume.
     */
    const FluidState &fluidState() const
    { return fluidState_; }

    /*!
     * \brief Returns the saturation of a given phase within
     *        the control volume in \f$[-]\f$.
     *
     * \param phaseIdx The phase index
     */
    Scalar saturation(int phaseIdx) const
    { return fluidState_.saturation(phaseIdx); }

    /*!
     * \brief Returns the mass density of a given phase within the
     *        control volume in \f$[kg/m^3]\f$.
     *
     * \param phaseIdx The phase index
     */
    Scalar density(int phaseIdx) const
    { return fluidState_.density(phaseIdx); }

    /*!
     * \brief Returns the effective pressure of a given phase within
     *        the control volume in \f$[kg/(m*s^2)=N/m^2=Pa]\f$.
     *
     * \param phaseIdx The phase index
     */
    Scalar pressure(int phaseIdx) const
    { return fluidState_.pressure(phaseIdx); }

    /*!
     * \brief Returns the capillary pressure within the control volume
     * in \f$[kg/(m*s^2)=N/m^2=Pa]\f$.
     */
    Scalar capillaryPressure() const
213
    { return pc_; }
214
215
216
217
218
219
220
221
222
223
224
225

    /*!
     * \brief Returns temperature inside the sub-control volume
     * in \f$[K]\f$.
     *
     * Note that we assume thermodynamic equilibrium, i.e. the
     * temperature of the rock matrix and of all fluid phases are
     * identical.
     */
    Scalar temperature() const
    { return fluidState_.temperature(/*phaseIdx=*/0); }

226
227
228
229
230
231
232
233
234
    /*!
     * \brief Returns the dynamic viscosity of the fluid within the
     *        control volume in \f$\mathrm{[Pa s]}\f$.
     *
     * \param phaseIdx The phase index
     */
    Scalar viscosity(int phaseIdx) const
    { return fluidState_.viscosity(phaseIdx); }

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
    /*!
     * \brief Returns the effective mobility of a given phase within
     *        the control volume in \f$[s*m/kg]\f$.
     *
     * \param phaseIdx The phase index
     */
    Scalar mobility(int phaseIdx) const
    { return mobility_[phaseIdx]; }

    /*!
     * \brief Returns the average porosity within the control volume in \f$[-]\f$.
     */
    Scalar porosity() const
    { return porosity_; }

250
251
252
    /*!
     * \brief Returns the permeability within the control volume in \f$[m^2]\f$.
     */
253
    const PermeabilityType& permeability() const
254
255
    { return permeability_; }

256
257
protected:
    FluidState fluidState_;
258
259

private:
260
    Scalar pc_;
261
    Scalar porosity_;
262
    PermeabilityType permeability_;
263
    Scalar mobility_[ModelTraits::numPhases()];
264
265
};

266
} // end namespace Dumux
267
268

#endif