version 3.11-dev
Loading...
Searching...
No Matches
fedofhelper.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//
13#ifndef DUMUX_DISCRETIZATION_FE_DOF_HELPER_HH
14#define DUMUX_DISCRETIZATION_FE_DOF_HELPER_HH
15
16#include <ranges>
17
18#include <dune/geometry/type.hh>
19#include <dune/geometry/referenceelements.hh>
20
23
24namespace Dumux::Experimental {
25
32template <class GridView>
34{
35 using Scalar = typename GridView::ctype;
36 using GlobalPosition = typename Dune::FieldVector<Scalar, GridView::dimensionworld>;
37 using LocalIndexType = typename IndexTraits<GridView>::LocalIndex;
38 using GridIndexType = typename IndexTraits<GridView>::GridIndex;
39
40 using Element = typename GridView::template Codim<0>::Entity;
41
42 static constexpr auto dim = GridView::dimension;
43
44public:
45
47 template<class LocalKey>
48 static auto localDofOnIntersection(Dune::GeometryType type, unsigned int iIdx, const LocalKey& localKey)
49 {
50 const auto& refElement = Dune::referenceElement<Scalar, dim>(type);
51 const auto numEntitiesIntersection = refElement.size(iIdx, 1, localKey.codim());
52 for (std::size_t idx = 0; idx < numEntitiesIntersection; idx++)
53 if (localKey.subEntity() == refElement.subEntity(iIdx, 1, idx, localKey.codim()))
54 return true;
55 return false;
56 }
57
62 template<class ElemDisc>
63 static auto localDofs(const ElemDisc& elemDisc)
64 {
65 return Dune::transformedRangeView(
66 Dune::range(elemDisc.numLocalDofs()),
67 [&](const auto i) {
68 return CVFE::LocalDof{
69 static_cast<LocalIndexType>(i),
70 static_cast<GridIndexType>(dofIndex(
71 elemDisc.gridDiscretization().dofMapper(),
72 elemDisc.element(),
73 elemDisc.feLocalCoefficients().localKey(i))),
74 static_cast<GridIndexType>(elemDisc.elementIndex())
75 };
76 }
77 );
78 }
79
86 template<class ElemDisc, class BoundaryFace>
87 static auto localDofsOnBoundaryFace(const ElemDisc& elemDisc, const BoundaryFace& boundaryFace)
88 {
89 const auto& gridDisc = [&]() -> const auto& {
90 if constexpr (requires { elemDisc.gridDiscretization(); })
91 return elemDisc.gridDiscretization();
92 else
93 return elemDisc.gridGeometry();
94 }();
95
96 // The following implementation is not the most efficient one, but it is general and does not require any assumptions on the ordering of the dofs.
97 // Discretization-specific implementations can override this with a more efficient implementation,
98 // e.g. by directly only iterating over vertices of the boundaryFace and the related intersection.
99 return std::views::iota(std::size_t(0), elemDisc.numLocalDofs())
100 | std::views::filter([&](std::size_t i) {
102 elemDisc.element().type(),
103 boundaryFace.intersectionIndex(),
104 elemDisc.feLocalCoefficients().localKey(i));
105 })
106 | std::views::transform([&](std::size_t i) {
107 return CVFE::LocalDof(
108 static_cast<LocalIndexType>(i),
109 static_cast<GridIndexType>(dofIndex(
110 gridDisc.dofMapper(),
111 elemDisc.element(),
112 elemDisc.feLocalCoefficients().localKey(i))),
113 static_cast<GridIndexType>(elemDisc.elementIndex())
114 );
115 });
116 }
117
119 template<class DofMapper, class LocalKey>
120 static auto dofIndex(const DofMapper& dofMapper, const Element& element, const LocalKey& localKey)
121 {
122 return dofMapper.subIndex(element, localKey.subEntity(), localKey.codim()) + localKey.index();
123 }
124
126 template<class Geometry, class LocalKey>
127 static GlobalPosition dofPosition(const Geometry& geo, const LocalKey& localKey)
128 {
129 if (localKey.codim() == dim)
130 return geo.corner(localKey.subEntity());
131 else if (localKey.codim() == 0)
132 return geo.center();
133 else
134 return geo.global(localDofPosition(geo.type(), localKey));
135 }
136
138 template<class LocalKey>
139 static typename Element::Geometry::LocalCoordinate localDofPosition(Dune::GeometryType type, const LocalKey& localKey)
140 {
141 return Dune::referenceElement<Scalar, dim>(type).position(localKey.subEntity(), localKey.codim());
142 }
143};
144
145} // end namespace Dumux::Experimental
146
147#endif
A local degree of freedom from an element perspective.
Definition localdof.hh:27
Class for a boundary face related to primary grid elements (dune intersections).
Definition boundaryface.hh:69
LocalIndexType intersectionIndex() const
The index of the intersection this face corresponds to (intersection.indexInInside()).
Definition boundaryface.hh:122
Default Dof helper for finite-element discretizations providing dof-related utility functions....
Definition fedofhelper.hh:34
static auto localDofs(const ElemDisc &elemDisc)
Iterator range over all local dofs on an element.
Definition fedofhelper.hh:63
static auto dofIndex(const DofMapper &dofMapper, const Element &element, const LocalKey &localKey)
global index of dof
Definition fedofhelper.hh:120
static GlobalPosition dofPosition(const Geometry &geo, const LocalKey &localKey)
global dof position
Definition fedofhelper.hh:127
static auto localDofOnIntersection(Dune::GeometryType type, unsigned int iIdx, const LocalKey &localKey)
Returns true if the local dof with a given local key is on the intersection with index iIdx.
Definition fedofhelper.hh:48
static Element::Geometry::LocalCoordinate localDofPosition(Dune::GeometryType type, const LocalKey &localKey)
local dof position
Definition fedofhelper.hh:139
static auto localDofsOnBoundaryFace(const ElemDisc &elemDisc, const BoundaryFace &boundaryFace)
Iterator range over all local dofs on a given boundary face. Uses a filter over all local dofs via lo...
Definition fedofhelper.hh:87
Defines the index types used for grid and local indices.
Class representing dofs on elements for control-volume finite element schemes.
Definition assembly/assembler.hh:44
typename GridView::IndexSet::IndexType GridIndex
Definition indextraits.hh:27
unsigned int LocalIndex
Definition indextraits.hh:28