Loading [MathJax]/extensions/tex2jax.js

DUNE-FUNCTIONS (unstable)

geometryinancestor.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_COMMON_GEOMETRYINANCESTOR_HH
8#define DUNE_FUNCTIONS_COMMON_GEOMETRYINANCESTOR_HH
9
10#include <vector>
11
12#include <dune/common/iteratorrange.hh>
13
14namespace Dune::Functions {
15
16
17
37template<class Element>
39{
40 using GeometryInFather = typename Element::LocalGeometry;
41
42 template<class V>
43 static auto reverse_view(V&& v)
44 {
45 return Dune::IteratorRange(v.rbegin(), v.rend());
46 }
47
48public:
49
51 using LocalCoordinate = typename Element::Geometry::LocalCoordinate;
52 //
54 using GlobalCoordinate = typename Element::Geometry::LocalCoordinate;
55
56 GeometryInAncestor() = default;
58
67 : storedFineElement_(other.storedFineElement_)
68 , storedCoarseElement_(other.storedCoarseElement_)
69 , fineElementPtr_(&storedFineElement_)
70 , coarseElementPtr_(&storedFineElement_)
71 , geometryInFathersVector_(other.geometryInFathersVector_)
72 {
73 // If other points to external fine element,
74 // we point to the same one.
75 if (other.fineElementPtr_ != & other.storedFineElement_)
76 fineElementPtr_ = other.fineElementPtr_;
77 // If the other coarse element is not the stored one,
78 // then it's the fine one.
79 if (other.coarseElementPtr_ != & other.storedCoarseElement_)
80 coarseElementPtr_ = fineElementPtr_;
81 }
82
90 : storedFineElement_(other.storedFineElement_)
91 , storedCoarseElement_(other.storedCoarseElement_)
92 , fineElementPtr_(&fineElement)
93 , coarseElementPtr_(&storedFineElement_)
94 , geometryInFathersVector_(other.geometryInFathersVector_)
95 {
96 // If the other coarse element is not the stored one,
97 // then it's the fine one.
98 if (other.coarseElementPtr_ != & other.storedCoarseElement_)
99 coarseElementPtr_ = fineElementPtr_;
100 }
101
117 template<class F>
118 requires (std::is_invocable_r_v<bool,F,Element>)
119 const Element& bind(const Element& fineElement, F&& includeFather)
120 {
121 fineElementPtr_ = &fineElement;
122 geometryInFathersVector_.clear();
123 coarseElementPtr_ = fineElementPtr_;
124 while (includeFather(*coarseElementPtr_))
125 {
126 geometryInFathersVector_.push_back(coarseElementPtr_->geometryInFather());
127 storedCoarseElement_ = coarseElementPtr_->father();
128 coarseElementPtr_ = &storedCoarseElement_;
129 }
130 return coarseElement();
131 }
132
148 template<class F>
149 requires (std::is_invocable_r_v<bool,F,Element>)
150 const Element& bind(Element&& fineElement, F&& includeFather)
151 {
152 storedFineElement_ = fineElement;
153 bind(storedFineElement_, includeFather);
154 }
155
157 const Element& fineElement() const
158 {
159 return *fineElementPtr_;
160 }
161
163 const Element& coarseElement() const
164 {
165 return *coarseElementPtr_;
166 }
167
170 {
171 for (const auto& g : geometryInFathersVector_)
172 x = g.global(x);
173 return x;
174 }
175
178 {
179 // Here we can be instead use std::ranges::reverse_view once
180 // all supported compilers provide this (gcc>=10, clang>=16).
181 for (const auto& g : reverse_view(geometryInFathersVector_))
182 x = g.local(x);
183 return x;
184 }
185
186private:
187 Element storedFineElement_;
188 Element storedCoarseElement_;
189 const Element* fineElementPtr_ = nullptr;
190 const Element* coarseElementPtr_ = nullptr;
191 std::vector<GeometryInFather> geometryInFathersVector_;
192};
193
194
195
196} // namespace Dune::Functions
197
198
199
200
201#endif // DUNE_FUNCTIONS_COMMON_GEOMETRYINANCESTOR_HH
A geometry embedding a descendent element into an ancestor.
Definition: geometryinancestor.hh:39
GeometryInAncestor(const GeometryInAncestor &other, const Element &fineElement)
Copy construction setting an external fine element.
Definition: geometryinancestor.hh:89
const Element & fineElement() const
Return the fine element.
Definition: geometryinancestor.hh:157
GlobalCoordinate global(LocalCoordinate x) const
Map local coordinate in fine element into coarse element.
Definition: geometryinancestor.hh:169
const Element & bind(const Element &fineElement, F &&includeFather)
Bind this GeometryInAncestor to a fine element and search coarse element.
Definition: geometryinancestor.hh:119
const Element & coarseElement() const
Return the coarse element.
Definition: geometryinancestor.hh:163
GeometryInAncestor(const GeometryInAncestor &other)
Copy constructor.
Definition: geometryinancestor.hh:66
LocalCoordinate local(GlobalCoordinate x) const
Map local coordinate in coarse element into fine element.
Definition: geometryinancestor.hh:177
typename Element::Geometry::LocalCoordinate LocalCoordinate
Type of local coordinate (local within fine element)
Definition: geometryinancestor.hh:51
typename Element::Geometry::LocalCoordinate GlobalCoordinate
Type of global coordinate (local within coarse element)
Definition: geometryinancestor.hh:54
const Element & bind(Element &&fineElement, F &&includeFather)
Bind this GeometryInAncestor to a fine element and search coarse element.
Definition: geometryinancestor.hh:150
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 16, 23:47, 2025)