search_points_by_cells.h
Go to the documentation of this file.
1 /*
2 This file is part of the Ristra portage project.
3 Please see the license file at the root of this repository, or at:
4  https://github.com/laristra/portage/blob/master/LICENSE
5 */
6 #ifndef SEARCH_POINTS_BY_CELLS_H
7 #define SEARCH_POINTS_BY_CELLS_H
8 
9 #include <memory>
10 #include <vector>
11 #include <cmath>
12 #include <list>
13 
15 
17 
18 #include "pile.hh"
19 #include "lretypes.hh"
20 #include "pairs.hh"
21 
22 using Wonton::Point;
23 
24 namespace Portage {
25 
33 template <int dim, class SourceSwarm, class TargetSwarm>
35 public:
36 
38  SearchPointsByCells() = delete;
39 
40  // Constructor with swarms and extents
51  SearchPointsByCells(SourceSwarm const& source_swarm,
52  TargetSwarm const& target_swarm,
53  Portage::vector<Point<dim>> const& source_extents,
54  Portage::vector<Point<dim>> const& target_extents,
55  Meshfree::WeightCenter center = Meshfree::Scatter)
56  : source_swarm_(source_swarm),
57  target_swarm_(target_swarm),
58  source_extents_(source_extents),
59  target_extents_(target_extents),
60  center_(center) {
61 
62  using namespace Meshfree;
63 
64  int const nb_source = source_swarm_.num_particles();
65  int const nb_target = target_swarm_.num_particles();
66  bool const do_scatter = (center == Scatter);
67 
68 #ifdef DEBUG
69  // check sizes
70  if (do_scatter) {
71  assert(unsigned(nb_source) == source_extents_.size());
72  } else {
73  assert(unsigned(nb_target) == target_extents_.size());
74  }
75 #endif
76 
77  // transpose geometry data to lre namespace structures
78  Pairs::vpile source_vp(dim, nb_source);
79  Pairs::vpile target_vp(dim, nb_target);
80  Pairs::vpile extents_vp(dim, do_scatter ? nb_source : nb_target);
81 
82  for (int i = 0; i < nb_source; i++ ) {
83  auto p = source_swarm_.get_particle_coordinates(i);
84  for (int m = 0; m < dim; m++) {
85  source_vp[m][i] = p[m];
86  }
87  }
88 
89  for (int i = 0; i < nb_target; i++ ) {
90  auto p = target_swarm_.get_particle_coordinates(i);
91  for (int m = 0; m < dim; m++) {
92  target_vp[m][i] = p[m];
93  }
94  }
95 
96  if (do_scatter) {
97  for (int i = 0; i < nb_source; i++ ) {
98  for (int m = 0; m < dim; m++) {
99  Point<dim> p = source_extents_[i];
100  extents_vp[m][i] = p[m];
101  source_extents_[i] = p;
102  }
103  }
104  } else if (center_ == Gather) {
105  for (int i = 0; i < nb_target; i++ ) {
106  for (int m = 0; m < dim; m++) {
107  Point<dim> p = target_extents_[i];
108  extents_vp[m][i] = p[m];
109  target_extents_[i] = p;
110  }
111  }
112  }
113  // h on source for scatter, on target for gather
114  pair_finder_ = std::make_shared<Pairs::CellPairFinder>(source_vp, target_vp,
115  extents_vp, do_scatter);
116  }
117 
119  SearchPointsByCells(SearchPointsByCells const&) = default;
120 
123 
125  ~SearchPointsByCells() = default;
126 
136  std::vector<int> operator() (int pointId) const {
137  auto result = pair_finder_->find(pointId);
138  return std::vector<int>(result.begin(), result.end());
139  }
140 
141 private:
142  // Aggregate data members
143  SourceSwarm const& source_swarm_;
144  TargetSwarm const& target_swarm_;
145  Portage::vector<Point<dim>> source_extents_;
146  Portage::vector<Point<dim>> target_extents_;
147  std::shared_ptr<Meshfree::Pairs::CellPairFinder> pair_finder_; // unavoidable
148  Meshfree::WeightCenter center_ = Meshfree::Scatter;
149 
150 }; // class SearchPointsByCells
151 
152 } // namespace Portage
153 
154 #endif // SEARCH_POINTS_BY_CELLS_H
155 
std::vector< T > vector
Definition: portage.h:238
A simple, crude search algorithm that does a linear-time search over a swarm of points.
Definition: search_points_by_cells.h:34
SearchPointsByCells()=delete
Default constructor (disabled)
~SearchPointsByCells()=default
Destructor.
SearchPointsByCells & operator=(SearchPointsByCells const &)=delete
Assignment operator (disabled)
Definition: coredriver.h:42
SearchPointsByCells(SourceSwarm const &source_swarm, TargetSwarm const &target_swarm, Portage::vector< Point< dim >> const &source_extents, Portage::vector< Point< dim >> const &target_extents, Meshfree::WeightCenter center=Meshfree::Scatter)
Builds the search structure for finding neighboring points.
Definition: search_points_by_cells.h:51
std::vector< int > operator()(int pointId) const
Find the source swarm points within an appropriate distance of a target point.
Definition: search_points_by_cells.h:136