Loading...
Searching...
No Matches
generalvertexorder.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_GEOMETRY_GENERALVERTEXORDER_HH
#define DUNE_GEOMETRY_GENERALVERTEXORDER_HH
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <vector>
#include <dune/common/iteratorfacades.hh>
#include "type.hh"
#include <dune/geometry/referenceelements.hh>
namespace Dune {
template<class InIterator, class OutIterator>
void reduceOrder(const InIterator& inBegin, const InIterator& inEnd,
OutIterator outIt)
{
for(InIterator inIt = inBegin; inIt != inEnd; ++inIt, ++outIt)
*outIt = std::count_if(inBegin, inEnd, [&](const auto& v)
{
return v < *inIt;
});
}
template<std::size_t dim, class Index_ = std::size_t>
class GeneralVertexOrder {
typedef ReferenceElements<double, dim> RefElems;
typedef typename RefElems::ReferenceElement RefElem;
RefElem refelem;
GeometryType gt;
std::vector<Index_> vertexOrder;
public:
typedef Index_ Index;
class iterator;
static const std::size_t dimension = dim;
const GeometryType &type() const { return gt; }
template<class InIterator>
GeneralVertexOrder(const GeometryType& gt_, const InIterator &inBegin,
const InIterator &inEnd) :
refelem(RefElems::general(gt_)), gt(gt_),
vertexOrder(refelem.size(dim))
{ reduceOrder(inBegin, inEnd, vertexOrder.begin()); }
iterator begin(std::size_t codim, std::size_t subEntity) const
{ return iterator(*this, codim, subEntity); }
iterator end(std::size_t codim, std::size_t subEntity) const {
return iterator(*this, codim, subEntity,
refelem.size(subEntity, codim, dim));
}
void getReduced(std::size_t codim, std::size_t subEntity,
std::vector<Index>& order) const
{
order.resize(refelem.size(subEntity, codim, dim));
reduceOrder(begin(codim, subEntity), end(codim, subEntity),
order.begin());
}
};
template<std::size_t dim, class Index_>
class GeneralVertexOrder<dim, Index_>::iterator :
public Dune::RandomAccessIteratorFacade<iterator, const Index_>
{
const GeneralVertexOrder *order;
std::size_t codim;
std::size_t subEntity;
std::size_t vertex;
iterator(const GeneralVertexOrder &order_, std::size_t codim_,
std::size_t subEntity_, std::size_t vertex_ = 0) :
order(&order_), codim(codim_), subEntity(subEntity_), vertex(vertex_)
{ }
public:
const Index &dereference() const {
return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
vertex, dim)];
}
const Index &elementAt(std::ptrdiff_t n) const {
return order->vertexOrder[order->refelem.subEntity(subEntity, codim,
vertex+n, dim)];
}
bool equals(const iterator &other) const {
return order == other.order && codim == other.codim &&
subEntity == other.subEntity && vertex == other.vertex;
}
void increment() { ++vertex; }
void decrement() { --vertex; }
void advance(std::ptrdiff_t n) { vertex += n; }
std::ptrdiff_t distanceTo(const iterator &other) const {
// make sure we reference the same container
assert(order == other.order && codim == other.codim &&
subEntity == other.subEntity);
if(vertex < other.vertex) return other.vertex - vertex;
else return -static_cast<std::ptrdiff_t>(vertex - other.vertex);
}
friend class GeneralVertexOrder<dim, Index>;
iterator() { }
};
} // namespace Dune
#endif // DUNE_GEOMETRY_GENERALVERTEXORDER_HH
referenceelements.hh
type.hh
A unique label for each type of element that can occur in a grid.
Dune
Definition affinegeometry.hh:22
Dune::reduceOrder
void reduceOrder(const InIterator &inBegin, const InIterator &inEnd, OutIterator outIt)
Algorithm to reduce vertex order information.
Definition generalvertexorder.hh:40
Dune::Geo::ReferenceElements
Class providing access to the singletons of the reference elements.
Definition referenceelements.hh:128
Dune::Geo::ReferenceElements::ReferenceElement
typename Container::ReferenceElement ReferenceElement
The reference element type.
Definition referenceelements.hh:146
Dune::GeneralVertexOrder::Index
Index_ Index
Type of indices.
Definition generalvertexorder.hh:77
Dune::GeneralVertexOrder::type
const GeometryType & type() const
get type of the entity's geometry
Definition generalvertexorder.hh:85
Dune::GeneralVertexOrder::dimension
static const std::size_t dimension
export the dimension of the entity we provide information for
Definition generalvertexorder.hh:83
Dune::GeneralVertexOrder::getReduced
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
Dune::GeneralVertexOrder::end
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
Dune::GeneralVertexOrder::GeneralVertexOrder
GeneralVertexOrder(const GeometryType &gt_, const InIterator &inBegin, const InIterator &inEnd)
construct a GeneralVertexOrder
Definition generalvertexorder.hh:97
Dune::GeneralVertexOrder::begin
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
Dune::GeneralVertexOrder::iterator
Iterate over the vertex indices of some sub-entity.
Definition generalvertexorder.hh:144
Dune::GeneralVertexOrder::iterator::iterator
iterator()
public default constructor
Definition generalvertexorder.hh:187
Dune::GeneralVertexOrder::iterator::decrement
void decrement()
Definition generalvertexorder.hh:169
Dune::GeneralVertexOrder::iterator::advance
void advance(std::ptrdiff_t n)
Definition generalvertexorder.hh:170
Dune::GeneralVertexOrder::iterator::dereference
const Index & dereference() const
Definition generalvertexorder.hh:156
Dune::GeneralVertexOrder::iterator::increment
void increment()
Definition generalvertexorder.hh:168
Dune::GeneralVertexOrder::iterator::equals
bool equals(const iterator &other) const
Definition generalvertexorder.hh:164
Dune::GeneralVertexOrder::iterator::distanceTo
std::ptrdiff_t distanceTo(const iterator &other) const
Definition generalvertexorder.hh:171
Dune::GeneralVertexOrder::iterator::elementAt
const Index & elementAt(std::ptrdiff_t n) const
Definition generalvertexorder.hh:160
Dune::GeometryType
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:114