dualgridindexset.hh 8.23 KB
Newer Older
Dennis Gläser's avatar
Dennis Gläser committed
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
Dennis Gläser's avatar
Dennis Gläser committed
21
22
 * \ingroup CCMpfaDiscretization
 * \brief Class for the index sets of the dual grid in mpfa schemes.
Dennis Gläser's avatar
Dennis Gläser committed
23
 */
24
25
#ifndef DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
#define DUMUX_DISCRETIZATION_MPFA_DUALGRID_INDEX_SET_HH
Dennis Gläser's avatar
Dennis Gläser committed
26

27
28
29
30
#include <cassert>
#include <vector>
#include <algorithm>

Dennis Gläser's avatar
Dennis Gläser committed
31
32
33
34
namespace Dumux
{

/*!
Dennis Gläser's avatar
Dennis Gläser committed
35
36
37
38
39
40
41
 * \ingroup CCMpfaDiscretization
 * \brief Nodal index set for mpfa schemes, constructed
 *        around grid vertices.
 *
 * \tparam GI The type used for indices on the grid
 * \tparam LI The type used for indexing in interaction volumes
 * \tparam dim The dimension of the grid
Dennis Gläser's avatar
Dennis Gläser committed
42
 */
Dennis Gläser's avatar
Dennis Gläser committed
43
template< class GI, class LI, int dim >
Dennis Gläser's avatar
Dennis Gläser committed
44
45
class DualGridNodalIndexSet
{
Dennis Gläser's avatar
Dennis Gläser committed
46
47
48
public:
    using GridIndexType = GI;
    using LocalIndexType = LI;
Dennis Gläser's avatar
Dennis Gläser committed
49

Dennis Gläser's avatar
Dennis Gläser committed
50
51
52
    // we use dynamic containers to store indices here
    using GridIndexContainer = std::vector<GridIndexType>;
    using LocalIndexContainer = std::vector<LocalIndexType>;
Dennis Gläser's avatar
Dennis Gläser committed
53

Dennis Gläser's avatar
Dennis Gläser committed
54
    //! Constructor
Dennis Gläser's avatar
Dennis Gläser committed
55
56
    DualGridNodalIndexSet() : numBoundaryScvfs_(0) {}

Dennis Gläser's avatar
Dennis Gläser committed
57
58
    //! Inserts data for a given scvf
    template<typename SubControlVolumeFace>
Dennis Gläser's avatar
Dennis Gläser committed
59
60
61
62
63
64
65
66
    void insert(const SubControlVolumeFace& scvf)
    {
        insert(scvf.boundary(),
               scvf.index(),
               scvf.insideScvIdx(),
               scvf.outsideScvIndices());
    }

Dennis Gläser's avatar
Dennis Gläser committed
67
    //! Inserts scvf data
Dennis Gläser's avatar
Dennis Gläser committed
68
    void insert(const bool boundary,
Dennis Gläser's avatar
Dennis Gläser committed
69
70
71
                const GridIndexType scvfIdx,
                const GridIndexType insideScvIdx,
                const std::vector<GridIndexType>& outsideScvIndices)
Dennis Gläser's avatar
Dennis Gläser committed
72
    {
Dennis Gläser's avatar
Dennis Gläser committed
73
74
75
        // this should always be called only once per scvf
        assert(std::find(scvfIndices_.begin(), scvfIndices_.end(), scvfIdx ) == scvfIndices_.end()
               && "scvf has already been inserted!");
Dennis Gläser's avatar
Dennis Gläser committed
76
77
78
79

        // the local index of the scvf data about to be inserted
        const LocalIndexType curScvfLocalIdx = scvfIndices_.size();

Dennis Gläser's avatar
Dennis Gläser committed
80
81
        // add grid scvf data
        GridIndexContainer scvIndices;
Dennis Gläser's avatar
Dennis Gläser committed
82
83
84
85
86
        scvIndices.reserve(outsideScvIndices.size()+1);
        scvIndices.push_back(insideScvIdx);
        scvIndices.insert(scvIndices.end(), outsideScvIndices.begin(), outsideScvIndices.end());

        // if scvf is on boundary, increase counter
87
88
        if (boundary)
            numBoundaryScvfs_++;
Dennis Gläser's avatar
Dennis Gläser committed
89

90
        // insert data on the new scv
Dennis Gläser's avatar
Dennis Gläser committed
91
92
        scvfIndices_.push_back(scvfIdx);
        scvfIsOnBoundary_.push_back(boundary);
93
        scvfNeighborScvIndices_.emplace_back( std::move(scvIndices) );
Dennis Gläser's avatar
Dennis Gläser committed
94

Dennis Gläser's avatar
Dennis Gläser committed
95
        // if entry for the inside scv exists, append scvf local index, create otherwise
Dennis Gläser's avatar
Dennis Gläser committed
96
97
        auto it = std::find( scvIndices_.begin(), scvIndices_.end(), insideScvIdx );
        if (it != scvIndices_.end())
98
            localScvfIndicesInScv_[ std::distance(scvIndices_.begin(), it) ].push_back(curScvfLocalIdx);
Dennis Gläser's avatar
Dennis Gläser committed
99
100
101
102
103
104
105
106
107
108
        else
        {
            LocalIndexContainer localScvfIndices;
            localScvfIndices.reserve(dim);
            localScvfIndices.push_back(curScvfLocalIdx);
            localScvfIndicesInScv_.emplace_back( std::move(localScvfIndices) );
            scvIndices_.push_back(insideScvIdx);
        }
    }

Dennis Gläser's avatar
Dennis Gläser committed
109
    //! returns the number of scvs around the node
110
    std::size_t numScvs() const { return scvIndices_.size(); }
Dennis Gläser's avatar
Dennis Gläser committed
111

Dennis Gläser's avatar
Dennis Gläser committed
112
    //! returns the number of scvfs around the node
113
    std::size_t numScvfs() const { return scvfIndices_.size(); }
Dennis Gläser's avatar
Dennis Gläser committed
114

Dennis Gläser's avatar
Dennis Gläser committed
115
    //! returns the number of boundary scvfs around the node
116
    std::size_t numBoundaryScvfs() const { return numBoundaryScvfs_; }
Dennis Gläser's avatar
Dennis Gläser committed
117
118

