version 3.11-dev
Loading...
Searching...
No Matches
discretization/pq3/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// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7// This file includes code adapted from dune-functions.
8// These parts are clearly marked with inline comments and were originally
9// licensed under LGPL-3.0-or-later. They are adapted and relicensed here
10// under the terms of the GNU GPL-3.0-or-later as permitted by LGPLv3 Sec. 3.
11//
12// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
13//
20#ifndef DUMUX_DISCRETIZATION_PQ3_GEOMETRY_HELPER_HH
21#define DUMUX_DISCRETIZATION_PQ3_GEOMETRY_HELPER_HH
22
23#include <array>
24
25#include <dune/common/exceptions.hh>
26#include <dune/geometry/type.hh>
27#include <dune/geometry/referenceelements.hh>
28#include <dune/geometry/multilineargeometry.hh>
29#include <dune/common/reservedvector.hh>
30
31#include <dumux/common/math.hh>
37
38namespace Dumux {
39
48template <class GridView, class ScvType, class ScvfType>
50{
51 using Scalar = typename GridView::ctype;
52 using GlobalPosition = typename Dune::FieldVector<Scalar, GridView::dimensionworld>;
53 using ScvCornerStorage = typename ScvType::Traits::CornerStorage;
54 using ScvfCornerStorage = typename ScvfType::Traits::CornerStorage;
55 using LocalIndexType = typename ScvType::Traits::LocalIndexType;
56
57 using Element = typename GridView::template Codim<0>::Entity;
58 using Intersection = typename GridView::Intersection;
59
60 static constexpr auto dim = GridView::dimension;
61 static constexpr auto dimWorld = GridView::dimensionworld;
62
64public:
66
67 HybridPQ3GeometryHelper(const typename Element::Geometry& geometry)
68 : geo_(geometry)
69 , boxHelper_(geometry)
70 {}
71
73 ScvCornerStorage getScvCorners(unsigned int localScvIdx) const
74 {
75 return getScvCorners(geo_.type(), [&](const auto& local){ return geo_.global(local); }, localScvIdx);
76 }
77
79 template<class Transformation>
80 static ScvCornerStorage getScvCorners(Dune::GeometryType type, Transformation&& trans, unsigned int localScvIdx)
81 {
82 const auto& ref = Dune::referenceElement<Scalar, dim>(type);
83 const auto numBoxScv = ref.size(dim);
84 if (localScvIdx < numBoxScv)
85 return BoxHelper::getScvCorners(type, trans, localScvIdx);
86
87 DUNE_THROW(Dune::NotImplemented, "PQ3 scv corners call for hybrid dofs");
88 }
89
90 Dune::GeometryType getScvGeometryType(unsigned int localScvIdx) const
91 {
92 const auto numBoxScv = boxHelper_.numScv();
93 if (localScvIdx < numBoxScv)
94 return Dune::GeometryTypes::cube(dim);
95
96 DUNE_THROW(Dune::NotImplemented, "PQ3 scv geometry call for hybrid dofs");
97 }
98
100 ScvfCornerStorage getScvfCorners(unsigned int localScvfIdx) const
101 {
102 return getScvfCorners(geo_.type(), [&](const auto& local){ return geo_.global(local); }, localScvfIdx);
103 }
104
106 template<class Transformation>
107 static ScvfCornerStorage getScvfCorners(Dune::GeometryType type, Transformation&& trans, unsigned int localScvfIdx)
108 {
109 const auto& ref = Dune::referenceElement<Scalar, dim>(type);
110 const auto numBoxScvf = ref.size(dim-1);
111 if (localScvfIdx < numBoxScvf)
112 return BoxHelper::getScvfCorners(type, trans, localScvfIdx);
113
114 DUNE_THROW(Dune::NotImplemented, "PQ3 scvf corners call for hybrid dofs");
115 }
116
117 Dune::GeometryType getInteriorScvfGeometryType(unsigned int localScvfIdx) const
118 {
119 const auto numBoxScvf = boxHelper_.numInteriorScvf();
120 if (localScvfIdx < numBoxScvf)
121 return Dune::GeometryTypes::cube(dim-1);
122
123 DUNE_THROW(Dune::NotImplemented, "PQ3 interior scvf geometry type call for hybrid dofs");
124 }
125
127 ScvfCornerStorage getBoundaryScvfCorners(unsigned int localFacetIndex, unsigned int indexInFacet) const
128 {
129 return boxHelper_.getBoundaryScvfCorners(localFacetIndex, indexInFacet);
130 }
131
132 Dune::GeometryType getBoundaryScvfGeometryType(unsigned int localScvfIdx) const
133 {
134 return Dune::GeometryTypes::cube(dim-1);
135 }
136
137 GlobalPosition normal(const ScvfCornerStorage& p, const std::array<LocalIndexType, 2>& scvPair)
138 {
139 auto normal = Detail::scvfUnitNormal(geo_, p);
140
141 GlobalPosition v = geo_.corner(scvPair[1]) - geo_.corner(scvPair[0]);
142
143 const auto s = v*normal;
144 if (std::signbit(s))
145 normal *= -1;
146
147 return normal;
148 }
149
151 const typename Element::Geometry& elementGeometry() const
152 { return geo_; }
153
155 static auto numInteriorScvf(Dune::GeometryType type)
156 {
157 return BoxHelper::numInteriorScvf(type);
158 }
159
161 static auto numBoundaryScvf(Dune::GeometryType type, unsigned int localFacetIndex)
162 {
163 return Dune::referenceElement<Scalar, dim>(type).size(localFacetIndex, 1, dim);
164 }
165
167 std::size_t numScv() const
168 {
169 return boxHelper_.numScv();
170 }
171
173 Scalar scvVolume(unsigned int localScvIdx, const ScvCornerStorage& p) const
174 {
175 const auto scvType = getScvGeometryType(localScvIdx);
177 scvType,
178 [&](unsigned int i){ return p[i]; }
179 );
180 }
181
182 std::array<LocalIndexType, 2> getScvPairForScvf(unsigned int localScvfIndex) const
183 {
184 const auto numBoxFaces = boxHelper_.numInteriorScvf();
185 if (localScvfIndex < numBoxFaces)
186 {
187 return {
188 static_cast<LocalIndexType>(referenceElement(geo_).subEntity(localScvfIndex, dim-1, 0, dim)),
189 static_cast<LocalIndexType>(referenceElement(geo_).subEntity(localScvfIndex, dim-1, 1, dim))
190 };
191 }
192
193 DUNE_THROW(Dune::NotImplemented, "PQ3 scv pair call for hybrid dofs");
194 }
195
196 std::array<LocalIndexType, 2> getScvPairForBoundaryScvf(unsigned int localFacetIndex, unsigned int localIsScvfIndex) const
197 {
198 const auto numBoxScvf = referenceElement(geo_).size(localFacetIndex, 1, dim);
199 if (localIsScvfIndex < numBoxScvf)
200 {
201 const LocalIndexType insideScvIdx
202 = static_cast<LocalIndexType>(referenceElement(geo_).subEntity(localFacetIndex, 1, localIsScvfIndex, dim));
203 return { insideScvIdx, insideScvIdx };
204 }
205
206 DUNE_THROW(Dune::NotImplemented, "PQ3 scv boundary pair call for hybrid dofs");
207 }
208
209 bool isOverlappingScvf(unsigned int localScvfIndex) const
210 { return false; }
211
212 bool isOverlappingBoundaryScvf(unsigned int localFacetIndex) const
213 { return false; }
214
215 bool isOverlappingScv(unsigned int localScvIndex) const
216 { return false; }
217
218private:
219 const typename Element::Geometry& geo_;
220 BoxHelper boxHelper_;
221};
222
223} // end namespace Dumux
224
225#endif
Helper class constructing the dual grid finite volume geometries for the box discretizazion method.
Create sub control volumes and sub control volume face geometries.
Definition boxgeometryhelper.hh:262
Dune::GeometryType getBoundaryScvfGeometryType(unsigned int localScvfIdx) const
Definition discretization/pq3/geometryhelper.hh:132
std::array< LocalIndexType, 2 > getScvPairForBoundaryScvf(unsigned int localFacetIndex, unsigned int localIsScvfIndex) const
Definition discretization/pq3/geometryhelper.hh:196
bool isOverlappingBoundaryScvf(unsigned int localFacetIndex) const
Definition discretization/pq3/geometryhelper.hh:212
HybridPQ3GeometryHelper(const typename Element::Geometry &geometry)
Definition discretization/pq3/geometryhelper.hh:67
bool isOverlappingScvf(unsigned int localScvfIndex) const
Definition discretization/pq3/geometryhelper.hh:209
ScvfCornerStorage getScvfCorners(unsigned int localScvfIdx) const
Create a vector with the corners of sub control volume faces.
Definition discretization/pq3/geometryhelper.hh:100
bool isOverlappingScv(unsigned int localScvIndex) const
Definition discretization/pq3/geometryhelper.hh:215
ScvCornerStorage getScvCorners(unsigned int localScvIdx) const
Create a vector with the scv corners.
Definition discretization/pq3/geometryhelper.hh:73
GlobalPosition normal(const ScvfCornerStorage &p, const std::array< LocalIndexType, 2 > &scvPair)
Definition discretization/pq3/geometryhelper.hh:137
std::size_t numScv() const
number of sub control volumes (one per vertex)
Definition discretization/pq3/geometryhelper.hh:167
Dune::GeometryType getInteriorScvfGeometryType(unsigned int localScvfIdx) const
Definition discretization/pq3/geometryhelper.hh:117
Dune::GeometryType getScvGeometryType(unsigned int localScvIdx) const
Definition discretization/pq3/geometryhelper.hh:90
ScvfCornerStorage getBoundaryScvfCorners(unsigned int localFacetIndex, unsigned int indexInFacet) const
Create the sub control volume face geometries on the boundary.
Definition discretization/pq3/geometryhelper.hh:127
Scalar scvVolume(unsigned int localScvIdx, const ScvCornerStorage &p) const
get scv volume
Definition discretization/pq3/geometryhelper.hh:173
const Element::Geometry & elementGeometry() const
the wrapped element geometry
Definition discretization/pq3/geometryhelper.hh:151
std::array< LocalIndexType, 2 > getScvPairForScvf(unsigned int localScvfIndex) const
Definition discretization/pq3/geometryhelper.hh:182
PQ3LagrangeDofHelper< GridView > DofHelper
Definition discretization/pq3/geometryhelper.hh:65
static ScvfCornerStorage getScvfCorners(Dune::GeometryType type, Transformation &&trans, unsigned int localScvfIdx)
Create a vector with the corners of sub control volume faces.
Definition discretization/pq3/geometryhelper.hh:107
static auto numInteriorScvf(Dune::GeometryType type)
number of interior sub control volume faces
Definition discretization/pq3/geometryhelper.hh:155
static auto numBoundaryScvf(Dune::GeometryType type, unsigned int localFacetIndex)
number of boundary sub control volume faces for face localFacetIndex
Definition discretization/pq3/geometryhelper.hh:161
static ScvCornerStorage getScvCorners(Dune::GeometryType type, Transformation &&trans, unsigned int localScvIdx)
Create a vector with the scv corners.
Definition discretization/pq3/geometryhelper.hh:80
DOF index and position helper for order-3 Lagrange discretizations.
Definition pq3/dofhelper.hh:51
Helper class constructing the dual grid finite volume geometries for the cvfe discretizazion method.
auto scvfUnitNormal(const ElementGeometry &geo, const CornerStorage &corners)
Unit normal of an interior sub-control volume face, up to sign.
Definition scvfnormal.hh:33
auto convexPolytopeVolume(Dune::GeometryType type, const CornerF &c)
Compute the volume of several common geometry types.
Definition volume.hh:41
Define some often used mathematical functions.
Definition adapt.hh:17
Lightweight DOF helper for order-3 Lagrange elements.
Normal vector of a sub-control volume face of an element-local dual grid.
Compute the volume of several common geometry types.