fvmpfao2dpressurevelocity2p.hh 23.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*****************************************************************************
 *   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/>.   *
 *****************************************************************************/

#ifndef DUMUX_MPFAO2DPRESSUREVELOCITIES2P_HH
#define DUMUX_MPFAO2DPRESSUREVELOCITIES2P_HH

21
#include <dune/common/float_cmp.hh>
22
23
24
25
26
27
28
29
30
31
32
33
#include "fvmpfao2dpressure2p.hh"
#include "fvmpfao2dvelocity2p.hh"

/**
 * @file
 * @brief  Velocity Field from a finite volume solution of a pressure equation using a MPFA O-method.
 */

namespace Dumux
{

//! \ingroup FVPressure2p
34
/*! \brief Class for the calculation of velocities from the  pressure solution of an IMPES scheme using a MPFA O-method.
35
 *
36
37
 * Can be used for calculating the complete velocity field before the solution of the transport equation (more efficient),
 * or for face-wise velocity calculation directly in the transport solution (less efficient).
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
 *
 * Remark1: only for 2-D quadrilateral grids!
 *
 * Remark2: can use UGGrid, ALUGrid or SGrid/YaspGrid!
 *
 * \tparam TypeTag The problem Type Tag
 */
template<class TypeTag> class FvMpfaO2dPressureVelocity2p: public FvMpfaO2dPressure2p<TypeTag>
{
    typedef FvMpfaO2dPressure2p<TypeTag> ParentType;

    typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;

    enum
    {
        dim = GridView::dimension, dimWorld = GridView::dimensionworld
    };

    typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
    typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
    typedef typename GET_PROP_TYPE(TypeTag, CellData) CellData;
    typedef typename GET_PROP_TYPE(TypeTag, BoundaryTypes) BoundaryTypes;
    typedef typename GET_PROP(TypeTag, SolutionTypes) SolutionTypes;
    typedef typename SolutionTypes::PrimaryVariables PrimaryVariables;

    typedef typename GET_PROP_TYPE(TypeTag, SpatialParams) SpatialParams;
    typedef typename SpatialParams::MaterialLaw MaterialLaw;

    typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
    typedef typename GET_PROP_TYPE(TypeTag, FluidState) FluidState;

    typedef typename GridView::template Codim<0>::Iterator ElementIterator;
    typedef typename GridView::template Codim<dim>::Iterator VertexIterator;
    typedef typename GridView::Traits::template Codim<dim>::Entity Vertex;
    typedef typename GridView::Traits::template Codim<0>::EntityPointer ElementPointer;
    typedef typename GridView::Traits::template Codim<dim>::EntityPointer VertexPointer;
    typedef typename GridView::Intersection Intersection;

76
77
    typedef typename Dune::ReferenceElements<Scalar, dim> ReferenceElements;
    typedef typename Dune::ReferenceElement<Scalar, dim> ReferenceElement;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

    typedef Dumux::FVMPFAOInteractionVolume<TypeTag> InteractionVolume;

    typedef typename GET_PROP_TYPE(TypeTag, Indices) Indices;
    enum
        {
            wPhaseIdx = Indices::wPhaseIdx,
            nPhaseIdx = Indices::nPhaseIdx,
            pw = Indices::pressureW,
            pn = Indices::pressureNw,
            vw = Indices::velocityW,
            vn = Indices::velocityNw,
            sw = Indices::saturationW,
            sn = Indices::saturationNw,
            pressureIdx = Indices::pressureIdx,
            saturationIdx = Indices::saturationIdx,
94
95
            pressEqIdx = Indices::pressureEqIdx,
            satEqIdx = Indices::satEqIdx,
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
            numPhases = GET_PROP_VALUE(TypeTag, NumPhases)
        };

    typedef Dune::FieldVector<Scalar, dimWorld> GlobalPosition;
    typedef Dune::FieldMatrix<Scalar, dim, dim> DimMatrix;

public:
    //! Constructs a FvMpfaO2dPressureVelocity2p object
    /*!
     * \param problem A problem class object
     */
    FvMpfaO2dPressureVelocity2p(Problem& problem) :
            ParentType(problem), problem_(problem), velocity_(problem)
    {
        density_[wPhaseIdx] = 0.;
        density_[nPhaseIdx] = 0.;
        viscosity_[wPhaseIdx] = 0.;
        viscosity_[nPhaseIdx] = 0.;

        calcVelocityInTransport_ = GET_PARAM_FROM_GROUP(TypeTag, bool, MPFA, CalcVelocityInTransport);
    }

    //Calculates the velocities at all cell-cell interfaces.
    void calculateVelocity();

    // Calculates the velocity at a cell-cell interface.
    void calculateVelocity(const Intersection&, CellData&);
    void calculateVelocityOnBoundary(const Intersection& intersection, CellData& cellData);

125
    //! Function for updating the velocity field if iterations are necessary in the transport solution
126
127
128
129
    void updateVelocity()
    {
        this->updateMaterialLaws();

130
        this->storePressureSolution();
131
132
133
134
135
136
137

        if (!calculateVelocityInTransport())
            calculateVelocity();
    }

    /*! \brief Initializes pressure and velocity
     *
Thomas Fetzer's avatar
Thomas Fetzer committed
138
     * \copydetails FVPressure::initialize()
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
     */
    void initialize()
    {
        ElementIterator element = problem_.gridView().template begin<0>();
        FluidState fluidState;
        fluidState.setPressure(wPhaseIdx, problem_.referencePressure(*element));
        fluidState.setPressure(nPhaseIdx, problem_.referencePressure(*element));
        fluidState.setTemperature(problem_.temperature(*element));
        fluidState.setSaturation(wPhaseIdx, 1.);
        fluidState.setSaturation(nPhaseIdx, 0.);
        density_[wPhaseIdx] = FluidSystem::density(fluidState, wPhaseIdx);
        density_[nPhaseIdx] = FluidSystem::density(fluidState, nPhaseIdx);
        viscosity_[wPhaseIdx] = FluidSystem::viscosity(fluidState, wPhaseIdx);
        viscosity_[nPhaseIdx] = FluidSystem::viscosity(fluidState, nPhaseIdx);

        ParentType::initialize();
        velocity_.initialize();
        if (!calculateVelocityInTransport())
            calculateVelocity();

        return;
    }

    /*! \brief Pressure and velocity update
     *
Thomas Fetzer's avatar
Thomas Fetzer committed
164
     * \copydetails FVPressure::update()
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
     */
    void update()
    {
        ParentType::update();
        if (!calculateVelocityInTransport())
            calculateVelocity();
    }

    /*! \brief Indicates if velocity is reconstructed in the pressure step or in the transport step
     *
     * Returns true (In the standard finite volume discretization the velocity is calculated during the saturation transport.)
     */
    bool calculateVelocityInTransport()
    {
        return calcVelocityInTransport_;
    }

    /*! \brief Adds velocity output to the output file
     *
     * Adds the phase velocities or a total velocity (depending on the formulation) to the output.
     * If the VtkOutputLevel is equal to zero (default) only primary variables are written,
     * if it is larger than zero also secondary variables are written.
     *
     * \tparam MultiWriter Class defining the output writer
     * \param writer The output writer (usually a <tt>VTKMultiWriter</tt> object)
     *
     */
    template<class MultiWriter>
    void addOutputVtkFields(MultiWriter &writer)
    {
            ParentType::addOutputVtkFields(writer);
            velocity_.addOutputVtkFields(writer);
    }

199
200
201
202
203
    FvMpfaO2dVelocity2P<TypeTag> velocity()
    {
        return velocity_;
    }

204
205
206
207
208
209
private:
    Problem& problem_;
    FvMpfaO2dVelocity2P<TypeTag> velocity_;
    Scalar density_[numPhases];
    Scalar viscosity_[numPhases];
    bool calcVelocityInTransport_;
210
    //! gives kind of pressure used (\f$ 0 = p_w\f$, \f$ 1 = p_n\f$, \f$ 2 = p_{global}\f$)
211
    static const int pressureType_ = GET_PROP_VALUE(TypeTag, PressureFormulation);
212
    //! gives kind of saturation used (\f$ 0 = S_w\f$, \f$ 1 = S_n\f$)
213
    static const int saturationType_ = GET_PROP_VALUE(TypeTag, SaturationFormulation);
214
215
216
};
// end of template

217
/*! \brief Calculates the velocities at a cell-cell interfaces for the entire simulation grid.
218
 *
219
 * Calculates the velocities at a cell-cell interfaces from a given pressure field for the entire simulation grid.
220
221
222
223
224
225
 *
 */
template<class TypeTag>
void FvMpfaO2dPressureVelocity2p<TypeTag>::calculateVelocity()
{
    // run through all elements
226
227
    VertexIterator vEndIt = problem_.gridView().template end<dim>();
    for (VertexIterator vIt = problem_.gridView().template begin<dim>(); vIt != vEndIt; ++vIt)
228
    {
229
        int vIdxGlobal = problem_.variables().index(*vIt);
230

231
        InteractionVolume& interactionVolume = this->interactionVolumes_[vIdxGlobal];
232
233
234
235
236
237
238
239
240

        if (interactionVolume.isInnerVolume())
        {
            ElementPointer & elementPointer1 = interactionVolume.getSubVolumeElement(0);
            ElementPointer & elementPointer2 = interactionVolume.getSubVolumeElement(1);
            ElementPointer & elementPointer3 = interactionVolume.getSubVolumeElement(2);
            ElementPointer & elementPointer4 = interactionVolume.getSubVolumeElement(3);

            // cell index
241
242
243
244
            int eIdxGlobal1 = problem_.variables().index(*elementPointer1);
            int eIdxGlobal2 = problem_.variables().index(*elementPointer2);
            int eIdxGlobal3 = problem_.variables().index(*elementPointer3);
            int eIdxGlobal4 = problem_.variables().index(*elementPointer4);
245
246

            //get the cell Data
247
248
249
250
            CellData& cellData1 = problem_.variables().cellData(eIdxGlobal1);
            CellData& cellData2 = problem_.variables().cellData(eIdxGlobal2);
            CellData& cellData3 = problem_.variables().cellData(eIdxGlobal3);
            CellData& cellData4 = problem_.variables().cellData(eIdxGlobal4);
251

252
253
            velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume, cellData1, cellData2, cellData3,
                                                              cellData4, this->innerBoundaryVolumeFaces_);
254
255
256
257
258
259
260
        }
        // at least one face on boundary!
        else
        {
            for (int elemIdx = 0; elemIdx < 2 * dim; elemIdx++)
            {
                bool isOutside = false;
261
                for (int fIdx = 0; fIdx < dim; fIdx++)
262
                {
263
                    int intVolFaceIdx = interactionVolume.getFaceIndexFromSubVolume(elemIdx, fIdx);
264
265
266
267
268
269
270
271
272
273
274
275
276
                    if (interactionVolume.isOutsideFace(intVolFaceIdx))
                    {
                        isOutside = true;
                        break;
                    }
                }
                if (isOutside)
                {
                    continue;
                }
                ElementPointer & elementPointer = interactionVolume.getSubVolumeElement(elemIdx);

                // cell index
277
                int eIdxGlobal = problem_.variables().index(*elementPointer);
278
                //get the cell Data
279
                CellData& cellData = problem_.variables().cellData(eIdxGlobal);
280
281
282
283
284
285
286
287
288
289

                velocity_.calculateBoundaryInteractionVolumeVelocity(interactionVolume, cellData, elemIdx);
            }
        } // end boundaries

    } // end vertex iterator

