| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <gtest/gtest.h> |
| 36 |
|
| 37 |
#include <stk_mesh/base/MetaData.hpp> |
| 38 |
#include <stk_mesh/base/BulkData.hpp> |
| 39 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 40 |
#include <stk_io/FillMesh.hpp> |
| 41 |
#include <stk_search/LocalCoarseSearch.hpp> |
| 42 |
#include <stk_search/CoarseSearch.hpp> |
| 43 |
#include <stk_unit_test_utils/Search_UnitTestUtils.hpp> |
| 44 |
#include <stk_unit_test_utils/MeshUtilsForBoundingVolumes.hpp> |
| 45 |
#include <stk_unit_test_utils/timer.hpp> |
| 46 |
#include "stk_search/SearchMethod.hpp" |
| 47 |
#include <Kokkos_Core.hpp> |
| 48 |
#include "stk_util/ngp/NgpSpaces.hpp" |
| 49 |
|
| 50 |
namespace { |
| 51 |
|
| 52 |
template<typename BoxVectorType> |
| 53 |
void run_volume_to_one_test(const std::string& meshFileName, |
| 54 |
stk::search::SearchMethod searchMethod, |
| 55 |
bool enforceSearchResultSymmetry = true) |
| 56 |
{ |
| 57 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 58 |
const unsigned NUM_RUNS = 5; |
| 59 |
const unsigned NUM_ITERS = 1000; |
| 60 |
const int pRank = stk::parallel_machine_rank(comm); |
| 61 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 62 |
batchTimer.initialize_batch_timer(); |
| 63 |
|
| 64 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 65 |
|
| 66 |
stk::mesh::MeshBuilder builder(comm); |
| 67 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 68 |
|
| 69 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 70 |
|
| 71 |
BoxVectorType elemBoxes; |
| 72 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK, elemBoxes); |
| 73 |
|
| 74 |
BoxVectorType supersetBoxVec { elemBoxes[0] }; |
| 75 |
auto & [supersetBox, supersetIdent] = supersetBoxVec[0]; |
| 76 |
supersetIdent.set_id(pRank); |
| 77 |
supersetIdent.set_proc(pRank); |
| 78 |
|
| 79 |
for (const auto & [box, ident] : elemBoxes) { |
| 80 |
stk::search::add_to_box(supersetBox, box); |
| 81 |
} |
| 82 |
|
| 83 |
batchTimer.start_batch_timer(); |
| 84 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 85 |
SearchResults searchResults; |
| 86 |
stk::search::coarse_search(elemBoxes, supersetBoxVec, searchMethod, comm, searchResults, enforceSearchResultSymmetry); |
| 87 |
} |
| 88 |
batchTimer.stop_batch_timer(); |
| 89 |
} |
| 90 |
|
| 91 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 92 |
} |
| 93 |
|
| 94 |
template<typename BoxIdentProcType> |
| 95 |
void run_volume_to_one_test_with_views(const std::string& meshFileName, |
| 96 |
stk::search::SearchMethod searchMethod, |
| 97 |
bool enforceSearchResultSymmetry = true) |
| 98 |
{ |
| 99 |
|
| 100 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 101 |
|
| 102 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 103 |
const unsigned NUM_RUNS = 5; |
| 104 |
const unsigned NUM_ITERS = 1000; |
| 105 |
const int pRank = stk::parallel_machine_rank(comm); |
| 106 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 107 |
batchTimer.initialize_batch_timer(); |
| 108 |
|
| 109 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 110 |
|
| 111 |
stk::mesh::MeshBuilder builder(comm); |
| 112 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 113 |
|
| 114 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 115 |
|
| 116 |
Kokkos::View<BoxIdentProcType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentProcType>(*bulkPtr, stk::topology::ELEM_RANK); |
| 117 |
auto elemBoxesHost = Kokkos::create_mirror_view(elemBoxes); |
| 118 |
Kokkos::deep_copy(elemBoxesHost, elemBoxes); |
| 119 |
|
| 120 |
Kokkos::View<BoxIdentProcType *, ExecSpace> supersetBoxes("Range Boxes", 1); |
| 121 |
auto supersetBoxesHost = Kokkos::create_mirror_view(supersetBoxes); |
| 122 |
supersetBoxesHost(0) = {elemBoxesHost[0].box, IdentProc(pRank, pRank)}; |
| 123 |
|
| 124 |
for (unsigned i = 0; i != elemBoxesHost.extent(0); ++i) { |
| 125 |
stk::search::add_to_box(supersetBoxesHost(0).box, elemBoxesHost(i).box); |
| 126 |
} |
| 127 |
|
| 128 |
Kokkos::deep_copy(supersetBoxes, supersetBoxesHost); |
| 129 |
|
| 130 |
batchTimer.start_batch_timer(); |
| 131 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 132 |
Kokkos::View<IdentProcIntersection*, ExecSpace> searchResults; |
| 133 |
stk::search::coarse_search(elemBoxes, supersetBoxes, searchMethod, comm, searchResults, |
| 134 |
ExecSpace{}, enforceSearchResultSymmetry); |
| 135 |
} |
| 136 |
batchTimer.stop_batch_timer(); |
| 137 |
} |
| 138 |
|
| 139 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 140 |
} |
| 141 |
|
| 142 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_KDTREE) |
| 143 |
{ |
| 144 |
run_volume_to_one_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 145 |
} |
| 146 |
|
| 147 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_MORTON_LBVH) |
| 148 |
{ |
| 149 |
run_volume_to_one_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 150 |
} |
| 151 |
|
| 152 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_ARBORX) |
| 153 |
{ |
| 154 |
run_volume_to_one_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 155 |
} |
| 156 |
|
| 157 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_with_views_MORTON_LBVH) |
| 158 |
{ |
| 159 |
run_volume_to_one_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 160 |
} |
| 161 |
|
| 162 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_with_views_ARBORX) |
| 163 |
{ |
| 164 |
run_volume_to_one_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 165 |
} |
| 166 |
|
| 167 |
template<typename BoxVectorType> |
| 168 |
void run_volume_to_one_test_local(const std::string& meshFileName, |
| 169 |
stk::search::SearchMethod searchMethod) |
| 170 |
{ |
| 171 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 172 |
const unsigned NUM_RUNS = 5; |
| 173 |
const unsigned NUM_ITERS = 1000; |
| 174 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 175 |
batchTimer.initialize_batch_timer(); |
| 176 |
|
| 177 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 178 |
|
| 179 |
stk::mesh::MeshBuilder builder(comm); |
| 180 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 181 |
|
| 182 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 183 |
|
| 184 |
BoxVectorType elemBoxes; |
| 185 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK, elemBoxes); |
| 186 |
|
| 187 |
BoxVectorType supersetBoxVec { elemBoxes[0] }; |
| 188 |
auto & [supersetBox, supersetIdent] = supersetBoxVec[0]; |
| 189 |
|
| 190 |
for (const auto & [box, ident] : elemBoxes) { |
| 191 |
stk::search::add_to_box(supersetBox, box); |
| 192 |
} |
| 193 |
|
| 194 |
batchTimer.start_batch_timer(); |
| 195 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 196 |
LocalSearchResults searchResults; |
| 197 |
stk::search::local_coarse_search(elemBoxes, supersetBoxVec, searchMethod, searchResults); |
| 198 |
} |
| 199 |
batchTimer.stop_batch_timer(); |
| 200 |
} |
| 201 |
|
| 202 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 203 |
} |
| 204 |
|
| 205 |
template<typename BoxIdentType> |
| 206 |
void run_volume_to_one_test_local_with_views(const std::string& meshFileName, |
| 207 |
stk::search::SearchMethod searchMethod) |
| 208 |
{ |
| 209 |
|
| 210 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 211 |
|
| 212 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 213 |
const unsigned NUM_RUNS = 5; |
| 214 |
const unsigned NUM_ITERS = 1000; |
| 215 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 216 |
batchTimer.initialize_batch_timer(); |
| 217 |
|
| 218 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 219 |
|
| 220 |
stk::mesh::MeshBuilder builder(comm); |
| 221 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 222 |
|
| 223 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 224 |
|
| 225 |
Kokkos::View<BoxIdentType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentType>(*bulkPtr, stk::topology::ELEM_RANK); |
| 226 |
auto elemBoxesHost = Kokkos::create_mirror_view(elemBoxes); |
| 227 |
Kokkos::deep_copy(elemBoxesHost, elemBoxes); |
| 228 |
|
| 229 |
Kokkos::View<BoxIdentType *, ExecSpace> supersetBoxes("Range Boxes", 1); |
| 230 |
auto supersetBoxesHost = Kokkos::create_mirror_view(supersetBoxes); |
| 231 |
supersetBoxesHost(0) = {elemBoxesHost[0].box, stk::parallel_machine_rank(comm)}; |
| 232 |
|
| 233 |
for (unsigned i = 0; i != elemBoxes.extent(0); ++i) { |
| 234 |
stk::search::add_to_box(supersetBoxesHost(0).box, elemBoxesHost(i).box); |
| 235 |
} |
| 236 |
|
| 237 |
Kokkos::deep_copy(supersetBoxes, supersetBoxesHost); |
| 238 |
|
| 239 |
batchTimer.start_batch_timer(); |
| 240 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 241 |
Kokkos::View<IdentIntersection*, ExecSpace> searchResults; |
| 242 |
stk::search::local_coarse_search(elemBoxes, supersetBoxes, searchMethod, searchResults, ExecSpace{}); |
| 243 |
} |
| 244 |
batchTimer.stop_batch_timer(); |
| 245 |
} |
| 246 |
|
| 247 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 248 |
} |
| 249 |
|
| 250 |
template<typename BoxIdentType> |
| 251 |
void run_one_to_volume_test_local_with_views(const std::string& meshFileName, |
| 252 |
stk::search::SearchMethod searchMethod) |
| 253 |
{ |
| 254 |
|
| 255 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 256 |
|
| 257 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 258 |
const unsigned NUM_RUNS = 5; |
| 259 |
const unsigned NUM_ITERS = 1000; |
| 260 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 261 |
batchTimer.initialize_batch_timer(); |
| 262 |
|
| 263 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 264 |
|
| 265 |
stk::mesh::MeshBuilder builder(comm); |
| 266 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 267 |
|
| 268 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 269 |
|
| 270 |
Kokkos::View<BoxIdentType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentType>(*bulkPtr, stk::topology::ELEM_RANK); |
| 271 |
auto elemBoxesHost = Kokkos::create_mirror_view(elemBoxes); |
| 272 |
Kokkos::deep_copy(elemBoxesHost, elemBoxes); |
| 273 |
|
| 274 |
Kokkos::View<BoxIdentType *, ExecSpace> supersetBoxes("Range Boxes", 1); |
| 275 |
auto supersetBoxesHost = Kokkos::create_mirror_view(supersetBoxes); |
| 276 |
supersetBoxesHost(0) = {elemBoxesHost[0].box, stk::parallel_machine_rank(comm)}; |
| 277 |
|
| 278 |
for (unsigned i = 0; i != elemBoxesHost.extent(0); ++i) { |
| 279 |
stk::search::add_to_box(supersetBoxesHost(0).box, elemBoxesHost(i).box); |
| 280 |
} |
| 281 |
|
| 282 |
Kokkos::deep_copy(supersetBoxes, supersetBoxesHost); |
| 283 |
|
| 284 |
batchTimer.start_batch_timer(); |
| 285 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 286 |
Kokkos::View<IdentIntersection*, ExecSpace> searchResults; |
| 287 |
stk::search::local_coarse_search(supersetBoxes, elemBoxes, searchMethod, searchResults, ExecSpace{}); |
| 288 |
} |
| 289 |
batchTimer.stop_batch_timer(); |
| 290 |
} |
| 291 |
|
| 292 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 293 |
} |
| 294 |
|
| 295 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_local_KDTREE) |
| 296 |
{ |
| 297 |
run_volume_to_one_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 298 |
} |
| 299 |
|
| 300 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_local_MORTON_LBVH) |
| 301 |
{ |
| 302 |
run_volume_to_one_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 303 |
} |
| 304 |
|
| 305 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_local_ARBORX) |
| 306 |
{ |
| 307 |
run_volume_to_one_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 308 |
} |
| 309 |
|
| 310 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_local_with_views_MORTON_LBVH) |
| 311 |
{ |
| 312 |
run_volume_to_one_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 313 |
} |
| 314 |
|
| 315 |
TEST(StkSearch_VolumeToOne, generatedMesh_floatBox_local_with_views_ARBORX) |
| 316 |
{ |
| 317 |
run_volume_to_one_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 318 |
} |
| 319 |
|
| 320 |
TEST(StkSearch_OneToVolume, generatedMesh_floatBox_local_with_views_ARBORX) |
| 321 |
{ |
| 322 |
run_one_to_volume_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 323 |
} |
| 324 |
|
| 325 |
TEST(StkSearch_OneToVolume, generatedMesh_floatBox_local_with_views_MORTON_LBVH) |
| 326 |
{ |
| 327 |
run_one_to_volume_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 328 |
} |
| 329 |
|
| 330 |
} // namespace |
| 331 |
|