| 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 <ArborX.hpp> |
| 47 |
|
| 48 |
namespace { |
| 49 |
|
| 50 |
template<typename BoxVectorType> |
| 51 |
void run_volume_to_surface_test(const std::string& meshFileName, |
| 52 |
stk::search::SearchMethod searchMethod, |
| 53 |
bool enforceSearchResultSymmetry = true) |
| 54 |
{ |
| 55 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 56 |
const unsigned NUM_RUNS = 5; |
| 57 |
const unsigned NUM_ITERS = 100; |
| 58 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 59 |
batchTimer.initialize_batch_timer(); |
| 60 |
|
| 61 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 62 |
|
| 63 |
stk::mesh::MeshBuilder builder(comm); |
| 64 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 65 |
|
| 66 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 67 |
|
| 68 |
BoxVectorType elemBoxes; |
| 69 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK, elemBoxes); |
| 70 |
|
| 71 |
BoxVectorType sideBoxes; |
| 72 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::FACE_RANK, sideBoxes); |
| 73 |
|
| 74 |
batchTimer.start_batch_timer(); |
| 75 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 76 |
SearchResults searchResults; |
| 77 |
stk::search::coarse_search(elemBoxes, sideBoxes, searchMethod, comm, searchResults, enforceSearchResultSymmetry); |
| 78 |
} |
| 79 |
batchTimer.stop_batch_timer(); |
| 80 |
} |
| 81 |
|
| 82 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 83 |
} |
| 84 |
|
| 85 |
template<typename BoxIdentProcType> |
| 86 |
void run_volume_to_surface_test_with_views(const std::string& meshFileName, |
| 87 |
stk::search::SearchMethod searchMethod, |
| 88 |
bool enforceSearchResultSymmetry = true) |
| 89 |
{ |
| 90 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 91 |
|
| 92 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 93 |
const unsigned NUM_RUNS = 5; |
| 94 |
const unsigned NUM_ITERS = 100; |
| 95 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 96 |
batchTimer.initialize_batch_timer(); |
| 97 |
|
| 98 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 99 |
|
| 100 |
stk::mesh::MeshBuilder builder(comm); |
| 101 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 102 |
|
| 103 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 104 |
|
| 105 |
Kokkos::View<BoxIdentProcType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentProcType>(*bulkPtr, |
| 106 |
stk::topology::ELEM_RANK); |
| 107 |
|
| 108 |
Kokkos::View<BoxIdentProcType *, ExecSpace> sideBoxes = createBoundingBoxesForEntities<BoxIdentProcType>(*bulkPtr, |
| 109 |
stk::topology::FACE_RANK); |
| 110 |
|
| 111 |
batchTimer.start_batch_timer(); |
| 112 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 113 |
Kokkos::View<IdentProcIntersection*, ExecSpace> searchResults; |
| 114 |
stk::search::coarse_search(elemBoxes, sideBoxes, searchMethod, comm, searchResults, |
| 115 |
ExecSpace{}, enforceSearchResultSymmetry); |
| 116 |
} |
| 117 |
batchTimer.stop_batch_timer(); |
| 118 |
} |
| 119 |
|
| 120 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 121 |
} |
| 122 |
|
| 123 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_KDTREE) |
| 124 |
{ |
| 125 |
run_volume_to_surface_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 126 |
} |
| 127 |
|
| 128 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_MORTON_LBVH) |
| 129 |
{ |
| 130 |
run_volume_to_surface_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 131 |
} |
| 132 |
|
| 133 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_ARBORX) |
| 134 |
{ |
| 135 |
run_volume_to_surface_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 136 |
} |
| 137 |
|
| 138 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_with_views_MORTON_LBVH) |
| 139 |
{ |
| 140 |
run_volume_to_surface_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 141 |
} |
| 142 |
|
| 143 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_with_views_ARBORX) |
| 144 |
{ |
| 145 |
run_volume_to_surface_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_KDTREE) |
| 150 |
{ |
| 151 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 152 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 153 |
|
| 154 |
run_volume_to_surface_test<FloatBoxIdentProcVector>(meshFileName, stk::search::KDTREE); |
| 155 |
} |
| 156 |
|
| 157 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_MORTON_LBVH) |
| 158 |
{ |
| 159 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 160 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 161 |
|
| 162 |
run_volume_to_surface_test<FloatBoxIdentProcVector>(meshFileName, stk::search::MORTON_LBVH); |
| 163 |
} |
| 164 |
|
| 165 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_ARBORX) |
| 166 |
{ |
| 167 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 168 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 169 |
|
| 170 |
run_volume_to_surface_test<FloatBoxIdentProcVector>(meshFileName, stk::search::ARBORX); |
| 171 |
} |
| 172 |
|
| 173 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_with_views_MORTON_LBVH) |
| 174 |
{ |
| 175 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 176 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 177 |
|
| 178 |
run_volume_to_surface_test_with_views<FloatBoxIdentProc>(meshFileName, stk::search::MORTON_LBVH); |
| 179 |
} |
| 180 |
|
| 181 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_with_views_ARBORX) |
| 182 |
{ |
| 183 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 184 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 185 |
|
| 186 |
run_volume_to_surface_test_with_views<FloatBoxIdentProc>(meshFileName, stk::search::ARBORX); |
| 187 |
} |
| 188 |
|
| 189 |
template<typename BoxVectorType> |
| 190 |
void run_volume_to_surface_test_local(const std::string& meshFileName, |
| 191 |
stk::search::SearchMethod searchMethod) |
| 192 |
{ |
| 193 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 194 |
const unsigned NUM_RUNS = 5; |
| 195 |
const unsigned NUM_ITERS = 100; |
| 196 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 197 |
batchTimer.initialize_batch_timer(); |
| 198 |
|
| 199 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 200 |
|
| 201 |
stk::mesh::MeshBuilder builder(comm); |
| 202 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 203 |
|
| 204 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 205 |
|
| 206 |
BoxVectorType elemBoxes; |
| 207 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK, elemBoxes); |
| 208 |
|
| 209 |
BoxVectorType sideBoxes; |
| 210 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::FACE_RANK, sideBoxes); |
| 211 |
|
| 212 |
batchTimer.start_batch_timer(); |
| 213 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 214 |
LocalSearchResults searchResults; |
| 215 |
stk::search::local_coarse_search(elemBoxes, sideBoxes, searchMethod, searchResults); |
| 216 |
} |
| 217 |
batchTimer.stop_batch_timer(); |
| 218 |
} |
| 219 |
|
| 220 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 221 |
} |
| 222 |
|
| 223 |
template<typename BoxIdentType> |
| 224 |
void run_volume_to_surface_test_local_with_views(const std::string& meshFileName, |
| 225 |
stk::search::SearchMethod searchMethod) |
| 226 |
{ |
| 227 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 228 |
|
| 229 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 230 |
const unsigned NUM_RUNS = 5; |
| 231 |
const unsigned NUM_ITERS = 100; |
| 232 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 233 |
batchTimer.initialize_batch_timer(); |
| 234 |
|
| 235 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 236 |
|
| 237 |
stk::mesh::MeshBuilder builder(comm); |
| 238 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 239 |
|
| 240 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 241 |
|
| 242 |
Kokkos::View<BoxIdentType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentType>(*bulkPtr, |
| 243 |
stk::topology::ELEM_RANK); |
| 244 |
|
| 245 |
Kokkos::View<BoxIdentType *, ExecSpace> sideBoxes = createBoundingBoxesForEntities<BoxIdentType>(*bulkPtr, |
| 246 |
stk::topology::FACE_RANK); |
| 247 |
|
| 248 |
batchTimer.start_batch_timer(); |
| 249 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 250 |
Kokkos::View<IdentIntersection*, ExecSpace> searchResults; |
| 251 |
stk::search::local_coarse_search(elemBoxes, sideBoxes, searchMethod, searchResults, ExecSpace{}); |
| 252 |
} |
| 253 |
batchTimer.stop_batch_timer(); |
| 254 |
} |
| 255 |
|
| 256 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 257 |
} |
| 258 |
|
| 259 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_local_KDTREE) |
| 260 |
{ |
| 261 |
run_volume_to_surface_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 262 |
} |
| 263 |
|
| 264 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_local_MORTON_LBVH) |
| 265 |
{ |
| 266 |
run_volume_to_surface_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 267 |
} |
| 268 |
|
| 269 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_local_ARBORX) |
| 270 |
{ |
| 271 |
run_volume_to_surface_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 272 |
} |
| 273 |
|
| 274 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_local_with_views_MORTON_LBVH) |
| 275 |
{ |
| 276 |
run_volume_to_surface_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 277 |
} |
| 278 |
|
| 279 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_local_with_views_ARBORX) |
| 280 |
{ |
| 281 |
run_volume_to_surface_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_local_KDTREE) |
| 286 |
{ |
| 287 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 288 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 289 |
|
| 290 |
run_volume_to_surface_test_local<FloatBoxIdentVector>(meshFileName, stk::search::KDTREE); |
| 291 |
} |
| 292 |
|
| 293 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_local_MORTON_LBVH) |
| 294 |
{ |
| 295 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 296 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 297 |
|
| 298 |
run_volume_to_surface_test_local<FloatBoxIdentVector>(meshFileName, stk::search::MORTON_LBVH); |
| 299 |
} |
| 300 |
|
| 301 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_local_ARBORX) |
| 302 |
{ |
| 303 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 304 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 305 |
|
| 306 |
run_volume_to_surface_test_local<FloatBoxIdentVector>(meshFileName, stk::search::ARBORX); |
| 307 |
} |
| 308 |
|
| 309 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_local_with_views_MORTON_LBVH) |
| 310 |
{ |
| 311 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 312 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 313 |
|
| 314 |
run_volume_to_surface_test_local_with_views<FloatBoxIdent>(meshFileName, stk::search::MORTON_LBVH); |
| 315 |
} |
| 316 |
|
| 317 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_local_with_views_ARBORX) |
| 318 |
{ |
| 319 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 320 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 321 |
|
| 322 |
run_volume_to_surface_test_local_with_views<FloatBoxIdent>(meshFileName, stk::search::ARBORX); |
| 323 |
} |
| 324 |
|
| 325 |
using ExecSpace = stk::ngp::ExecSpace; |
| 326 |
using MemSpace = stk::ngp::ExecSpace::memory_space; |
| 327 |
|
| 328 |
inline Kokkos::View<ArborX::Box *, MemSpace> |
| 329 |
createArborXBoundingBoxesForEntities(const stk::mesh::BulkData &bulk, |
| 330 |
stk::mesh::EntityRank rank) |
| 331 |
{ |
| 332 |
stk::mesh::EntityVector entities; |
| 333 |
const bool sortById = true; |
| 334 |
stk::mesh::get_entities(bulk, rank, bulk.mesh_meta_data().locally_owned_part(), entities, sortById); |
| 335 |
|
| 336 |
size_t numberBoundingBoxes = entities.size(); |
| 337 |
Kokkos::View<ArborX::Box *, MemSpace> boundingBoxes("ArborX BBs", numberBoundingBoxes); |
| 338 |
auto boundingBoxesHost = Kokkos::create_mirror_view(boundingBoxes); |
| 339 |
|
| 340 |
stk::mesh::FieldBase const * coords = bulk.mesh_meta_data().coordinate_field(); |
| 341 |
|
| 342 |
std::vector<double> boxCoordinates(6); |
| 343 |
|
| 344 |
for (size_t i = 0; i < entities.size(); ++i) { |
| 345 |
unsigned num_nodes = bulk.num_nodes(entities[i]); |
| 346 |
std::vector<double> coordinates(3*num_nodes,0); |
| 347 |
const stk::mesh::Entity* nodes = bulk.begin_nodes(entities[i]); |
| 348 |
for (unsigned j = 0; j < num_nodes; ++j) { |
| 349 |
double* data = static_cast<double*>(stk::mesh::field_data(*coords, nodes[j])); |
| 350 |
coordinates[3*j] = data[0]; |
| 351 |
coordinates[3*j+1] = data[1]; |
| 352 |
coordinates[3*j+2] = data[2]; |
| 353 |
} |
| 354 |
findBoundingBoxCoordinates(coordinates, boxCoordinates); |
| 355 |
ArborX::Point min_point(boxCoordinates[0], boxCoordinates[1], boxCoordinates[2]); |
| 356 |
ArborX::Point max_point(boxCoordinates[3], boxCoordinates[4], boxCoordinates[5]); |
| 357 |
boundingBoxesHost(i) = {min_point, max_point}; |
| 358 |
} |
| 359 |
|
| 360 |
Kokkos::deep_copy(boundingBoxes, boundingBoxesHost); |
| 361 |
|
| 362 |
return boundingBoxes; |
| 363 |
} |
| 364 |
|
| 365 |
void arborx_coarse_search(Kokkos::View<ArborX::Box *, MemSpace> elemBoxes, |
| 366 |
Kokkos::View<ArborX::Box *, MemSpace> sideBoxes) |
| 367 |
{ |
| 368 |
ExecSpace execSpace; |
| 369 |
|
| 370 |
ArborX::BVH<MemSpace> bvh{execSpace, elemBoxes}; |
| 371 |
|
| 372 |
const int numQueries = sideBoxes.extent(0); |
| 373 |
Kokkos::View<ArborX::Intersects<ArborX::Box> *, MemSpace> queries(Kokkos::ViewAllocateWithoutInitializing("queries"), numQueries); |
| 374 |
|
| 375 |
Kokkos::parallel_for("setup_queries", Kokkos::RangePolicy<ExecSpace>(0, numQueries), |
| 376 |
KOKKOS_LAMBDA(int i) { queries(i) = ArborX::intersects(sideBoxes(i)); }); |
| 377 |
Kokkos::fence(); |
| 378 |
|
| 379 |
Kokkos::View<int *, MemSpace> indices("Example::indices", 0); |
| 380 |
Kokkos::View<int *, MemSpace> offsets("Example::offsets", 0); |
| 381 |
|
| 382 |
bvh.query(execSpace, queries, indices, offsets); |
| 383 |
} |
| 384 |
|
| 385 |
void run_search_test_arborx(const std::string& meshFileName) |
| 386 |
{ |
| 387 |
const unsigned NUM_RUNS = 5; |
| 388 |
const unsigned NUM_ITERS = 100; |
| 389 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 390 |
batchTimer.initialize_batch_timer(); |
| 391 |
|
| 392 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 393 |
|
| 394 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 395 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 396 |
|
| 397 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 398 |
|
| 399 |
Kokkos::View<ArborX::Box *, MemSpace> elemBoxes = createArborXBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK); |
| 400 |
Kokkos::View<ArborX::Box *, MemSpace> sideBoxes = createArborXBoundingBoxesForEntities(*bulkPtr, stk::topology::FACE_RANK); |
| 401 |
|
| 402 |
batchTimer.start_batch_timer(); |
| 403 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 404 |
arborx_coarse_search(elemBoxes, sideBoxes); |
| 405 |
} |
| 406 |
batchTimer.stop_batch_timer(); |
| 407 |
} |
| 408 |
|
| 409 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 410 |
} |
| 411 |
|
| 412 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_rawARBORX) { |
| 413 |
run_search_test_arborx("generated:40x80x20|sideset:xXyYzZ"); |
| 414 |
} |
| 415 |
|
| 416 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_rawARBORX) { |
| 417 |
|
| 418 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 419 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 420 |
|
| 421 |
run_search_test_arborx(meshFileName); |
| 422 |
} |
| 423 |
|
| 424 |
void distributed_arborx_coarse_search(Kokkos::View<ArborX::Box *, MemSpace> elemBoxes, |
| 425 |
Kokkos::View<ArborX::Box *, MemSpace> sideBoxes, |
| 426 |
MPI_Comm comm) |
| 427 |
{ |
| 428 |
|
| 429 |
ExecSpace execSpace; |
| 430 |
|
| 431 |
ArborX::DistributedTree<MemSpace> tree(comm, execSpace, elemBoxes); |
| 432 |
|
| 433 |
const int numQueries = sideBoxes.extent(0); |
| 434 |
Kokkos::View<ArborX::Intersects<ArborX::Box> *, MemSpace> queries(Kokkos::ViewAllocateWithoutInitializing("queries"), numQueries); |
| 435 |
|
| 436 |
Kokkos::parallel_for("setup_queries", Kokkos::RangePolicy<ExecSpace>(0, numQueries), |
| 437 |
KOKKOS_LAMBDA(int i) { queries(i) = ArborX::intersects(sideBoxes(i)); }); |
| 438 |
Kokkos::fence(); |
| 439 |
|
| 440 |
Kokkos::View<ArborX::PairIndexRank *, MemSpace> values("indicesAndRanks", 0); |
| 441 |
Kokkos::View<int *, MemSpace> offsets("offsets", 0); |
| 442 |
|
| 443 |
tree.query(execSpace, queries, values, offsets); |
| 444 |
} |
| 445 |
|
| 446 |
void run_search_test_distributed_arborx(const std::string& meshFileName) |
| 447 |
{ |
| 448 |
const unsigned NUM_RUNS = 5; |
| 449 |
const unsigned NUM_ITERS = 100; |
| 450 |
stk::unit_test_util::BatchTimer batchTimer(MPI_COMM_WORLD); |
| 451 |
batchTimer.initialize_batch_timer(); |
| 452 |
|
| 453 |
for (unsigned j = 0; j < NUM_RUNS; j++) { |
| 454 |
|
| 455 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 456 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 457 |
|
| 458 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 459 |
|
| 460 |
Kokkos::View<ArborX::Box *, MemSpace> elemBoxes = createArborXBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK); |
| 461 |
Kokkos::View<ArborX::Box *, MemSpace> sideBoxes = createArborXBoundingBoxesForEntities(*bulkPtr, stk::topology::FACE_RANK); |
| 462 |
|
| 463 |
batchTimer.start_batch_timer(); |
| 464 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 465 |
distributed_arborx_coarse_search(elemBoxes, sideBoxes, MPI_COMM_WORLD); |
| 466 |
} |
| 467 |
batchTimer.stop_batch_timer(); |
| 468 |
} |
| 469 |
|
| 470 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 471 |
} |
| 472 |
|
| 473 |
TEST(StkSearch_VolumeToSurface, generatedMesh_floatBox_distributed_rawARBORX) { |
| 474 |
run_search_test_distributed_arborx("generated:40x80x20|sideset:xXyYzZ"); |
| 475 |
} |
| 476 |
|
| 477 |
TEST(StkSearch_VolumeToSurface, casaMesh_floatBox_distributed_rawARBORX) { |
| 478 |
|
| 479 |
std::string meshFileName = stk::unit_test_util::get_option("-m", "none-specified"); |
| 480 |
if (meshFileName == "none-specified") GTEST_SKIP(); |
| 481 |
|
| 482 |
run_search_test_distributed_arborx(meshFileName); |
| 483 |
} |
| 484 |
|
| 485 |
} // namespace |
| 486 |
|