PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
anonymous_namespace{testNSearchLib.cpp} Namespace Reference

Functions

bool isInList (const std::vector< size_t > *list, size_t i)
 
void stats (const std::vector< double > &x, double &mean, double &std)
 
void lattice (double L, size_t Nx, size_t Ny, size_t Nz, double dL, int seed, std::vector< util::Point > &x, int dim=3)
 
void assignRandomTags (std::vector< util::Point > &x, int numTags, int seed, std::vector< size_t > &xTags)
 
template<class NSearch >
double neighSearchTree (const std::vector< util::Point > &x, const std::unique_ptr< NSearch > &nsearch, const double &r, std::vector< std::vector< size_t > > &neigh, std::vector< std::vector< float > > &neigh_sq_dist)
 
template<class NSearch >
double neighSearchTreeSizet (const std::vector< util::Point > &x, const std::unique_ptr< NSearch > &nsearch, const double &r, std::vector< std::vector< size_t > > &neigh, std::vector< std::vector< float > > &neigh_sq_dist)
 
template<class NSearch >
double neighSearchTreeSizetExcludeInclude (const std::vector< util::Point > &x, const std::vector< size_t > &xTags, const std::unique_ptr< NSearch > &nsearch, const double &r, std::vector< std::vector< size_t > > &neigh, std::vector< std::vector< float > > &neigh_sq_dist, int selection_criteria)
 
double neighSearchBrute (const std::vector< util::Point > &x, const double &r, std::vector< std::vector< size_t > > &neigh, std::vector< std::vector< float > > &neigh_sq_dist)
 
double neighSearchBruteExcludeInclude (const std::vector< util::Point > &x, const std::vector< size_t > &xTags, const double &r, std::vector< std::vector< size_t > > &neigh, std::vector< std::vector< float > > &neigh_sq_dist, int selection_criteria)
 
template<class NSearch >
double neighSearchTreeClosestPointSizet (const std::vector< util::Point > &x, const std::unique_ptr< NSearch > &nsearch, const int &seed, const double &L, const double &dL, std::vector< util::Point > &search_points, std::vector< size_t > &err_points, std::vector< double > &err_dist)
 
std::string compare_results (const std::vector< std::vector< size_t > > &neigh1, const std::vector< std::vector< size_t > > &neigh2, std::vector< std::string > tags, int check_nodes_num=-1, bool only_err_count=false)
 
std::string compare_closest_point_results (const std::vector< util::Point > &x, const std::vector< util::Point > &search_points, const std::vector< size_t > &err_points, const std::vector< double > &err_dist, bool only_err_count=false)
 

Function Documentation

◆ assignRandomTags()

void anonymous_namespace{testNSearchLib.cpp}::assignRandomTags ( std::vector< util::Point > &  x,
int  numTags,
int  seed,
std::vector< size_t > &  xTags 
)

Definition at line 95 of file testNSearchLib.cpp.

98 {
100 UniformIntDistribution dist(0, numTags - 1);
101
102 for (size_t i=0; i<x.size(); i++)
103 xTags[i] = dist(gen);
104}
RandGenerator get_rd_gen(int seed=-1)
Return random number generator.
Definition randomDist.h:30
std::mt19937 RandGenerator
Definition randomDist.h:16
std::uniform_int_distribution UniformIntDistribution
Definition randomDist.h:20

References util::get_rd_gen().

Referenced by test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare_closest_point_results()

std::string anonymous_namespace{testNSearchLib.cpp}::compare_closest_point_results ( const std::vector< util::Point > &  x,
const std::vector< util::Point > &  search_points,
const std::vector< size_t > &  err_points,
const std::vector< double > &  err_dist,
bool  only_err_count = false 
)

Definition at line 460 of file testNSearchLib.cpp.

