subcontrolvolume.hh 4.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// -*- 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
 * \brief Base class for a sub control volume
 */
#ifndef DUMUX_DISCRETIZATION_BOX_SUBCONTROLVOLUME_HH
#define DUMUX_DISCRETIZATION_BOX_SUBCONTROLVOLUME_HH

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

namespace Dumux
{
32
33
template<class ScvGeometryTraits>
class BoxSubControlVolume : public SubControlVolumeBase<BoxSubControlVolume<ScvGeometryTraits>, ScvGeometryTraits>
34
{
35
36
37
38
39
40
41
    using ParentType = SubControlVolumeBase<BoxSubControlVolume<ScvGeometryTraits>, ScvGeometryTraits>;
    using Geometry = typename ScvGeometryTraits::Geometry;
    using GridIndexType = typename ScvGeometryTraits::GridIndexType;
    using LocalIndexType = typename ScvGeometryTraits::LocalIndexType;
    using Scalar = typename ScvGeometryTraits::Scalar;
    using GlobalPosition = typename ScvGeometryTraits::GlobalPosition;
    using CornerStorage = typename ScvGeometryTraits::CornerStorage;
42
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
43

44
public:
45
46
47
    //! state the traits public and thus export all types
    using Traits = ScvGeometryTraits;

Timo Koch's avatar
Timo Koch committed
48
49
50
    //! The default constructor
    BoxSubControlVolume() = default;

51
    // the contructor in the box case
Timo Koch's avatar
Timo Koch committed
52
53
    template<class GeometryHelper>
    BoxSubControlVolume(const GeometryHelper& geometryHelper,
54
55
56
                        LocalIndexType scvIdx,
                        GridIndexType elementIndex,
                        GridIndexType dofIndex)
Timo Koch's avatar
Timo Koch committed
57
    : corners_(geometryHelper.getScvCorners(scvIdx)),
58
      center_(0.0),
Timo Koch's avatar
Timo Koch committed
59
60
61
62
63
      volume_(geometryHelper.scvVolume(corners_)),
      elementIndex_(elementIndex),
      scvIdx_(scvIdx),
      dofIndex_(dofIndex)
    {
64
65
66
67
        // compute center point
        for (const auto& corner : corners_)
            center_ += corner;
        center_ /= corners_.size();
Timo Koch's avatar
Timo Koch committed
68
    }
69
70
71
72
73
74

    //! The center of the sub control volume
    GlobalPosition center() const
    {
        return center_;
    }
75

76
77
78
79
80
81
82
83
84
85
    //! 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
    {
86
#if DUNE_VERSION_NEWER(DUNE_COMMON,2,6)
87
        return Geometry(Dune::GeometryTypes::cube(dim), corners_);
88
89
90
#else
        return Geometry(Dune::GeometryType(Dune::GeometryType::cube, dim), corners_);
#endif
91
92
93
    }

    //! The global index of this scv
94
    LocalIndexType indexInElement() const
95
96
97
98
    {
        return scvIdx_;
    }

99
    //! The index of the dof this scv is embedded in
100
    GridIndexType dofIndex() const
101
102
103
104
    {
        return dofIndex_;
    }

105
    // The position of the dof this scv is embedded in
106
107
    GlobalPosition dofPosition() const
    {
108
109
110
111
112
        // The corner list is defined such that the first entry is the vertex itself
        return corner(0);
    }

    //! The global index of the element this scv is embedded in
113
    GridIndexType elementIndex() const
114
115
116
117
118
    {
        return elementIndex_;
    }

    //! Return the corner for the given local index
119
    GlobalPosition corner(LocalIndexType localIdx) const
120
121
122
    {
        assert(localIdx < corners_.size() && "provided index exceeds the number of corners");
        return corners_[localIdx];
123
124
125
    }

private:
126
    CornerStorage corners_;
127
128
    GlobalPosition center_;
    Scalar volume_;
129
130
131
    GridIndexType elementIndex_;
    LocalIndexType scvIdx_;
    GridIndexType dofIndex_;
132
133
134
135
136
};

} // end namespace

#endif