3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
staggered/freeflow/connectivitymap.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_STAGGERED_FREEFLOW_CONNECTIVITY_MAP_HH
25#define DUMUX_STAGGERED_FREEFLOW_CONNECTIVITY_MAP_HH
26
27#include <vector>
29
30namespace Dumux {
31
37template<class GridGeometry>
39{
40 using GridView = typename GridGeometry::GridView;
41 using FVElementGeometry = typename GridGeometry::LocalView;
42 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
43
44 using Element = typename GridView::template Codim<0>::Entity;
45 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
46
47 using CellCenterIdxType = typename GridGeometry::DofTypeIndices::CellCenterIdx;
48 using FaceIdxType = typename GridGeometry::DofTypeIndices::FaceIdx;
49
50 using SmallLocalIndex = typename IndexTraits<GridView>::SmallLocalIndex;
51
52 using Stencil = std::vector<GridIndexType>;
53 using Map = std::vector<Stencil>;
54
55 static constexpr SmallLocalIndex upwindSchemeOrder = GridGeometry::upwindSchemeOrder;
56 static constexpr bool useHigherOrder = upwindSchemeOrder > 1;
57
58public:
59
61 void update(const GridGeometry& gridGeometry)
62 {
63 const auto numDofsCC = gridGeometry.gridView().size(0);
64 const auto numDofsFace = gridGeometry.gridView().size(1);
65 const auto numBoundaryFacets = gridGeometry.numBoundaryScvf();
66
67 // reinitialize maps
68 cellCenterToCellCenterMap_ = Map(numDofsCC);
69 cellCenterToFaceMap_ = Map(numDofsCC);
70 faceToCellCenterMap_ = Map(2*numDofsFace - numBoundaryFacets);
71 faceToFaceMap_ = Map(2*numDofsFace - numBoundaryFacets);
72
73 // restrict the FvGeometry locally
74 auto fvGeometry = localView(gridGeometry);
75 for(auto&& element: elements(gridGeometry.gridView()))
76 {
77 // bind the FvGeometry to the element
78 fvGeometry.bindElement(element);
79
80 // loop over sub control faces
81 for (auto&& scvf : scvfs(fvGeometry))
82 {
83 // handle the cell center dof stencils first
84 const auto dofIdxCellCenter = gridGeometry.elementMapper().index(element);
85
86 // the stencil for cell center dofs w.r.t. to other cell center dofs,
87 // includes all neighboring element indices
88 if (!scvf.boundary())
89 cellCenterToCellCenterMap_[dofIdxCellCenter].push_back(scvf.outsideScvIdx());
90
91 // the stencil for cell center dofs w.r.t. face dofs, includes the face dof indices of the current element
92 cellCenterToFaceMap_[dofIdxCellCenter].push_back(scvf.dofIndex());
93
94 // handle the face dof stencils
95 const auto scvfIdx = scvf.index();
96 computeFaceToCellCenterStencil_(faceToCellCenterMap_[scvfIdx], fvGeometry, scvf);
97 computeFaceToFaceStencil_(faceToFaceMap_[scvfIdx], fvGeometry, scvf);
98 }
99 }
100 }
101
103 const Stencil& operator() (CellCenterIdxType, CellCenterIdxType, const GridIndexType globalI) const
104 {
105 return cellCenterToCellCenterMap_[globalI];
106 }
107
109 const Stencil& operator() (CellCenterIdxType, FaceIdxType, const GridIndexType globalI) const
110 {
111 return cellCenterToFaceMap_[globalI];
112 }
113
115 const Stencil& operator() (FaceIdxType, CellCenterIdxType, const GridIndexType globalI) const
116 {
117 return faceToCellCenterMap_[globalI];
118 }
119
121 const Stencil& operator() (FaceIdxType, FaceIdxType, const GridIndexType globalI) const
122 {
123 return faceToFaceMap_[globalI];
124 }
125
126private:
127
128 /*
129 * \brief Computes the stencil for face dofs w.r.t to cell center dofs.
130 * Basically, these are the dof indices of the elements adjacent to the face and those of
131 * the elements adjacent to the faces parallel to the own face.
132 */
133 void computeFaceToCellCenterStencil_(Stencil& stencil,
134 const FVElementGeometry& fvGeometry,
135 const SubControlVolumeFace& scvf)
136 {
137 const auto eIdx = scvf.insideScvIdx();
138 stencil.push_back(eIdx);
139
140 for (const auto& data : scvf.pairData())
141 {
142 auto& lateralFace = fvGeometry.scvf(eIdx, data.localLateralFaceIdx);
143 if (!lateralFace.boundary())
144 {
145 const auto firstParallelElementDofIdx = lateralFace.outsideScvIdx();
146 stencil.push_back(firstParallelElementDofIdx);
147 }
148 }
149 }
150
151 /*
152 * \brief Computes the stencil for face dofs w.r.t to face dofs.
153 * For a full description of the stencil, please see the document under dumux/doc/docextra/staggered
154 */
155 void computeFaceToFaceStencil_(Stencil& stencil,
156 const FVElementGeometry& fvGeometry,
157 const SubControlVolumeFace& scvf)
158 {
159 stencil.push_back(scvf.axisData().oppositeDof);
160 addHigherOrderInAxisDofs_(scvf, stencil, std::integral_constant<bool, useHigherOrder>{});
161
162 for (const auto& data : scvf.pairData())
163 {
164 // add normal dofs
165 stencil.push_back(data.lateralPair.first);
166 if (!scvf.boundary())
167 stencil.push_back(data.lateralPair.second);
168
169 // add parallel dofs
170 for (SmallLocalIndex i = 0; i < upwindSchemeOrder; i++)
171 {
172 if (data.hasParallelNeighbor[i])
173 stencil.push_back(data.parallelDofs[i]);
174 }
175 }
176 }
177
178 void addHigherOrderInAxisDofs_(const SubControlVolumeFace& scvf, Stencil& stencil, std::false_type) {}
179
180 void addHigherOrderInAxisDofs_(const SubControlVolumeFace& scvf, Stencil& stencil, std::true_type)
181 {
182 for (SmallLocalIndex i = 0; i < upwindSchemeOrder - 1; i++)
183 {
184 if (scvf.hasBackwardNeighbor(i))
185 stencil.push_back(scvf.axisData().inAxisBackwardDofs[i]);
186
187 if (scvf.hasForwardNeighbor(i))
188 stencil.push_back(scvf.axisData().inAxisForwardDofs[i]);
189 }
190 }
191
192 Map cellCenterToCellCenterMap_;
193 Map cellCenterToFaceMap_;
194 Map faceToCellCenterMap_;
195 Map faceToFaceMap_;
196};
197
198} // end namespace Dumux
199
200#endif
Defines the index types used for grid and local indices.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
Definition: adapt.hh:29
typename GridView::IndexSet::IndexType GridIndex
Definition: indextraits.hh:39
std::uint_least8_t SmallLocalIndex
Definition: indextraits.hh:41
Stores the dof indices corresponding to the neighboring cell centers and faces that contribute to the...
Definition: staggered/freeflow/connectivitymap.hh:39
void update(const GridGeometry &gridGeometry)
Update the map and prepare the stencils.
Definition: staggered/freeflow/connectivitymap.hh:61
const Stencil & operator()(CellCenterIdxType, CellCenterIdxType, const GridIndexType globalI) const
Returns the stencil of a cell center dof w.r.t. other cell center dofs.
Definition: staggered/freeflow/connectivitymap.hh:103