subcontrolvolumeface.hh 9.37 KB
Newer Older
1
2
3
4
5
6
7
// -*- 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    *
8
 *   the Free Software Foundation, either version 3 of the License, or       *
9
10
11
12
13
14
15
16
17
18
19
20
 *   (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
Dennis Gläser's avatar
Dennis Gläser committed
21
22
 * \ingroup CCMpfaDiscretization
 * \brief The sub control volume face
23
24
25
26
 */
#ifndef DUMUX_DISCRETIZATION_CC_MPFA_SUBCONTROLVOLUMEFACE_HH
#define DUMUX_DISCRETIZATION_CC_MPFA_SUBCONTROLVOLUMEFACE_HH

Timo Koch's avatar
Timo Koch committed
27
#include <vector>
28
#include <array>
29

30
31
#include <dune/common/reservedvector.hh>
#include <dune/common/fvector.hh>
Timo Koch's avatar
Timo Koch committed
32
#include <dune/geometry/type.hh>
33
#include <dune/geometry/multilineargeometry.hh>
Dennis Gläser's avatar
Dennis Gläser committed
34

35
36
#include <dumux/common/indextraits.hh>

37
namespace Dumux {
38

39
40
41
42
43
44
/*!
 * \ingroup CCMpfaDiscretization
 * \brief Default traits class to be used for the sub-control volume faces
 *        for the cell-centered finite volume scheme using MPFA
 * \tparam GV the type of the grid view
 */
45
46
47
48
49
50
51
52
53
template<class GridView>
struct CCMpfaDefaultScvfGeometryTraits
{
    using Grid = typename GridView::Grid;

    static const int dim = Grid::dimension;
    static const int dimWorld = Grid::dimensionworld;

    using Scalar = typename Grid::ctype;
54
55
    using GridIndexType = typename IndexTraits<GridView>::GridIndex;
    using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
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
    using OutsideGridIndexStorage = typename std::conditional_t< (dim<dimWorld),
                                                                 std::vector<GridIndexType>,
                                                                 Dune::ReservedVector<GridIndexType, 1> >;

    // we use geometry traits that use static corner vectors to and a fixed geometry type
    template <class ct>
    struct ScvfMLGTraits : public Dune::MultiLinearGeometryTraits<ct>
    {
        // we use static vectors to store the corners as we know
        // the number of corners in advance (2^(dim-1) corners (1<<(dim-1))
        template< int mydim, int cdim >
        struct CornerStorage
        {
            using Type = std::array< Dune::FieldVector< ct, cdim >, (1<<(dim-1)) >;
        };

        // we know all scvfs will have the same geometry type
        template< int dim >
        struct hasSingleGeometryType
        {
            static const bool v = true;
            static const unsigned int topologyId = Dune::Impl::CubeTopology< dim >::type::id;
        };
    };

    using Geometry = Dune::MultiLinearGeometry<Scalar, dim-1, dimWorld, ScvfMLGTraits<Scalar> >;
    using CornerStorage = typename ScvfMLGTraits<Scalar>::template CornerStorage<dim-1, dimWorld>::Type;
    using GlobalPosition = typename CornerStorage::value_type;
};

86
/*!
Dennis Gläser's avatar
Dennis Gläser committed
87
 * \ingroup CCMpfaDiscretization
88
89
 * \brief Class for a sub control volume face in mpfa methods, i.e a part of the boundary
 *        of a control volume we compute fluxes on.
90
91
 * \tparam GV the type of the grid view
 * \tparam T the scvf geometry traits
92
 */
93
94
template<class GV,
         class T = CCMpfaDefaultScvfGeometryTraits<GV> >
95
class CCMpfaSubControlVolumeFace
96
{
97
98
99
100
101
    using GridIndexType = typename T::GridIndexType;
    using Scalar = typename T::Scalar;
    using CornerStorage = typename T::CornerStorage;
    using OutsideGridIndexStorage = typename T::OutsideGridIndexStorage;
    using Geometry = typename T::Geometry;
102
103

public:
104
    //! export the type used for global coordinates
105
    using GlobalPosition = typename T::GlobalPosition;
106
    //! state the traits public and thus export all types
107
    using Traits = T;
Dennis Gläser's avatar
Dennis Gläser committed
108

109
    /*!
110
     * \brief Constructor
111
     *
Dennis Gläser's avatar
Dennis Gläser committed
112
     * \param helper The helper class for mpfa schemes
113
114
115
     * \param corners The corners of the scv face
     * \param unitOuterNormal The unit outer normal vector of the scvf
     * \param vIdxGlobal The global vertex index the scvf is connected to
116
     * \param vIdxLocal The element-local vertex index the scvf is connected to
117
     * \param scvfIndex The global index of this scv face
118
119
     * \param insideScvIdx The inside scv index connected to this face
     * \param outsideScvIndices The outside scv indices connected to this face
120
121
122
     * \param q The parameterization of the quadrature point on the scvf for flux calculation
     * \param boundary Boolean to specify whether or not the scvf is on a boundary
     */
123
    template<class MpfaHelper>
124
125
126
127
128
129
130
    CCMpfaSubControlVolumeFace(const MpfaHelper& helper,
                               CornerStorage&& corners,
                               GlobalPosition&& unitOuterNormal,
                               GridIndexType vIdxGlobal,
                               unsigned int vIdxLocal,
                               GridIndexType scvfIndex,
                               GridIndexType insideScvIdx,
131
                               const OutsideGridIndexStorage& outsideScvIndices,
132
133
                               Scalar q,
                               bool boundary)
Dennis Gläser's avatar
Dennis Gläser committed
134
    : boundary_(boundary)
Dennis Gläser's avatar
Dennis Gläser committed
135
136
137
138
139
140
141
142
    , vertexIndex_(vIdxGlobal)
    , scvfIndex_(scvfIndex)
    , insideScvIdx_(insideScvIdx)
    , outsideScvIndices_(outsideScvIndices)
    , vIdxInElement_(vIdxLocal)
    , corners_(std::move(corners))
    , center_(0.0)
    , unitOuterNormal_(std::move(unitOuterNormal))
Dennis Gläser's avatar
Dennis Gläser committed
143
144
145
146
147
148
149
150
    {
          // compute the center of the scvf
          for (const auto& corner : corners_)
              center_ += corner;
          center_ /= corners_.size();

          // use helper class to obtain area & integration point
          ipGlobal_ = helper.getScvfIntegrationPoint(corners_, q);
151
          area_ = helper.computeScvfArea(corners_);
Dennis Gläser's avatar
Dennis Gläser committed
152
    }
153
154

    //! The area of the sub control volume face
155
156
    Scalar area() const
    { return area_; }
157

Dennis Gläser's avatar
Dennis Gläser committed
158
    //! returns true if the sub control volume face is on the domain boundary
159
160
    bool boundary() const
    { return boundary_; }
161
162

    //! The global index of this sub control volume face
163
164
    GridIndexType index() const
    { return scvfIndex_; }
165
166

    //! Returns the index of the vertex the scvf is connected to
167
168
    GridIndexType vertexIndex() const
    { return vertexIndex_; }
169
170

    //! Returns the element-local vertex index the scvf is connected to
171
172
    unsigned int vertexIndexInElement() const
    { return vIdxInElement_; }
173
174

    //! index of the inside sub control volume
175
176
    GridIndexType insideScvIdx() const
    { return insideScvIdx_; }
177

Dennis Gläser's avatar
Dennis Gläser committed
178
    //! The number of scvs on the outside of this scv face
179
180
    std::size_t numOutsideScvs() const
    { return outsideScvIndices_.size(); }
181

Dennis Gläser's avatar
Dennis Gläser committed
182
183
    //! Index of the i-th outside sub control volume or boundary scv index.
    // Results in undefined behaviour if i >= numOutsideScvs()
184
185
    GridIndexType outsideScvIdx(int i = 0) const
    { return outsideScvIndices_[i]; }
186
187

    //! returns the outside scv indices (can be more than one index for dim < dimWorld)
188
189
    const OutsideGridIndexStorage& outsideScvIndices() const
    { return outsideScvIndices_; }
190
191

    //! Returns the number of corners
192
193
    std::size_t corners() const
    { return corners_.size(); }
194
195
196
197
198
199
200
201
202

    //! Returns the corner for a given local index
    const GlobalPosition& corner(unsigned int localIdx) const
    {
        assert(localIdx < corners_.size() && "provided index exceeds the number of corners");
        return corners_[localIdx];
    }

    //! Returns the global position of the vertex the scvf is connected to
203
204
    const GlobalPosition& vertexCorner() const
    { return corners_.back(); }
205
206

    //! Returns the global position of the center of the element facet this scvf is embedded in
207
208
    const GlobalPosition& facetCorner() const
    { return corner(0); }
209
210

    //! The center of the sub control volume face
211
212
    const GlobalPosition& center() const
    { return center_; }
213
214

    //! The integration point for flux evaluations in global coordinates
215
216
    const GlobalPosition& ipGlobal() const
    { return ipGlobal_; }
217
218

    //! returns the unit outer normal vector (assumes non-curved geometries)
219
220
    const GlobalPosition& unitOuterNormal() const
    { return unitOuterNormal_; }
221
222

    //! The geometry of the sub control volume face
223
224
    Geometry geometry() const
    { return Geometry(Dune::GeometryTypes::cube(Geometry::mydimension), corners_); }
225
226
227
228
229
230

private:
    bool boundary_;
    GridIndexType vertexIndex_;
    GridIndexType scvfIndex_;
    GridIndexType insideScvIdx_;
231
    OutsideGridIndexStorage outsideScvIndices_;
232
233
234
235
236
237
238
    unsigned int vIdxInElement_;

    CornerStorage corners_;
    GlobalPosition center_;
    GlobalPosition ipGlobal_;
    GlobalPosition unitOuterNormal_;
    Scalar area_;
239
};
240

241
} // end namespace Dumux
242

243
#endif