Dune Core Modules (2.7.1)

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
4#ifndef DUNE_GEOMETRY_GENERALVERTEXORDER_HH
5#define DUNE_GEOMETRY_GENERALVERTEXORDER_HH
6
7#include <algorithm>
8#include <cassert>
9#include <cstddef>
10#include <iterator>
11#include <vector>
12
14
15#include "type.hh"
16#include <dune/geometry/referenceelements.hh>
17
18namespace Dune {
19
37 template<class InIterator, class OutIterator>
38 void reduceOrder(const InIterator& inBegin, const InIterator& inEnd,
39 OutIterator outIt)
40 {
41 for(InIterator inIt = inBegin; inIt != inEnd; ++inIt, ++outIt)
42 *outIt = std::count_if(inBegin, inEnd, [&](const auto& v)
43 {
44 return v < *inIt;
45 });
46 }
47
49
64 template<std::size_t dim, class Index_ = std::size_t>
67 typedef typename RefElems::ReferenceElement RefElem;
68
69 RefElem refelem;
70 GeometryType gt;
71 std::vector<Index_> vertexOrder;
72
73 public:
75 typedef Index_ Index;
76
78 class iterator;
79
81 static const std::size_t dimension = dim;
83 const GeometryType &type() const { return gt; }
84
86
94 template<class InIterator>
95 GeneralVertexOrder(const GeometryType& gt_, const InIterator &inBegin,
96 const InIterator &inEnd) :
97 refelem(RefElems::general(gt_)), gt(gt_),
98 vertexOrder(refelem.size(dim))
99 { reduceOrder(inBegin, inEnd, vertexOrder.begin()); }
100
102
106 iterator begin(std::size_t codim, std::size_t subEntity) const
107 { return iterator(*this, codim, subEntity); }
109
113 iterator end(std::size_t codim, std::size_t subEntity) const {
114 return iterator(*this, codim, subEntity,
115 refelem.size(subEntity, codim, dim));
116 }
117
119
126 void getReduced(std::size_t codim, std::size_t subEntity,
127 std::vector<Index>& order) const
128 {
129 order.resize(refelem.size(subEntity, codim, dim));
130 reduceOrder(begin(codim, subEntity), end(codim, subEntity),
131 order.begin());
132 }
133 };
134
136
139 template<std::size_t dim, class Index_>
140 class GeneralVertexOrder<dim, Index_>::iterator :
141 public Dune::RandomAccessIteratorFacade<iterator, const Index_>
142 {
143 const GeneralVertexOrder *order;
144 std::size_t codim;
145 std::size_t subEntity;
146 std::size_t vertex;
147
148 iterator(const GeneralVertexOrder &order_, std::size_t codim_,
149 std::size_t subEntity_, std::size_t vertex_ = 0) :
150 order(&order_), codim(codim_), subEntity(subEntity_), vertex(vertex_)
151 { }
152
153 public:
154 const Index &dereference() const {
155 return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
156 vertex, dim)];
157 }
158 const Index &elementAt(std::ptrdiff_t n) const {
159 return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
160 vertex+n, dim)];
161 }
162 bool equals(const iterator &other) const {
163 return order == other.order && codim == other.codim &&
164 subEntity == other.subEntity && vertex == other.vertex;
165 }
166 void increment() { ++vertex; }
167 void decrement() { --vertex; }
168 void advance(std::ptrdiff_t n) { vertex += n; }
169 std::ptrdiff_t distanceTo(const iterator &other) const {
170 // make sure we reference the same container
171 assert(order == other.order && codim == other.codim &&
172 subEntity == other.subEntity);
173 if(vertex < other.vertex) return other.vertex - vertex;
174 else return -static_cast<std::ptrdiff_t>(vertex - other.vertex);
175 }
176
177 friend class GeneralVertexOrder<dim, Index>;
178
180
186 };
187} // namespace Dune
188
189#endif // DUNE_GEOMETRY_GENERALVERTEXORDER_HH
Iterate over the vertex indices of some sub-entity.
Definition: generalvertexorder.hh:142
iterator()
public default constructor
Definition: generalvertexorder.hh:185
Class providing information on the ordering of vertices.
Definition: generalvertexorder.hh:65
Index_ Index
Type of indices.
Definition: generalvertexorder.hh:75
const GeometryType & type() const
get type of the entity's geometry
Definition: generalvertexorder.hh:83
static const std::size_t dimension
export the dimension of the entity we provide information for
Definition: generalvertexorder.hh:81
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:126
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:113
GeneralVertexOrder(const GeometryType &gt_, const InIterator &inBegin, const InIterator &inEnd)
construct a GeneralVertexOrder
Definition: generalvertexorder.hh:95
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:106
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:279
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:432
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:797
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:401
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:134
This file implements iterator facade classes for writing stl conformant iterators.
Dune namespace.
Definition: alignedallocator.hh:14
void reduceOrder(const InIterator &inBegin, const InIterator &inEnd, OutIterator outIt)
Algorithm to reduce vertex order information.
Definition: generalvertexorder.hh:38
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:168
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition: referenceelements.hh:186
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 (Nov 13, 23:29, 2024)