subcontrolvolume.hh 6.35 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

27
28
#include <dune/common/version.hh>

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

33
34
35
36
37
38
39
40
41
42
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
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
76
77
78
79
80
81
82
83
84
85
86
    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;
        };
    };

    using GridIndexType = typename Grid::LeafGridView::IndexSet::IndexType;
    using LocalIndexType = unsigned int;
    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>
87
{
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 GlobalPosition = typename T::GlobalPosition;
    using CornerStorage = typename T::CornerStorage;
96
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
97

98
public:
99
    //! state the traits public and thus export all types
100
    using Traits = T;
101

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

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

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

130
131
132
133
134
135
136
137
138
139
    //! 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
    {
140
#if DUNE_VERSION_NEWER(DUNE_COMMON,2,6)
141
        return Geometry(Dune::GeometryTypes::cube(dim), corners_);
142
143
144
#else
        return Geometry(Dune::GeometryType(Dune::GeometryType::cube, dim), corners_);
#endif
145
146
147
    }

    //! The global index of this scv
148
    LocalIndexType indexInElement() const
149
150
151
152
    {
        return scvIdx_;
    }

153
    //! The index of the dof this scv is embedded in
154
    GridIndexType dofIndex() const
155
156
157
158
    {
        return dofIndex_;
    }

159
    // The position of the dof this scv is embedded in
160
    const GlobalPosition& dofPosition() const
161
    {
162
        // The corner list is defined such that the first entry is the vertex itself
163
        return corners_[0];
164
165
166
    }

    //! The global index of the element this scv is embedded in
167
    GridIndexType elementIndex() const
168
169
170
171
172
    {
        return elementIndex_;
    }

    //! Return the corner for the given local index
173
    const GlobalPosition& corner(LocalIndexType localIdx) const
174
175
176
    {
        assert(localIdx < corners_.size() && "provided index exceeds the number of corners");
        return corners_[localIdx];
177
178
179
    }

private:
180
    CornerStorage corners_;
181
182
    GlobalPosition center_;
    Scalar volume_;
183
184
185
    GridIndexType elementIndex_;
    LocalIndexType scvIdx_;
    GridIndexType dofIndex_;
186
187
188
189
190
};

} // end namespace

#endif