    //! returns the global scv indices connected to this dual grid node
Dennis Gläser's avatar
Dennis Gläser committed
119
    const GridIndexContainer& globalScvIndices() const { return scvIndices_; }
Dennis Gläser's avatar
Dennis Gläser committed
120
121

    //! returns the global scvf indices connected to this dual grid node
Dennis Gläser's avatar
Dennis Gläser committed
122
123
124
125
    const GridIndexContainer& globalScvfIndices() const { return scvfIndices_; }

    //! returns whether or not the i-th scvf is on a domain boundary
    bool scvfIsOnBoundary(unsigned int i) const { return scvfIsOnBoundary_[i]; }
Dennis Gläser's avatar
Dennis Gläser committed
126

127
    //! returns the global scv idx of the i-th scv
Dennis Gläser's avatar
Dennis Gläser committed
128
    GridIndexType scvIdxGlobal(unsigned int i) const { return scvIndices_[i]; }
129
130

    //! returns the index of the i-th scvf
Dennis Gläser's avatar
Dennis Gläser committed
131
    GridIndexType scvfIdxGlobal(unsigned int i) const { return scvfIndices_[i]; }
Dennis Gläser's avatar
Dennis Gläser committed
132

133
    //! returns the global index of the j-th scvf embedded in the i-th scv
Dennis Gläser's avatar
Dennis Gläser committed
134
    GridIndexType scvfIdxGlobal(unsigned int i, unsigned int j) const
Dennis Gläser's avatar
Dennis Gläser committed
135
    {
136
137
        assert(j < dim); // only dim faces can be embedded in an scv
        return scvfIndices_[ localScvfIndicesInScv_[i][j] ];
Dennis Gläser's avatar
Dennis Gläser committed
138
139
    }

Dennis Gläser's avatar
Dennis Gläser committed
140
141
    //! returns the node-local index of the j-th scvf embedded in the i-th scv
    LocalIndexType scvfIdxLocal(unsigned int i, unsigned int j) const
Dennis Gläser's avatar
Dennis Gläser committed
142
    {
143
144
        assert(j < dim); // only dim faces can be embedded in an scv
        return localScvfIndicesInScv_[i][j];
Dennis Gläser's avatar
Dennis Gläser committed
145
146
    }

147
    //! returns the indices of the neighboring scvs of the i-th scvf
Dennis Gläser's avatar
Dennis Gläser committed
148
    const GridIndexContainer& neighboringScvIndices(unsigned int i) const
149
150
151
    { return scvfNeighborScvIndices_[i]; }

private:
Dennis Gläser's avatar
Dennis Gläser committed
152
153
154
155
156
157
158
    GridIndexContainer scvIndices_;                          //!< The indices of the scvs around a dual grid node
    std::vector<LocalIndexContainer> localScvfIndicesInScv_; //!< Maps to each scv a list of scvf indices embedded in it