    return;
} // end method calcTotalVelocity

290
291
292
293
294
295
296
/*! \brief Calculates the velocity at a cell-cell interface.
 *
 * Calculates the velocity at a cell-cell interface from a given pressure field.
 *
 * \param intersection Intersection of two grid cells
 * \param cellData Object containing all model relevant cell data
 */
297
298
299
300
301
302
303
304
template<class TypeTag>
void FvMpfaO2dPressureVelocity2p<TypeTag>::calculateVelocity(const Intersection& intersection, CellData& cellData)
{
    int numVertices = intersection.geometry().corners();

    ElementPointer elementPtrI = intersection.inside();
    ElementPointer elementPtrJ = intersection.outside();

305
306
    int eIdxGlobalI = problem_.variables().index(*elementPtrI);
    int eIdxGlobalJ = problem_.variables().index(*elementPtrJ);
307

308
    CellData& cellDataJ = problem_.variables().cellData(eIdxGlobalJ);
309

310
    const ReferenceElement& referenceElement = ReferenceElements::general(elementPtrI->geometry().type());
311
312
313
314
315
316

    int indexInInside = intersection.indexInInside();
    int indexInOutside = intersection.indexInOutside();

    Dune::FieldVector<CellData, 4> cellDataTemp;

317
    for (int vIdx = 0; vIdx < numVertices; vIdx++)
318
    {
319
        int localVertIdx = referenceElement.subEntity(indexInInside, dim - 1, vIdx, dim);
320

321
        int vIdxGlobal = problem_.variables().index(
322
323
                *((*elementPtrI).template subEntity < dim > (localVertIdx)));

324
        InteractionVolume& interactionVolume = this->interactionVolumes_[vIdxGlobal];
325
326
327
328
329
330
331
332
333
334

        if (interactionVolume.isInnerVolume())
        {

        ElementPointer & elementPointer1 = interactionVolume.getSubVolumeElement(0);
        ElementPointer & elementPointer2 = interactionVolume.getSubVolumeElement(1);
        ElementPointer & elementPointer3 = interactionVolume.getSubVolumeElement(2);
        ElementPointer & elementPointer4 = interactionVolume.getSubVolumeElement(3);

        // cell index
335
336
337
338
339
        int eIdxGlobal[4];
        eIdxGlobal[0] = problem_.variables().index(*elementPointer1);
        eIdxGlobal[1] = problem_.variables().index(*elementPointer2);
        eIdxGlobal[2] = problem_.variables().index(*elementPointer3);
        eIdxGlobal[3] = problem_.variables().index(*elementPointer4);
340
341

        //get the cell Data
342
343
344
345
        cellDataTemp[0] = problem_.variables().cellData(eIdxGlobal[0]);
        cellDataTemp[1] = problem_.variables().cellData(eIdxGlobal[1]);
        cellDataTemp[2] = problem_.variables().cellData(eIdxGlobal[2]);
        cellDataTemp[3] = problem_.variables().cellData(eIdxGlobal[3]);
346

347
348
        velocity_.calculateInnerInteractionVolumeVelocity(interactionVolume, cellDataTemp[0], cellDataTemp[1],
                                                          cellDataTemp[2], cellDataTemp[3], this->innerBoundaryVolumeFaces_);
349
350
351

        for (int i = 0; i < 4; i++)
        {
352
            if (eIdxGlobal[i] == eIdxGlobalI)
353
            {
354
355
356
357
358
359
360
361
                 cellData.fluxData().setVelocity(wPhaseIdx, indexInInside,
                                                 cellDataTemp[i].fluxData().velocity(wPhaseIdx, indexInInside));
                 cellData.fluxData().setVelocity(nPhaseIdx, indexInInside,
                                                 cellDataTemp[i].fluxData().velocity(nPhaseIdx, indexInInside));
                 cellData.fluxData().setUpwindPotential(wPhaseIdx, indexInInside,
                                                        cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInInside));
                 cellData.fluxData().setUpwindPotential(nPhaseIdx, indexInInside,
                                                        cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInInside));
362
            }
363
            else if (eIdxGlobal[i] == eIdxGlobalJ)
364
            {
365
366
367
368
369
370
371
372
                cellDataJ.fluxData().setVelocity(wPhaseIdx, indexInOutside,
                                                 cellDataTemp[i].fluxData().velocity(wPhaseIdx, indexInOutside));
                cellDataJ.fluxData().setVelocity(nPhaseIdx, indexInOutside,
                                                 cellDataTemp[i].fluxData().velocity(nPhaseIdx, indexInOutside));
                cellDataJ.fluxData().setUpwindPotential(wPhaseIdx, indexInOutside,
                                                        cellDataTemp[i].fluxData().upwindPotential(wPhaseIdx, indexInOutside));
                cellDataJ.fluxData().setUpwindPotential(nPhaseIdx, indexInOutside,
                                                        cellDataTemp[i].fluxData().upwindPotential(nPhaseIdx, indexInOutside));
373
374
375
376
            }
        }
    }
    }
