PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
testNSearch.cpp
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#include <PeriDEMConfig.h>
12#include "testNSearchLib.h"
13#include "util/io.h"
14#include "util/parallelUtil.h" // MPI-related functions
15#include <fmt/format.h>
16#include <iostream>
17
18
19int main(int argc, char *argv[]) {
20
21 // init parallel
22 util::parallel::initMpi(argc, argv);
23 int mpiSize = util::parallel::mpiSize(), mpiRank = util::parallel::mpiRank();
24 util::io::print(fmt::format("Initialized MPI. MPI size = {}, MPI rank = {}\n", mpiSize, mpiRank));
26
27 util::io::InputParser input(argc, argv);
28
29 if (input.cmdOptionExists("-h") or !input.cmdOptionExists("-i")) {
30 // print help
31 std::cout << argv[0] << " (Version " << MAJOR_VERSION << "."
32 << MINOR_VERSION << "." << UPDATE_VERSION
33 << ") -i <num-points> -o <select-test; 0 - test with different lattice, 1 - profile nanoflann, 2 - test closest point search>" << std::endl;
34 //exit(EXIT_FAILURE);
35 }
36
37 // read input file
38 int N;
39 if (input.cmdOptionExists("-i")) N = std::stoi(input.getCmdOption("-i"));
40 else {
41 N = 20;
42 std::cout << "Running test with default num-points = " << N << "\n";
43 }
44
45 int testSelect;
46 if (input.cmdOptionExists("-o")) testSelect = std::stoi(input.getCmdOption("-o"));
47 else {
48 testSelect = 0;
49 std::cout << "Running test with default test selection = " << testSelect << "\n";
50 }
51
52 std::vector<int> leafMaxSizes = {2, 5, 8, 10, 12, 15, 20};
53 std::vector<double> L_test = {1., 0.01};
54 std::vector<double> dL_test = {0.2, 0.5};
55 std::vector<int> seeds = {1093};//, 13828, 78474};
56 std::vector<int> N_test = {N};
57 std::vector<int> dims{2, 3};
58 std::vector<int> numTags{4, 8, 12};
59 int test_count = 0;
60
61
62 if (testSelect == 0) {
63 // test 1
64 std::cout << "\n\nTesting Exclude and Include tag for different lattice sizes\n\n";
65
66 for (auto L: L_test) {
67 for (auto dL: dL_test) {
68 for (auto seed: seeds) {
69 for (auto n: N_test) {
70 for (auto dim: dims) {
71
72 std::string msg;
74 data.d_dim = dim;
75 data.d_numTags = numTags[0];
76 data.d_leafMaxSize = leafMaxSizes[0];
77
78 std::cout << "\n**** Test number = " << test_count++ << " ****\n";
79 std::cout << fmt::format("Test parameters: L = {}, lattice "
80 "perturbation = {}, seed = {}, "
81 "N = {}, leafMaxSize = {}, num_tags = {}, "
82 "dim = {}\n\n",
83 L, dL * L, seed, n,
84 data.d_leafMaxSize,
85 data.d_numTags, data.d_dim);
86
87
88 if (dim == 2)
89 msg = test::testNanoflannExcludeInclude<2>(n, L, dL * L, seed,
90 data);
91 else if (dim == 3)
92 msg = test::testNanoflannExcludeInclude<3>(n, L, dL * L, seed,
93 data);
94
95 std::cout << msg;
96
97 } // loop dim
98 } // loop N
99 } // loop seed
100 } // loop dL
101 } // loop L
102 }
103 else if (testSelect == 1) {
104 // test 2
105 std::cout
106 << "\n\nTesting Exclude and Include tag type neighbor search for different leaf sizes and number of tags\n\n";
107
108 test_count = 0;
109 std::vector<std::vector<std::vector<test::testNSearchData> > > data_set(
110 leafMaxSizes.size());
111
112 for (size_t i = 0; i < leafMaxSizes.size(); i++) {
113
114 data_set[i].resize(numTags.size());
115
116 for (size_t j = 0; j < numTags.size(); j++) {
117
118 data_set[i][j].resize(dims.size());
119
120 for (size_t k = 0; k < dims.size(); k++) {
121
122 auto L = L_test[0];
123 auto dL = dL_test[0];
124 auto seed = seeds[0];
125 auto n = N_test[0];
126
127 std::string msg;
129 data.d_dim = dims[k];
130 data.d_numTags = numTags[j];
131 data.d_leafMaxSize = leafMaxSizes[i];
132
133 std::cout << "\n**** Test number = " << test_count++ << " ****\n";
134 std::cout << fmt::format("Test parameters: L = {}, lattice "
135 "perturbation = {}, seed = {}, "
136 "N = {}, leafMaxSize = {}, num_tags = {}, "
137 "dim = {}\n\n",
138 L, dL * L, seed, n,
139 data.d_leafMaxSize,
140 data.d_numTags, data.d_dim);
141
142
143 if (data.d_dim == 2)
144 msg = test::testNanoflannExcludeInclude<2>(n, L, dL * L, seed,
145 data);
146 else if (data.d_dim == 3)
147 msg = test::testNanoflannExcludeInclude<3>(n, L, dL * L, seed,
148 data);
149
150 std::cout << msg;
151
152 data_set[i][j][k] = data;
153 } // loop dim
154 }// loop numTag
155 } // loop leaf
156
157 std::cout << "\n\nSummarize results of test 2\n\n";
158 for (size_t k = 0; k < dims.size(); k++) {
159 std::cout << "Dim = " << dims[k] << "\n";
160 for (size_t j = 0; j < numTags.size(); j++) {
161 std::cout << fmt::format(" numTag = {:2d}\n", numTags[j]);
162 for (size_t i = 0; i < leafMaxSizes.size(); i++) {
163 const auto &data = data_set[i][j][k];
164 std::cout << fmt::format(
165 " leafMaxSize = {:2d}, numPoints = {:8d}, bld_time = {:8d}\n"
166 " (brute-search) def_time = {:8d}, exc_time = {:8d}, inc_time = {:8d}\n"
167 " (nflan-search) def_time = {:8d}, exc_time = {:8d}, inc_time = {:8d}\n",
168 data.d_leafMaxSize,
169 data.d_numPoints,
170 int(data.d_treeBuildTime),
171 int(data.d_defaultBruteSearchTime),
172 int(data.d_excludeBruteSearchTime),
173 int(data.d_includeBruteSearchTime),
174 int(data.d_defaultNFlannSearchTime),
175 int(data.d_excludeNFlannSearchTime),
176 int(data.d_includeNFlannSearchTime));
177 }
178 }
179 }
180 }
181 else if (testSelect == 2) {
182 // test 2
183 std::cout << "\n\nTesting closest point search for different lattice sizes\n\n";
184
185 // L_test = {1.};
186 // dL_test = {0.2};
187 for (auto L: L_test) {
188 for (auto dL: dL_test) {
189 for (auto seed: seeds) {
190 for (auto n: N_test) {
191
192 std::string msg;
194 data.d_dim = 3;
195 data.d_numTags = numTags[0];
196 data.d_leafMaxSize = leafMaxSizes[0];
197
198 std::cout << "\n**** Test number = " << test_count++ << " ****\n";
199 std::cout << fmt::format("Test parameters: L = {}, lattice "
200 "perturbation = {}, seed = {}, "
201 "N = {}, leafMaxSize = {}, num_tags = {}"
202 "\n\n",
203 L, dL * L, seed, n,
204 data.d_leafMaxSize,
205 data.d_numTags);
206
207
208 msg = test::testNanoflannClosestPoint(n, L, dL * L, seed);
209
210 std::cout << msg;
211
212 } // loop N
213 } // loop seed
214 } // loop dL
215 } // loop L
216 }
217
218 return EXIT_SUCCESS;
219}
size_t const MINOR_VERSION
size_t const UPDATE_VERSION
size_t const MAJOR_VERSION
Input command line argument parser.
Definition io.h:355
bool cmdOptionExists(const std::string &option) const
Check if argument exists.
Definition io.h:387
const std::string & getCmdOption(const std::string &option) const
Get value of argument specified by key.
Definition io.h:372
std::string testNanoflannClosestPoint(size_t N, double L, double dL, int seed)
Perform test on nsearch.
void print(const T &msg, int nt=print_default_tab, int printMpiRank=print_default_mpi_rank)
Prints formatted information.
Definition io.h:108
const MpiStatus * getMpiStatus()
Returns pointer to MpiStatus struct.
void initMpi(int argc=0, char *argv[]=nullptr)
Initializes MPI and also creates MpiStatus struct.
int mpiSize()
Get size (number) of processors.
int mpiRank()
get rank (id) of this processor
int main()