fluxvariables.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*****************************************************************************
 *   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
 *        all fluxes of fluid phases over a face of a finite volume in the
 *        two phase discrete fracture-matrix model.
 */
#ifndef DUMUX_MODELS_2PDFM_FLUX_VARIABLES_HH
#define DUMUX_MODELS_2PDFM_FLUX_VARIABLES_HH

#include <dune/common/float_cmp.hh>

#include <dumux/common/math.hh>
#include <dumux/common/parameters.hh>
#include <dumux/common/valgrind.hh>
#include <dumux/porousmediumflow/implicit/darcyfluxvariables.hh>

#include "properties.hh"

namespace Dumux
{

/*!
 * \ingroup TwoPDFMModel
 * \ingroup ImplicitFluxVariables
 * \brief Contains the data which is required to calculate the fluxes of
 *        the fluid phases over a face of a finite volume for the two-phase
 *        discrete fracture-matrix model.
 *
 * This means pressure and concentration gradients, phase densities at
 * the intergration point, etc.
 */
template <class TypeTag>
class TwoPDFMFluxVariables : public ImplicitDarcyFluxVariables<TypeTag>
{
    typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
    typedef typename GET_PROP_TYPE(TypeTag, ElementVolumeVariables) ElementVolumeVariables;

    typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
    typedef typename GridView::template Codim<0>::Entity Element;
    enum {
        dimWorld = GridView::dimensionworld,
        numPhases = GET_PROP_VALUE(TypeTag, NumPhases)
    };

    typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;

    typedef typename GET_PROP_TYPE(TypeTag, FVElementGeometry) FVElementGeometry;
    typedef typename FVElementGeometry::SubControlVolumeFace SCVFace;
    typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition;
    typedef Dune::FieldVector<Scalar, numPhases> PhasesVector;

public:
    /*!
     * \brief The constructor
     *
     * \param problem The problem
     * \param element The finite element
     * \param fvGeometry The finite-volume geometry in the fully implicit scheme
     * \param fIdx The local index of the SCV (sub-control-volume) face
     * \param elemVolVars The volume variables of the current element
     * \param onBoundary A boolean variable to specify whether the flux variables
     * are calculated for interior SCV faces or boundary faces, default=false
     */
    TwoPDFMFluxVariables(const Problem &problem,
                 const Element &element,
                 const FVElementGeometry &fvGeometry,
                 int fIdx,
                 const ElementVolumeVariables &elemVolVars,
                 const bool onBoundary = false)
        : ImplicitDarcyFluxVariables<TypeTag>(problem, element, fvGeometry, fIdx, elemVolVars, onBoundary),
          fvGeometry_(fvGeometry), faceIdx_(fIdx), onBoundary_(onBoundary)
    {
        faceSCV_ = &this->face();

        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
        {
            potentialGradFracture_[phaseIdx] = 0.0;
        }

        calculateGradientsInFractures_(problem, element, elemVolVars, fIdx);
        calculateVelocitiesFracture_(problem, element, elemVolVars, fIdx);
    };

public:
    /*!
     * \brief Calculates the velocities in the lower-dimenstional fracture.
     *
     * \param problem The problem
     * \param element The finite element
     * \param elemVolVars The volume variables of the current element
     * \param fIdx The local index of the SCV (sub-control-volume) face
     */
    void calculateVelocitiesFracture_(const Problem &problem,
                                      const Element &element,
                                      const ElementVolumeVariables &elemVolVars,
                                      int fIdx)
    {
        isFracture_ = problem.spatialParams().isEdgeFracture(element, fIdx);
        fractureWidth_ = problem.spatialParams().fractureWidth(element, fIdx);

        Scalar KFracture, KFi, KFj; //permeabilities of the fracture
        if (isFracture_)
        {
            KFi = problem.spatialParams().
                intrinsicPermeabilityFracture(element, this->fvGeometry_, this->face().i);
            KFj = problem.spatialParams().
                intrinsicPermeabilityFracture(element, this->fvGeometry_, this->face().j);
        }
        else
        {
            KFi = 0;
            KFj = 0;
        }

        KFracture = Dumux::harmonicMean(KFi, KFj);

        // temporary vector for the Darcy velocity
        Scalar vDarcyFracture = 0;
        for (int phaseIdx=0; phaseIdx < numPhases; phaseIdx++)
        {
            vDarcyFracture = - (KFracture * potentialGradFracture_[phaseIdx]);

            Valgrind::CheckDefined(KFracture);
            Valgrind::CheckDefined(fractureWidth_);
            vDarcyFracture_[phaseIdx] = (vDarcyFracture * fractureWidth_);
            Valgrind::CheckDefined(vDarcyFracture_[phaseIdx]);
        }

        // set the upstream and downstream vertices
        for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
        {
            upstreamFractureIdx[phaseIdx] = faceSCV_->i;
            downstreamFractureIdx[phaseIdx] = faceSCV_->j;

            if (vDarcyFracture_[phaseIdx] < 0)
            {
                std::swap(upstreamFractureIdx[phaseIdx],
                          downstreamFractureIdx[phaseIdx]);
            }
        }
    }

