subcontrolvolume.hh 4.75 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
// -*- 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

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

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

namespace Dumux
{
34
35
template<class ScvGeometryTraits>
class BoxSubControlVolume : public SubControlVolumeBase<BoxSubControlVolume<ScvGeometryTraits>, ScvGeometryTraits>
36
{
37
38
39
40
41
42
43
    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;
44
    enum { dim = Geometry::mydimension };
Timo Koch's avatar
Timo Koch committed
45

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

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

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

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

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

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

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

107
    // The position of the dof this scv is embedded in
108
109
    GlobalPosition dofPosition() const
    {
110
111
112
113
114
        // 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
115
    GridIndexType elementIndex() const
116
117
118
119
120
    {
        return elementIndex_;
    }

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

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

} // end namespace

#endif