377
378


379
380
381
382
    cellData.fluxData().setVelocityMarker(indexInInside);
    cellDataJ.fluxData().setVelocityMarker(indexInOutside);
}

383
384
385
386
387
388
389
/*! \brief Calculates the velocity at a boundary.
 *
 * Calculates the velocity at a boundary from a given pressure field.
 *
 * \param intersection Boundary intersection
 * \param cellData Object containing all model relevant cell data
 */
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
template<class TypeTag>
void FvMpfaO2dPressureVelocity2p<TypeTag>::calculateVelocityOnBoundary(const Intersection& intersection, CellData& cellData)
{
    ElementPointer element = intersection.inside();

    //get face index
    int isIndex = intersection.indexInInside();

    //get face normal
    const Dune::FieldVector<Scalar, dim>& unitOuterNormal = intersection.centerUnitOuterNormal();

    BoundaryTypes bcType;
    //get boundary type
    problem_.boundaryTypes(bcType, intersection);
    PrimaryVariables boundValues(0.0);

406
    if (bcType.isDirichlet(pressEqIdx))
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
    {
        problem_.dirichlet(boundValues, intersection);

        // get global coordinates of cell centers
        const GlobalPosition& globalPosI = element->geometry().center();

        // center of face in global coordinates
        const GlobalPosition& globalPosJ = intersection.geometry().center();

        // get mobilities and fractional flow factors
        Scalar lambdaWI = cellData.mobility(wPhaseIdx);
        Scalar lambdaNwI = cellData.mobility(nPhaseIdx);

        // get capillary pressure
        Scalar pcI = cellData.capillaryPressure();

        // distance vector between barycenters
        GlobalPosition distVec = globalPosJ - globalPosI;

        // compute distance between cell centers
        Scalar dist = distVec.two_norm();

        //permeability vector at boundary
        // compute vectorized permeabilities
        DimMatrix meanPermeability(0);

        problem_.spatialParams().meanK(meanPermeability, problem_.spatialParams().intrinsicPermeability(*element));

        Dune::FieldVector<Scalar, dim> permeability(0);
        meanPermeability.mv(unitOuterNormal, permeability);

        //determine saturation at the boundary -> if no saturation is known directly at the boundary use the cell saturation
        Scalar satW = 0;
440
        if (bcType.isDirichlet(satEqIdx))
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
        {
            switch (saturationType_)
            {
            case sw:
            {
                satW = boundValues[saturationIdx];
                break;
            }
            case sn:
            {
                satW = 1 - boundValues[saturationIdx];
                break;
            }
            }
        }
        else
        {
            satW = cellData.saturation(wPhaseIdx);
        }

        Scalar pressBound = boundValues[pressureIdx];
        Scalar pcBound = MaterialLaw::pc(problem_.spatialParams().materialLawParams(*element), satW);

        //determine phase pressures from primary pressure variable
        Scalar pressWBound = 0;
        Scalar pressNwBound = 0;
        if (pressureType_ == pw)
        {
            pressWBound = pressBound;
            pressNwBound = pressBound + pcBound;
        }
        else if (pressureType_ == pn)
        {
            pressWBound = pressBound - pcBound;
            pressNwBound = pressBound;
        }

        Scalar lambdaWBound = MaterialLaw::krw(problem_.spatialParams().materialLawParams(*element), satW)
                / viscosity_[wPhaseIdx];
        Scalar lambdaNwBound = MaterialLaw::krn(problem_.spatialParams().materialLawParams(*element), satW)
                / viscosity_[nPhaseIdx];

        Scalar potentialDiffW = cellData.fluxData().upwindPotential(wPhaseIdx, isIndex);
        Scalar potentialDiffNw = cellData.fluxData().upwindPotential(nPhaseIdx, isIndex);

        //calculate potential gradient
487
488
        potentialDiffW = (cellData.pressure(wPhaseIdx) - pressWBound);
        potentialDiffNw = (cellData.pressure(nPhaseIdx) - pressNwBound);
489
490
491
492
493
494
495
496
497
498

        potentialDiffW += density_[wPhaseIdx] * (distVec * problem_.gravity());
        potentialDiffNw += density_[nPhaseIdx] * (distVec * problem_.gravity());

        //store potential gradients for further calculations
        cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, potentialDiffW);
        cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, potentialDiffNw);

        //do the upwinding of the mobility depending on the phase potentials
        Scalar lambdaW = (potentialDiffW > 0.) ? lambdaWI : lambdaWBound;
