fluxstencil.hh 6.33 KB
Newer Older
Timo Koch's avatar
Timo Koch committed
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
22
 * \ingroup Discretization
 * \brief The flux stencil specialized for different discretization schemes
Timo Koch's avatar
Timo Koch committed
23
24
25
26
 */
#ifndef DUMUX_DISCRETIZATION_FLUXSTENCIL_HH
#define DUMUX_DISCRETIZATION_FLUXSTENCIL_HH

27
#include <dune/common/reservedvector.hh>
Timo Koch's avatar
Timo Koch committed
28
#include <dumux/common/properties.hh>
Timo Koch's avatar
Timo Koch committed
29
30
31
32
33
34
35
36
37
38
39
#include <dumux/discretization/methods.hh>

namespace Dumux
{

//! Forward declaration of the upwind scheme implementation
template<class TypeTag, DiscretizationMethods Method>
class FluxStencilImplementation;

/*!
 * \ingroup Discretization
40
 * \brief The flux stencil specialized for different discretization schemes
Timo Koch's avatar
Timo Koch committed
41
42
43
44
45
46
47
48
49
 * \note There might be different stencils used for e.g. advection and diffusion for schemes
 *       where the stencil depends on variables. Also schemes might even have solution dependent
 *       stencil. However, we always reserve the stencil or all DOFs that are possibly involved
 *       since we use the flux stencil for matrix and assembly. This might lead to some zeros stored
 *       in the matrix.
 */
template<class TypeTag>
using FluxStencil = FluxStencilImplementation<TypeTag, GET_PROP_VALUE(TypeTag, DiscretizationMethod)>;

50
51
52
53
/*
 * \ingroup Discretization
 * \brief Flux stencil specialization for the cell-centered tpfa scheme
 */
Timo Koch's avatar
Timo Koch committed
54
55
56
57
58
59
60
61
62
63
template<class TypeTag>
class FluxStencilImplementation<TypeTag, DiscretizationMethods::CCTpfa>
{
    using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
    using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry);
    using SubControlVolumeFace = typename GET_PROP_TYPE(TypeTag, SubControlVolumeFace);
    using Element = typename GridView::template Codim<0>::Entity;
    using IndexType = typename GridView::IndexSet::IndexType;

public:
64
65
    //! The maximum number of elements in a flux stencil
    static constexpr int maxFluxStencilSize = GET_PROP_VALUE(TypeTag, MaxNumNeighborsPerScvf);
66

67
68
    //! Each cell I couples to a cell J always only via one face
    using ScvfStencilIForJ = Dune::ReservedVector<IndexType, 1>;
69
70
71

    //! The flux stencil type
    using Stencil = Dune::ReservedVector<IndexType, maxFluxStencilSize>;
72

73
    static Stencil stencil(const Element& element,
Timo Koch's avatar
Timo Koch committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
                           const FVElementGeometry& fvGeometry,
                           const SubControlVolumeFace& scvf)
    {
        if (scvf.boundary())
            return Stencil({scvf.insideScvIdx()});
        else if (scvf.numOutsideScvs() > 1)
        {
            Stencil stencil({scvf.insideScvIdx()});
            for (unsigned int i = 0; i < scvf.numOutsideScvs(); ++i)
                stencil.push_back(scvf.outsideScvIdx(i));
            return stencil;
        }
        else
            return Stencil({scvf.insideScvIdx(), scvf.outsideScvIdx()});
    }
};

91
92
93
94
/*
 * \ingroup Discretization
 * \brief Flux stencil specialization for the cell-centered mpfa scheme
 */
Timo Koch's avatar
Timo Koch committed
95
96
97
98
99
100
101
102
template<class TypeTag>
class FluxStencilImplementation<TypeTag, DiscretizationMethods::CCMpfa>
{
    using GridView = typename GET_PROP_TYPE(TypeTag, GridView);
    using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry);
    using SubControlVolumeFace = typename GET_PROP_TYPE(TypeTag, SubControlVolumeFace);
    using Element = typename GridView::template Codim<0>::Entity;
    using IndexType = typename GridView::IndexSet::IndexType;
103
104
105
106
    static constexpr int dim = GridView::dimension;

    // Use the stencil type of the primary interaction volume
    using NodalIndexSet = typename GET_PROP_TYPE(TypeTag, DualGridNodalIndexSet);
Timo Koch's avatar
Timo Koch committed
107
108

public:
109
110
    //! The maximum number of elements in a flux stencil (equal to number of elements at node)
    static constexpr int maxFluxStencilSize = NodalIndexSet::maxNumElementsAtNode;
111

112
113
    //! We don't know yet how many faces couple to a neighboring element
    using ScvfStencilIForJ = std::vector<IndexType>;
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

    //! The flux stencil type
    using Stencil = typename NodalIndexSet::GridStencilType;

    /*
     * \brief Returns a set of grid element indices that participate in the
     *        flux calculations on a given scvf.
     *
     * \note The interaction volume index sets must use the same type for the
     *       stencils as the nodal index set. If not, the compiler will complain here.
     *
     * \param element The grid element
     * \param fvGeometry The finite volume geometry of this element
     * \param scvf The sub-control volume face embedded in this element
     */
    static const Stencil& stencil(const Element& element,
                                  const FVElementGeometry& fvGeometry,
                                  const SubControlVolumeFace& scvf)
Timo Koch's avatar
Timo Koch committed
132
    {
133
        const auto& fvGridGeometry = fvGeometry.fvGridGeometry();
Timo Koch's avatar
Timo Koch committed
134
135

        // return the scv (element) indices in the interaction region
Dennis Gläser's avatar
Dennis Gläser committed
136
        if (fvGridGeometry.vertexUsesSecondaryInteractionVolume(scvf.vertexIndex()))
137
            return fvGridGeometry.gridInteractionVolumeIndexSets().secondaryIndexSet(scvf).globalScvIndices();
Timo Koch's avatar
Timo Koch committed
138
        else
139
            return fvGridGeometry.gridInteractionVolumeIndexSets().primaryIndexSet(scvf).globalScvIndices();
Timo Koch's avatar
Timo Koch committed
140
141
142
143
144
145
    }
};

} // end namespace Dumux

#endif