9#include <kernel/shape.hpp>
10#include <kernel/adjacency/permutation.hpp>
33 template<
int num_indices_>
36 static_assert(num_indices_ > 0,
"invalid number of indices");
80 template<
int num_indices_>
83 static_assert(num_indices_ > 0,
"invalid index count");
120 Index num_entities = 0,
121 Index index_bound = 0)
143 _indices = std::forward<std::vector<IndexTupleType>>(
other._indices);
156 return IndexSet(this->_index_bound, this->_indices);
159 void set_indices(std::vector<IndexTupleType>&& vec)
161 this->_indices = std::move(vec);
310 if(!inv_perm_face.
empty())
314 for(
Index i(0); i < n; ++i)
315 _indices.at(i).permute_map(inv_perm_face);
326 return "IndexSet<" +
stringify(num_indices_) +
">";
348 return reinterpret_cast<const Index*
>(&
_indices.data()[domain_node]);
355 return reinterpret_cast<const Index*
>(&
_indices.data()[domain_node+1]);
366 int face_dim_ = Shape_::dimension - 1>
367 class IndexSetWrapper :
368 public IndexSetWrapper<Shape_, face_dim_ - 1>
370 static_assert(face_dim_ < Shape_::dimension,
"invalid face dimension");
371 static_assert(face_dim_ > 0,
"invalid face dimension");
374 typedef IndexSetWrapper<Shape_, face_dim_ - 1> BaseClass;
375 typedef IndexSet<Shape::FaceTraits<Shape_, face_dim_>::count> IndexSetType;
378 IndexSetType _index_set;
387 explicit IndexSetWrapper(
const Index num_entities[]) :
388 BaseClass(num_entities),
390 num_entities[Shape_::dimension],
391 num_entities[face_dim_])
395 template<std::
size_t m_>
396 explicit IndexSetWrapper(
const std::array<Index, m_>& num_entities) :
397 BaseClass(num_entities),
399 num_entities[Shape_::dimension],
400 num_entities[face_dim_])
402 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
405 IndexSetWrapper(IndexSetWrapper&& other) :
406 BaseClass(std::forward<BaseClass>(
other)),
407 _index_set(std::forward<IndexSetType>(
other._index_set))
411 IndexSetWrapper& operator=(IndexSetWrapper&& other)
416 BaseClass::operator=(std::forward<BaseClass>(other));
417 _index_set = std::forward<IndexSetType>(
other._index_set);
422 virtual ~IndexSetWrapper()
426 void clone(
const IndexSetWrapper& other)
428 BaseClass::clone(other);
429 this->_index_set =
other._index_set.clone();
432 IndexSetWrapper clone()
const
439 template<
int face_dim__>
440 IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
442 static_assert(face_dim__ >= 0,
"invalid face dimension");
443 static_assert(face_dim__ < Shape_::dimension,
"invalid face dimension");
444 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
447 template<
int face_dim__>
448 const IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
const
450 static_assert(face_dim__ >= 0,
"invalid face dimension");
451 static_assert(face_dim__ < Shape_::dimension,
"invalid face dimension");
452 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
455 template<std::
size_t np_>
456 void permute(
const Adjacency::Permutation& shape_perm,
457 const std::array<Adjacency::Permutation, np_>& inv_perm)
459 BaseClass::permute(shape_perm, inv_perm);
460 _index_set.permute(shape_perm, inv_perm.at(face_dim_));
465 return "IndexSetWrapper<" + Shape_::name() +
"," +
stringify(face_dim_) +
">";
468 std::size_t bytes()
const
470 return BaseClass::bytes() + _index_set.bytes();
474 template<
typename Shape_>
475 class IndexSetWrapper<Shape_, 0>
477 static_assert(Shape_::dimension > 0,
"invalid shape dimension");
480 typedef IndexSet<Shape::FaceTraits<Shape_, 0>::count> IndexSetType;
483 IndexSetType _index_set;
491 explicit IndexSetWrapper(
const Index num_entities[]) :
493 num_entities[Shape_::dimension],
498 template<std::
size_t m_>
499 explicit IndexSetWrapper(
const std::array<Index, m_>& num_entities) :
501 num_entities[Shape_::dimension],
504 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
507 IndexSetWrapper(IndexSetWrapper&& other) :
508 _index_set(std::forward<IndexSetType>(
other._index_set))
512 IndexSetWrapper& operator=(IndexSetWrapper&& other)
517 _index_set = std::forward<IndexSetType>(
other._index_set);
522 virtual ~IndexSetWrapper()
526 void clone(
const IndexSetWrapper& other)
528 this->_index_set =
other._index_set.clone();
531 IndexSetWrapper clone()
const
538 template<
int face_dim__>
539 IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
541 static_assert(face_dim__ == 0,
"invalid face dimension");
542 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
545 template<
int face_dim__>
546 const IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
const
548 static_assert(face_dim__ == 0,
"invalid face dimension");
549 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
552 template<std::
size_t np_>
553 void permute(
const Adjacency::Permutation& shape_perm,
554 const std::array<Adjacency::Permutation, np_>& inv_perm)
556 _index_set.permute(shape_perm, inv_perm.at(0));
561 return "IndexSetWrapper<" + Shape_::name() +
",0>";
564 std::size_t bytes()
const
566 return _index_set.bytes();
603 template<
typename Shape_>
604 class IndexSetHolder :
605 public IndexSetHolder<typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType>
608 typedef IndexSetHolder<
typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType> BaseClass;
609 typedef IndexSetWrapper<Shape_> IndexSetWrapperType;
617 typedef Geometry::IndexSet
621 typename Shape::FaceTraits<Shape_, cell_dim_> ::ShapeType,
629 IndexSetWrapperType _index_set_wrapper;
638 explicit IndexSetHolder(
const Index num_entities[]) :
639 BaseClass(num_entities),
640 _index_set_wrapper(num_entities)
644 template<std::
size_t m_>
645 explicit IndexSetHolder(
const std::array<Index, m_>& num_entities) :
646 BaseClass(num_entities),
647 _index_set_wrapper(num_entities)
649 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
652 IndexSetHolder(IndexSetHolder&& other) :
653 BaseClass(std::forward<BaseClass>(
other)),
654 _index_set_wrapper(std::forward<IndexSetWrapperType>(
other._index_set_wrapper))
658 IndexSetHolder& operator=(IndexSetHolder&& other)
663 BaseClass::operator=(std::forward<BaseClass>(other));
664 _index_set_wrapper = std::forward<IndexSetWrapperType>(
other._index_set_wrapper);
669 virtual ~IndexSetHolder()
673 void clone(
const IndexSetHolder& other)
675 BaseClass::clone(other);
676 this->_index_set_wrapper.clone(
other._index_set_wrapper);
679 IndexSetHolder clone()
const
686 template<
int shape_dim_>
687 IndexSetWrapper<typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType>& get_index_set_wrapper()
689 static_assert(shape_dim_ > 0,
"invalid shape dimension");
690 static_assert(shape_dim_ <= Shape_::dimension,
"invalid shape dimension");
691 typedef typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType ShapeType;
692 return IndexSetHolder<ShapeType>::_index_set_wrapper;
695 template<
int shape_dim_>
696 const IndexSetWrapper<typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType>& get_index_set_wrapper()
const
698 static_assert(shape_dim_ > 0,
"invalid shape dimension");
699 static_assert(shape_dim_ <= Shape_::dimension,
"invalid shape dimension");
700 typedef typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType ShapeType;
701 return IndexSetHolder<ShapeType>::_index_set_wrapper;
709 typename Shape::FaceTraits<
717 static_assert(cell_dim_ <= Shape_::dimension,
"invalid cell dimension");
718 static_assert(face_dim_ < cell_dim_,
"invalid face/cell dimension");
719 static_assert(face_dim_ >= 0,
"invalid face dimension");
720 return get_index_set_wrapper<cell_dim_>().template get_index_set<face_dim_>();
726 const Geometry::IndexSet<
728 typename Shape::FaceTraits<
734 get_index_set()
const
736 static_assert(cell_dim_ <= Shape_::dimension,
"invalid cell dimension");
737 static_assert(face_dim_ < cell_dim_,
"invalid face/cell dimension");
738 static_assert(face_dim_ >= 0,
"invalid face dimension");
739 return get_index_set_wrapper<cell_dim_>().template get_index_set<face_dim_>();
742 template<std::
size_t np_>
743 void permute(
const std::array<Adjacency::Permutation, np_>& perms,
744 const std::array<Adjacency::Permutation, np_>& inv_perms)
746 BaseClass::permute(perms, inv_perms);
747 _index_set_wrapper.permute(perms.at(Shape_::dimension), inv_perms);
752 return "IndexSetHolder<" + Shape_::name() +
">";
755 std::size_t bytes()
const
757 return BaseClass::bytes() + _index_set_wrapper.bytes();
762 class IndexSetHolder<Shape::Vertex>
769 explicit IndexSetHolder(
const Index* )
773 template<std::
size_t m_>
774 explicit IndexSetHolder(
const std::array<Index, m_>&)
778 IndexSetHolder(IndexSetHolder&&)
782 IndexSetHolder& operator=(IndexSetHolder&&)
787 virtual ~IndexSetHolder()
791 void clone(
const IndexSetHolder&)
795 IndexSetHolder clone()
const
797 return IndexSetHolder();
800 template<std::
size_t np_>
801 void permute(
const std::array<Adjacency::Permutation, np_>&,
802 const std::array<Adjacency::Permutation, np_>&)
808 return "IndexSetHolder<Vertex>";
811 std::size_t bytes()
const
813 return std::size_t(0);
843 template<
int shape_dim_,
int co_dim_>
844 struct IndexSetHolderDimensionUpdater
855 template<
typename IndexSetHolderType_>
856 static void update(IndexSetHolderType_& DOXY(ish))
866 template<
int shape_dim_>
867 struct IndexSetHolderDimensionUpdater<shape_dim_,1>
869 template<
typename IndexSetHolderType_>
870 static void update(IndexSetHolderType_& ish)
872 auto& vert_at_subshape_index_set(ish.template get_index_set<shape_dim_-1,0>());
874 Index num_shapes(ish.template get_index_set<shape_dim_,0>().get_num_entities());
876 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_, shape_dim_-1>()) )>::type
878 subshape_at_shape_index_set(num_shapes, vert_at_subshape_index_set.get_num_entities());
882 ish.template get_index_set<shape_dim_, shape_dim_-1>() = std::move(subshape_at_shape_index_set);
890 template<
int shape_dim_>
891 struct IndexSetHolderDimensionUpdater<shape_dim_,2>
893 template<
typename IndexSetHolderType_>
894 static void update(IndexSetHolderType_& ish)
898 auto& vert_at_subshape_index_set(ish.template get_index_set<shape_dim_-2,0>());
900 Index num_shapes(ish.template get_index_set<shape_dim_,0>().get_num_entities());
902 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_, shape_dim_-2>()) )>::type
904 subshape_at_shape_index_set(num_shapes, vert_at_subshape_index_set.get_num_entities());
907 ish.template get_index_set<shape_dim_, shape_dim_-2>() = std::move(subshape_at_shape_index_set);
911 Index num_intermediate_shapes(ish.template get_index_set<shape_dim_-1,0>().get_num_entities());
913 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_-1, shape_dim_-2>()) )>::type
915 subshape_at_intermediate_index_set(
916 num_intermediate_shapes, vert_at_subshape_index_set.get_num_entities());
919 ish.template get_index_set<shape_dim_-1, shape_dim_-2>() = std::move(subshape_at_intermediate_index_set);
940 struct NumEntitiesExtractor
955 template<
typename IndexSetHolderType_>
956 static void set_num_entities(
const IndexSetHolderType_& ish, Index* num_entities)
959 num_entities[dim_] = ish.template get_index_set<dim_,0>().get_num_entities();
961 NumEntitiesExtractor<dim_-1>::set_num_entities(ish, num_entities);
964 template<
typename IndexSetHolderType_>
965 static void set_num_entities_with_numverts(
const IndexSetHolderType_& ish, Index* num_entities)
968 num_entities[dim_] = ish.template get_index_set<dim_,0>().get_num_entities();
970 NumEntitiesExtractor<dim_-1>::set_num_entities_with_numverts(ish, num_entities);
981 struct NumEntitiesExtractor<1>
983 template<
typename IndexSetHolderType_>
984 static void set_num_entities(
const IndexSetHolderType_& ish, Index* num_entities)
986 num_entities[1] = ish.template get_index_set<1,0>().get_num_entities();
989 template<
typename IndexSetHolderType_>
990 static void set_num_entities_with_numverts(
const IndexSetHolderType_& ish, Index* num_entities)
992 num_entities[0] = ish.template get_index_set<1,0>().get_index_bound();
993 num_entities[1] = ish.template get_index_set<1,0>().get_num_entities();
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XASSERT(expr)
Assertion macro definition.
Index size() const
returns the size of the permutation
bool empty() const
Checks whether the permutation is empty.
void apply(Tx_ *x, bool invert=false) const
Applies In-Situ permutation.
Conformal Index-Set class template.
Index get_num_nodes_domain() const
Returns the number of domain nodes.
Index & operator()(Index i, int j)
Maps a face index.
IndexSet(IndexSet &&other)
move constructor
static constexpr int num_indices
number of indices per entry
IndexSet(Index num_entities=0, Index index_bound=0)
Constructor.
IndexSet(Index idx_bnd, const std::vector< IndexTupleType > &idx)
internal clone constructor
std::size_t bytes() const
const Index * ImageIterator
ImageIterator type for Adjactor interface implementation.
virtual ~IndexSet()
virtual destructor
void set_index_bound(Index bound)
Sets the index bound.
IndexTupleType * get_indices()
Returns the index vector array.
Index get_index_bound() const
Returns the index bound.
std::vector< IndexTupleType > _indices
index vector array
const Index & operator()(Index i, int j) const
Maps a face index.
const IndexTupleType & operator[](Index i) const
Returns a reference to an index tuple.
ImageIterator image_begin(Index domain_node) const
Returns an iterator for the first adjacent image node.
void permute(const Adjacency::Permutation &perm, const Adjacency::Permutation &inv_perm_face)
Permutes this index set in-situ.
const IndexTupleType * get_indices() const
Returns the index vector array.
IndexTupleType & operator[](Index i)
Returns a reference to an index tuple.
IndexTuple< num_indices > IndexTupleType
index tuple type
Index get_num_entities() const
Returns the number of entities.
Index get_num_nodes_image() const
Returns the number of image nodes.
static String name()
Returns the name of the class.
IndexSet & operator=(IndexSet &&other)
move-assignment operator
ImageIterator image_end(Index domain_node) const
Returns an iterator for the first position past the last adjacent image node.
int get_num_indices() const
Returns the number of indices per entity.
String class implementation.
@ other
generic/other permutation strategy
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
Index Tuple class template.
const Index & operator[](int i) const
access operator
Index & operator[](int i)
access operator
static constexpr int num_indices
number of indices per tuple
Index indices[num_indices]
indices array