search_simple.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 
7 #ifndef PORTAGE_SEARCH_SEARCH_SIMPLE_H_
8 #define PORTAGE_SEARCH_SEARCH_SIMPLE_H_
9 
10 #include <vector>
11 #include <algorithm>
12 
13 // portage includes
15 #include "wonton/support/Point.h"
16 using Wonton::Point;
17 
19 namespace search_simple {
20 
31 inline
33  const std::vector<Point<2>> &cell_coord,
34  double* xlow, double* xhigh,
35  double* ylow, double* yhigh)
36 {
37  const double big = 1.e99;
38  double xl = big; double xh = -big;
39  double yl = big; double yh = -big;
40 
41  for (const auto& p : cell_coord) {
42  const double x = p[0];
43  const double y = p[1];
44  xl = std::min(xl, x); xh = std::max(xh, x);
45  yl = std::min(yl, y); yh = std::max(yh, y);
46  }
47 
48  *xlow = xl; *xhigh = xh;
49  *ylow = yl; *yhigh = yh;
50 
51 } // getBoundingBox
52 
53 } // search_simple
54 
55 
56 namespace Portage {
57 
67 template <typename SourceMeshType, typename TargetMeshType>
68 class SearchSimple {
69  public:
70 
72  SearchSimple() = delete;
73 
74  // Constructor with Meshes
85  SearchSimple(const SourceMeshType & source_mesh,
86  const TargetMeshType & target_mesh)
87  : sourceMesh_(source_mesh), targetMesh_(target_mesh) {
88 
89  const int numCells = sourceMesh_.num_owned_cells() +
90  sourceMesh_.num_ghost_cells();
91  xlow_.reserve(numCells);
92  xhigh_.reserve(numCells);
93  ylow_.reserve(numCells);
94  yhigh_.reserve(numCells);
95 
96  // find bounding boxes for all cells
97  for (int c = 0; c < numCells; ++c) {
98  std::vector<Point<2>> cell_coord;
99  sourceMesh_.cell_get_coordinates(c, &cell_coord);
101  &xlow_[c], &xhigh_[c],
102  &ylow_[c], &yhigh_[c]);
103  }
104  } // SearchSimple::SearchSimple
105 
107  SearchSimple(const SearchSimple &) = delete;
108 
110  SearchSimple & operator = (const SearchSimple &) = delete;
111 
113  ~SearchSimple() = default;
114 
124  void operator() (const int cellId, std::vector<int> *candidates) const;
125 
126  private:
127 
128  // Aggregate data members
129  const SourceMeshType & sourceMesh_;
130  const TargetMeshType & targetMesh_;
131  std::vector<double> xlow_;
132  std::vector<double> xhigh_;
133  std::vector<double> ylow_;
134  std::vector<double> yhigh_;
135 
136 }; // class SearchSimple
137 
138 
139 
140 template<typename SourceMeshType, typename TargetMeshType>
142 operator() (const int cellId, std::vector<int> *candidates)
143 const {
144  // find bounding box for target cell
145  std::vector<Point<2>> cell_coord;
146  targetMesh_.cell_get_coordinates(cellId, &cell_coord);
147  double txlow, txhigh, tylow, tyhigh;
148  search_simple::getBoundingBox(cell_coord, &txlow, &txhigh, &tylow, &tyhigh);
149 
150  // now see which sourceMesh cells have bounding boxes overlapping
151  // with target cell
152  // do a naive linear search
153  const int numCells = sourceMesh_.num_owned_cells() +
154  sourceMesh_.num_ghost_cells();
155  for (int c = 0; c < numCells; ++c) {
156  if (std::max(txlow, xlow_[c]) < std::min(txhigh, xhigh_[c]) &&
157  std::max(tylow, ylow_[c]) < std::min(tyhigh, yhigh_[c])) {
158  candidates->push_back(c);
159  }
160  }
161 
162 } // SearchSimple::operator()
163 
164 
165 
166 
167 } // namespace Portage
168 
169 #endif // PORTAGE_SEARCH_SEARCH_SIMPLE_H_
file-local namespace
Definition: search_simple.h:19
SearchSimple(const SourceMeshType &source_mesh, const TargetMeshType &target_mesh)
Builds the search structure for finding intersection.
Definition: search_simple.h:85
std::vector< T > vector
Definition: portage.h:238
void getBoundingBox(const std::vector< Point< 2 >> &cell_coord, double *xlow, double *xhigh, double *ylow, double *yhigh)
Given a list of 2d coordinates, find the coordinates of the bounding box.
Definition: search_simple.h:32
Definition: coredriver.h:42
A simple, crude search algorithm that utilizes bounding boxes in 2d.
Definition: search_simple.h:68