465 {
466
467 size_t error_size = 0;
468 std::ostringstream composs;
469
470 for (size_t i = 0; i < err_points.size(); i++) {
471
472 if (err_points[i] != -1) {
473 composs << fmt::format(" Node = {} at location = {}, "
474 "Search point = {}, closest point id = {} at"
475 " location = {}. True dist = {}, found "
476 "dist = {}\n",
477 i, x[i].printStr(), search_points[i]
478 .printStr(), err_points[i], x[err_points[i]]
479 .printStr(), (x[i] - search_points[i])
480 .length(), err_dist[i]);
481 error_size++;
482 }
483 }
484
485 if (only_err_count)
486 return fmt::format(" error_size = {}\n", error_size);
487 else
488 return fmt::format(" error_size = {}\n", error_size) +
489 composs.str();
490 }

Referenced by test::testNanoflannClosestPoint().

Here is the caller graph for this function:

◆ compare_results()

std::string anonymous_namespace{testNSearchLib.cpp}::compare_results ( const std::vector< std::vector< size_t > > &  neigh1,
const std::vector< std::vector< size_t > > &  neigh2,
std::vector< std::string >  tags,
int  check_nodes_num = -1,
bool  only_err_count = false 
)

Definition at line 408 of file testNSearchLib.cpp.

412 {
413 size_t error_size = 0;
414 size_t error_nodes = 0;
415 size_t error_neighs = 0;
416 std::ostringstream composs;
417 for (size_t i = 0; i < neigh1.size(); i++) {
418
419 if (check_nodes_num > 0 and i > check_nodes_num)
420 continue;
421
422 size_t err_neighs = 0;
423 auto &n1 = neigh1[i];
424 auto &n2 = neigh2[i];
425
426 bool header_done = false;
427 if (n1.size() != n2.size()) {
428 composs << " Node = " << i << " \n";
429 composs << fmt::format(" size ({}) {} != {} ({}) not matching\n",
430 tags[0], n1.size(), n2.size(), tags[1]);
431 header_done = true;
432 error_size++;
433 }
434
435 for (auto j : n2) {
436 if (!isInList(&n1, j)) {
437 if (!header_done)
438 composs << " Node = " << i << " \n";
439
440 composs << fmt::format(" neigh = {} in {} search not found in {} "
441 "search neighs list\n",
442 j, tags[1], tags[0]);
443 err_neighs += 1;
444 }
445 }
446
447 if (err_neighs > 0)
448 error_neighs += err_neighs;
449 }
450
451 if (only_err_count)
452 return fmt::format(" error_size = {}, error_neighs = {}\n", error_size,
453 error_neighs);
454 else
455 return fmt::format(" error_size = {}, error_neighs = {}\n", error_size,
456 error_neighs) +
457 composs.str();
458}
bool isInList(const std::vector< size_t > *list, size_t i)

References isInList().

Referenced by test::testNanoflann(), and test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInList()

bool anonymous_namespace{testNSearchLib.cpp}::isInList ( const std::vector< size_t > *  list,
size_t  i 
)

Definition at line 31 of file testNSearchLib.cpp.

31 {
32 for (auto j : *list)
33 if (j == i)
34 return true;
35
36 return false;
37}

Referenced by compare_results().

Here is the caller graph for this function:

◆ lattice()

void anonymous_namespace{testNSearchLib.cpp}::lattice ( double  L,
size_t  Nx,
size_t  Ny,
size_t  Nz,
double  dL,
int  seed,
std::vector< util::Point > &  x,
int  dim = 3 
)

Definition at line 54 of file testNSearchLib.cpp.

55 {
56
58 UniformDistribution dist(-dL, dL);
59
60 if (dim == 2)
61 x.resize(Nx * Ny);
62 else if (dim == 3)
63 x.resize(Nx * Ny * Nz);
64 else {
65 std::cerr << "Dimension = " << dim << " not supprted.\n";
66 exit(EXIT_FAILURE);
67 }
68
69 size_t count = 0;
70 for (size_t i = 0; i < Nx; i++) {
71 for (size_t j = 0; j < Ny; j++) {
72 if (dim == 2) {
73 auto y = util::Point();
74 y.d_x = i * L + dist(gen);
75 y.d_y = j * L + dist(gen);
76 y.d_z = 0.;
77
78 x[count] = y;
79 count++;
80 } else if (dim == 3) {
81 for (size_t k = 0; k < Nz; k++) {
82 auto y = util::Point();
83 y.d_x = i * L + dist(gen);
84 y.d_y = j * L + dist(gen);
85 y.d_z = k * L + dist(gen);
86
87 x[count] = y;
88 count++;
89 } // loop over k
90 } // if-else
91 } // loop over j
92 } // loop over i
93}
std::uniform_real_distribution UniformDistribution
Definition randomDist.h:18
A structure to represent 3d vectors.
Definition point.h:30

