NiHu  2.0
cluster.hpp
Go to the documentation of this file.
1 
6 #ifndef NIHU_CLUSTER_HPP_INCLUDED
7 #define NIHU_CLUSTER_HPP_INCLUDED
8 
9 #include "bounding_box.hpp"
10 #include "util/crtp_base.hpp"
11 
12 #include <algorithm> // std::find, std::copy
13 #include <cstddef>
14 #include <iostream> // std::ostream
15 #include <iterator> // std::ostream_iterator
16 #include <vector> // idx_list
17 #include <stdexcept> // std::logic_error
18 
19 namespace NiHu
20 {
21 namespace fmm
22 {
32 template <class Derived>
34 
39 template <class Derived>
41 {
42 public:
45 
47  static size_t const dimension = traits_t::dimension;
48 
53 
55  typedef std::vector<size_t> idx_list_t;
56 
58  typedef typename traits_t::multipole_t multipole_t;
60  typedef typename traits_t::local_t local_t;
61 
62 public:
64 
69  void set_level(size_t level)
70  {
71  m_level = level;
72  }
73 
78  size_t get_level() const
79  {
80  return m_level;
81  }
82 
87  void set_parent(size_t parent)
88  {
89  m_parent = parent;
90  }
91 
95  size_t get_parent() const
96  {
97  return m_parent;
98  }
99 
104  {
105  m_bb = bb;
106  }
107 
112  {
113  return m_bb;
114  }
115 
119  void set_src_node_idx(idx_list_t const &node_idx)
120  {
121  m_src_node_idx = node_idx;
122  }
123 
128  template <class ForwardIt>
129  void set_src_node_idx(ForwardIt begin, ForwardIt end)
130  {
131  m_src_node_idx = idx_list_t(begin, end);
132  }
133 
138  {
139  return m_src_node_idx;
140  }
141 
145  size_t get_n_src_nodes() const
146  {
147  return m_src_node_idx.size();
148  }
149 
153  void set_rec_node_idx(idx_list_t const &node_idx)
154  {
155  m_rec_node_idx = node_idx;
156  }
157 
162  template <class ForwardIt>
163  void set_rec_node_idx(ForwardIt begin, ForwardIt end)
164  {
165  m_rec_node_idx = idx_list_t(begin, end);
166  }
167 
172  {
173  return m_rec_node_idx;
174  }
175 
179  size_t get_n_rec_nodes() const
180  {
181  return m_rec_node_idx.size();
182  }
183 
189  void add_child(size_t child)
190  {
191  if (std::find(m_children.begin(), m_children.end(), child) ==
192  m_children.end())
193  m_children.push_back(child);
194  else throw std::logic_error("Child already contained");
195  }
196 
200  idx_list_t const &get_children() const
201  {
202  return m_children;
203  }
204 
209  bool is_leaf() const
210  {
211  return m_children.empty();
212  }
213 
217  bool is_root() const
218  {
219  return m_level == 0;
220  }
221 
226  bool is_source() const
227  {
228  return !m_src_node_idx.empty();
229  }
230 
235  bool is_receiver() const
236  {
237  return !m_rec_node_idx.empty();
238  }
239 
243  void print_debug(std::ostream &os = std::cout) const
244  {
245  os << "Level:" << this->get_level() << std::endl;
246  os << "Bounding box: " << m_bb << std::endl;
247  std::ostream_iterator<size_t> out_it(os, ", ");
248  os << "Source indices:" << std::endl;
249  std::copy(this->get_src_node_idx().begin(), this->get_src_node_idx().end(), out_it);
250  os << std::endl;
251  os << "Receiver indices:" << std::endl;
252  std::copy(this->get_rec_node_idx().begin(), this->get_rec_node_idx().end(), out_it);
253  }
254 
259  {
260  return derived().zero_multipole();
261  }
262 
267  {
268  return derived().zero_local();
269  }
270 
271 private:
272  bounding_box_t m_bb;
273  size_t m_level;
274  size_t m_parent;
275  idx_list_t m_children;
276 
277  idx_list_t m_src_node_idx;
278  idx_list_t m_rec_node_idx;
279 };
280 
286 template <class Derived>
287 std::ostream &operator<<(std::ostream &os, cluster_base<Derived> const &c)
288 {
289  c.print_debug(os);
290  return os;
291 }
292 
293 } // namespace fmm
294 } // namespace NiHu
295 
296 #endif /* NIHU_CLUSTER_HPP_INCLUDED */
NiHu::fmm::cluster_base::idx_list_t
std::vector< size_t > idx_list_t
Index list type for storing children and contained nodes.
Definition: cluster.hpp:55
NiHu::fmm::cluster_base::set_bounding_box
void set_bounding_box(bounding_box_t const &bb)
set the cluster's bounding box
Definition: cluster.hpp:103
NiHu::fmm::cluster_base::zero_local
local_t zero_local() const
return a cleared (zero) local contribution
Definition: cluster.hpp:266
NiHu::fmm::cluster_base::get_n_rec_nodes
size_t get_n_rec_nodes() const
get number of receiver nodes contained in cluster
Definition: cluster.hpp:179
NiHu::fmm::cluster_base::get_rec_node_idx
const idx_list_t & get_rec_node_idx() const
get indices of receiver nodes
Definition: cluster.hpp:171
NiHu::fmm::cluster_base::get_bounding_box
const bounding_box_t & get_bounding_box() const
return cluster's bounding box
Definition: cluster.hpp:111
NiHu::fmm::cluster_base::dimension
static const size_t dimension
Space dimension.
Definition: cluster.hpp:47
NiHu::fmm::cluster_base::local_t
traits_t::local_t local_t
Local type.
Definition: cluster.hpp:60
NiHu::operator<<
std::ostream & operator<<(std::ostream &os, const quadrature_base< Derived > &Q)
print a quadrature into an ouput stream
Definition: quadrature.hpp:317
NiHu::fmm::cluster_base::get_children
const idx_list_t & get_children() const
get indices of children
Definition: cluster.hpp:200
NiHu::fmm::bounding_box< dimension, double >::location_t
Eigen::Matrix< scalar_t, dimension, 1 > location_t
the location type in the bounding box
Definition: bounding_box.hpp:38
NiHu::fmm::cluster_base::set_src_node_idx
void set_src_node_idx(ForwardIt begin, ForwardIt end)
set indices of source nodes with range
Definition: cluster.hpp:129
NiHu::fmm::cluster_base::add_child
void add_child(size_t child)
add a new child to a cluster
Definition: cluster.hpp:189
NiHu::fmm::cluster_base::bounding_box_t
bounding_box< dimension, double > bounding_box_t
Bounding box type.
Definition: cluster.hpp:50
NiHu::fmm::cluster_base::traits_t
cluster_traits< Derived > traits_t
Traits structure.
Definition: cluster.hpp:44
bounding_box.hpp
Implementation of class NiHu::fmm::bounding_box.
NIHU_CRTP_HELPERS
#define NIHU_CRTP_HELPERS
define CRTP helper function
Definition: crtp_base.hpp:29
NiHu::fmm::cluster_base::get_src_node_idx
const idx_list_t & get_src_node_idx() const
get indices of source nodes
Definition: cluster.hpp:137
NiHu::fmm::cluster_base::get_level
size_t get_level() const
Get cluster's level.
Definition: cluster.hpp:78
NiHu::fmm::cluster_traits
CRTP traits structure of a cluster.
Definition: cluster.hpp:33
NiHu::fmm::cluster_base::set_parent
void set_parent(size_t parent)
Set the parent cluster's index.
Definition: cluster.hpp:87
NiHu::fmm::cluster_base::set_rec_node_idx
void set_rec_node_idx(idx_list_t const &node_idx)
set indices of receiver nodes
Definition: cluster.hpp:153
NiHu::fmm::cluster_base
CRTP base class of clusters.
Definition: cluster.hpp:40
crtp_base.hpp
Define CRTP helper functions and metafunctions.
NiHu::fmm::cluster_base::print_debug
void print_debug(std::ostream &os=std::cout) const
prints debug information of the cluster to an output stream
Definition: cluster.hpp:243
NiHu::fmm::cluster_base::is_source
bool is_source() const
indicates if cluster is source
Definition: cluster.hpp:226
NiHu::fmm::cluster_base::multipole_t
traits_t::multipole_t multipole_t
Multipole type.
Definition: cluster.hpp:58
NiHu::fmm::cluster_base::set_src_node_idx
void set_src_node_idx(idx_list_t const &node_idx)
set indices of source nodes
Definition: cluster.hpp:119
NiHu::fmm::cluster_base::zero_multipole
multipole_t zero_multipole() const
return a cleared (zero) multipole contribution
Definition: cluster.hpp:258
NiHu::fmm::cluster_base::set_level
NIHU_CRTP_HELPERS void set_level(size_t level)
Set cluster's level.
Definition: cluster.hpp:69
NiHu::fmm::cluster_base::get_n_src_nodes
size_t get_n_src_nodes() const
return number of sources contained in cluster
Definition: cluster.hpp:145
NiHu::fmm::bounding_box< dimension, double >
NiHu::fmm::cluster_base::location_t
bounding_box_t::location_t location_t
Location type.
Definition: cluster.hpp:52
NiHu::fmm::cluster_base::is_receiver
bool is_receiver() const
indicates if cluster is receiver
Definition: cluster.hpp:235
NiHu::fmm::cluster_base::is_leaf
bool is_leaf() const
indicates if cluster is leaf
Definition: cluster.hpp:209
NiHu::fmm::cluster_base::set_rec_node_idx
void set_rec_node_idx(ForwardIt begin, ForwardIt end)
set indices of receiver nodes with range
Definition: cluster.hpp:163
NiHu::fmm::cluster_base::is_root
bool is_root() const
indicates if cluster is root (0-level)
Definition: cluster.hpp:217
NiHu::fmm::cluster_base::get_parent
size_t get_parent() const
return parent cluster's index
Definition: cluster.hpp:95