darcyslaw.hh 10.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// -*- 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
 * \brief This file contains the data which is required to calculate
 *        volume and mass fluxes of fluid phases over a face of a finite volume by means
 *        of the Darcy approximation. Specializations are provided for the different discretization methods.
 */
#ifndef DUMUX_DISCRETIZATION_CC_MPFA_DARCYS_LAW_HH
#define DUMUX_DISCRETIZATION_CC_MPFA_DARCYS_LAW_HH

#include <memory>

#include <dune/common/float_cmp.hh>

#include <dumux/common/math.hh>
#include <dumux/common/parameters.hh>
#include <dumux/implicit/properties.hh>
35
#include <dumux/discretization/cellcentered/mpfa/facetypes.hh>
36
37
38
39
40
41
42
43
44
45
46
47

namespace Dumux
{

namespace Properties
{
// forward declaration of properties
NEW_PROP_TAG(ProblemEnableGravity);
}

/*!
 * \ingroup DarcysLaw
Dennis Gläser's avatar
Dennis Gläser committed
48
 * \brief Specialization of Darcy's Law for the CCMpfa method.
49
50
51
52
 */
template <class TypeTag>
class DarcysLawImplementation<TypeTag, DiscretizationMethods::CCMpfa>
{
53
    using Scalar = typename GET_PROP_TYPE(TypeTag, Scalar);
54
55
    using Problem = typename GET_PROP_TYPE(TypeTag, Problem);
    using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
56
    using MpfaHelper = typename GET_PROP_TYPE(TypeTag, MpfaHelper);
57
    using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry);
58
59
60
    using SubControlVolume = typename GET_PROP_TYPE(TypeTag, SubControlVolume);
    using SubControlVolumeFace = typename GET_PROP_TYPE(TypeTag, SubControlVolumeFace);
    using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables);
61
    using ElementVolumeVariables = typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables);
62
    using ElementFluxVarsCache = typename GET_PROP_TYPE(TypeTag, ElementFluxVariablesCache);
63
64
65
66
67
    using ElementSolutionVector = typename GET_PROP_TYPE(TypeTag, ElementSolutionVector);

    // Always use the dynamic type for vectors (compatibility with the boundary)
    using BoundaryInteractionVolume = typename GET_PROP_TYPE(TypeTag, BoundaryInteractionVolume);
    using DynamicVector = typename BoundaryInteractionVolume::Vector;
68
69
70
71
72

    using Element = typename GridView::template Codim<0>::Entity;
    using IndexType = typename GridView::IndexSet::IndexType;
    using Stencil = std::vector<IndexType>;

73
74
75
    static constexpr bool facetCoupling = GET_PROP_VALUE(TypeTag, MpfaFacetCoupling);
    static constexpr bool useTpfaBoundary = GET_PROP_VALUE(TypeTag, UseTpfaBoundary);
    static constexpr bool enableInteriorBoundaries = GET_PROP_VALUE(TypeTag, EnableInteriorBoundaries);
76

77
public:
78
79
80
    // state the discretization method this implementation belongs to
    static const DiscretizationMethods myDiscretizationMethod = DiscretizationMethods::CCMpfa;

81
82
83
84
85
86
    static Scalar flux(const Problem& problem,
                       const Element& element,
                       const FVElementGeometry& fvGeometry,
                       const ElementVolumeVariables& elemVolVars,
                       const SubControlVolumeFace& scvf,
                       const unsigned int phaseIdx,
87
                       const ElementFluxVarsCache& elemFluxVarsCache)
88
    {
89
        const bool gravity = GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity);
90
91

        const auto& fluxVarsCache = elemFluxVarsCache[scvf];
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
        const auto& volVarsStencil = fluxVarsCache.advectionVolVarsStencil();
        const auto& volVarsPositions = fluxVarsCache.advectionVolVarsPositions();
        const auto& tij = fluxVarsCache.advectionTij();

        const bool isInteriorBoundary = enableInteriorBoundaries && fluxVarsCache.isInteriorBoundary();
        // For interior Neumann boundaries when using Tpfa for Neumann boundary conditions, we simply
        // return the user-specified flux. We assume phaseIdx = eqIdx here.
        if (isInteriorBoundary
            && useTpfaBoundary
            && fluxVarsCache.interiorBoundaryDataSelf().faceType() == MpfaFaceTypes::interiorNeumann)
            return scvf.area()*
                   elemVolVars[scvf.insideScvIdx()].extrusionFactor()*
                   problem.neumann(element,
                                   fvGeometry,
                                   elemVolVars,
                                   scvf)[phaseIdx];

        // Calculate the interface density for gravity evaluation
        const auto rho = [&] ()
        {
            if (!gravity)
                return Scalar(0.0);
            else
            {
                // Treat interior boundaries differently
                if (enableInteriorBoundaries && isInteriorBoundary)
                {
                    const auto& data = fluxVarsCache.interiorBoundaryDataSelf();
                    if (facetCoupling || data.faceType() == MpfaFaceTypes::interiorDirichlet)
                        return data.facetVolVars(fvGeometry).density(phaseIdx);
                    else
                        return interpolateDensity(elemVolVars, scvf, phaseIdx);
                }
                else
                    return interpolateDensity(elemVolVars, scvf, phaseIdx);
            }
        } ();