References util::get_rd_gen().

Referenced by test::testNanoflann(), test::testNanoflannClosestPoint(), and test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighSearchBrute()

double anonymous_namespace{testNSearchLib.cpp}::neighSearchBrute ( const std::vector< util::Point > &  x,
const double &  r,
std::vector< std::vector< size_t > > &  neigh,
std::vector< std::vector< float > > &  neigh_sq_dist 
)

Definition at line 236 of file testNSearchLib.cpp.

238 {
239
240 neigh.resize(x.size());
241 neigh_sq_dist.resize(x.size());
242
243 auto t1 = steady_clock::now();
244
245 tf::Executor executor(util::parallel::getNThreads());
246 tf::Taskflow taskflow;
247
248 taskflow.for_each_index((std::size_t) 0,
249 x.size(),
250 (std::size_t) 1,
251 [&x,
252 &neigh,
253 &neigh_sq_dist,
254 r](std::size_t i) {
255 auto searchPoint = x[i];
256
257 for (size_t j = 0; j < x.size(); j++) {
258 auto dx = searchPoint - x[j];
259 auto l = dx.length();
260 if (util::isLess(l, r) and j != i) {
261 neigh[i].push_back(j);
262 neigh_sq_dist[i].push_back(l);
263 }
264 }
265 }
266 ); // for_each
267
268 executor.run(taskflow).get();
269
270 auto t2 = steady_clock::now();
271 return util::methods::timeDiff(t1, t2, "microseconds");
272}
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
Definition methods.h:304
unsigned int getNThreads()
Get number of threads to be used by taskflow.

References util::parallel::getNThreads().

Referenced by test::testNanoflann(), and test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighSearchBruteExcludeInclude()

double anonymous_namespace{testNSearchLib.cpp}::neighSearchBruteExcludeInclude ( const std::vector< util::Point > &  x,
const std::vector< size_t > &  xTags,
const double &  r,
std::vector< std::vector< size_t > > &  neigh,
std::vector< std::vector< float > > &  neigh_sq_dist,
int  selection_criteria 
)

Definition at line 275 of file testNSearchLib.cpp.

280 {
281
282 // selection_criteria = 1 --> exclude search
283 // selection_criteria = 2 --> include search
284
285 neigh.resize(x.size());
286 neigh_sq_dist.resize(x.size());
287
288 auto t1 = steady_clock::now();
289
290 tf::Executor executor(util::parallel::getNThreads());
291 tf::Taskflow taskflow;
292
293 taskflow.for_each_index((std::size_t) 0,
294 x.size(),
295 (std::size_t) 1,
296 [&x,
297 &xTags,
298 &neigh,
299 &neigh_sq_dist,
300 r,
301 selection_criteria](std::size_t i) {
302
303 auto searchPoint = x[i];
304 auto searchPointTag = xTags[i];
305
306 for (size_t j = 0; j < x.size(); j++) {
307 auto dx = searchPoint - x[j];
308 auto l = dx.length();
309 if (util::isLess(l, r) and j != i) {
310
311 if (selection_criteria == 1) {
312 if (xTags[j] != searchPointTag) {
313 neigh[i].push_back(j);
314 neigh_sq_dist[i].push_back(l);
315 }
316 }
317 else if (selection_criteria == 2) {
318 if (xTags[j] == searchPointTag) {
319 neigh[i].push_back(j);
320 neigh_sq_dist[i].push_back(l);
321 }
322 }
323 }
324 }
325 }
326 ); // for_each
327
328 executor.run(taskflow).get();
329
330 auto t2 = steady_clock::now();
331 return util::methods::timeDiff(t1, t2, "microseconds");
332}

References util::parallel::getNThreads().

Referenced by test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighSearchTree()