499
        lambdaW = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffW, 0.0, 1.0e-30)) ? 0.5 * (lambdaWI + lambdaWBound) : lambdaW;
500
        Scalar lambdaNw = (potentialDiffNw > 0.) ? lambdaNwI : lambdaNwBound;
501
        lambdaNw = (Dune::FloatCmp::eq<Scalar, Dune::FloatCmp::absolute>(potentialDiffNw, 0.0, 1.0e-30)) ? 0.5 * (lambdaNwI + lambdaNwBound) : lambdaNw;
502
503
504
505
506
507
508
509
510
511
512


        Scalar scalarPerm = permeability.two_norm();

        //calculate the gravity term
        Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
        Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);

        //calculate unit distVec
        distVec /= dist;
        Scalar areaScaling = (unitOuterNormal * distVec);
513
514
        //this treatment of g allows to account for gravity flux through faces where the face normal
        //has no z component (e.g. parallelepiped grids)
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
        Scalar gravityTermW = (problem_.gravity() * distVec) * density_[wPhaseIdx] * areaScaling;
        Scalar gravityTermNw = (problem_.gravity() * distVec) * density_[nPhaseIdx] * areaScaling;

        //calculate velocity depending on the pressure used -> use pc = pn - pw
        switch (pressureType_)
        {
        case pw:
        {
            velocityW *= lambdaW * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermW);
            velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(wPhaseIdx) - pressBound) / dist + gravityTermNw)
                    + 0.5 * (lambdaNwI + lambdaNwBound) * scalarPerm * (pcI - pcBound) / dist;
            break;
        }
        case pn:
        {
            velocityW *= lambdaW * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermW)
                    - 0.5 * (lambdaWI + lambdaWBound) * scalarPerm * (pcI - pcBound) / dist;
            velocityNw *= lambdaNw * scalarPerm * ((cellData.pressure(nPhaseIdx) - pressBound) / dist + gravityTermNw);
            break;
        }
        }

        //store velocities
        cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
        cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
        cellData.fluxData().setVelocityMarker(isIndex);

    } //end dirichlet boundary

544
    else if (bcType.isNeumann(pressEqIdx))
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
    {
        problem_.neumann(boundValues, intersection);

        Dune::FieldVector<Scalar, dimWorld> velocityW(unitOuterNormal);
        Dune::FieldVector<Scalar, dimWorld> velocityNw(unitOuterNormal);

        velocityW *= boundValues[wPhaseIdx];
        velocityNw *= boundValues[nPhaseIdx];

            velocityW /= density_[wPhaseIdx];
            velocityNw /= density_[nPhaseIdx];

        //store potential gradients for further calculations
        cellData.fluxData().setUpwindPotential(wPhaseIdx, isIndex, boundValues[wPhaseIdx]);
        cellData.fluxData().setUpwindPotential(nPhaseIdx, isIndex, boundValues[nPhaseIdx]);

        cellData.fluxData().setVelocity(wPhaseIdx, isIndex, velocityW);
        cellData.fluxData().setVelocity(nPhaseIdx, isIndex, velocityNw);
        cellData.fluxData().setVelocityMarker(isIndex);
    } //end neumann boundary
    else
    {
        DUNE_THROW(Dune::NotImplemented, "No valid boundary condition type defined for pressure equation!");
    }
}

}
// end of Dune namespace
#endif