WaveBlocksND
shape_enum_subset.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <array>
5 
6 #include "../../types.hpp"
7 
8 #include "shape_enum.hpp"
9 
10 
11 namespace waveblocks {
12  namespace wavepackets {
13  namespace shapes {
14  namespace shape_enum {
15  template<dim_t D>
16  bool _copy_subset__fast_equals(const std::array<int,D>& lhs, const std::array<int,D>& rhs)
17  {
18  // multi-indices are lexically sorted therefore first entries will almost always be identical
19  // this function compares entries beginning on last entries
20 
21  for (dim_t i = D; i > 0; i--) {
22  if (lhs[i-1] != rhs[i-1])
23  return false;
24  }
25  return true;
26  }
27 
42  template<dim_t D, class MultiIndex, int N>
43  void copy_subset(const HaWpBasisVector<N>& superset_data, std::size_t offset1,
44  HaWpBasisVector<N>& subset_data, std::size_t offset2,
45  const ShapeSlice<D,MultiIndex>& superset_slice,
46  const ShapeSlice<D,MultiIndex>& subset_slice)
47  {
48  auto superset_it = superset_slice.begin();
49  auto subset_it = subset_slice.begin();
50 
51  while (superset_it != superset_slice.end() && subset_it != subset_slice.end()) {
52  if (*superset_it == *subset_it) {
53  std::size_t sub = offset2 + (subset_it - subset_slice.begin());
54  std::size_t super = offset1 + (superset_it - superset_slice.begin());
55 
56  subset_data.row(sub) = superset_data.row(super);
57  ++subset_it;
58  }
59  ++superset_it;
60  }
61  }
62 
63  template<dim_t D, class MultiIndex, int N>
65  const ShapeSlice<D,MultiIndex>& superset_slice,
66  const ShapeSlice<D,MultiIndex>& subset_slice)
67  {
68  HaWpBasisVector<N> subset_data(subset_slice.size(), superset_data.cols());
69  copy_subset(superset_data, 0, subset_data, 0, superset_slice, subset_slice);
70  return subset_data;
71  }
72 
73  template<dim_t D, class MultiIndex, int N>
75  const ShapeEnum<D,MultiIndex>* superset_enum,
76  const ShapeEnum<D,MultiIndex>* subset_enum)
77  {
78  HaWpBasisVector<N> subset_data(subset_enum->n_entries(), superset_data.cols());
79 
80  std::size_t i_off = 0;
81  std::size_t o_off = 0;
82  for (int islice = 0; islice < subset_enum->n_slices(); islice++) {
83  copy_subset(superset_data, i_off, subset_data, o_off, superset_enum->slice(islice), subset_enum->slice(islice));
84  i_off += superset_enum->slice(islice).size();
85  o_off += subset_enum->slice(islice).size();
86  }
87 
88  return subset_data;
89  }
90  }
91  }
92  }
93 }
Definition: coefficients_file_parser.cpp:10
std::size_t size() const
Definition: shape_enum.hpp:93
int n_slices() const
Retrieves the number of slices.
Definition: shape_enum.hpp:457
A shape enumeration is a complete, ordered list of all lattice nodes that are part of the basis shape...
Definition: shape_enum.hpp:353
std::size_t n_entries() const
Retrieves the number of nodes.
Definition: shape_enum.hpp:449
bool _copy_subset__fast_equals(const std::array< int, D > &lhs, const std::array< int, D > &rhs)
Definition: shape_enum_subset.hpp:16
CArray< Eigen::Dynamic, N > HaWpBasisVector
Definition: types.hpp:31
const_iterator begin() const
Returns a const-iterator pointing to the first node.
Definition: shape_enum.hpp:101
const_iterator end() const
Returns a const-iterator referring to the past-the-end node.
Definition: shape_enum.hpp:109
void copy_subset(const HaWpBasisVector< N > &superset_data, std::size_t offset1, HaWpBasisVector< N > &subset_data, std::size_t offset2, const ShapeSlice< D, MultiIndex > &superset_slice, const ShapeSlice< D, MultiIndex > &subset_slice)
Definition: shape_enum_subset.hpp:43
The -th slice of a shape enumeration contains all multi-indices that satisfy .
Definition: shape_enum.hpp:18
int dim_t
Definition: types.hpp:16
const ShapeSlice< D, MultiIndex > & slice(int islice) const
Returns a reference to a slice.
Definition: shape_enum.hpp:409