    GridIndexContainer scvfIndices_;                         //!< the indices of the scvfs around a dual grid node
    std::vector<bool> scvfIsOnBoundary_;                     //!< Maps to each scvf a boolean to indicate if it is on the boundary
    std::vector<GridIndexContainer> scvfNeighborScvIndices_; //!< The neighboring scvs for the scvfs (order: 0 - inside, 1..n - outside)
    std::size_t numBoundaryScvfs_;                           //!< stores how many boundary scvfs are embedded in this dual grid node
Dennis Gläser's avatar
Dennis Gläser committed
159
160
161
};

/*!
Dennis Gläser's avatar
Dennis Gläser committed
162
 * \ingroup CCMpfaDiscretization
Dennis Gläser's avatar
Dennis Gläser committed
163
 * \brief Class for the index sets of the dual grid in mpfa schemes.
Dennis Gläser's avatar
Dennis Gläser committed
164
165
166
167
 *
 * \tparam GridIndexType The type used for indices on the grid
 * \tparam LocalIndexType The type used for indexing in interaction volumes
 * \tparam dim The dimension of the grid
Dennis Gläser's avatar
Dennis Gläser committed
168
 */
Dennis Gläser's avatar
Dennis Gläser committed
169
template< class GridIndexType, class LocalIndexType, int dim >
170
class CCMpfaDualGridIndexSet
Dennis Gläser's avatar
Dennis Gläser committed
171
172
{
public:
Dennis Gläser's avatar
Dennis Gläser committed
173
    using NodalIndexSet = DualGridNodalIndexSet< GridIndexType, LocalIndexType, dim >;
Dennis Gläser's avatar
Dennis Gläser committed
174

Dennis Gläser's avatar
Dennis Gläser committed
175
    //! Default constructor should not be used
176
177
    CCMpfaDualGridIndexSet() = delete;

Dennis Gläser's avatar
Dennis Gläser committed
178
179
180
    //! Constructor taking a grid view
    template< class GridView >
    CCMpfaDualGridIndexSet(const GridView& gridView) : nodalIndexSets_(gridView.size(dim)) {}
Dennis Gläser's avatar
Dennis Gläser committed
181

Dennis Gläser's avatar
Dennis Gläser committed
182
183
    //! Access with an scvf
    template< class SubControlVolumeFace >
Dennis Gläser's avatar
Dennis Gläser committed
184
    const NodalIndexSet& operator[] (const SubControlVolumeFace& scvf) const
185
    { return nodalIndexSets_[scvf.vertexIndex()]; }
Dennis Gläser's avatar
Dennis Gläser committed
186
187

    template< class SubControlVolumeFace >
Dennis Gläser's avatar
Dennis Gläser committed
188
    NodalIndexSet& operator[] (const SubControlVolumeFace& scvf)
189
    { return nodalIndexSets_[scvf.vertexIndex()]; }
Dennis Gläser's avatar
Dennis Gläser committed
190

Dennis Gläser's avatar
Dennis Gläser committed
191
192
193
    //! Access with an index
    const NodalIndexSet& operator[] (GridIndexType i) const { return nodalIndexSets_[i]; }
    NodalIndexSet& operator[] (GridIndexType i) { return nodalIndexSets_[i]; }
194
195
196

private:
    std::vector<NodalIndexSet> nodalIndexSets_;
Dennis Gläser's avatar
Dennis Gläser committed
197
198
};

Dennis Gläser's avatar
Dennis Gläser committed
199
} // end namespace Dumux
Dennis Gläser's avatar
Dennis Gläser committed
200
201

#endif