| 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 "stk_ngp_test/ngp_test.hpp" |
| 36 |
#include <stk_mesh/base/Ngp.hpp> |
| 37 |
#include <stk_mesh/base/NgpMesh.hpp> |
| 38 |
#include <stk_mesh/base/NgpReductions.hpp> |
| 39 |
#include <stk_util/ngp/NgpSpaces.hpp> |
| 40 |
#include <stk_unit_test_utils/getOption.h> |
| 41 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 42 |
#include <stk_unit_test_utils/stk_mesh_fixtures/TestHexFixture.hpp> |
| 43 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 44 |
#include <stk_mesh/base/CreateEdges.hpp> |
| 45 |
#include <stk_mesh/base/MetaData.hpp> |
| 46 |
#include <stk_mesh/base/BulkData.hpp> |
| 47 |
#include <stk_mesh/base/Bucket.hpp> |
| 48 |
#include <stk_mesh/base/Field.hpp> |
| 49 |
#include <stk_mesh/base/GetEntities.hpp> |
| 50 |
#include <stk_mesh/base/Entity.hpp> |
| 51 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 52 |
#include <stk_mesh/base/NgpForEachEntity.hpp> |
| 53 |
#include <stk_util/stk_config.h> |
| 54 |
#include <stk_util/environment/WallTime.hpp> |
| 55 |
#include <stk_util/util/StkNgpVector.hpp> |
| 56 |
#include "stk_mesh/base/FieldParallel.hpp" |
| 57 |
#include "stk_mesh/base/GetNgpMesh.hpp" |
| 58 |
|
| 59 |
#include <limits> |
| 60 |
|
| 61 |
using NgpMeshDefaultMemSpace = stk::mesh::NgpMeshDefaultMemSpace; |
| 62 |
|
| 63 |
class NgpMeshTest : public stk::mesh::fixtures::TestHexFixture |
| 64 |
{ |
| 65 |
public: |
| 66 |
void run_get_nodes_using_FastMeshIndex_test() |
| 67 |
{ |
| 68 |
setup_mesh(1, 1, 4); |
| 69 |
|
| 70 |
stk::NgpVector<double> numNodesVec("numNodes", 1); |
| 71 |
|
| 72 |
stk::mesh::NgpMesh & ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 73 |
Kokkos::parallel_for(stk::ngp::DeviceRangePolicy(0, 1), |
| 74 |
KOKKOS_LAMBDA(const int /*i*/) |
| 75 |
{ |
| 76 |
stk::mesh::NgpMesh::ConnectedNodes nodes = ngpMesh.get_nodes(stk::topology::ELEM_RANK, stk::mesh::FastMeshIndex{0,0}); |
| 77 |
numNodesVec.device_get(0) = nodes.size(); |
| 78 |
}); |
| 79 |
|
| 80 |
numNodesVec.copy_device_to_host(); |
| 81 |
ASSERT_EQ(8u, numNodesVec[0]); |
| 82 |
} |
| 83 |
|
| 84 |
template <typename NgpMemSpace> |
| 85 |
void run_get_nodes_using_FastMeshIndex_test() |
| 86 |
{ |
| 87 |
setup_mesh(1, 1, 4); |
| 88 |
|
| 89 |
stk::NgpVector<double> numNodesVec("numNodes", 1); |
| 90 |
|
| 91 |
stk::mesh::NgpMeshT<NgpMemSpace> & ngpMesh = stk::mesh::get_updated_ngp_mesh<NgpMemSpace>(get_bulk()); |
| 92 |
Kokkos::parallel_for(stk::ngp::DeviceRangePolicy(0, 1), |
| 93 |
KOKKOS_LAMBDA(const int /*i*/) |
| 94 |
{ |
| 95 |
stk::mesh::NgpMesh::ConnectedNodes nodes = ngpMesh.get_nodes(stk::topology::ELEM_RANK, stk::mesh::FastMeshIndex{0,0}); |
| 96 |
numNodesVec.device_get(0) = nodes.size(); |
| 97 |
}); |
| 98 |
|
| 99 |
numNodesVec.copy_device_to_host(); |
| 100 |
ASSERT_EQ(8u, numNodesVec[0]); |
| 101 |
} |
| 102 |
|
| 103 |
void run_edge_check(unsigned numExpectedEdgesPerElem) |
| 104 |
{ |
| 105 |
stk::mesh::NgpMesh& ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 106 |
stk::mesh::for_each_entity_run(ngpMesh, stk::topology::ELEM_RANK, get_meta().universal_part(), |
| 107 |
KOKKOS_LAMBDA(const stk::mesh::FastMeshIndex& entityIndex) { |
| 108 |
stk::mesh::ConnectedEntities edges = ngpMesh.get_edges(stk::topology::ELEM_RANK, entityIndex); |
| 109 |
NGP_EXPECT_EQ(numExpectedEdgesPerElem, edges.size()); |
| 110 |
} |
| 111 |
); |
| 112 |
} |
| 113 |
|
| 114 |
void delete_edge_on_each_element() |
| 115 |
{ |
| 116 |
get_bulk().modification_begin(); |
| 117 |
|
| 118 |
stk::mesh::Entity elem1 = get_bulk().get_entity(stk::topology::ELEM_RANK, 1); |
| 119 |
stk::mesh::ConnectedEntities edges = get_bulk().get_connected_entities(elem1, stk::topology::EDGE_RANK); |
| 120 |
stk::mesh::ConnectedEntities edgeElems = get_bulk().get_connected_entities(edges[0], stk::topology::ELEM_RANK); |
| 121 |
EXPECT_EQ(1u, edgeElems.size()); |
| 122 |
EXPECT_EQ(elem1, edgeElems[0]); |
| 123 |
|
| 124 |
const stk::mesh::ConnectivityOrdinal* edgeElemOrds = get_bulk().begin_ordinals(edges[0], stk::topology::ELEM_RANK); |
| 125 |
stk::mesh::Entity edge = edges[0]; |
| 126 |
EXPECT_TRUE(get_bulk().destroy_relation(elem1, edge, edgeElemOrds[0])); |
| 127 |
EXPECT_TRUE(get_bulk().destroy_entity(edge)); |
| 128 |
|
| 129 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 130 |
edges = get_bulk().get_connected_entities(elem2, stk::topology::EDGE_RANK); |
| 131 |
EXPECT_EQ(12u, edges.size()); |
| 132 |
edgeElems = get_bulk().get_connected_entities(edges[5], stk::topology::ELEM_RANK); |
| 133 |
EXPECT_EQ(1u, edgeElems.size()); |
| 134 |
EXPECT_EQ(elem2, edgeElems[0]); |
| 135 |
edgeElemOrds = get_bulk().begin_ordinals(edges[5], stk::topology::ELEM_RANK); |
| 136 |
edge = edges[5]; |
| 137 |
EXPECT_TRUE(get_bulk().destroy_relation(elem2, edge, edgeElemOrds[0])); |
| 138 |
EXPECT_TRUE(get_bulk().destroy_entity(edge)); |
| 139 |
|
| 140 |
get_bulk().modification_end(); |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
NGP_TEST_F(NgpMeshTest, get_nodes_using_FastMeshIndex) |
| 145 |
{ |
| 146 |
run_get_nodes_using_FastMeshIndex_test(); |
| 147 |
} |
| 148 |
|
| 149 |
NGP_TEST_F(NgpMeshTest, get_nodes_using_FastMeshIndex_custom_NgpMemSpace) |
| 150 |
{ |
| 151 |
run_get_nodes_using_FastMeshIndex_test<NgpMeshDefaultMemSpace>(); |
| 152 |
} |
| 153 |
|
| 154 |
NGP_TEST_F(NgpMeshTest, hexes_with_edges_update_connectivity) |
| 155 |
{ |
| 156 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); } |
| 157 |
|
| 158 |
setup_mesh(1,1,2); |
| 159 |
stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 160 |
|
| 161 |
stk::mesh::Part& edgePart = get_meta().declare_part("edges", stk::topology::EDGE_RANK); |
| 162 |
|
| 163 |
stk::mesh::create_edges(get_bulk(), get_meta().universal_part(), &edgePart); |
| 164 |
stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 165 |
|
| 166 |
EXPECT_EQ(20u, stk::mesh::count_entities(get_bulk(), stk::topology::EDGE_RANK, edgePart)); |
| 167 |
|
| 168 |
unsigned numExpectedEdgesPerElement = 12; |
| 169 |
run_edge_check(numExpectedEdgesPerElement); |
| 170 |
|
| 171 |
delete_edge_on_each_element(); |
| 172 |
EXPECT_EQ(18u, stk::mesh::count_entities(get_bulk(), stk::topology::EDGE_RANK, edgePart)); |
| 173 |
|
| 174 |
numExpectedEdgesPerElement = 11; |
| 175 |
run_edge_check(numExpectedEdgesPerElement); |
| 176 |
} |
| 177 |
|
| 178 |
class NgpMeshRankLimit : public stk::mesh::fixtures::TestHexFixture {}; |
| 179 |
|
| 180 |
TEST_F(NgpMeshRankLimit, tooManyRanksThrowWithMessage) |
| 181 |
{ |
| 182 |
setup_mesh(1,1,1, {"NODE","EDGE","FACE","ELEM","CONSTRAINT","JULIA"}); |
| 183 |
|
| 184 |
try { |
| 185 |
stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 186 |
FAIL()<< "expected throw but didn't throw"; |
| 187 |
} |
| 188 |
catch(std::exception& e) { |
| 189 |
std::string expectedMsg("stk::mesh::NgpMesh: too many entity ranks (6). Required to be less-or-equal stk::topology::NUM_RANKS"); |
| 190 |
std::string msg(e.what()); |
| 191 |
EXPECT_TRUE((msg.find(expectedMsg) != std::string::npos)); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
TEST_F(NgpMeshRankLimit, tooManyRanksThrowWithMessage_custom_NgpMemSpace) |
| 196 |
{ |
| 197 |
setup_mesh(1,1,1, {"NODE","EDGE","FACE","ELEM","CONSTRAINT","JULIA"}); |
| 198 |
|
| 199 |
try { |
| 200 |
stk::mesh::get_updated_ngp_mesh<NgpMeshDefaultMemSpace>(get_bulk()); |
| 201 |
FAIL()<< "expected throw but didn't throw"; |
| 202 |
} |
| 203 |
catch(std::exception& e) { |
| 204 |
std::string expectedMsg("stk::mesh::NgpMesh: too many entity ranks (6). Required to be less-or-equal stk::topology::NUM_RANKS"); |
| 205 |
std::string msg(e.what()); |
| 206 |
EXPECT_TRUE((msg.find(expectedMsg) != std::string::npos)); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
class EntityIndexSpace : public stk::mesh::fixtures::TestHexFixture {}; |
| 211 |
|
| 212 |
TEST_F(EntityIndexSpace, accessingLocalData_useLocalOffset) |
| 213 |
{ |
| 214 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { |
| 215 |
return; |
| 216 |
} |
| 217 |
setup_mesh(1, 1, 1); |
| 218 |
std::vector<unsigned> entityToLocalOffset(get_bulk().get_size_of_entity_index_space(), 0); |
| 219 |
|
| 220 |
stk::mesh::EntityRank endRank = static_cast<stk::mesh::EntityRank>(get_meta().entity_rank_count()); |
| 221 |
for(stk::mesh::EntityRank rank=stk::topology::NODE_RANK; rank<endRank; ++rank) |
| 222 |
{ |
| 223 |
unsigned localOffset = 0; |
| 224 |
const stk::mesh::BucketVector &buckets = get_bulk().buckets(stk::topology::NODE_RANK); |
| 225 |
for(const stk::mesh::Bucket *bucket : buckets) |
| 226 |
{ |
| 227 |
for(stk::mesh::Entity entity : *bucket) |
| 228 |
{ |
| 229 |
entityToLocalOffset[entity.local_offset()] = localOffset; |
| 230 |
localOffset++; |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
std::vector<unsigned> gold {0,0,0,1,3,2,4,5,7,6}; |
| 236 |
ASSERT_EQ(gold.size(), entityToLocalOffset.size()); |
| 237 |
for(size_t i=0; i<gold.size(); i++) |
| 238 |
{ |
| 239 |
EXPECT_EQ(gold[i], entityToLocalOffset[i]); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
void run_vector_gpu_test() |
| 244 |
{ |
| 245 |
size_t n = 10; |
| 246 |
stk::NgpVector<double> vec("vec", n); |
| 247 |
Kokkos::parallel_for(stk::ngp::DeviceRangePolicy(0, n), |
| 248 |
KOKKOS_LAMBDA(const int i) |
| 249 |
{ |
| 250 |
vec.device_get(i) = i; |
| 251 |
}); |
| 252 |
vec.copy_device_to_host(); |
| 253 |
for(size_t i=0; i<n; i++) |
| 254 |
EXPECT_EQ(i, vec[i]); |
| 255 |
} |
| 256 |
|
| 257 |
TEST(StkVectorGpuTest, gpu_runs) |
| 258 |
{ |
| 259 |
run_vector_gpu_test(); |
| 260 |
} |
| 261 |
|
| 262 |
void check_volatile_fast_shared_comm_map_values_on_device(const stk::mesh::NgpMesh & ngpMesh, int proc, const stk::mesh::DeviceCommMapIndices & deviceCommMapIndicesGold) |
| 263 |
{ |
| 264 |
auto test = KOKKOS_LAMBDA(size_t /*i*/) |
| 265 |
{ |
| 266 |
stk::mesh::DeviceCommMapIndices deviceCommMapIndices = ngpMesh.volatile_fast_shared_comm_map(stk::topology::NODE_RANK, proc); |
| 267 |
|
| 268 |
for (size_t entry = 0; entry < deviceCommMapIndices.size(); ++entry) { |
| 269 |
NGP_EXPECT_EQ(deviceCommMapIndicesGold[entry].bucket_id, deviceCommMapIndices[entry].bucket_id); |
| 270 |
NGP_EXPECT_EQ(deviceCommMapIndicesGold[entry].bucket_ord, deviceCommMapIndices[entry].bucket_ord); |
| 271 |
} |
| 272 |
}; |
| 273 |
|
| 274 |
if constexpr (std::is_same_v<Kokkos::DefaultExecutionSpace, Kokkos::DefaultHostExecutionSpace>) { |
| 275 |
test(0); |
| 276 |
} else { |
| 277 |
Kokkos::parallel_for(stk::ngp::DeviceRangePolicy(0, 1), test); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
NGP_TEST_F(NgpMeshTest, volatileFastSharedCommMap) |
| 282 |
{ |
| 283 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) { GTEST_SKIP(); } |
| 284 |
|
| 285 |
setup_mesh(1, 1, 4); |
| 286 |
|
| 287 |
stk::mesh::NgpMesh & ngpMesh = stk::mesh::get_updated_ngp_mesh(get_bulk()); |
| 288 |
std::vector<int> comm_procs = get_bulk().all_sharing_procs(stk::topology::NODE_RANK); |
| 289 |
|
| 290 |
for (int proc : comm_procs) { |
| 291 |
stk::mesh::HostCommMapIndices hostNgpMeshIndices = get_bulk().template volatile_fast_shared_comm_map<stk::ngp::MemSpace>(stk::topology::NODE_RANK, proc); |
| 292 |
stk::mesh::DeviceCommMapIndices deviceNgpMeshIndices("deviceNgpMeshIndices", hostNgpMeshIndices.extent(0)); |
| 293 |
|
| 294 |
Kokkos::deep_copy(deviceNgpMeshIndices, hostNgpMeshIndices); |
| 295 |
check_volatile_fast_shared_comm_map_values_on_device(ngpMesh, proc, deviceNgpMeshIndices); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
NGP_TEST_F(NgpMeshTest, volatileFastSharedCommMap_custom_NgpMemSpace) |
| 300 |
{ |
| 301 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) { GTEST_SKIP(); } |
| 302 |
|
| 303 |
setup_mesh(1, 1, 4); |
| 304 |
|
| 305 |
stk::mesh::NgpMeshT<stk::mesh::NgpMeshDefaultMemSpace> & ngpMesh = stk::mesh::get_updated_ngp_mesh<stk::mesh::NgpMeshDefaultMemSpace>(get_bulk()); |
| 306 |
std::vector<int> comm_procs = get_bulk().all_sharing_procs(stk::topology::NODE_RANK); |
| 307 |
|
| 308 |
for (int proc : comm_procs) { |
| 309 |
stk::mesh::HostCommMapIndices hostNgpMeshIndices = get_bulk().template volatile_fast_shared_comm_map<stk::mesh::NgpMeshDefaultMemSpace>(stk::topology::NODE_RANK, proc); |
| 310 |
stk::mesh::DeviceCommMapIndices deviceNgpMeshIndices("deviceNgpMeshIndices", hostNgpMeshIndices.extent(0)); |
| 311 |
|
| 312 |
Kokkos::deep_copy(deviceNgpMeshIndices, hostNgpMeshIndices); |
| 313 |
check_volatile_fast_shared_comm_map_values_on_device(ngpMesh, proc, deviceNgpMeshIndices); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
void test_ngp_permutations_1side_2perms(const stk::mesh::BulkData& mesh, |
| 318 |
const stk::mesh::Part& sidePart) |
| 319 |
{ |
| 320 |
stk::mesh::NgpMesh& ngpMesh = stk::mesh::get_updated_ngp_mesh(mesh); |
| 321 |
|
| 322 |
stk::mesh::EntityRank sideRank = mesh.mesh_meta_data().side_rank(); |
| 323 |
stk::mesh::EntityVector sides; |
| 324 |
stk::mesh::get_entities(mesh, sideRank, sidePart, sides); |
| 325 |
EXPECT_EQ(1u, sides.size()); |
| 326 |
EXPECT_EQ(2u, mesh.num_connectivity(sides[0], stk::topology::ELEM_RANK)); |
| 327 |
const stk::mesh::Permutation* hostPerms = mesh.begin_permutations(sides[0], stk::topology::ELEM_RANK); |
| 328 |
stk::mesh::Permutation expectedPerm1 = hostPerms[0]; |
| 329 |
stk::mesh::Permutation expectedPerm2 = hostPerms[1]; |
| 330 |
|
| 331 |
stk::mesh::for_each_entity_run(ngpMesh, sideRank, sidePart, |
| 332 |
KOKKOS_LAMBDA(const stk::mesh::FastMeshIndex& sideIndex) { |
| 333 |
stk::mesh::NgpMesh::Permutations perms = ngpMesh.get_permutations(sideRank, sideIndex, stk::topology::ELEM_RANK); |
| 334 |
NGP_EXPECT_EQ(2u, perms.size()); |
| 335 |
NGP_EXPECT_EQ(expectedPerm1, perms[0]); |
| 336 |
NGP_EXPECT_EQ(expectedPerm2, perms[1]); |
| 337 |
}); |
| 338 |
} |
| 339 |
|
| 340 |
NGP_TEST(TestNgpMesh, permutations) |
| 341 |
{ |
| 342 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); } |
| 343 |
|
| 344 |
std::string meshDesc = |
| 345 |
"0,1,TRI_3_2D,1,2,3,block_1\n" |
| 346 |
"0,2,TRI_3_2D,2,4,3,block_2\n" |
| 347 |
"|dimension:2|sideset:name=surface_1; data=1,2"; |
| 348 |
|
| 349 |
std::shared_ptr<stk::mesh::BulkData> mesh = stk::mesh::MeshBuilder(MPI_COMM_WORLD) |
| 350 |
.set_spatial_dimension(2).create(); |
| 351 |
stk::unit_test_util::setup_text_mesh(*mesh, meshDesc); |
| 352 |
|
| 353 |
stk::mesh::EntityRank sideRank = mesh->mesh_meta_data().side_rank(); |
| 354 |
stk::mesh::Part* sidePart = mesh->mesh_meta_data().get_part("surface_1"); |
| 355 |
STK_ThrowAssertMsg(sidePart != nullptr, "failed to find part for surface_1"); |
| 356 |
|
| 357 |
stk::mesh::EntityVector sides; |
| 358 |
stk::mesh::get_entities(*mesh, sideRank, *sidePart, sides); |
| 359 |
EXPECT_EQ(1u, sides.size()); |
| 360 |
EXPECT_EQ(2u, mesh->num_connectivity(sides[0], stk::topology::ELEM_RANK)); |
| 361 |
|
| 362 |
stk::mesh::Permutation expectedPerm1 = static_cast<stk::mesh::Permutation>(0); |
| 363 |
stk::mesh::Permutation expectedPerm2 = static_cast<stk::mesh::Permutation>(1); |
| 364 |
const stk::mesh::Permutation* permutations = mesh->begin_permutations(sides[0], stk::topology::ELEM_RANK); |
| 365 |
EXPECT_EQ(expectedPerm1, permutations[0]); |
| 366 |
EXPECT_EQ(expectedPerm2, permutations[1]); |
| 367 |
|
| 368 |
test_ngp_permutations_1side_2perms(*mesh, *sidePart); |
| 369 |
} |
| 370 |
|
| 371 |
namespace { |
| 372 |
double reduce_on_host(stk::mesh::BulkData& bulk) |
| 373 |
{ |
| 374 |
auto ngp_mesh = stk::mesh::HostMesh(bulk); |
| 375 |
|
| 376 |
double max_val = 0.0; |
| 377 |
Kokkos::Max<double> max_reduction(max_val); |
| 378 |
|
| 379 |
stk::mesh::for_each_entity_reduce( |
| 380 |
ngp_mesh, |
| 381 |
stk::topology::NODE_RANK, |
| 382 |
!stk::mesh::Selector(), |
| 383 |
max_reduction, |
| 384 |
KOKKOS_LAMBDA(const stk::mesh::FastMeshIndex /*i*/, double& thread_value) { |
| 385 |
max_reduction.join(thread_value, 1.0); |
| 386 |
}); |
| 387 |
|
| 388 |
return max_val; |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
TEST(NgpHostMesh, FieldForEachEntityReduceOnHost_fromTylerVoskuilen) |
| 393 |
{ |
| 394 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { GTEST_SKIP(); } |
| 395 |
stk::mesh::fixtures::HexFixture fixture(MPI_COMM_WORLD, 2, 2, 2); |
| 396 |
fixture.m_meta.commit(); |
| 397 |
fixture.generate_mesh(); |
| 398 |
|
| 399 |
auto maxZ = reduce_on_host(fixture.m_bulk_data); |
| 400 |
EXPECT_EQ(1.0, maxZ); |
| 401 |
} |
| 402 |
|
| 403 |
TEST(NgpDeviceMesh, dont_let_stacksize_get_out_of_control) |
| 404 |
{ |
| 405 |
constexpr size_t tol = 50; |
| 406 |
|
| 407 |
#ifdef SIERRA_MIGRATION |
| 408 |
constexpr size_t expectedBulkDataSize = 1320; |
| 409 |
#else |
| 410 |
constexpr size_t expectedBulkDataSize = 1256; |
| 411 |
#endif |
| 412 |
EXPECT_NEAR(expectedBulkDataSize, sizeof(stk::mesh::BulkData), tol); |
| 413 |
|
| 414 |
constexpr size_t expectedBucketSize = 1120; |
| 415 |
EXPECT_NEAR(expectedBucketSize, sizeof(stk::mesh::Bucket), tol); |
| 416 |
|
| 417 |
constexpr size_t expectedDeviceMeshSize = 536; |
| 418 |
EXPECT_NEAR(expectedDeviceMeshSize, sizeof(stk::mesh::DeviceMesh), tol); |
| 419 |
|
| 420 |
constexpr size_t expectedDeviceBucketSize = 264; |
| 421 |
EXPECT_NEAR(expectedDeviceBucketSize, sizeof(stk::mesh::DeviceBucket), tol); |
| 422 |
} |
| 423 |
|
| 424 |
void add_elements(std::unique_ptr<stk::mesh::BulkData>& bulk) |
| 425 |
{ |
| 426 |
stk::mesh::MetaData& meta = bulk->mesh_meta_data(); |
| 427 |
stk::mesh::Part& part_1 = meta.declare_part_with_topology("part_1", stk::topology::HEX_8); |
| 428 |
|
| 429 |
const int rank = stk::parallel_machine_rank(MPI_COMM_WORLD); |
| 430 |
const stk::mesh::EntityId elemId = rank + 1; |
| 431 |
const stk::mesh::EntityId firstNodeId = rank * 8 + 1; |
| 432 |
|
| 433 |
stk::mesh::EntityIdVector nodeIds(8, 0); |
| 434 |
for (unsigned i = 0; i < nodeIds.size(); ++i) { |
| 435 |
nodeIds[i] = firstNodeId + i; |
| 436 |
} |
| 437 |
|
| 438 |
bulk->modification_begin(); |
| 439 |
stk::mesh::declare_element(*bulk, part_1, elemId, nodeIds); |
| 440 |
bulk->modification_end(); |
| 441 |
} |
| 442 |
|
| 443 |
TEST(NgpTeardownOrdering, BulkDataOutlivesNgpMesh) |
| 444 |
{ |
| 445 |
std::unique_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).set_spatial_dimension(3).create(); |
| 446 |
add_elements(bulk); |
| 447 |
|
| 448 |
[[maybe_unused]] stk::mesh::NgpMesh ngpMesh = stk::mesh::get_updated_ngp_mesh(*bulk); |
| 449 |
|
| 450 |
// The "expect" for this test is a clean Valgrind run and no seg-faults |
| 451 |
} |
| 452 |
|
| 453 |
TEST(NgpTeardownOrdering, NgpMeshOutlivesBulkData) |
| 454 |
{ |
| 455 |
stk::mesh::NgpMesh ngpMesh; |
| 456 |
std::unique_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(MPI_COMM_WORLD).set_spatial_dimension(3).create(); |
| 457 |
add_elements(bulk); |
| 458 |
|
| 459 |
ngpMesh = stk::mesh::get_updated_ngp_mesh(*bulk); |
| 460 |
|
| 461 |
// The "expect" for this test is a clean Valgrind run and no seg-faults |
| 462 |
} |
| 463 |
|