3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
discretization/facecentered/staggered/geometryhelper.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_DISCRETIZATION_FACECENTERED_STAGGERED_GEOMETRY_HELPER_HH
25#define DUMUX_DISCRETIZATION_FACECENTERED_STAGGERED_GEOMETRY_HELPER_HH
26
27#include <array>
28#include <cassert>
29#include <dune/common/exceptions.hh>
32
33namespace Dumux {
34
35template<class GridView>
37{
38 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
39 using SmallLocalIndexType = typename IndexTraits<GridView>::SmallLocalIndex;
40 using Element = typename GridView::template Codim<0>::Entity;
41 using Facet = typename GridView::template Codim<1>::Entity;
42
43public:
44 static constexpr auto dim = GridView::Grid::dimension;
45 static constexpr auto numElementFaces = dim * 2;
46 static constexpr auto numLateralFacesPerScv = 2 * (dim - 1);
47
48 FaceCenteredStaggeredGeometryHelper(const GridView& gridView) : gridView_(gridView) {}
49
51 static constexpr SmallLocalIndexType localOppositeIdx(const SmallLocalIndexType ownLocalFaceIndex)
52 {
53 return isOdd_(ownLocalFaceIndex) ? (ownLocalFaceIndex - 1) : (ownLocalFaceIndex + 1);
54 }
55
57 static constexpr int lateralOrthogonalScvfLocalIndex(const SmallLocalIndexType ownLocalScvfIndex)
58 {
59 if constexpr(GridView::Grid::dimension == 1)
60 {
61 assert(false && "There are no lateral scvfs in 1D");
62 return -1;
63 }
64
65 if constexpr (GridView::Grid::dimension == 2)
66 {
67 switch (ownLocalScvfIndex)
68 {
69 case 1: return 7;
70 case 7: return 1;
71 case 2: return 10;
72 case 10: return 2;
73 case 4: return 8;
74 case 8: return 4;
75 case 5: return 11;
76 case 11: return 5;
77 default:
78 {
79 assert(false && "No lateral orthogonal scvf found");
80 return -1;
81 }
82 }
83 }
84 else
85 {
86 switch (ownLocalScvfIndex)
87 {
88 case 1: return 11;
89 case 11: return 1;
90 case 2: return 16;
91 case 16: return 2;
92 case 3: return 21;
93 case 21: return 3;
94 case 4: return 26;
95 case 26: return 4;
96 case 6: return 12;
97 case 12: return 6;
98 case 7: return 17;
99 case 17: return 7;
100 case 8: return 22;
101 case 22: return 8;
102 case 9: return 27;
103 case 27: return 9;
104 case 13: return 23;
105 case 23: return 13;
106 case 14: return 28;
107 case 28: return 14;
108 case 18: return 24;
109 case 24: return 18;
110 case 19: return 29;
111 case 29: return 19;
112
113 default:
114 {
115 assert(false && "No lateral orthogonal scvf found");
116 return -1;
117 }
118 }
119 }
120 }
121
123 static constexpr auto localLaterFaceIndices(const SmallLocalIndexType ownLocalFaceIndex)
124 {
125 constexpr auto table = []
126 {
127 using Table = std::array<std::array<SmallLocalIndexType, numLateralFacesPerScv>, numElementFaces>;
128 if constexpr (dim == 1)
129 return Table{};
130 else if constexpr (dim == 2)
131 return Table {{ {2,3}, {2,3}, {0,1}, {0,1} }};
132 else
133 return Table {{ {2,3,4,5}, {2,3,4,5}, {0,1,4,5}, {0,1,4,5}, {0,1,2,3}, {0,1,2,3} }};
134 }();
135
136 return table[ownLocalFaceIndex];
137 }
138
140 static Facet facet(const SmallLocalIndexType localFacetIdx, const Element& element)
141 {
142 return element.template subEntity <1> (localFacetIdx);
143 }
144
146 auto intersection(const SmallLocalIndexType localFacetIdx, const Element& element) const
147 {
148 for (const auto& intersection : intersections(gridView(), element))
149 {
150 if (intersection.indexInInside() == localFacetIdx)
151 return intersection;
152 }
153 DUNE_THROW(Dune::InvalidStateException, "localFacetIdx " << localFacetIdx << " out of range");
154 }
155
157 template<class FVElementGeometry, class SubControlVolumeFace>
158 static bool scvfIntegrationPointInConcaveCorner(const FVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
159 {
160 assert (scvf.isLateral());
161
162 using Grid = typename FVElementGeometry::GridGeometry::Grid;
164 return false;
165 else
166 {
167 if (scvf.boundary())
168 return false;
169
170 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
171 const auto& outsideScv = fvGeometry.scv(scvf.outsideScvIdx());
172 int onBoundaryCounter = 0;
173 onBoundaryCounter += static_cast<int>(insideScv.boundary());
174 onBoundaryCounter += static_cast<int>(outsideScv.boundary());
175 return onBoundaryCounter == 1;
176 }
177 }
178
179 template<class SubControlVolumeFace, class SubControlVolume>
180 static SmallLocalIndexType localIndexOutsideScvfWithSameIntegrationPoint(const SubControlVolumeFace& scvf,
181 const SubControlVolume& scv)
182 {
183 // In 2D there are 3 non-boundary faces per scv. In 3D, there are 5.
184 // This number of scvfs per scv is used as an offset to find the indexes in the outside half-scv.
185 const SmallLocalIndexType offset = (dim == 2) ? 3 : 5;
186 // For half-scvs with odd indexes, the outside half-scv has scvf local indexes with + offset.
187 // For half-scvs with even indexes, the outside half-scv has scvf local indexes have a - offset.
188 return isOdd_(scv.indexInElement()) ? scvf.localIndex() - offset : scvf.localIndex() + offset;
189 }
190
191 template<class FVElementGeometry, class SubControlVolumeFace>
192 [[deprecated("The interface outsideScvfWithSameIntegrationPoint() is deprecated and the function is moved to the FVElementGeometry. Use the new interface localIndexOutsideScvfWithSameIntegrationPoint() instead. Will be removed after 3.5")]]
193 static const SubControlVolumeFace& outsideScvfWithSameIntegrationPoint(const FVElementGeometry& fvGeometry, const SubControlVolumeFace& scvf)
194 {
195 const auto& lateralOrthogonalScvf = fvGeometry.lateralOrthogonalScvf(scvf);
196 assert(!lateralOrthogonalScvf.boundary());
197
198 const int offset = (dim == 2) ? 3 : 5;
199 const auto otherLocalIdx = isOdd_(scvf.localIndex()) ? scvf.localIndex() - offset : scvf.localIndex() + offset;
200
201 auto outsideFVGeometry = localView(fvGeometry.gridGeometry());
202 const auto outsideElementIdx = fvGeometry.scv(lateralOrthogonalScvf.outsideScvIdx()).elementIndex();
203 outsideFVGeometry.bindElement(fvGeometry.gridGeometry().element(outsideElementIdx));
204
205 for (const auto& otherScvf : scvfs(outsideFVGeometry))
206 {
207 if (otherScvf.localIndex() == otherLocalIdx)
208 return otherScvf;
209 }
210
211 DUNE_THROW(Dune::InvalidStateException, "No outside scvf found");
212 }
213
214 const GridView& gridView() const
215 { return gridView_; }
216
217private:
218
219 static constexpr bool isOdd_(int number)
220 { return number % 2; }
221
222 GridView gridView_;
223};
224
225} // end namespace Dumux
226
227#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
Definition: discretization/facecentered/staggered/geometryhelper.hh:37
static Facet facet(const SmallLocalIndexType localFacetIdx, const Element &element)
Returns an element's facet based on the local facet index.
Definition: discretization/facecentered/staggered/geometryhelper.hh:140
static constexpr auto localLaterFaceIndices(const SmallLocalIndexType ownLocalFaceIndex)
Returns the local indices of the faces lateral to the own one.
Definition: discretization/facecentered/staggered/geometryhelper.hh:123
static bool scvfIntegrationPointInConcaveCorner(const FVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Returns true if the IP of an scvf lies on a concave corner.
Definition: discretization/facecentered/staggered/geometryhelper.hh:158
static constexpr SmallLocalIndexType localOppositeIdx(const SmallLocalIndexType ownLocalFaceIndex)
Returns the local index of the opposing face.
Definition: discretization/facecentered/staggered/geometryhelper.hh:51
static constexpr auto numLateralFacesPerScv
Definition: discretization/facecentered/staggered/geometryhelper.hh:46
const GridView & gridView() const
Definition: discretization/facecentered/staggered/geometryhelper.hh:214
static constexpr auto numElementFaces
Definition: discretization/facecentered/staggered/geometryhelper.hh:45
FaceCenteredStaggeredGeometryHelper(const GridView &gridView)
Definition: discretization/facecentered/staggered/geometryhelper.hh:48
static SmallLocalIndexType localIndexOutsideScvfWithSameIntegrationPoint(const SubControlVolumeFace &scvf, const SubControlVolume &scv)
Definition: discretization/facecentered/staggered/geometryhelper.hh:180
auto intersection(const SmallLocalIndexType localFacetIdx, const Element &element) const
Returns an element's intersection based on the local facet index.
Definition: discretization/facecentered/staggered/geometryhelper.hh:146
static constexpr int lateralOrthogonalScvfLocalIndex(const SmallLocalIndexType ownLocalScvfIndex)
Return the local index of a lateral orthogonal scvf.
Definition: discretization/facecentered/staggered/geometryhelper.hh:57
static constexpr auto dim
Definition: discretization/facecentered/staggered/geometryhelper.hh:44
static const SubControlVolumeFace & outsideScvfWithSameIntegrationPoint(const FVElementGeometry &fvGeometry, const SubControlVolumeFace &scvf)
Definition: discretization/facecentered/staggered/geometryhelper.hh:193
Type trait to determine if a grid supports concave corners (e.g. by cutting out a hole from the domai...
Definition: gridsupportsconcavecorners.hh:43