subcontrolvolume.hh 6.6 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
21
22
 * \ingroup BoxDiscretization
 * \brief the sub control volume for the box scheme
23
24
25
26
 */
#ifndef DUMUX_DISCRETIZATION_BOX_SUBCONTROLVOLUME_HH
#define DUMUX_DISCRETIZATION_BOX_SUBCONTROLVOLUME_HH

27
#include <dune/geometry/type.hh>
Dennis Gläser's avatar
Dennis Gläser committed
28
#include <dune/geometry/multilineargeometry.hh>
29

30
31
#include <dumux/common/math.hh>
#include <dumux/common/indextraits.hh>
32
#include <dumux/discretization/subcontrolvolumebase.hh>
Timo Koch's avatar
Timo Koch committed
33
#include <dumux/discretization/box/boxgeometryhelper.hh>
34

35
36
37
38
39
40
41
42
43
44
namespace Dumux {

/*!
 * \ingroup BoxDiscretization
 * \brief Default traits class to be used for the sub-control volumes
 *        for the box scheme
 * \tparam GV the type of the grid view
 */
template<class GridView>
struct BoxDefaultScvGeometryTraits
45
{
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
    using Grid = typename GridView::Grid;

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

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

        // we know all scvfs will have the same geometry type
        template< int mydim >
        struct hasSingleGeometryType
        {
            static const bool v = true;
67
            static const unsigned int topologyId = Dune::GeometryTypes::cube(mydim).id();
68
69
70
        };
    };

71
72
    using GridIndexType = typename IndexTraits<GridView>::GridIndex;
    using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    using Scalar = typename Grid::ctype;
    using Geometry = Dune::MultiLinearGeometry<Scalar, dim, dimWorld, ScvMLGTraits<Scalar>>;
    using CornerStorage = typename ScvMLGTraits<Scalar>::template CornerStorage<dim, dimWorld>::Type;
    using GlobalPosition = typename CornerStorage::value_type;
};

/*!
 * \ingroup BoxDiscretization
 * \brief the sub control volume for the box scheme
 * \tparam GV the type of the grid view
 * \tparam T the scvf geometry traits
 */
template<class GV,
         class T = BoxDefaultScvGeometryTraits<GV> >
class BoxSubControlVolume
: public SubControlVolumeBase<BoxSubControlVolume<GV, T>, T>
89
{
90
91
92
93
94
95
96
    using ThisType = BoxSubControlVolume<GV, T>;
    using ParentType = SubControlVolumeBase<ThisType, T>;
    using Geometry = typename T::Geometry;
    using GridIndexType = typename T::GridIndexType;
    using LocalIndexType = typename T::LocalIndexType;
    using Scalar = typename T::Scalar;
    using CornerStorage = typename T::CornerStorage;
97
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
98

99
public:
100
    //! export the type used for global coordinates
101
    using GlobalPosition = typename T::GlobalPosition;
102
    //! state the traits public and thus export all types
103
    using Traits = T;
104

Timo Koch's avatar
Timo Koch committed
105
106
107
    //! The default constructor
    BoxSubControlVolume() = default;

108
    // the contructor in the box case
Timo Koch's avatar
Timo Koch committed
109
110
    template<class GeometryHelper>
    BoxSubControlVolume(const GeometryHelper& geometryHelper,
111
112
113
                        LocalIndexType scvIdx,
                        GridIndexType elementIndex,
                        GridIndexType dofIndex)
Timo Koch's avatar
Timo Koch committed
114
    : corners_(geometryHelper.getScvCorners(scvIdx)),
115
      center_(0.0),
Timo Koch's avatar
Timo Koch committed
116
117
      volume_(geometryHelper.scvVolume(corners_)),
      elementIndex_(elementIndex),
Dennis Gläser's avatar
Dennis Gläser committed
118
      localDofIdx_(scvIdx),
Timo Koch's avatar
Timo Koch committed
119
120
      dofIndex_(dofIndex)
    {
121
122
123
124
        // compute center point
        for (const auto& corner : corners_)
            center_ += corner;
        center_ /= corners_.size();
Timo Koch's avatar
Timo Koch committed
125
    }
126
127

    //! The center of the sub control volume
128
    const GlobalPosition& center() const
129
130
131
    {
        return center_;
    }
132

133
134
135
136
137
138
139
140
141
142
    //! The volume of the sub control volume
    Scalar volume() const
    {
        return volume_;
    }

    //! The geometry of the sub control volume
    // e.g. for integration
    Geometry geometry() const
    {
143
        return Geometry(Dune::GeometryTypes::cube(dim), corners_);
144
145
    }

Dennis Gläser's avatar
Dennis Gläser committed
146
    //! The element-local index of the dof this scv is embedded in
147
    LocalIndexType localDofIndex() const
148
    {
Dennis Gläser's avatar
Dennis Gläser committed
149
        return localDofIdx_;
150
151
    }

152
153
154
155
156
157
158
    //! The element-local index of this scv.
    //! For the standard box scheme this is the local dof index.
    LocalIndexType indexInElement() const
    {
        return localDofIdx_;
    }

159
    //! The index of the dof this scv is embedded in
160
    GridIndexType dofIndex() const
161
162
163
164
    {
        return dofIndex_;
    }

165
    // The position of the dof this scv is embedded in
166
    const GlobalPosition& dofPosition() const
167
    {
168
        // The corner list is defined such that the first entry is the vertex itself
169
        return corners_[0];
170
171
172
    }

    //! The global index of the element this scv is embedded in
173
    GridIndexType elementIndex() const
174
175
176
177
178
    {
        return elementIndex_;
    }

    //! Return the corner for the given local index
179
    const GlobalPosition& corner(LocalIndexType localIdx) const
180
181
182
    {
        assert(localIdx < corners_.size() && "provided index exceeds the number of corners");
        return corners_[localIdx];
183
184
185
    }

private:
186
    CornerStorage corners_;
187
188
    GlobalPosition center_;
    Scalar volume_;
189
    GridIndexType elementIndex_;
Dennis Gläser's avatar
Dennis Gläser committed
190
    LocalIndexType localDofIdx_;
191
    GridIndexType dofIndex_;
192
193
};

194
} // end namespace Dumux
195
196

#endif