Dune Core Modules (2.10.0)

generalvertexorder.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5
6#ifndef DUNE_GEOMETRY_GENERALVERTEXORDER_HH
7#define DUNE_GEOMETRY_GENERALVERTEXORDER_HH
8
9#include <algorithm>
10#include <cassert>
11#include <cstddef>
12#include <iterator>
13#include <vector>
14
16
17#include "type.hh"
18#include <dune/geometry/referenceelements.hh>
19
20namespace Dune {
21
39 template<class InIterator, class OutIterator>
40 void reduceOrder(const InIterator& inBegin, const InIterator& inEnd,
41 OutIterator outIt)
42 {
43 for(InIterator inIt = inBegin; inIt != inEnd; ++inIt, ++outIt)
44 *outIt = std::count_if(inBegin, inEnd, [&](const auto& v)
45 {
46 return v < *inIt;
47 });
48 }
49
51
66 template<std::size_t dim, class Index_ = std::size_t>
69 typedef typename RefElems::ReferenceElement RefElem;
70
71 RefElem refelem;
72 GeometryType gt;
73 std::vector<Index_> vertexOrder;
74
75 public:
77 typedef Index_ Index;
78
80 class iterator;
81
83 static const std::size_t dimension = dim;
85 const GeometryType &type() const { return gt; }
86
88
96 template<class InIterator>
97 GeneralVertexOrder(const GeometryType& gt_, const InIterator &inBegin,
98 const InIterator &inEnd) :
99 refelem(RefElems::general(gt_)), gt(gt_),
100 vertexOrder(refelem.size(dim))
101 { reduceOrder(inBegin, inEnd, vertexOrder.begin()); }
102
104
108 iterator begin(std::size_t codim, std::size_t subEntity) const
109 { return iterator(*this, codim, subEntity); }
111
115 iterator end(std::size_t codim, std::size_t subEntity) const {
116 return iterator(*this, codim, subEntity,
117 refelem.size(subEntity, codim, dim));
118 }
119
121
128 void getReduced(std::size_t codim, std::size_t subEntity,
129 std::vector<Index>& order) const
130 {
131 order.resize(refelem.size(subEntity, codim, dim));
132 reduceOrder(begin(codim, subEntity), end(codim, subEntity),
133 order.begin());
134 }
135 };
136
138
141 template<std::size_t dim, class Index_>
142 class GeneralVertexOrder<dim, Index_>::iterator :
143 public Dune::RandomAccessIteratorFacade<iterator, const Index_>
144 {
145 const GeneralVertexOrder *order;
146 std::size_t codim;
147 std::size_t subEntity;
148 std::size_t vertex;
149
150 iterator(const GeneralVertexOrder &order_, std::size_t codim_,
151 std::size_t subEntity_, std::size_t vertex_ = 0) :
152 order(&order_), codim(codim_), subEntity(subEntity_), vertex(vertex_)
153 { }
154
155 public:
156 const Index &dereference() const {
157 return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
158 vertex, dim)];
159 }
160 const Index &elementAt(std::ptrdiff_t n) const {
161 return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
162 vertex+n, dim)];
163 }
164 bool equals(const iterator &other) const {
165 return order == other.order && codim == other.codim &&
166 subEntity == other.subEntity && vertex == other.vertex;
167 }
168 void increment() { ++vertex; }
169 void decrement() { --vertex; }
170 void advance(std::ptrdiff_t n) { vertex += n; }
171 std::ptrdiff_t distanceTo(const iterator &other) const {
172 // make sure we reference the same container
173 assert(order == other.order && codim == other.codim &&
174 subEntity == other.subEntity);
175 if(vertex < other.vertex) return other.vertex - vertex;
176 else return -static_cast<std::ptrdiff_t>(vertex - other.vertex);
177 }
178
179 friend class GeneralVertexOrder<dim, Index>;
180
182
188 };
189} // namespace Dune
190
191#endif // DUNE_GEOMETRY_GENERALVERTEXORDER_HH
Iterate over the vertex indices of some sub-entity.
Definition: generalvertexorder.hh:144
iterator()
public default constructor
Definition: generalvertexorder.hh:187
Class providing information on the ordering of vertices.
Definition: generalvertexorder.hh:67
Index_ Index
Type of indices.
Definition: generalvertexorder.hh:77
const GeometryType & type() const
get type of the entity's geometry
Definition: generalvertexorder.hh:85
static const std::size_t dimension
export the dimension of the entity we provide information for
Definition: generalvertexorder.hh:83
void getReduced(std::size_t codim, std::size_t subEntity, std::vector< Index > &order) const
get a vector of reduced indices for some sub-entity
Definition: generalvertexorder.hh:128
iterator end(std::size_t codim, std::size_t subEntity) const
get end iterator for the vertex indices of some sub-entity
Definition: generalvertexorder.hh:115
GeneralVertexOrder(const GeometryType &gt_, const InIterator &inBegin, const InIterator &inEnd)
construct a GeneralVertexOrder
Definition: generalvertexorder.hh:97
iterator begin(std::size_t codim, std::size_t subEntity) const
get begin iterator for the vertex indices of some sub-entity
Definition: generalvertexorder.hh:108
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:435
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:126
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
void reduceOrder(const InIterator &inBegin, const InIterator &inEnd, OutIterator outIt)
Algorithm to reduce vertex order information.
Definition: generalvertexorder.hh:40
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:128
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:146
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)