template<class NSearch >
double anonymous_namespace{testNSearchLib.cpp}::neighSearchTree ( const std::vector< util::Point > &  x,
const std::unique_ptr< NSearch > &  nsearch,
const double &  r,
std::vector< std::vector< size_t > > &  neigh,
std::vector< std::vector< float > > &  neigh_sq_dist 
)

Definition at line 107 of file testNSearchLib.cpp.

111 {
112 neigh.resize(x.size());
113 neigh_sq_dist.resize(x.size());
114 auto t1 = steady_clock::now();
115
116 tf::Executor executor(util::parallel::getNThreads());
117 tf::Taskflow taskflow;
118
119 taskflow.for_each_index((std::size_t) 0, x.size(), (std::size_t) 1, [&x, &neigh, &neigh_sq_dist, &nsearch, r](std::size_t i) {
120 std::vector<int> neighs;
121 std::vector<float> sqr_dist;
122
123 if (nsearch->radiusSearch(x[i], r, neighs, sqr_dist) >
124 0) {
125 for (std::size_t j = 0; j < neighs.size(); ++j)
126 if (size_t(neighs[j]) != i) {
127 neigh[i].push_back(size_t(neighs[j]));
128 neigh_sq_dist[i].push_back(sqr_dist[j]);
129 }
130 }
131 }
132 ); // for_each
133
134 executor.run(taskflow).get();
135
136 auto t2 = steady_clock::now();
137 return util::methods::timeDiff(t1, t2, "microseconds");
138}
Methods for performing efficient search of neighboring points.
Definition nflannSetup.h:17

References util::parallel::getNThreads().

Here is the call graph for this function:

◆ neighSearchTreeClosestPointSizet()

template<class NSearch >
double anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeClosestPointSizet ( const std::vector< util::Point > &  x,
const std::unique_ptr< NSearch > &  nsearch,
const int &  seed,
const double &  L,
const double &  dL,
std::vector< util::Point > &  search_points,
std::vector< size_t > &  err_points,
std::vector< double > &  err_dist 
)

Definition at line 336 of file testNSearchLib.cpp.

343 {
344
345 search_points.resize(x.size());
346 err_points.resize(x.size());
347 err_dist.resize(x.size());
348
349 // set perturbation length much smaller than the dL
350 double dx_perturb = dL/100;
351
352 // random number generator
354 UniformDistribution dist(-dx_perturb, dx_perturb);
355
356 for (size_t i=0; i<x.size(); i++) {
357 const auto &xi = x[i];
358
359 // get a query point that is close to xi
360 auto xi_perturb = xi;
361 for (size_t k=0; k<3; k++)
362 xi_perturb[k] += dist(gen);
363
364 search_points[i] = xi_perturb;
365 }
366
367 auto t1 = steady_clock::now();
368
369 tf::Executor executor(util::parallel::getNThreads());
370 tf::Taskflow taskflow;
371
372 taskflow.for_each_index((std::size_t) 0, x.size(), (std::size_t) 1, [&x,
373 &search_points,
374 &err_points, &err_dist, &nsearch](std::size_t i) {
375
376 const auto &xi = x[i];
377
378 // get a query point that is close to xi
379 const auto &xi_perturb = search_points[i];
380
381 // set true values
382 size_t true_neigh = i;
383 double true_dist = (xi - xi_perturb).length();
384
385 size_t found_neigh;
386 double found_dist = 0.;
387
388 // find closest neighbor using nsearch
389 nsearch->closestPoint(xi_perturb, found_neigh, found_dist);
390
391 if (true_neigh != found_neigh) {
392 err_points[i] = found_neigh;
393 err_dist[i] = true_dist - found_dist;
394 }
395 else {
396 err_points[i] = -1;
397 err_dist[i] = 0.;
398 }
399 }
400 ); // for_each
401
402 executor.run(taskflow).get();
403
404 auto t2 = steady_clock::now();
405 return util::methods::timeDiff(t1, t2, "microseconds");
406}

References util::get_rd_gen(), and util::parallel::getNThreads().

Referenced by test::testNanoflannClosestPoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighSearchTreeSizet()

template<class NSearch >
double anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeSizet ( const std::vector< util::Point > &  x,
const std::unique_ptr< NSearch > &  nsearch,
const double &  r,
std::vector< std::vector< size_t > > &  neigh,
std::vector< std::vector< float > > &  neigh_sq_dist 
)

