9#include <kernel/geometry/intern/index_representative.hpp>
10#include <kernel/geometry/intern/face_index_mapping.hpp>
11#include <kernel/geometry/index_set.hpp>
29 template<
typename Shape_>
54 Index& operator[](
int i)
59 const Index& operator[](
int i)
const
69 if (idx[i] <
other[i])
73 else if (idx[i] >
other[i])
85 typedef std::set<IndexVector>
RepSet;
125 typename RepSet::const_iterator iter =
_rep_set_vec[i].begin();
126 std::advance(iter, (
typename std::iterator_traits<
decltype(iter)>::difference_type)j);
146 template<
typename IndexVectorType_>
147 std::pair<bool,Index>
find(
const IndexVectorType_& index_vector)
const
151 Intern::IndexRepresentative<Shape_>::compute(representative, index_vector);
157 typename RepSet::const_iterator iter = rep_set.find(representative);
158 if(iter == rep_set.end())
159 return std::make_pair(
false,
Index(0));
161 return std::make_pair(
true,
Index((*iter)[0]));
173 template<
typename IndexVectorType_>
178 Intern::IndexRepresentative<Shape_>::compute(representative, index_vector);
181 Index first_index = representative[0];
184 representative[0] = id;
194 template<
typename IndexSet_>
195 void parse(
const IndexSet_& index_set)
197 static_assert(int(IndexSet_::num_indices) == int(
num_indices),
"index count mismatch");
200 const Index num_entities = index_set.get_num_entities();
203 for(
Index i(0); i < num_entities; ++i)
226 for(
Index i(0); i < n; ++i)
230 for(; it != jt; ++it, ++cur_id)
238 auto hint = std::next(it);
240 mod_el.value()[0] = cur_id;
252 return "IndexTree<" + Shape_::name() +
">";
301 typename IndexSetIn_,
302 typename IndexSetOut_>
305 const IndexSetIn_& index_set_in,
306 IndexSetOut_& index_set_out)
309 typedef typename IndexSetIn_::IndexTupleType IndexTupleTypeIn;
310 typedef Intern::FaceIndexMapping<Shape_, face_dim_, 0> FimType;
313 const Index num_entities = index_set_in.get_num_entities();
318 for(
Index i(0); i < num_entities; ++i)
321 const IndexTupleTypeIn& current_cell_in = index_set_in[i];
324 for(
int j(0); j < IndexSetOut_::num_indices; ++j)
330 current_face_indices[k] = current_cell_in[FimType::map(j, k)];
334 std::pair<bool, Index> bi = index_tree.
find(current_face_indices);
337 index_set_out[i][j] = bi.second;
348 template<
typename IndexSetIn_,
typename IndexSetOut_>
352 typedef Intern::FaceIndexMapping<Shape_, face_dim_, 0> FimType;
354 const Index num_shapes(index_set_in.get_num_entities());
356 const Index num_verts(index_set_in.get_index_bound());
368 for(
Index k(0); k < num_shapes; ++k)
370 for(
int l(0); l < num_subshapes_shape; ++l)
373 for(
int i(0); i < num_verts_subshape; ++i)
374 current_face_indices[i] = index_set_in[k][FimType::map(l,i)];
378 my_index_tree.
insert(current_face_indices, num_verts+1);
388 IndexSetOut_ my_index_set(num_subshapes, num_verts);
389 index_set_out = std::move(my_index_set);
391 for(
Index i(0); i < num_verts; ++i)
397 for(
Index j(0); j < n; ++j)
401 index_set_out[my_index][0] = i;
406 index_set_out[my_index][k] = my_index_tree.
get_index(i, j, k);
416 return "IndexCalculator<" + Shape_::name() +
"," +
stringify(face_dim_) +
">";
423 template<
typename Shape_,
int face_dim_,
int cell_dim_ = Shape_::dimension>
429 static void compute(IndexSetHolder<Shape_>& ish, IndexTree<FaceType>& idx_tree)
432 RisbHelper<Shape_, face_dim_, cell_dim_ - 1>::compute(ish, idx_tree);
435 bool success = IndexCalculator<CellType, face_dim_>::compute(
437 ish.template get_index_set<cell_dim_, 0>(),
438 ish.template get_index_set<cell_dim_, face_dim_>());
443 template<
typename Shape_,
int face_dim_>
444 struct RisbHelper<Shape_, face_dim_, face_dim_>
446 typedef typename Shape::FaceTraits<Shape_, face_dim_>::ShapeType FaceType;
448 static void compute(IndexSetHolder<Shape_>&, IndexTree<FaceType>&)
466 template<
typename Shape_,
int face_dim_ = Shape_::dimension - 1>
469 typedef typename Shape::FaceTraits<Shape_, face_dim_>::ShapeType FaceType;
470 static constexpr int num_verts = Shape::FaceTraits<FaceType, 0>::count;
482 static void wrap(IndexSetHolder<Shape_>& ish)
484 auto& vert_at_subshape_index_set(ish.template get_index_set<face_dim_,0>());
487 if(vert_at_subshape_index_set.get_num_entities() == 0)
489 IndexCalculator<Shape_, face_dim_>::compute_vertex_subshape(
490 ish.template get_index_set<Shape_::dimension, 0>(), vert_at_subshape_index_set);
493 IndexSetHolderDimensionUpdater<Shape_::dimension, Shape_::dimension-face_dim_>::update(ish);
497 RisbWrapper<Shape_, face_dim_ - 1>::wrap(ish);
500 IndexSet<num_verts>& vert_adj(vert_at_subshape_index_set);
503 IndexTree<FaceType> idx_tree(vert_adj.get_index_bound());
504 idx_tree.parse(vert_adj);
508 RisbHelper<Shape_, face_dim_>::compute(ish, idx_tree);
512 template<
typename Shape_>
513 struct RisbWrapper<Shape_, 0>
515 static void wrap(IndexSetHolder<Shape_>& )
530 template<
typename Shape_>
535 static void compute(IndexSetHolder<Shape_>& index_set_holder)
537 Intern::RisbWrapper<Shape_>::wrap(index_set_holder);
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
#define XASSERT(expr)
Assertion macro definition.
Calculates the missing index sets if the vertex-at-shape index sets are given.
static void compute_vertex_subshape(const IndexSetIn_ &index_set_in, IndexSetOut_ &index_set_out)
For given vertex@shape information, numbers subshapes and calculates vertex@subshape.
IndexTree< FaceType > IndexTreeType
Type for the IndexTree containing vertex@subshape information.
Shape::FaceTraits< Shape_, face_dim_ >::ShapeType FaceType
Type of the subshape to calculate the missing information at.
static bool compute(const IndexTreeType &index_tree, const IndexSetIn_ &index_set_in, IndexSetOut_ &index_set_out)
Calculates an index set from vertex@shape information.
static String name()
Returns the class name.
Stores the index representatives of an index set.
RepSetVector _rep_set_vec
representative set vector
std::set< IndexVector > RepSet
Set of IndexVector representatives.
void parse(const IndexSet_ &index_set)
Parses an index set into the tree.
int get_num_indices() const
returns number of indices of an index-representative
static constexpr int num_indices
number of indices per index vector
void insert(const IndexVectorType_ &index_vector, Index id)
Inserts an index vector's representative into the index tree.
static String name()
Returns the class name.
Index get_index(Index i, Index j, int k) const
returns the value of the k-th component of the j-th index-representative in the i-th set
virtual ~IndexTree()
Destructor.
Index enumerate()
Enumerates the index vector representatives.
IndexTree(Index num_vertices)
Constructor.
Index get_set_size(Index i) const
returns size of the i-th representative set
std::vector< RepSet > RepSetVector
Vector of IV rep sets.
std::pair< bool, Index > find(const IndexVectorType_ &index_vector) const
Searches for an index vector within the tree.
Builder for redundant index sets.
static void compute(IndexSetHolder< Shape_ > &index_set_holder)
Routine that does the actual work.
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.
Face traits tag struct template.