subcontrolvolume.hh 6.46 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
#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
    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;
95
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
96

97
public:
98
99
    using GlobalPosition = typename T::GlobalPosition;

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

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

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

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

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

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

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

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

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

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

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

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

} // end namespace

#endif