WaveBlocksND
shape_hypercubic.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <array>
5 #include <stdexcept>
6 #include <initializer_list>
7 
8 #include "../../types.hpp"
9 
10 #include "shape_base.hpp"
11 
12 
13 namespace waveblocks {
14  namespace wavepackets {
15  namespace shapes {
29  template<dim_t D>
30  class HyperCubicShape : public AbstractShape<D>
31  {
32  private:
33  std::array<int,D> limits_;
34 
35  public:
39  HyperCubicShape(const std::array<int,D> &limits)
40  : limits_(limits)
41  { }
42 
49  {
50  for (std::size_t d = 0; d < D; d++)
51  limits_[d] = limit;
52  }
53 
57  HyperCubicShape(std::initializer_list<int> list)
58  {
59  int deflt = 0;
60  std::size_t i = 0;
61  for (int e : list) {
62  limits_[i++] = deflt = e;
63  }
64  //fill remaining elements with last value of initializer list
65  while (i < D) {
66  limits_[i++] = deflt;
67  }
68  }
69 
71  : limits_(that.limits_)
72  { }
73 
75  {
76  limits_ = that.limits_;
77  return *this;
78  }
79 
80  virtual int limit(int const* base_node, dim_t axis) const override
81  {
82  { (void)(base_node); } //disable unused-parameter warning
83 
84  for (dim_t d = 0; d < D; d++) {
85  if (d != axis && base_node[d] >= limits_[d])
86  return -1;
87  }
88  return limits_[axis]-1;
89  }
90 
91  virtual int bbox(dim_t axis) const override
92  {
93  return limits_[axis]-1;
94  }
95 
96  virtual void print(std::ostream & out) const override
97  {
98  out << "HyperCubicShape{ limits (exclusive): [";
99  for (dim_t i = 0; i < D-1; i++) {
100  out << limits_[i] << ",";
101  }
102  out << limits_[D-1] << "]";
103  out << "}";
104  }
105  };
106  }
107  }
108 }
HyperCubicShape(const HyperCubicShape &that)
Definition: shape_hypercubic.hpp:70
This class implements the hypercubic basis shape.
Definition: shape_hypercubic.hpp:30
Definition: coefficients_file_parser.cpp:10
virtual int limit(int const *base_node, dim_t axis) const override
Evaluates one surface function on a base node.
Definition: shape_hypercubic.hpp:80
virtual void print(std::ostream &out) const override
Prints a pretty description of the shape.
Definition: shape_hypercubic.hpp:96
HyperCubicShape(std::initializer_list< int > list)
Definition: shape_hypercubic.hpp:57
HyperCubicShape & operator=(const HyperCubicShape &that)
Definition: shape_hypercubic.hpp:74
Subclasses provide a description of a basis shape.
Definition: shape_base.hpp:34
HyperCubicShape(int limit)
Set limits to .
Definition: shape_hypercubic.hpp:48
virtual int bbox(dim_t axis) const override
Retrieves the length of the minimum bounding box in one direction.
Definition: shape_hypercubic.hpp:91
HyperCubicShape(const std::array< int, D > &limits)
Definition: shape_hypercubic.hpp:39
int dim_t
Definition: types.hpp:16
std::array< int, D > limits_
Definition: shape_hypercubic.hpp:33