    /*!
     * \brief Return the pressure potential gradient in the lower dimensional fracture.
     *
     * \param phaseIdx The index of the fluid phase
     */
    const Scalar &potentialGradFracture(int phaseIdx) const
    {
        return potentialGradFracture_[phaseIdx];
    }


    PhasesVector vDarcyFracture_;

    int upstreamFractureIdx[numPhases];
    int downstreamFractureIdx[numPhases];
protected:
    // gradients
    Scalar potentialGradFracture_[numPhases];
    const FVElementGeometry &fvGeometry_;
    int faceIdx_;
    const bool onBoundary_;
    bool isFracture_;
    Scalar fractureWidth_;
    const SCVFace *faceSCV_;

private:
    /*!
     * \brief Calculates the gradients in the lower-dimenstional fracture.
     *
     * \param problem The problem
     * \param element The finite element
     * \param elemVolVars The volume variables of the current element
     * \param fIdx The local index of the SCV (sub-control-volume) face
     */
    void calculateGradientsInFractures_(const Problem &problem,
                                        const Element &element,
                                        const ElementVolumeVariables &elemVolVars,
                                        int fIdx)
    {
        // calculate gradients, loop over adjacent vertices
        for (unsigned int idx = 0; idx < this->face().numFap; idx++)
        {
            int i = this->face().i;
            int j = this->face().j;

            const auto geometry = element.geometry();

            // compute sum of pressure gradients for each phase
            for (int phaseIdx = 0; phaseIdx < numPhases; phaseIdx++)
            {
                const GlobalPosition localIdx_i = geometry.corner(i);
                const GlobalPosition localIdx_j = geometry.corner(j);

                isFracture_ = problem.spatialParams().isEdgeFracture(element, fIdx);

                if (isFracture_)
                {
                    GlobalPosition diff_ij = localIdx_j;
                    diff_ij -= localIdx_i;
                    potentialGradFracture_[phaseIdx] =
                        (elemVolVars[j].pressure(phaseIdx) - elemVolVars[i].pressure(phaseIdx))
                        / diff_ij.two_norm();

                    // correct the pressure gradient by the gravitational acceleration
                    if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity))
                    {
                        // ask for the gravitational acceleration at the given SCV face
                        GlobalPosition g(problem.gravityAtPos(this->face().ipGlobal));

                        // calculate the phase density at the integration point. we
                        // only do this if the wetting phase is present in both cells
230
231
232
233
                        Scalar SI = elemVolVars[this->face().i].saturation(phaseIdx);
                        Scalar SJ = elemVolVars[this->face().j].saturation(phaseIdx);
                        Scalar rhoI = elemVolVars[this->face().i].density(phaseIdx);
                        Scalar rhoJ = elemVolVars[this->face().j].density(phaseIdx);
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
                        Scalar fI = std::max(0.0, std::min(SI/1e-5, 0.5));
                        Scalar fJ = std::max(0.0, std::min(SJ/1e-5, 0.5));
                        if (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(fI + fJ, 0.0, 1.0e-30))
                            // doesn't matter because no wetting phase is present in
                            // both cells!
                            fI = fJ = 0.5;
                        const Scalar density = (fI*rhoI + fJ*rhoJ)/(fI + fJ);

                        // make gravity acceleration a force
                        GlobalPosition f(g);
                        f *= density;

                        //transform into fracture local coordinates
                        diff_ij/=diff_ij.two_norm();
                        Scalar fractureLocalGravityForce=diff_ij*f;

                        // calculate the final potential gradient
                        potentialGradFracture_[phaseIdx] -= fractureLocalGravityForce;
                    }// gravity
                }
                else
                {
                    potentialGradFracture_[phaseIdx] = 0;
                }
            }
        }
    }
};

} // end namespace

#endif // DUMUX_MODELS_2PDFM_FLUX_VARIABLES_HH