search_simple_points.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 PORTAGE_SEARCH_SEARCH_SIMPLE_POINTS_H_
7 #define PORTAGE_SEARCH_SEARCH_SIMPLE_POINTS_H_
8 
9 #include <memory>
10 #include <vector>
11 #include <cmath>
12 
13 
16 #include "wonton/support/Point.h"
17 
18 using Wonton::Point;
19 
20 namespace Portage {
21 
29 template<int dim, class SourceSwarm, class TargetSwarm>
31 public:
32 
34  SearchSimplePoints() = delete;
35 
36  // Constructor with swarms and extents
48  SourceSwarm const& source_swarm,
49  TargetSwarm const& target_swarm,
50  Portage::vector<Point<dim>> const& source_extents,
51  Portage::vector<Point<dim>> const& target_extents,
52  Meshfree::WeightCenter center = Meshfree::Scatter)
53  : source_swarm_(source_swarm),
54  target_swarm_(target_swarm),
55  source_extents_(source_extents),
56  target_extents_(target_extents),
57  center_(center)
58  {} // SearchSimplePoints::SearchSimplePoints
59 
61  // SearchSimplePoints(const SearchSimplePoints &) = delete;
62 
65 
67  ~SearchSimplePoints() = default;
68 
78  std::vector<int> operator() (int point_id) const {
79 
80  std::vector<int> candidates;
81 
82  // find coordinates of target point
83  Point<dim> target_coord = target_swarm_.get_particle_coordinates(point_id);
84 
85  // now see which source points are within an appropriate distance
86  // of the target point
87  // do a naive linear search
88  int const nb_points = source_swarm_.num_particles(Wonton::ALL);
89  for (int i = 0; i < nb_points; ++i) {
90  Point<dim> source_coord = source_swarm_.get_particle_coordinates(i);
91  bool contained = true;
92  Point<dim> source_point_extent = source_extents_[i];
93  Point<dim> target_point_extent = target_extents_[point_id];
94 
95  for (int d = 0; d < dim; ++d) {
96  double maxdist = 0.;
97  if (center_ == Meshfree::Scatter) {
98  maxdist = 2. * source_point_extent[d];
99  } else if (center_ == Meshfree::Gather) {
100  maxdist = 2. * target_point_extent[d];
101  }
102  contained &= (std::abs(target_coord[d] - source_coord[d]) < maxdist);
103  if (!contained)
104  break;
105  }
106  if (contained)
107  candidates.push_back(i);
108  }
109 
110  return candidates;
111  }
112 
113 private:
114  // Aggregate data members
115  SourceSwarm const& source_swarm_;
116  TargetSwarm const& target_swarm_;
117  Portage::vector<Point<dim>> const& source_extents_;
118  Portage::vector<Point<dim>> const& target_extents_;
119  Meshfree::WeightCenter center_ = Meshfree::Scatter;
120 
121 }; // class SearchSimplePoints
122 
123 } // namespace Portage
124 
125 #endif // PORTAGE_SEARCH_SEARCH_SIMPLE_POINTS_H_
SearchSimplePoints(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_simple_points.h:47
std::vector< T > vector
Definition: portage.h:238
std::vector< int > operator()(int point_id) const
Find the source swarm points within an appropriate distance of a target point.
Definition: search_simple_points.h:78
~SearchSimplePoints()=default
Destructor.
Definition: coredriver.h:42
A simple, crude search algorithm that does a quadratic-time search over a swarm of points...
Definition: search_simple_points.h:30
SearchSimplePoints & operator=(SearchSimplePoints const &)=delete
Copy constructor - use default - std::transfor needs this.
SearchSimplePoints()=delete
Default constructor (disabled)