| 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 |
|
| 47 |
namespace { |
| 48 |
|
| 49 |
template<typename BoxVectorType> |
| 50 |
void run_volume_to_volume_test(const std::string& meshFileName, |
| 51 |
stk::search::SearchMethod searchMethod, |
| 52 |
bool enforceSearchResultSymmetry = true) |
| 53 |
{ |
| 54 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 55 |
const unsigned NUM_RUNS = 5; |
| 56 |
const unsigned NUM_ITERS = 20; |
| 57 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 58 |
batchTimer.initialize_batch_timer(); |
| 59 |
|
| 60 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 61 |
|
| 62 |
stk::mesh::MeshBuilder builder(comm); |
| 63 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 64 |
|
| 65 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 66 |
|
| 67 |
BoxVectorType elemBoxes; |
| 68 |
createBoundingBoxesForEntities(*bulkPtr, stk::topology::ELEM_RANK, elemBoxes); |
| 69 |
|
| 70 |
SearchResults searchResults; |
| 71 |
|
| 72 |
batchTimer.start_batch_timer(); |
| 73 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 74 |
stk::search::coarse_search(elemBoxes, elemBoxes, searchMethod, comm, searchResults, enforceSearchResultSymmetry); |
| 75 |
} |
| 76 |
batchTimer.stop_batch_timer(); |
| 77 |
} |
| 78 |
|
| 79 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 80 |
} |
| 81 |
|
| 82 |
template<typename BoxIdentProcType> |
| 83 |
void run_volume_to_volume_test_with_views(const std::string& meshFileName, |
| 84 |
stk::search::SearchMethod searchMethod, |
| 85 |
bool enforceSearchResultSymmetry = true) |
| 86 |
{ |
| 87 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 88 |
|
| 89 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 90 |
const unsigned NUM_RUNS = 5; |
| 91 |
const unsigned NUM_ITERS = 20; |
| 92 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 93 |
batchTimer.initialize_batch_timer(); |
| 94 |
|
| 95 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 96 |
|
| 97 |
stk::mesh::MeshBuilder builder(comm); |
| 98 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 99 |
|
| 100 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 101 |
|
| 102 |
Kokkos::View<BoxIdentProcType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentProcType>(*bulkPtr, |
| 103 |
stk::topology::ELEM_RANK); |
| 104 |
|
| 105 |
batchTimer.start_batch_timer(); |
| 106 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 107 |
Kokkos::View<IdentProcIntersection*, ExecSpace> searchResults; |
| 108 |
stk::search::coarse_search(elemBoxes, elemBoxes, searchMethod, comm, searchResults, |
| 109 |
ExecSpace{}, enforceSearchResultSymmetry); |
| 110 |
} |
| 111 |
batchTimer.stop_batch_timer(); |
| 112 |
} |
| 113 |
|
| 114 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 115 |
} |
| 116 |
|
| 117 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_KDTREE) |
| 118 |
{ |
| 119 |
run_volume_to_volume_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 120 |
} |
| 121 |
|
| 122 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_KDTREE) |
| 123 |
{ |
| 124 |
run_volume_to_volume_test<StkBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 125 |
} |
| 126 |
|
| 127 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_MORTON_LBVH) |
| 128 |
{ |
| 129 |
run_volume_to_volume_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 130 |
} |
| 131 |
|
| 132 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_MORTON_LBVH) |
| 133 |
{ |
| 134 |
run_volume_to_volume_test<StkBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 135 |
} |
| 136 |
|
| 137 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_with_views_MORTON_LBVH) |
| 138 |
{ |
| 139 |
run_volume_to_volume_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 140 |
} |
| 141 |
|
| 142 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_with_views_MORTON_LBVH) |
| 143 |
{ |
| 144 |
run_volume_to_volume_test_with_views<StkBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 145 |
} |
| 146 |
|
| 147 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_ARBORX) |
| 148 |
{ |
| 149 |
run_volume_to_volume_test<FloatBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 150 |
} |
| 151 |
|
| 152 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_ARBORX) |
| 153 |
{ |
| 154 |
run_volume_to_volume_test<StkBoxIdentProcVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 155 |
} |
| 156 |
|
| 157 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_with_views_ARBORX) |
| 158 |
{ |
| 159 |
run_volume_to_volume_test_with_views<FloatBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 160 |
} |
| 161 |
|
| 162 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_with_views_ARBORX) |
| 163 |
{ |
| 164 |
run_volume_to_volume_test_with_views<StkBoxIdentProc>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 165 |
} |
| 166 |
|
| 167 |
template<typename BoxVectorType> |
| 168 |
void run_volume_to_volume_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 = 20; |
| 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 |
batchTimer.start_batch_timer(); |
| 188 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 189 |
LocalSearchResults searchResults; |
| 190 |
stk::search::local_coarse_search(elemBoxes, elemBoxes, searchMethod, searchResults); |
| 191 |
} |
| 192 |
batchTimer.stop_batch_timer(); |
| 193 |
} |
| 194 |
|
| 195 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 196 |
} |
| 197 |
|
| 198 |
template<typename BoxIdentProcType> |
| 199 |
void run_volume_to_volume_test_local_with_views(const std::string& meshFileName, |
| 200 |
stk::search::SearchMethod searchMethod) |
| 201 |
{ |
| 202 |
using ExecSpace = Kokkos::DefaultExecutionSpace; |
| 203 |
|
| 204 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 205 |
const unsigned NUM_RUNS = 5; |
| 206 |
const unsigned NUM_ITERS = 20; |
| 207 |
stk::unit_test_util::BatchTimer batchTimer(comm); |
| 208 |
batchTimer.initialize_batch_timer(); |
| 209 |
|
| 210 |
for (unsigned run = 0; run < NUM_RUNS; ++run) { |
| 211 |
|
| 212 |
stk::mesh::MeshBuilder builder(comm); |
| 213 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 214 |
|
| 215 |
stk::io::fill_mesh_with_auto_decomp(meshFileName, *bulkPtr); |
| 216 |
|
| 217 |
Kokkos::View<BoxIdentProcType *, ExecSpace> elemBoxes = createBoundingBoxesForEntities<BoxIdentProcType>(*bulkPtr, |
| 218 |
stk::topology::ELEM_RANK); |
| 219 |
|
| 220 |
|
| 221 |
batchTimer.start_batch_timer(); |
| 222 |
for (unsigned i = 0; i < NUM_ITERS; ++i) { |
| 223 |
Kokkos::View<IdentIntersection*, ExecSpace> searchResults; |
| 224 |
stk::search::local_coarse_search(elemBoxes, elemBoxes, searchMethod, searchResults, ExecSpace{}); |
| 225 |
} |
| 226 |
batchTimer.stop_batch_timer(); |
| 227 |
} |
| 228 |
|
| 229 |
batchTimer.print_batch_timing(NUM_ITERS); |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_local_KDTREE) |
| 234 |
{ |
| 235 |
run_volume_to_volume_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 236 |
} |
| 237 |
|
| 238 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_local_KDTREE) |
| 239 |
{ |
| 240 |
run_volume_to_volume_test_local<StkBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::KDTREE); |
| 241 |
} |
| 242 |
|
| 243 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_local_MORTON_LBVH) |
| 244 |
{ |
| 245 |
run_volume_to_volume_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 246 |
} |
| 247 |
|
| 248 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_local_MORTON_LBVH) |
| 249 |
{ |
| 250 |
run_volume_to_volume_test_local<StkBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 251 |
} |
| 252 |
|
| 253 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_local_with_views_MORTON_LBVH) |
| 254 |
{ |
| 255 |
run_volume_to_volume_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 256 |
} |
| 257 |
|
| 258 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_local_with_views_MORTON_LBVH) |
| 259 |
{ |
| 260 |
run_volume_to_volume_test_local_with_views<StkBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::MORTON_LBVH); |
| 261 |
} |
| 262 |
|
| 263 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_local_ARBORX) |
| 264 |
{ |
| 265 |
run_volume_to_volume_test_local<FloatBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 266 |
} |
| 267 |
|
| 268 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_local_ARBORX) |
| 269 |
{ |
| 270 |
run_volume_to_volume_test_local<StkBoxIdentVector>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 271 |
} |
| 272 |
|
| 273 |
TEST(StkSearch_VolumeToVolume, generatedMesh_floatBox_local_with_views_ARBORX) |
| 274 |
{ |
| 275 |
run_volume_to_volume_test_local_with_views<FloatBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 276 |
} |
| 277 |
|
| 278 |
TEST(StkSearch_VolumeToVolume, generatedMesh_doubleBox_local_with_views_ARBORX) |
| 279 |
{ |
| 280 |
run_volume_to_volume_test_local_with_views<StkBoxIdent>("generated:40x80x20|sideset:xXyYzZ", stk::search::ARBORX); |
| 281 |
} |
| 282 |
} // namespace |
| 283 |
|