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);
305 if(!inv_perm_face.
empty())
309 for(
Index i(0); i < n; ++i)
310 _indices.at(i).permute_map(inv_perm_face);
321 return "IndexSet<" +
stringify(num_indices_) +
">";
343 return reinterpret_cast<const Index*
>(&
_indices.data()[domain_node]);
350 return reinterpret_cast<const Index*
>(&
_indices.data()[domain_node+1]);
361 int face_dim_ = Shape_::dimension - 1>
362 class IndexSetWrapper :
363 public IndexSetWrapper<Shape_, face_dim_ - 1>
365 static_assert(face_dim_ < Shape_::dimension,
"invalid face dimension");
366 static_assert(face_dim_ > 0,
"invalid face dimension");
369 typedef IndexSetWrapper<Shape_, face_dim_ - 1> BaseClass;
370 typedef IndexSet<Shape::FaceTraits<Shape_, face_dim_>::count> IndexSetType;
373 IndexSetType _index_set;
382 explicit IndexSetWrapper(
const Index num_entities[]) :
383 BaseClass(num_entities),
385 num_entities[Shape_::dimension],
386 num_entities[face_dim_])
390 template<std::
size_t m_>
391 explicit IndexSetWrapper(
const std::array<Index, m_>& num_entities) :
392 BaseClass(num_entities),
394 num_entities[Shape_::dimension],
395 num_entities[face_dim_])
397 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
400 IndexSetWrapper(IndexSetWrapper&& other) :
401 BaseClass(std::forward<BaseClass>(
other)),
402 _index_set(std::forward<IndexSetType>(
other._index_set))
406 IndexSetWrapper& operator=(IndexSetWrapper&& other)
411 BaseClass::operator=(std::forward<BaseClass>(other));
412 _index_set = std::forward<IndexSetType>(
other._index_set);
417 virtual ~IndexSetWrapper()
421 void clone(
const IndexSetWrapper& other)
423 BaseClass::clone(other);
424 this->_index_set =
other._index_set.clone();
427 IndexSetWrapper clone()
const
434 template<
int face_dim__>
435 IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
437 static_assert(face_dim__ >= 0,
"invalid face dimension");
438 static_assert(face_dim__ < Shape_::dimension,
"invalid face dimension");
439 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
442 template<
int face_dim__>
443 const IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
const
445 static_assert(face_dim__ >= 0,
"invalid face dimension");
446 static_assert(face_dim__ < Shape_::dimension,
"invalid face dimension");
447 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
450 template<std::
size_t np_>
451 void permute(
const Adjacency::Permutation& shape_perm,
452 const std::array<Adjacency::Permutation, np_>& inv_perm)
454 BaseClass::permute(shape_perm, inv_perm);
455 _index_set.permute(shape_perm, inv_perm.at(face_dim_));
460 return "IndexSetWrapper<" + Shape_::name() +
"," +
stringify(face_dim_) +
">";
463 std::size_t bytes()
const
465 return BaseClass::bytes() + _index_set.bytes();
469 template<
typename Shape_>
470 class IndexSetWrapper<Shape_, 0>
472 static_assert(Shape_::dimension > 0,
"invalid shape dimension");
475 typedef IndexSet<Shape::FaceTraits<Shape_, 0>::count> IndexSetType;
478 IndexSetType _index_set;
486 explicit IndexSetWrapper(
const Index num_entities[]) :
488 num_entities[Shape_::dimension],
493 template<std::
size_t m_>
494 explicit IndexSetWrapper(
const std::array<Index, m_>& num_entities) :
496 num_entities[Shape_::dimension],
499 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
502 IndexSetWrapper(IndexSetWrapper&& other) :
503 _index_set(std::forward<IndexSetType>(
other._index_set))
507 IndexSetWrapper& operator=(IndexSetWrapper&& other)
512 _index_set = std::forward<IndexSetType>(
other._index_set);
517 virtual ~IndexSetWrapper()
521 void clone(
const IndexSetWrapper& other)
523 this->_index_set =
other._index_set.clone();
526 IndexSetWrapper clone()
const
533 template<
int face_dim__>
534 IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
536 static_assert(face_dim__ == 0,
"invalid face dimension");
537 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
540 template<
int face_dim__>
541 const IndexSet<Shape::FaceTraits<Shape_, face_dim__>::count>& get_index_set()
const
543 static_assert(face_dim__ == 0,
"invalid face dimension");
544 return IndexSetWrapper<Shape_, face_dim__>::_index_set;
547 template<std::
size_t np_>
548 void permute(
const Adjacency::Permutation& shape_perm,
549 const std::array<Adjacency::Permutation, np_>& inv_perm)
551 _index_set.permute(shape_perm, inv_perm.at(0));
556 return "IndexSetWrapper<" + Shape_::name() +
",0>";
559 std::size_t bytes()
const
561 return _index_set.bytes();
598 template<
typename Shape_>
599 class IndexSetHolder :
600 public IndexSetHolder<typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType>
603 typedef IndexSetHolder<
typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType> BaseClass;
604 typedef IndexSetWrapper<Shape_> IndexSetWrapperType;
612 typedef Geometry::IndexSet
616 typename Shape::FaceTraits<Shape_, cell_dim_> ::ShapeType,
624 IndexSetWrapperType _index_set_wrapper;
633 explicit IndexSetHolder(
const Index num_entities[]) :
634 BaseClass(num_entities),
635 _index_set_wrapper(num_entities)
639 template<std::
size_t m_>
640 explicit IndexSetHolder(
const std::array<Index, m_>& num_entities) :
641 BaseClass(num_entities),
642 _index_set_wrapper(num_entities)
644 static_assert(int(m_) > Shape_::dimension,
"invalid array size");
647 IndexSetHolder(IndexSetHolder&& other) :
648 BaseClass(std::forward<BaseClass>(
other)),
649 _index_set_wrapper(std::forward<IndexSetWrapperType>(
other._index_set_wrapper))
653 IndexSetHolder& operator=(IndexSetHolder&& other)
658 BaseClass::operator=(std::forward<BaseClass>(other));
659 _index_set_wrapper = std::forward<IndexSetWrapperType>(
other._index_set_wrapper);
664 virtual ~IndexSetHolder()
668 void clone(
const IndexSetHolder& other)
670 BaseClass::clone(other);
671 this->_index_set_wrapper.clone(
other._index_set_wrapper);
674 IndexSetHolder clone()
const
681 template<
int shape_dim_>
682 IndexSetWrapper<typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType>& get_index_set_wrapper()
684 static_assert(shape_dim_ > 0,
"invalid shape dimension");
685 static_assert(shape_dim_ <= Shape_::dimension,
"invalid shape dimension");
686 typedef typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType ShapeType;
687 return IndexSetHolder<ShapeType>::_index_set_wrapper;
690 template<
int shape_dim_>
691 const IndexSetWrapper<typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType>& get_index_set_wrapper()
const
693 static_assert(shape_dim_ > 0,
"invalid shape dimension");
694 static_assert(shape_dim_ <= Shape_::dimension,
"invalid shape dimension");
695 typedef typename Shape::FaceTraits<Shape_, shape_dim_>::ShapeType ShapeType;
696 return IndexSetHolder<ShapeType>::_index_set_wrapper;
704 typename Shape::FaceTraits<
712 static_assert(cell_dim_ <= Shape_::dimension,
"invalid cell dimension");
713 static_assert(face_dim_ < cell_dim_,
"invalid face/cell dimension");
714 static_assert(face_dim_ >= 0,
"invalid face dimension");
715 return get_index_set_wrapper<cell_dim_>().template get_index_set<face_dim_>();
721 const Geometry::IndexSet<
723 typename Shape::FaceTraits<
729 get_index_set()
const
731 static_assert(cell_dim_ <= Shape_::dimension,
"invalid cell dimension");
732 static_assert(face_dim_ < cell_dim_,
"invalid face/cell dimension");
733 static_assert(face_dim_ >= 0,
"invalid face dimension");
734 return get_index_set_wrapper<cell_dim_>().template get_index_set<face_dim_>();
737 template<std::
size_t np_>
738 void permute(
const std::array<Adjacency::Permutation, np_>& perms,
739 const std::array<Adjacency::Permutation, np_>& inv_perms)
741 BaseClass::permute(perms, inv_perms);
742 _index_set_wrapper.permute(perms.at(Shape_::dimension), inv_perms);
747 return "IndexSetHolder<" + Shape_::name() +
">";
750 std::size_t bytes()
const
752 return BaseClass::bytes() + _index_set_wrapper.bytes();
757 class IndexSetHolder<Shape::Vertex>
764 explicit IndexSetHolder(
const Index* )
768 template<std::
size_t m_>
769 explicit IndexSetHolder(
const std::array<Index, m_>&)
773 IndexSetHolder(IndexSetHolder&&)
777 IndexSetHolder& operator=(IndexSetHolder&&)
782 virtual ~IndexSetHolder()
786 void clone(
const IndexSetHolder&)
790 IndexSetHolder clone()
const
792 return IndexSetHolder();
795 template<std::
size_t np_>
796 void permute(
const std::array<Adjacency::Permutation, np_>&,
797 const std::array<Adjacency::Permutation, np_>&)
803 return "IndexSetHolder<Vertex>";
806 std::size_t bytes()
const
808 return std::size_t(0);
838 template<
int shape_dim_,
int co_dim_>
839 struct IndexSetHolderDimensionUpdater
850 template<
typename IndexSetHolderType_>
851 static void update(IndexSetHolderType_& DOXY(ish))
861 template<
int shape_dim_>
862 struct IndexSetHolderDimensionUpdater<shape_dim_,1>
864 template<
typename IndexSetHolderType_>
865 static void update(IndexSetHolderType_& ish)
867 auto& vert_at_subshape_index_set(ish.template get_index_set<shape_dim_-1,0>());
869 Index num_shapes(ish.template get_index_set<shape_dim_,0>().get_num_entities());
871 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_, shape_dim_-1>()) )>::type
873 subshape_at_shape_index_set(num_shapes, vert_at_subshape_index_set.get_num_entities());
877 ish.template get_index_set<shape_dim_, shape_dim_-1>() = std::move(subshape_at_shape_index_set);
885 template<
int shape_dim_>
886 struct IndexSetHolderDimensionUpdater<shape_dim_,2>
888 template<
typename IndexSetHolderType_>
889 static void update(IndexSetHolderType_& ish)
893 auto& vert_at_subshape_index_set(ish.template get_index_set<shape_dim_-2,0>());
895 Index num_shapes(ish.template get_index_set<shape_dim_,0>().get_num_entities());
897 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_, shape_dim_-2>()) )>::type
899 subshape_at_shape_index_set(num_shapes, vert_at_subshape_index_set.get_num_entities());
902 ish.template get_index_set<shape_dim_, shape_dim_-2>() = std::move(subshape_at_shape_index_set);
906 Index num_intermediate_shapes(ish.template get_index_set<shape_dim_-1,0>().get_num_entities());
908 typename std::remove_reference<
decltype( (ish.template get_index_set<shape_dim_-1, shape_dim_-2>()) )>::type
910 subshape_at_intermediate_index_set(
911 num_intermediate_shapes, vert_at_subshape_index_set.get_num_entities());
914 ish.template get_index_set<shape_dim_-1, shape_dim_-2>() = std::move(subshape_at_intermediate_index_set);
935 struct NumEntitiesExtractor
950 template<
typename IndexSetHolderType_>
951 static void set_num_entities(
const IndexSetHolderType_& ish, Index* num_entities)
954 num_entities[dim_] = ish.template get_index_set<dim_,0>().get_num_entities();
956 NumEntitiesExtractor<dim_-1>::set_num_entities(ish, num_entities);
959 template<
typename IndexSetHolderType_>
960 static void set_num_entities_with_numverts(
const IndexSetHolderType_& ish, Index* num_entities)
963 num_entities[dim_] = ish.template get_index_set<dim_,0>().get_num_entities();
965 NumEntitiesExtractor<dim_-1>::set_num_entities_with_numverts(ish, num_entities);
976 struct NumEntitiesExtractor<1>
978 template<
typename IndexSetHolderType_>
979 static void set_num_entities(
const IndexSetHolderType_& ish, Index* num_entities)
981 num_entities[1] = ish.template get_index_set<1,0>().get_num_entities();
984 template<
typename IndexSetHolderType_>
985 static void set_num_entities_with_numverts(
const IndexSetHolderType_& ish, Index* num_entities)
987 num_entities[0] = ish.template get_index_set<1,0>().get_index_bound();
988 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
Type
bitmask for zfp header
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