WaveBlocksND
shape_enum_extended.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "shape_enum.hpp"
4 #include "shape_enum_union.hpp"
5 
6 
7 namespace waveblocks {
8  namespace wavepackets {
9  namespace shapes {
10  namespace shape_enum {
11 
12  template<class MultiIndex>
13  std::vector<MultiIndex> _extend(const std::vector<MultiIndex>& source, dim_t start, dim_t len)
14  {
15  assert (len != 0);
16 
17  if (len == 1) {
18  std::vector<MultiIndex> next(source);
19  for (std::size_t i = 0; i < source.size(); i++) {
20  next[i][start] += 1;
21  }
22  return next;
23  } else {
24  // use divide and conquer approach
25  std::vector<MultiIndex> lhs = _extend(source, start, len/2);
26  std::vector<MultiIndex> rhs = _extend(source, start + len/2, len - len/2);
27 
28  std::vector<MultiIndex> sink(lhs.size() + rhs.size());
29 
30  auto seek = strict_union(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), sink.begin(), std::less<MultiIndex>{});
31 
32  sink.resize(seek - sink.begin());
33 
34  return sink;
35  }
36  }
37 
38  template<dim_t D, class MultiIndex>
40  {
41  std::vector<MultiIndex> result = _extend(slice._table(), 0, D);
42 
43  return {std::move(result), offset};
44  }
45 
54  template<dim_t D, class MultiIndex>
56  {
57  std::vector< ShapeSlice<D, MultiIndex> > slices(source->n_slices()+1);
58  std::size_t offset = 1;
59 
60  slices[0] = source->slice(0);
61  for (int islice = 0; islice < source->n_slices(); islice++) {
62  slices[islice+1] = _extend(source->slice(islice), offset);
63  offset += slices[islice+1].size();
64  }
65 
66  MultiIndex limits = source->limits();
67  for (dim_t d = 0; d < D; d++) {
68  limits[d] += 1;
69  }
70 
71  return {std::move(slices), offset, limits};
72  }
73  }
74  }
75  }
76 }
const MultiIndex & limits() const
Retrieves the minimum bounding box which contains all nodes.
Definition: shape_enum.hpp:472
Definition: coefficients_file_parser.cpp:10
Output strict_union(Input1 begin1, Input1 end1, Input2 begin2, Input2 end2, Output sink, Compare less)
Creates union of two shape slices.
Definition: shape_enum_union.hpp:35
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::vector< MultiIndex > _extend(const std::vector< MultiIndex > &source, dim_t start, dim_t len)
Definition: shape_enum_extended.hpp:13
ShapeEnum< D, MultiIndex > extend(const ShapeEnum< D, MultiIndex > *source)
For a given enumerated shape, enumerate its extension.
Definition: shape_enum_extended.hpp:55
std::vector< MultiIndex > & _table()
Definition: shape_enum.hpp:70
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