WaveBlocksND
shape_hyperbolic.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 #include <string>
5 #include <sstream>
6 
7 #include "../../types.hpp"
8 
9 #include "shape_base.hpp"
10 
11 
12 namespace waveblocks {
13  namespace wavepackets {
14  namespace shapes {
30  template<dim_t D>
32  {
33  private:
34  int S_;
35 
36  public:
42  HyperbolicCutShape(int S) : S_(S) {}
43 
44  virtual int bbox(dim_t axis) const override
45  {
46  (void)(axis); // unused
47  return S_ - 1;
48  }
49 
50  virtual int limit(int const* base_node, dim_t axis) const override
51  {
52  double s = S_;
53 
54  for (dim_t i = 0; i < D; i++) {
55  if (i != axis) {
56  s /= 1 + base_node[i];
57  }
58  }
59 
60  return (int)s - 1;
61  }
62 
63  virtual void print(std::ostream & out) const override
64  {
65  out << "HyperbolicCutShape{sparsity: " << S_ << "}";
66  }
67  };
68 
87  template<dim_t D>
89  {
90  private:
91  int S_;
92  std::array<int,D> limits_;
93 
94  public:
101  LimitedHyperbolicCutShape(int S, const std::array<int,D> &limits)
102  : S_(S)
103  , limits_(limits)
104  { }
105 
112  LimitedHyperbolicCutShape(int S, int size)
113  : S_(S)
114  {
115  for (std::size_t d = 0; d < D; d++)
116  limits_[d] = size;
117  }
118 
125  LimitedHyperbolicCutShape(int S, std::initializer_list<int> list)
126  : S_(S)
127  {
128  int deflt = 0;
129  std::size_t i = 0;
130  for (int e : list) {
131  limits_[i++] = deflt = e;
132  }
133  //fill remaining elements with last value of initializer list
134  while (i < D) {
135  limits_[i++] = deflt;
136  }
137  }
138 
139  virtual int bbox(dim_t axis) const override
140  {
141  return std::min( limits_[axis]-1, S_ - 1);
142  }
143 
144  virtual int limit(int const* base_node, dim_t axis) const override
145  {
146  double s = S_;
147 
148  for (dim_t i = 0; i < D; i++) {
149  if (i != axis) {
150  if (base_node[i] >= limits_[i])
151  return -1;
152  else
153  s /= 1 + base_node[i];
154  }
155  }
156 
157  return std::min((int)limits_[axis]-1, (int)s - 1);
158  }
159 
160  virtual void print(std::ostream & out) const override
161  {
162  out << "LimitedHyperbolicCutShape{ sparsity: " << S_ << ", limits (exclusive): [";
163  for (dim_t i = 0; i < D-1; i++) {
164  out << limits_[i] << ",";
165  }
166  out << limits_[D-1] << "]";
167  out << "}";
168  }
169  };
170  }
171  }
172 }
This class implements the hyperbolic cut shape.
Definition: shape_hyperbolic.hpp:31
Definition: coefficients_file_parser.cpp:10
HyperbolicCutShape(int S)
General constructor to set the sparsity parameter .
Definition: shape_hyperbolic.hpp:42
virtual int bbox(dim_t axis) const override
Retrieves the length of the minimum bounding box in one direction.
Definition: shape_hyperbolic.hpp:139
virtual void print(std::ostream &out) const override
Prints a pretty description of the shape.
Definition: shape_hyperbolic.hpp:160
LimitedHyperbolicCutShape(int S, const std::array< int, D > &limits)
General constructor to define sparsity parameter and limits.
Definition: shape_hyperbolic.hpp:101
virtual void print(std::ostream &out) const override
Prints a pretty description of the shape.
Definition: shape_hyperbolic.hpp:63
LimitedHyperbolicCutShape(int S, int size)
Specialized constructor to set all limits to the same value .
Definition: shape_hyperbolic.hpp:112
virtual int limit(int const *base_node, dim_t axis) const override
Evaluates one surface function on a base node.
Definition: shape_hyperbolic.hpp:50
virtual int bbox(dim_t axis) const override
Retrieves the length of the minimum bounding box in one direction.
Definition: shape_hyperbolic.hpp:44
virtual int limit(int const *base_node, dim_t axis) const override
Evaluates one surface function on a base node.
Definition: shape_hyperbolic.hpp:144
LimitedHyperbolicCutShape(int S, std::initializer_list< int > list)
General constructor to define sparsity parameter and limits.
Definition: shape_hyperbolic.hpp:125
int S_
Definition: shape_hyperbolic.hpp:34
std::array< int, D > limits_
Definition: shape_hyperbolic.hpp:92
This class implements the limited hyperbolic cut shape.
Definition: shape_hyperbolic.hpp:88
Subclasses provide a description of a basis shape.
Definition: shape_base.hpp:34
int dim_t
Definition: types.hpp:16