129

130
131
132
133
134
135
136
137
        // calculate Tij*pj
        Scalar flux(0.0);
        unsigned int localIdx = 0;
        for (const auto volVarIdx : volVarsStencil)
        {
            const auto& volVars = elemVolVars[volVarIdx];
            Scalar h = volVars.pressure(phaseIdx);

138
            // if gravity is enabled, add gravitational acceleration
139
            if (gravity)
140
141
142
143
144
145
146
            {
                // gravitational acceleration in the center of the actual element
                const auto x = volVarsPositions[localIdx];
                const auto g = problem.gravityAtPos(x);

                h -= rho*(g*x);
            }
147

148
149
150
            flux += tij[localIdx++]*h;
        }

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
213
214
215
        // if no interior boundaries are present, return the flux
        if (!enableInteriorBoundaries)
            return useTpfaBoundary ? flux : flux + fluxVarsCache.advectionNeumannFlux(phaseIdx);

        //////////////////////////////////////////////////////////////////
        // Handle interior boundaries
        //////////////////////////////////////////////////////////////////

        // For active facet coupling we will have to transform the interior flux vector
        const auto& cij = fluxVarsCache.advectionCij();

        // The vector of interior neumann fluxes
        DynamicVector facetCouplingFluxes(cij.size(), 0.0);
        for (auto&& data : fluxVarsCache.interiorBoundaryData())
        {
            // Add additional Dirichlet fluxes for interior Dirichlet faces
            if (data.faceType() == MpfaFaceTypes::interiorDirichlet)
            {
                Scalar h = data.facetVolVars(fvGeometry).pressure(phaseIdx);

                if (gravity)
                {
                    const auto x = fvGeometry.scvf(data.scvfIndex()).ipGlobal();
                    const auto g = problem.gravityAtPos(x);

                    h -= rho*(g*x);
                }

                // The transmissibilities of interior dirichlet boundaries are placed at the end
                // So we simply keep incrementing the local index
                flux += tij[localIdx + data.localIndexInInteractionVolume()]*h;
            }

            // add neumann fluxes for interior Neumann faces if facet coupling is active
            if (facetCoupling && data.faceType() == MpfaFaceTypes::interiorNeumann)
            {
                // get the volvars of the actual interior neumann face
                const auto facetVolVars = data.facetVolVars(fvGeometry);

                // get the scvf corresponding to actual interior neumann face
                const auto& curScvf = fvGeometry.scvf(data.scvfIndex());

                // calculate "lekage factor"
                const auto n = curScvf.unitOuterNormal();
                const auto v = [&] ()
                                {
                                    auto res = n;
                                    res *= -0.5*facetVolVars.extrusionFactor();
                                    res -= curScvf.ipGlobal();
                                    res += curScvf.facetCorner();
                                    res /= res.two_norm2();
                                    return res;
                                } ();

                // add value to vector of interior neumann fluxes
                facetCouplingFluxes[data.localIndexInInteractionVolume()] -= facetVolVars.pressure(phaseIdx)*
                                                                             MpfaHelper::nT_M_v(n, facetVolVars.permeability(), v);
            }
        }

        // return overall resulting flux
        const Scalar interiorNeumannFlux = facetCoupling ? cij*facetCouplingFluxes : 0.0;
        return useTpfaBoundary ?
               flux + interiorNeumannFlux :
               flux + interiorNeumannFlux + fluxVarsCache.advectionNeumannFlux(phaseIdx);
216
217
    }

218
219
220
221
222
223
224
225
226
private:
    static Scalar interpolateDensity(const ElementVolumeVariables& elemVolVars,
                                     const SubControlVolumeFace& scvf,
                                     const unsigned int phaseIdx)
    {
        // use arithmetic mean of the densities around the scvf
        if (!scvf.boundary())
        {
            Scalar rho = elemVolVars[scvf.insideScvIdx()].density(phaseIdx);
227
            for (auto outsideIdx : scvf.outsideScvIndices())
228
                rho += elemVolVars[outsideIdx].density(phaseIdx);
229
            return rho/(scvf.outsideScvIndices().size()+1);
230
231
232
233
        }
        else
            return elemVolVars[scvf.outsideScvIdx()].density(phaseIdx);
    }
234
235
236
237
238
};

} // end namespace

#endif