version 3.11-dev
Loading...
Searching...
No Matches
pq3/fegriddiscretization.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//
12#ifndef DUMUX_DISCRETIZATION_PQ3_FE_GRID_DISCRETIZATION_HH
13#define DUMUX_DISCRETIZATION_PQ3_FE_GRID_DISCRETIZATION_HH
14
15#include <dune/localfunctions/lagrange/lagrangelfecache.hh>
16
23
24#include "dofhelper.hh"
25
26namespace Dumux::Experimental {
27
32template<class GridView,
33 class ElementRule = Dumux::QuadratureRules::DuneQuadrature<6>,
34 class IntersectionRule = Dumux::QuadratureRules::DuneQuadrature<6>,
35 class BoundaryFaceRule = Dumux::QuadratureRules::DuneQuadrature<6>>
37{
38 using ElementQuadratureRule = ElementRule;
39 using IntersectionQuadratureRule = IntersectionRule;
40 using BoundaryFaceQuadratureRule = BoundaryFaceRule;
41};
42
49template<class GridView,
50 class Scalar,
51 class MapperTraits = Dumux::PQ3MapperTraits<GridView>,
52 class QuadratureTraits = PQ3FEQuadratureTraits<GridView>>
54: public MapperTraits, public QuadratureTraits
55{
56 using FeCache = Dune::LagrangeLocalFiniteElementCache<typename GridView::ctype, Scalar, GridView::dimension, 3>;
58
59 template<class GridDiscretization, bool enableCache>
61
62 // Maximum number of element-local DOFs (for cubes, order 3)
63 static constexpr std::size_t maxNumElementDofs = []()
64 {
65 if constexpr (GridView::dimension == 1)
66 return 4; // Q3 interval: 2 vertices + 2 edge interior
67 else if constexpr (GridView::dimension == 2)
68 return 16; // Q3 quad: 4 vertices + 8 edge + 4 interior
69 else if constexpr (GridView::dimension == 3)
70 return 64; // Q3 hex: 8 vertices + 24 edge + 24 face + 8 interior
71 }();
72};
73
78template<class Scalar,
79 class GV,
80 bool enableCaching = true,
81 class Traits = PQ3FEDefaultGridDiscretizationTraits<GV, Scalar>>
83: public BaseGridGeometry<GV, Traits>
84{
86 using ParentType = BaseGridGeometry<GV, Traits>;
87 using GridIndexType = typename IndexTraits<GV>::GridIndex;
88 using LocalIndexType = typename IndexTraits<GV>::LocalIndex;
89 static const int dim = GV::dimension;
90
91public:
94 static constexpr DiscretizationMethod discMethod{};
95
96 static constexpr std::size_t maxNumElementDofs = Traits::maxNumElementDofs;
97
100
104 using LocalView = typename Traits::template LocalView<ThisType, true>;
108 using DofMapper = typename Traits::DofMapper;
110 using FeCache = typename Traits::FeCache;
112 using GridView = GV;
116 using ElementQuadratureRule = typename Traits::ElementQuadratureRule;
118 using IntersectionQuadratureRule = typename Traits::IntersectionQuadratureRule;
120 using BoundaryFaceQuadratureRule = typename Traits::BoundaryFaceQuadratureRule;
121
123 PQ3FEGridDiscretization(std::shared_ptr<BasicGridGeometry> gg)
124 : ParentType(std::move(gg))
125 , dofMapper_(this->gridView(), Traits::layout())
126 , cache_(*this)
127 , periodicGridTraits_(this->gridView().grid())
128 {
129 update_();
130 }
131
136
138 const DofMapper& dofMapper() const
139 { return dofMapper_; }
140
142 std::size_t numDofs() const
143 { return this->dofMapper().size(); }
144
147 {
149 update_();
150 }
151
154 {
155 ParentType::update(std::move(gridView));
156 update_();
157 }
158
160 const FeCache& feCache() const
161 { return feCache_; }
162
164 bool dofOnBoundary(GridIndexType dofIdx) const
165 { return boundaryDofIndices_[dofIdx]; }
166
168 bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
169 { return periodicDofMap_.count(dofIdx); }
170
172 GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
173 { return periodicDofMap_.at(dofIdx); }
174
176 const std::unordered_map<GridIndexType, GridIndexType>& periodicDofMap() const
177 { return periodicDofMap_; }
178
181 { return { gg.cache_ }; }
182
183private:
184 class PQ3FEGridDiscretizationCache
185 {
186 friend class PQ3FEGridDiscretization;
187 public:
189 using DofHelper = typename Traits::DofHelper;
190
191 explicit PQ3FEGridDiscretizationCache(const PQ3FEGridDiscretization& gg)
192 : gridDiscretization_(&gg)
193 {}
194
195 const PQ3FEGridDiscretization& gridDiscretization() const
196 { return *gridDiscretization_; }
197
199 auto boundaryFaces(GridIndexType eIdx) const -> std::span<const BoundaryFace>
200 {
201 if (auto it = boundaryFaces_.find(eIdx); it != boundaryFaces_.end())
202 return {it->second};
203 return {};
204 }
205
206 private:
207 void clear_()
208 { boundaryFaces_.clear(); }
209
210 std::unordered_map<GridIndexType, Dune::ReservedVector<BoundaryFace, 2*dim>> boundaryFaces_;
211
212 const PQ3FEGridDiscretization* gridDiscretization_;
213 };
214
215public:
218 using Cache = PQ3FEGridDiscretizationCache;
219
220private:
222 void update_()
223 {
224 using DofHelper = typename Cache::DofHelper;
225
226 dofMapper_.update(this->gridView());
227 cache_.clear_();
228 boundaryDofIndices_.assign(numDofs(), false);
229 const auto& idSet = this->gridView().grid().globalIdSet();
230
231 for (const auto& element : elements(this->gridView()))
232 {
233 auto elementGeometry = element.geometry();
234 const auto& localCoefficients = this->feCache().get(element.type()).localCoefficients();
235 const auto eIdx = this->elementMapper().index(element);
236
237 LocalIndexType numBoundaryFaces = 0;
238 for (const auto& intersection : intersections(this->gridView(), element))
239 {
240 if (intersection.boundary() && !periodicGridTraits_.isPeriodic(intersection))
241 {
242 // add one boundary face per boundary intersection
243 const auto isGeometry = intersection.geometry();
244 cache_.boundaryFaces_[eIdx].push_back(BoundaryFace{
245 isGeometry.center(),
246 isGeometry.volume(),
247 intersection.centerUnitOuterNormal(),
248 numBoundaryFaces++,
249 static_cast<LocalIndexType>(intersection.indexInInside()),
250 typename BoundaryFace::Traits::BoundaryFlag{intersection}
251 });
252
253 // mark all dofs on this intersection as boundary dofs
254 for (LocalIndexType keyIdx = 0; keyIdx < localCoefficients.size(); ++keyIdx)
255 {
256 if (DofHelper::localDofOnIntersection(elementGeometry.type(),
257 intersection.indexInInside(),
258 localCoefficients.localKey(keyIdx)))
259 {
260 const auto dofIdxGlobal = DofHelper::dofIndex(
261 this->dofMapper(), element, localCoefficients.localKey(keyIdx), idSet);
262 boundaryDofIndices_[dofIdxGlobal] = true;
263 }
264 }
265 }
266
267 // inform the grid discretization if we have periodic boundaries
268 else if (periodicGridTraits_.isPeriodic(intersection))
269 {
270 this->setPeriodic();
271
272 const auto eps = 1e-7*(elementGeometry.corner(1) - elementGeometry.corner(0)).two_norm();
273 for (int localDofIdx = 0; localDofIdx < localCoefficients.size(); ++localDofIdx)
274 {
275 if (!DofHelper::localDofOnIntersection(elementGeometry.type(),
276 intersection.indexInInside(),
277 localCoefficients.localKey(localDofIdx)))
278 continue;
279
280 const auto dofIdxGlobal = DofHelper::dofIndex(
281 this->dofMapper(), element, localCoefficients.localKey(localDofIdx), idSet);
282 const auto dofPos = DofHelper::dofPosition(elementGeometry, localCoefficients.localKey(localDofIdx));
283
284 const auto& outside = intersection.outside();
285 const auto outsideGeometry = outside.geometry();
286 const auto& localCoefficientsOut = this->feCache().get(outsideGeometry.type()).localCoefficients();
287 for (const auto& isOutside : intersections(this->gridView(), outside))
288 {
289 if (periodicGridTraits_.isPeriodic(isOutside))
290 {
291 for (int localDofIdxOut = 0; localDofIdxOut < localCoefficientsOut.size(); ++localDofIdxOut)
292 {
293 const auto& localKeyOut = localCoefficientsOut.localKey(localDofIdxOut);
294 if (!DofHelper::localDofOnIntersection(outsideGeometry.type(),
295 isOutside.indexInInside(),
296 localKeyOut))
297 continue;
298
299 const auto dofIdxGlobalOut = DofHelper::dofIndex(this->dofMapper(), outside, localKeyOut, idSet);
300 const auto dofPosOutside = DofHelper::dofPosition(outsideGeometry, localKeyOut);
301 const auto shift = std::abs((this->bBoxMax()-this->bBoxMin())*intersection.centerUnitOuterNormal());
302 if (std::abs((dofPosOutside - dofPos).two_norm() - shift) < eps)
303 periodicDofMap_[dofIdxGlobal] = dofIdxGlobalOut;
304 }
305 }
306 }
307 }
308 }
309 }
310 }
311
312 // error check: periodic boundaries currently don't work in parallel
313 if (this->isPeriodic() && this->gridView().comm().size() > 1)
314 DUNE_THROW(Dune::NotImplemented, "Periodic boundaries for FE PQ3 method for parallel simulations!");
315 }
316
317 DofMapper dofMapper_;
318 const FeCache feCache_;
319 // dofs on the boundary
320 std::vector<bool> boundaryDofIndices_;
321 // a map for periodic boundary dofs
322 std::unordered_map<GridIndexType, GridIndexType> periodicDofMap_;
323 Cache cache_;
325};
326
327} // end namespace Dumux::Experimental
328
329#endif
const ElementMapper & elementMapper() const
Returns the mapper for elements to indices for constant grids.
Definition basegridgeometry.hh:112
void setPeriodic(bool value=true)
Set the periodicity of the grid geometry.
Definition basegridgeometry.hh:169
const GlobalCoordinate & bBoxMax() const
The coordinate of the corner of the GridView's bounding box with the largest values.
Definition basegridgeometry.hh:156
Element element(GridIndexType eIdx) const
Definition basegridgeometry.hh:142
const GridView & gridView() const
Definition basegridgeometry.hh:100
void update(const GridView &gridView)
Update all fvElementGeometries (call this after grid adaption).
Definition basegridgeometry.hh:88
const GlobalCoordinate & bBoxMin() const
The coordinate of the corner of the GridView's bounding box with the smallest values.
Definition basegridgeometry.hh:149
bool isPeriodic() const
Returns if the grid geometry is periodic (at all).
Definition basegridgeometry.hh:162
Class for a boundary face related to primary grid elements (dune intersections).
Definition boundaryface.hh:69
Default class for the local finite element discretization. All schemes share the same structure....
Definition feelementdiscretization.hh:41
Class for pq3 finite element grid discretizations.
Definition pq3/fegriddiscretization.hh:84
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::template LocalView< ThisType, true > LocalView
Definition pq3/fegriddiscretization.hh:104
void update(GridView &&gridView)
update all geometries (call this after grid adaption)
Definition pq3/fegriddiscretization.hh:153
GridIndexType periodicallyMappedDof(GridIndexType dofIdx) const
The index of the d.o.f. on the other side of the periodic boundary.
Definition pq3/fegriddiscretization.hh:172
typename PeriodicGridTraits< typename GridView::Grid >::SupportsPeriodicity SupportsPeriodicity
Definition pq3/fegriddiscretization.hh:114
void update(const GridView &gridView)
update all geometries (call this after grid adaption)
Definition pq3/fegriddiscretization.hh:146
static constexpr DiscretizationMethod discMethod
Definition pq3/fegriddiscretization.hh:94
Experimental::BoundaryFace< GridView > BoundaryFace
Definition pq3/fegriddiscretization.hh:99
PQ3FEGridDiscretization(const GridView &gridView)
Constructor.
Definition pq3/fegriddiscretization.hh:133
bool dofOnBoundary(GridIndexType dofIdx) const
If a d.o.f. is on the boundary.
Definition pq3/fegriddiscretization.hh:164
GridView GridView
Definition pq3/fegriddiscretization.hh:112
Extrusion_t< PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar > > Extrusion
Definition pq3/fegriddiscretization.hh:106
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::DofMapper DofMapper
Definition pq3/fegriddiscretization.hh:108
PQ3FEGridDiscretizationCache Cache
Definition pq3/fegriddiscretization.hh:218
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::IntersectionQuadratureRule IntersectionQuadratureRule
Definition pq3/fegriddiscretization.hh:118
PQ3FEGridDiscretization(std::shared_ptr< BasicGridGeometry > gg)
Constructor.
Definition pq3/fegriddiscretization.hh:123
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::FeCache FeCache
Definition pq3/fegriddiscretization.hh:110
const std::unordered_map< GridIndexType, GridIndexType > & periodicDofMap() const
Returns the map between dofs across periodic boundaries.
Definition pq3/fegriddiscretization.hh:176
std::size_t numDofs() const
The total number of degrees of freedom.
Definition pq3/fegriddiscretization.hh:142
friend LocalView localView(const PQ3FEGridDiscretization &gg)
local view of this object (constructed with the internal cache)
Definition pq3/fegriddiscretization.hh:180
const FeCache & feCache() const
The finite element cache for creating local FE bases.
Definition pq3/fegriddiscretization.hh:160
const DofMapper & dofMapper() const
The dof mapper.
Definition pq3/fegriddiscretization.hh:138
bool dofOnPeriodicBoundary(GridIndexType dofIdx) const
If a d.o.f. is on a periodic boundary.
Definition pq3/fegriddiscretization.hh:168
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::ElementQuadratureRule ElementQuadratureRule
Definition pq3/fegriddiscretization.hh:116
static constexpr std::size_t maxNumElementDofs
Definition pq3/fegriddiscretization.hh:96
BasicGridGeometry_t< GridView, PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar > > BasicGridGeometry
Definition pq3/fegriddiscretization.hh:102
typename DiscretizationMethods::PQ3 DiscretizationMethod
Definition pq3/fegriddiscretization.hh:93
typename PQ3FEDefaultGridDiscretizationTraits< GridView, Scalar >::BoundaryFaceQuadratureRule BoundaryFaceQuadratureRule
Definition pq3/fegriddiscretization.hh:120
DOF index and position helper for order-3 Lagrange discretizations.
Definition pq3/dofhelper.hh:51
Defines the default element and vertex mapper types.
Base class for the finite volume geometry vector for the pq3 method This builds up the sub control vo...
Default class for the local finite element discretization. All schemes share the same structure....
Default class for finite element grid discretizations.
Dune::Std::detected_or_t< Dumux::BasicGridGeometry< GV, typename T::ElementMapper, typename T::VertexMapper >, Detail::SpecifiesBaseGridGeometry, T > BasicGridGeometry_t
Type of the basic grid geometry implementation used as backend.
Definition basegridgeometry.hh:38
BaseGridGeometry(std::shared_ptr< BaseImplementation > impl)
Constructor from a BaseImplementation.
Definition basegridgeometry.hh:72
The available discretization methods in Dumux.
CVFE< CVFEMethods::PQ3 > PQ3
Definition method.hh:138
Definition assembly/assembler.hh:44
typename Extrusion< T >::type Extrusion_t
Convenience alias for obtaining the extrusion type.
Definition extrusion.hh:236
Lightweight DOF helper for order-3 Lagrange elements.
Quadrature rules over sub-control volumes and sub-control volume faces.
The default traits for the PQ3 finite element grid discretization.
Definition pq3/fegriddiscretization.hh:55
Dune::LagrangeLocalFiniteElementCache< typename GridView::ctype, Scalar, GridView::dimension, 3 > FeCache
Definition pq3/fegriddiscretization.hh:56
PQ3LagrangeDofHelper< GridView > DofHelper
Definition pq3/fegriddiscretization.hh:57
FEElementDiscretization< GridDiscretization, enableCache > LocalView
Definition pq3/fegriddiscretization.hh:60
static constexpr std::size_t maxNumElementDofs
Definition pq3/fegriddiscretization.hh:63
Quadrature rule traits for PQ3 FE discretization.
Definition pq3/fegriddiscretization.hh:37
ElementRule ElementQuadratureRule
Definition pq3/fegriddiscretization.hh:38
IntersectionRule IntersectionQuadratureRule
Definition pq3/fegriddiscretization.hh:39
BoundaryFaceRule BoundaryFaceQuadratureRule
Definition pq3/fegriddiscretization.hh:40
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28
Mapper traits for PQ3: vertices get 1 DOF, edges get 2 DOFs, quad faces/elements get 4 DOFs,...
Definition discretization/pq3/fvgridgeometry.hh:81
Definition periodicgridtraits.hh:24
Definition periodicgridtraits.hh:23