Definition at line 141 of file testNSearchLib.cpp.

145 {
146 neigh.resize(x.size());
147 neigh_sq_dist.resize(x.size());
148 auto t1 = steady_clock::now();
149
150 tf::Executor executor(util::parallel::getNThreads());
151 tf::Taskflow taskflow;
152
153 taskflow.for_each_index((std::size_t) 0, x.size(), (std::size_t) 1, [&x, &neigh, &neigh_sq_dist, &nsearch, r](std::size_t i) {
154 std::vector<size_t> neighs;
155 std::vector<double> sqr_dist;
156
157 if (nsearch->radiusSearch(x[i], r, neighs, sqr_dist) >
158 0) {
159 for (std::size_t j = 0; j < neighs.size(); ++j)
160 if (size_t(neighs[j]) != i) {
161 neigh[i].push_back(size_t(neighs[j]));
162 neigh_sq_dist[i].push_back(sqr_dist[j]);
163 }
164 }
165 }
166 ); // for_each
167
168 executor.run(taskflow).get();
169
170 auto t2 = steady_clock::now();
171 return util::methods::timeDiff(t1, t2, "microseconds");
172}

References util::parallel::getNThreads().

Referenced by test::testNanoflann(), and test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighSearchTreeSizetExcludeInclude()

template<class NSearch >
double anonymous_namespace{testNSearchLib.cpp}::neighSearchTreeSizetExcludeInclude ( const std::vector< util::Point > &  x,
const std::vector< size_t > &  xTags,
const std::unique_ptr< NSearch > &  nsearch,
const double &  r,
std::vector< std::vector< size_t > > &  neigh,
std::vector< std::vector< float > > &  neigh_sq_dist,
int  selection_criteria 
)

Definition at line 175 of file testNSearchLib.cpp.

181 {
182
183 // selection_criteria = 1 --> exclude search
184 // selection_criteria = 2 --> include search
185
186 neigh.resize(x.size());
187 neigh_sq_dist.resize(x.size());
188 auto t1 = steady_clock::now();
189
190 tf::Executor executor(util::parallel::getNThreads());
191 tf::Taskflow taskflow;
192
193 taskflow.for_each_index((std::size_t) 0,
194 x.size(),
195 (std::size_t) 1,
196 [&x,
197 &xTags,
198 &neigh,
199 &neigh_sq_dist,
200 &nsearch,
201 r,
202 selection_criteria](std::size_t i) {
203
204 std::vector<size_t> neighs;
205 std::vector<double> sqr_dist;
206 size_t n = 0;
207
208 if (selection_criteria == 1)
209 n = nsearch->radiusSearchExcludeTag(x[i], r,
210 neighs,
211 sqr_dist,
212 xTags[i],
213 xTags);
214 else if (selection_criteria == 2)
215 n = nsearch->radiusSearchIncludeTag(x[i], r,
216 neighs,
217 sqr_dist,
218 xTags[i],
219 xTags);
220 if (n > 0) {
221 for (std::size_t j = 0; j < neighs.size(); ++j)
222 if (size_t(neighs[j]) != i) {
223 neigh[i].push_back(size_t(neighs[j]));
224 neigh_sq_dist[i].push_back(sqr_dist[j]);
225 }
226 }
227 }
228 ); // for_each
229
230 executor.run(taskflow).get();
231
232 auto t2 = steady_clock::now();
233 return util::methods::timeDiff(t1, t2, "microseconds");
234}

References util::parallel::getNThreads().

Referenced by test::testNanoflannExcludeInclude().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stats()

void anonymous_namespace{testNSearchLib.cpp}::stats ( const std::vector< double > &  x,
double &  mean,
double &  std 
)

Definition at line 39 of file testNSearchLib.cpp.

39 {
40 double mu = 0.;
41 for (auto &y : x)
42 mu += y;
43 mu = mu / x.size();
44
45 double s = 0.;
46 for (auto &y : x)
47 s += (y - mu) * (y - mu);
48 s = s / x.size();
49
50 std = std::sqrt(s);
51 mean = mu;
52}