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_GRID_UTILITY_VERTEXORDERFACTORY_HH 5 #define DUNE_GRID_UTILITY_VERTEXORDERFACTORY_HH 6 7 #include <algorithm> 8 #include <cstddef> 9 #include <functional> 10 #include <vector> 11 12 #include <dune/geometry/referenceelements.hh> 13 #include <dune/geometry/generalvertexorder.hh> 14 15 namespace Dune { 16 17 //! Factory for GeneralVertexOrder objects using an IdSet 18 /** 19 * \tparam IdSet Type used to get the ids of the vertices. 20 * \tparam Index Type of the indices provided by the vertex ordering 21 * object. Must be integral, may be non-negative. 22 * 23 * \warning The Interface of the VertexOrder stuff is subject to change. It 24 * is currently needed to use some global-valued finite elements 25 * from dune-localfunctions. 26 * 27 * \sa GeneralVertexOrder, reduceOrder() 28 */ 29 template<class IdSet, class Index = std::size_t> 30 class VertexOrderByIdFactory { 31 const IdSet& idset; 32 33 public: 34 //! type of vertex order object may depend on the dimension of the element 35 template<std::size_t dim> 36 struct VertexOrder { 37 //! type of vertex order object 38 typedef GeneralVertexOrder<dim, Index> type; 39 }; 40 41 //! construct a factory object 42 /** 43 * \tparam idset_ IdSet to use to extract the vertex ids. 44 * 45 * This factory object stores a reference to the IdSet object. The 46 * factory object's value will become singular when the stored reference 47 * becomes invalid. The only valid operation on a factory with singular 48 * value is destruction, all other operations will result in undefined 49 * behaviour. 50 */ VertexOrderByIdFactory(const IdSet & idset_)51 VertexOrderByIdFactory(const IdSet &idset_) : idset(idset_) { } 52 53 //! construct a vertex ordering object 54 /** 55 * \param e Grid element to create the vertex ordering object for. 56 * 57 * The returned object will remain valid even after the factory has become 58 * singular or has been destroyed. 59 */ 60 template<typename Element> 61 typename VertexOrder<Element::mydimension>::type make(const Element & e) const62 make(const Element &e) const { 63 64 std::size_t size = referenceElement(e.geometry()).size(Element::mydimension); 65 66 std::vector<typename IdSet::IdType> ids(size); 67 for(std::size_t i = 0; i < size; ++i) 68 ids[i] = idset.subId(e, i, Element::mydimension); 69 return GeneralVertexOrder<Element::mydimension, Index> 70 (e.type(), ids.begin(), ids.end()); 71 } 72 }; 73 74 } // namespace Dune 75 76 #endif // DUNE_GRID_UTILITY_VERTEXORDERFACTORY_HH 77