volumevariables.hh 11.9 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 <dumux/porousmediumflow/nonisothermal/volumevariables.hh>
Timo Koch's avatar
Timo Koch committed
30
31
#include <dumux/material/solidstates/updatesolidvolumefractions.hh>
#include <dumux/porousmediumflow/2p/formulation.hh>
32

33
34
namespace Dumux {

35
36
37
38
39
/*!
 * \ingroup TwoPModel
 * \brief Contains the quantities which are are constant within a
 *        finite volume in the two-phase model.
 */
40
41
template <class Traits>
class TwoPVolumeVariables
42
: public PorousMediumFlowVolumeVariables<Traits>
Katharina Heck's avatar
Katharina Heck committed
43
, public EnergyVolumeVariables<Traits, TwoPVolumeVariables<Traits> >
44
{
45
46
    using ParentType = PorousMediumFlowVolumeVariables<Traits>;
    using EnergyVolVars = EnergyVolumeVariables<Traits, TwoPVolumeVariables<Traits> >;
47
48
49
50
    using PermeabilityType = typename Traits::PermeabilityType;
    using ModelTraits = typename Traits::ModelTraits;
    using Indices = typename ModelTraits::Indices;
    using Scalar = typename Traits::PrimaryVariables::value_type;
51
    using FS = typename Traits::FluidSystem;
52
    static constexpr int numFluidComps = ParentType::numFluidComponents();
53
54
    enum
    {
55
56
        pressureIdx = Indices::pressureIdx,
        saturationIdx = Indices::saturationIdx,
57
58
59

        phase0Idx = FS::phase0Idx,
        phase1Idx = FS::phase1Idx
60
61
    };

62
    static constexpr auto formulation = ModelTraits::priVarFormulation();
63

64
public:
65
66
67
68
    //! export type of fluid system
    using FluidSystem = typename Traits::FluidSystem;
    //! export type of fluid state
    using FluidState = typename Traits::FluidState;
69
70
71
72
    //! export type of solid state
    using SolidState = typename Traits::SolidState;
    //! export type of solid system
    using SolidSystem = typename Traits::SolidSystem;
73
74

    /*!
75
76
77
78
79
80
81
82
     * \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
    */
83
84
    template<class ElemSol, class Problem, class Element, class Scv>
    void update(const ElemSol &elemSol,
85
86
                const Problem &problem,
                const Element &element,
87
                const Scv& scv)
88
    {
89
        ParentType::update(elemSol, problem, element, scv);
90

91
        completeFluidState(elemSol, problem, element, scv, fluidState_, solidState_);
92

93
        using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
94
        const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
95

96
97
98
        const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
        const int nPhaseIdx = 1 - wPhaseIdx;

99
100
101
102
103
104
105
106
        mobility_[wPhaseIdx] =
            MaterialLaw::krw(materialParams, fluidState_.saturation(wPhaseIdx))
            / fluidState_.viscosity(wPhaseIdx);

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

107
        // porosity calculation over inert volumefraction
Katharina Heck's avatar
Katharina Heck committed
108
        updateSolidVolumeFractions(elemSol, problem, element, scv, solidState_, numFluidComps);
109
        EnergyVolVars::updateSolidEnergyParams(elemSol, problem, element, scv, solidState_);
110
        permeability_ = problem.spatialParams().permeability(element, scv, elemSol);
Katharina Heck's avatar
Katharina Heck committed
111
    }
112
113

    /*!
114
     * \brief Set complete fluid state
115
116
     *
     * \param elemSol A vector containing all primary variables connected to the element
117
118
119
120
121
     * \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
     * \param fluidState A container with the current (physical) state of the fluid
     * \param solidState A container with the current (physical) state of the solid
122
123
     *
     * Set temperature, saturations, capillary pressures, viscosities, densities and enthalpies.
124
     */
125
    template<class ElemSol, class Problem, class Element, class Scv>
126
127
128
129
    void completeFluidState(const ElemSol& elemSol,
                            const Problem& problem,
                            const Element& element,
                            const Scv& scv,
130
131
                            FluidState& fluidState,
                            SolidState& solidState)
132
    {
133
        EnergyVolVars::updateTemperature(elemSol, problem, element, scv, fluidState, solidState);
134

135
        using MaterialLaw = typename Problem::SpatialParams::MaterialLaw;
136
        const auto& materialParams = problem.spatialParams().materialLawParams(element, scv, elemSol);
137
        const auto& priVars = elemSol[scv.localDofIndex()];
138

139
140
141
142
        const int wPhaseIdx = problem.spatialParams().template wettingPhase<FluidSystem>(element, scv, elemSol);
        if (formulation == TwoPFormulation::p0s1)
        {
            fluidState.setPressure(phase0Idx, priVars[pressureIdx]);
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
            if (wPhaseIdx == phase1Idx)
            {
                fluidState.setSaturation(phase1Idx, priVars[saturationIdx]);
                fluidState.setSaturation(phase0Idx, 1 - priVars[saturationIdx]);
                pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
                fluidState.setPressure(phase1Idx, priVars[pressureIdx] - pc_);
            }
            else
            {
                const auto Sn = Traits::SaturationReconstruction::reconstructSn(problem.spatialParams(), element,
                                                                                scv, elemSol, priVars[saturationIdx]);
                fluidState.setSaturation(phase1Idx, Sn);
                fluidState.setSaturation(phase0Idx, 1 - Sn);
                pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
                fluidState.setPressure(phase1Idx, priVars[pressureIdx] + pc_);
            }
159
        }
160
161
162
        else if (formulation == TwoPFormulation::p1s0)
        {
            fluidState.setPressure(phase1Idx, priVars[pressureIdx]);
163
164
165
166
167
168
169
170
171
172
173
            if (wPhaseIdx == phase1Idx)
            {
                const auto Sn = Traits::SaturationReconstruction::reconstructSn(problem.spatialParams(), element,
                                                                                scv, elemSol, priVars[saturationIdx]);
                fluidState.setSaturation(phase0Idx, Sn);
                fluidState.setSaturation(phase1Idx, 1 - Sn);
                pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
                fluidState.setPressure(phase0Idx, priVars[pressureIdx] + pc_);
            }
            else
            {
174
175
                fluidState.setSaturation(phase0Idx, priVars[saturationIdx]);
                fluidState.setSaturation(phase1Idx, 1 - priVars[saturationIdx]);
176
177
178
                pc_ = MaterialLaw::pc(materialParams, fluidState.saturation(wPhaseIdx));
                fluidState.setPressure(phase0Idx, priVars[pressureIdx] - pc_);
            }
179
180
181
182
183
        }

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

184
        for (int phaseIdx = 0; phaseIdx < ModelTraits::numFluidPhases(); ++phaseIdx) {
185
186
187
188
189
190
191
192
193
            // 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
194
            Scalar h = EnergyVolVars::enthalpy(fluidState, paramCache, phaseIdx);
195
196
197
198
199
200
201
202
203
204
            fluidState.setEnthalpy(phaseIdx, h);
        }
    }

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

205
206
207
208
209
210
    /*!
     * \brief Returns the phase state for the control volume.
     */
    const SolidState &solidState() const
    { return solidState_; }

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
    /*!
     * \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
243
    { return pc_; }
244
245
246
247
248
249
250
251
252
253
254
255

    /*!
     * \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); }

256
257
258
259
260
261
262
263
264
    /*!
     * \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); }

265
266
267
268
269
270
271
272
273
274
275
276
277
    /*!
     * \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
278
    { return solidState_.porosity(); }
279

280
281
282
    /*!
     * \brief Returns the permeability within the control volume in \f$[m^2]\f$.
     */
283
    const PermeabilityType& permeability() const
284
285
    { return permeability_; }

286
287
protected:
    FluidState fluidState_;
288
    SolidState solidState_;
289
290

private:
291
    Scalar pc_;
292
    Scalar porosity_;
293
    PermeabilityType permeability_;
294
    Scalar mobility_[ModelTraits::numFluidPhases()];
295
296
};

297
} // end namespace Dumux
298
299

#endif