subcontrolvolume.hh 6.58 KB
Newer Older
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 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

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

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

34
35
36
37
38
39
40
41
42
43
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
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
    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;
            static const unsigned int topologyId = Dune::Impl::CubeTopology< mydim >::type::id;
        };
    };

70
71
    using GridIndexType = typename IndexTraits<GridView>::GridIndex;
    using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    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>
88
{
89
90
91
92
93
94
95
    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;
96
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
97

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

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

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

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

132
133
134
135
136
137
138
139
140
141
    //! 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
    {
142
        return Geometry(Dune::GeometryTypes::cube(dim), corners_);
143
144
    }

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

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

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

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

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

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

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

193
} // end namespace Dumux
194
195

#endif