mylocalresidual.hh 6.56 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
Bernd Flemisch's avatar
Bernd Flemisch committed
21
22
23
 * \ingroup PorousmediumImmiscible
 * \brief Element-wise calculation of the residual for problems
 *        using the n-phase immiscible fully implicit models.
24
 */
Bernd Flemisch's avatar
Bernd Flemisch committed
25
26
#ifndef DUMUX_MY_LOCAL_RESIDUAL_HH
#define DUMUX_MY_LOCAL_RESIDUAL_HH
27
28
29

#include <dumux/common/properties.hh>

Bernd Flemisch's avatar
Bernd Flemisch committed
30
31
namespace Dumux
{
32
/*!
Bernd Flemisch's avatar
Bernd Flemisch committed
33
34
35
 * \ingroup PorousmediumImmiscible
 * \brief Element-wise calculation of the residual for problems
 *        using the n-phase immiscible fully implicit models.
36
37
 */
template<class TypeTag>
38
class MyLocalResidual : public GetPropType<TypeTag, Properties::BaseLocalResidual>
39
{
40
41
42
43
44
45
46
47
48
    using ParentType = GetPropType<TypeTag, Properties::BaseLocalResidual>;
    using Scalar = GetPropType<TypeTag, Properties::Scalar>;
    using Problem = GetPropType<TypeTag, Properties::Problem>;
    using NumEqVector = GetPropType<TypeTag, Properties::NumEqVector>;
    using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
    using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
    using FluxVariables = GetPropType<TypeTag, Properties::FluxVariables>;
    using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
    using FVElementGeometry = typename GetPropType<TypeTag, Properties::FVGridGeometry>::LocalView;
49
50
    using SubControlVolume = typename FVElementGeometry::SubControlVolume;
    using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
51
    using GridView = GetPropType<TypeTag, Properties::GridView>;
52
    using Element = typename GridView::template Codim<0>::Entity;
53
    using EnergyLocalResidual = GetPropType<TypeTag, Properties::EnergyLocalResidual>;
54

55
    using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
Bernd Flemisch's avatar
Bernd Flemisch committed
56
57
    static constexpr int numPhases = ModelTraits::numPhases();
    static constexpr int conti0EqIdx = ModelTraits::Indices::conti0EqIdx; //!< first index for the mass balance
58
59
60
61
62

public:
    using ParentType::ParentType;

    /*!
Bernd Flemisch's avatar
Bernd Flemisch committed
63
64
65
66
67
68
69
70
71
     * \brief Evaluate the rate of change of all conservation
     *        quantites (e.g. phase mass) within a sub-control
     *        volume of a finite volume element for the immiscible models.
     * \param problem The problem
     * \param scv The sub control volume
     * \param volVars The current or previous volVars
     * \note This function should not include the source and sink terms.
     * \note The volVars can be different to allow computing
     *       the implicit euler time derivative here
72
     */
Bernd Flemisch's avatar
Bernd Flemisch committed
73
74
75
76
    // TODO: eliminate density from the storage term
    NumEqVector computeStorage(const Problem& problem,
                               const SubControlVolume& scv,
                               const VolumeVariables& volVars) const
77
    {
Bernd Flemisch's avatar
Bernd Flemisch committed
78
79
        // partial time derivative of the phase mass
        NumEqVector storage;
80
81
        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
        {
Bernd Flemisch's avatar
Bernd Flemisch committed
82
83
84
85
86
87
88
            auto eqIdx = conti0EqIdx + phaseIdx;
            storage[eqIdx] = volVars.porosity()
                             * volVars.density(phaseIdx)
                             * volVars.saturation(phaseIdx);

            //! The energy storage in the fluid phase with index phaseIdx
            EnergyLocalResidual::fluidPhaseStorage(storage, scv, volVars, phaseIdx);
89
90
        }

Bernd Flemisch's avatar
Bernd Flemisch committed
91
92
93
        //! The energy storage in the solid matrix
        EnergyLocalResidual::solidPhaseStorage(storage, scv, volVars);

94
95
96
        return storage;
    }

Bernd Flemisch's avatar
Bernd Flemisch committed
97

98
    /*!
Bernd Flemisch's avatar
Bernd Flemisch committed
99
     * \brief Evaluate the mass flux over a face of a sub control volume
100
     *
Bernd Flemisch's avatar
Bernd Flemisch committed
101
102
103
104
105
106
     * \param problem The problem
     * \param element The element
     * \param fvGeometry The finite volume geometry context
     * \param elemVolVars The volume variables for all flux stencil elements
     * \param scvf The sub control volume face to compute the flux on
     * \param elemFluxVarsCache The cache related to flux compuation
107
     */
Bernd Flemisch's avatar
Bernd Flemisch committed
108
109
110
111
112
113
114
    // TODO: eliminate the density from the flux term
    NumEqVector computeFlux(const Problem& problem,
                            const Element& element,
                            const FVElementGeometry& fvGeometry,
                            const ElementVolumeVariables& elemVolVars,
                            const SubControlVolumeFace& scvf,
                            const ElementFluxVariablesCache& elemFluxVarsCache) const
115
116
117
118
    {
        FluxVariables fluxVars;
        fluxVars.init(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache);

Bernd Flemisch's avatar
Bernd Flemisch committed
119
        NumEqVector flux;
120
121
        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
        {
Bernd Flemisch's avatar
Bernd Flemisch committed
122
123
124
125
126
127
            // the physical quantities for which we perform upwinding
            auto upwindTerm = [phaseIdx](const auto& volVars)
                              { return volVars.density(phaseIdx)*volVars.mobility(phaseIdx); };

            auto eqIdx = conti0EqIdx + phaseIdx;
            flux[eqIdx] = fluxVars.advectiveFlux(phaseIdx, upwindTerm);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

            //! Add advective phase energy fluxes. For isothermal model the contribution is zero.
            EnergyLocalResidual::heatConvectionFlux(flux, fluxVars, phaseIdx);
        }

        //! Add diffusive energy fluxes. For isothermal model the contribution is zero.
        EnergyLocalResidual::heatConductionFlux(flux, fluxVars);

        return flux;
    }
};

} // end namespace Dumux

#endif