| 1 |
|
| 2 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 3 |
#include <stddef.h> // for size_t |
| 4 |
#include <ostream> // for basic_ostream::operator<<, etc |
| 5 |
#include <stdexcept> // for logic_error |
| 6 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData, etc |
| 7 |
#include <stk_mesh/base/FEMHelpers.hpp> // for declare_element |
| 8 |
#include <stk_mesh/base/Field.hpp> // for Field |
| 9 |
#include <stk_mesh/base/GetEntities.hpp> // for count_entities |
| 10 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, entity_rank_names, etc |
| 11 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 12 |
#include <stk_unit_test_utils/ioUtils.hpp> // for fill_mesh_using_stk_io |
| 13 |
#include <stk_util/environment/WallTime.hpp> // for wall_time |
| 14 |
#include <stk_util/environment/memory_util.hpp> |
| 15 |
#include <stk_util/parallel/Parallel.hpp> // for parallel_machine_rank, etc |
| 16 |
#include <string> // for string |
| 17 |
#include <utility> // for pair, make_pair |
| 18 |
#include <vector> // for vector |
| 19 |
#include "ElementGraphTester.hpp" // for ElemElemGraphTester |
| 20 |
#include "mpi.h" // for MPI_COMM_WORLD, MPI_Comm, etc |
| 21 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 22 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 23 |
#include "stk_mesh/base/Types.hpp" // for PartVector, EntityId, etc |
| 24 |
#include "stk_unit_test_utils/unittestMeshUtils.hpp" |
| 25 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 26 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> // for change_entity_owner, etc |
| 27 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp> // for parallel_info |
| 28 |
#include <stk_mesh/baseImpl/elementGraph/ProcessKilledElements.hpp> |
| 29 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphUpdater.hpp> |
| 30 |
|
| 31 |
namespace stk { namespace mesh { class Part; } } |
| 32 |
|
| 33 |
namespace { |
| 34 |
|
| 35 |
void expect_elem_connected_to_local_elem_id_via_side(const stk::mesh::BulkData& bulkData, stk::mesh::ElemElemGraph& elemGraph, |
| 36 |
stk::mesh::Entity elem, stk::mesh::EntityId connectedId, int viaSide) |
| 37 |
{ |
| 38 |
stk::mesh::EntityId elemId = bulkData.identifier(elem); |
| 39 |
size_t numConnected = elemGraph.get_num_connected_elems(elem); |
| 40 |
bool foundLocallyConnectedId = false; |
| 41 |
for(size_t i=0; i<numConnected; ++i) { |
| 42 |
if (elemGraph.is_connected_elem_locally_owned(elem, i)) { |
| 43 |
stk::mesh::impl::ElementViaSidePair elemViaSidePair = elemGraph.get_connected_element_and_via_side(elem, i); |
| 44 |
if (bulkData.identifier(elemViaSidePair.element) == connectedId && elemViaSidePair.side == viaSide) { |
| 45 |
foundLocallyConnectedId = true; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
ASSERT_TRUE(foundLocallyConnectedId) << "elem " << elemId << " expected local elem " << connectedId; |
| 50 |
} |
| 51 |
|
| 52 |
void expect_elem_connected_to_remote_elem_id_via_side(const stk::mesh::BulkData& bulkData, stk::mesh::ElemElemGraph& elemGraph, |
| 53 |
stk::mesh::Entity elem, stk::mesh::EntityId connectedId, int viaSide) |
| 54 |
{ |
| 55 |
stk::mesh::EntityId elemId = bulkData.identifier(elem); |
| 56 |
size_t numConnected = elemGraph.get_num_connected_elems(elem); |
| 57 |
bool foundRemotelyConnectedId = false; |
| 58 |
for(size_t i=0; i<numConnected; ++i) { |
| 59 |
if (!elemGraph.is_connected_elem_locally_owned(elem, i)) { |
| 60 |
stk::mesh::impl::IdViaSidePair idViaSidePair = elemGraph.get_connected_remote_id_and_via_side(elem, i); |
| 61 |
if (idViaSidePair.id == connectedId && idViaSidePair.side == viaSide) { |
| 62 |
foundRemotelyConnectedId = true; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
ASSERT_TRUE(foundRemotelyConnectedId) << "elem " << elemId << " expected remote elem " << connectedId; |
| 67 |
} |
| 68 |
|
| 69 |
class ElemGraphChangeOwner : public stk::unit_test_util::MeshTestFixture |
| 70 |
{ |
| 71 |
protected: |
| 72 |
void expect_initial_graph_correct() |
| 73 |
{ |
| 74 |
if(get_bulk().parallel_rank() == 0) |
| 75 |
check_element2_connected_to_element1_locally_and_element3_remotely(); |
| 76 |
else if(get_bulk().parallel_rank() == 1) |
| 77 |
check_element3_conencted_to_element4_locally_and_element2_remotely(); |
| 78 |
} |
| 79 |
|
| 80 |
void check_element2_connected_to_element1_locally_and_element3_remotely() |
| 81 |
{ |
| 82 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 83 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(elem2)); |
| 84 |
expect_connected_to_local_elem_id_via_side(elem2, 1, 4); |
| 85 |
expect_element2_connected_to_3_remotely_via_side_5(); |
| 86 |
} |
| 87 |
|
| 88 |
void check_element3_conencted_to_element4_locally_and_element2_remotely() |
| 89 |
{ |
| 90 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 91 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(elem3)); |
| 92 |
expect_connected_to_local_elem_id_via_side(elem3, 4, 5); |
| 93 |
expect_element3_connected_to_2_remotely_via_side_4(); |
| 94 |
} |
| 95 |
|
| 96 |
void expect_element2_connected_to_3_remotely_via_side_5() |
| 97 |
{ |
| 98 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 99 |
expect_connected_to_remote_elem_id_via_side(elem2, 3, 5); |
| 100 |
expect_parallel_info_from_elem2_to_3(); |
| 101 |
} |
| 102 |
|
| 103 |
void expect_element3_connected_to_2_remotely_via_side_4() |
| 104 |
{ |
| 105 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 106 |
expect_connected_to_remote_elem_id_via_side(elem3, 2, 4); |
| 107 |
expect_parallel_info_from_elem3_to_2(); |
| 108 |
} |
| 109 |
|
| 110 |
void expect_parallel_info_from_elem2_to_3() |
| 111 |
{ |
| 112 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 113 |
const stk::mesh::impl::ParallelInfo &parInfo = get_elem_graph().get_parallel_edge_info(elem2, 5, 3, 4); |
| 114 |
expect_otherProc_permutation_chosenId(parInfo, 1, 4); |
| 115 |
} |
| 116 |
|
| 117 |
void expect_parallel_info_from_elem3_to_2() |
| 118 |
{ |
| 119 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 120 |
const stk::mesh::impl::ParallelInfo &parInfo = get_elem_graph().get_parallel_edge_info(elem3, 4, 2, 5); |
| 121 |
expect_otherProc_permutation_chosenId(parInfo, 0, 4); |
| 122 |
} |
| 123 |
|
| 124 |
void expect_connected_to_local_elem_id_via_side(stk::mesh::Entity elem, stk::mesh::EntityId connectedId, int viaSide) |
| 125 |
{ |
| 126 |
expect_elem_connected_to_local_elem_id_via_side(get_bulk(), get_elem_graph(), elem, connectedId, viaSide); |
| 127 |
} |
| 128 |
|
| 129 |
void expect_connected_to_remote_elem_id_via_side(stk::mesh::Entity elem, stk::mesh::EntityId connectedId, int viaSide) |
| 130 |
{ |
| 131 |
expect_elem_connected_to_remote_elem_id_via_side(get_bulk(), get_elem_graph(), elem, connectedId, viaSide); |
| 132 |
} |
| 133 |
|
| 134 |
void expect_connected_to_remote_elem_id(stk::mesh::Entity elem, |
| 135 |
size_t connectedIndex, |
| 136 |
stk::mesh::EntityId connectedId) |
| 137 |
{ |
| 138 |
stk::mesh::EntityId elemId = get_bulk().identifier(elem); |
| 139 |
ASSERT_TRUE(!get_elem_graph().is_connected_elem_locally_owned(elem, connectedIndex)) |
| 140 |
<< "elem " << elemId << " expected remote elem " << connectedId; |
| 141 |
EXPECT_EQ(connectedId, get_elem_graph().get_connected_remote_id_and_via_side(elem, connectedIndex).id) << "elem " << elemId; |
| 142 |
} |
| 143 |
|
| 144 |
void expect_otherProc_permutation_chosenId(const stk::mesh::impl::ParallelInfo &parInfo, |
| 145 |
int otherProc, |
| 146 |
int perm) |
| 147 |
{ |
| 148 |
EXPECT_EQ(otherProc, parInfo.get_proc_rank_of_neighbor()); |
| 149 |
EXPECT_EQ(perm, parInfo.m_permutation); |
| 150 |
} |
| 151 |
|
| 152 |
void move_elements(const stk::mesh::EntityIdProcVec &elementIdProcsToMove) |
| 153 |
{ |
| 154 |
stk::mesh::EntityProcVec elemProcPairsToMove; |
| 155 |
for(const stk::mesh::EntityIdProc &entityIdProc : elementIdProcsToMove) |
| 156 |
append_element_if_owned(entityIdProc.first, entityIdProc.second, elemProcPairsToMove); |
| 157 |
get_bulk().change_entity_owner(elemProcPairsToMove); |
| 158 |
} |
| 159 |
|
| 160 |
void append_element_if_owned(stk::mesh::EntityId elementId, int destProc, stk::mesh::EntityProcVec &elemProcPairsToMove) |
| 161 |
{ |
| 162 |
stk::mesh::Entity element = get_bulk().get_entity(stk::topology::ELEM_RANK, elementId); |
| 163 |
if(is_owned_on_this_proc(element)) |
| 164 |
elemProcPairsToMove.push_back(stk::mesh::EntityProc(element, destProc)); |
| 165 |
} |
| 166 |
|
| 167 |
bool is_owned_on_this_proc(stk::mesh::Entity element) |
| 168 |
{ |
| 169 |
return (get_bulk().is_valid(element) && get_bulk().bucket(element).owned()); |
| 170 |
} |
| 171 |
|
| 172 |
void create_elem_graph() |
| 173 |
{ |
| 174 |
elemElemGraph = new ElemElemGraphTester(get_bulk()); |
| 175 |
elemElemGraphUpdater = std::make_shared<stk::mesh::ElemElemGraphUpdater>(get_bulk(), *elemElemGraph); |
| 176 |
get_bulk().register_observer(elemElemGraphUpdater); |
| 177 |
} |
| 178 |
|
| 179 |
ElemElemGraphTester &get_elem_graph() |
| 180 |
{ |
| 181 |
return *elemElemGraph; |
| 182 |
} |
| 183 |
|
| 184 |
ElemGraphChangeOwner() |
| 185 |
: elemElemGraph(nullptr), elemElemGraphUpdater() |
| 186 |
{ |
| 187 |
} |
| 188 |
|
| 189 |
~ElemGraphChangeOwner() |
| 190 |
{ |
| 191 |
delete elemElemGraph; |
| 192 |
} |
| 193 |
|
| 194 |
protected: |
| 195 |
ElemElemGraphTester *elemElemGraph; |
| 196 |
std::shared_ptr<stk::mesh::ElemElemGraphUpdater> elemElemGraphUpdater; |
| 197 |
}; |
| 198 |
|
| 199 |
|
| 200 |
class ElemGraphChangeOwnerMoveFrom1To0 : public ElemGraphChangeOwner |
| 201 |
{ |
| 202 |
protected: |
| 203 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 204 |
{ |
| 205 |
setup_mesh("generated:1x1x4", auraOption); |
| 206 |
test_graph_updated_with_elem_3_moving_to_proc_0(); |
| 207 |
} |
| 208 |
|
| 209 |
void test_graph_updated_with_elem_3_moving_to_proc_0() |
| 210 |
{ |
| 211 |
create_elem_graph(); |
| 212 |
expect_initial_graph_correct(); |
| 213 |
move_elements({stk::mesh::EntityIdProc(3, 0)}); |
| 214 |
expect_graph_updated_after_elem_3_moved_to_0(); |
| 215 |
} |
| 216 |
|
| 217 |
void expect_graph_updated_after_elem_3_moved_to_0() |
| 218 |
{ |
| 219 |
if(get_bulk().parallel_rank() == 0) |
| 220 |
{ |
| 221 |
check_element2_connected_to_element1_and_element3_locally(); |
| 222 |
check_element3_connected_to_element2_locally_and_element4_remotely(); |
| 223 |
} |
| 224 |
else |
| 225 |
{ |
| 226 |
check_element4_connected_to_element3_remotely(); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
void check_element2_connected_to_element1_and_element3_locally() |
| 231 |
{ |
| 232 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 233 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(elem2)); |
| 234 |
expect_connected_to_local_elem_id_via_side(elem2, 1, 4); |
| 235 |
expect_connected_to_local_elem_id_via_side(elem2, 3, 5); |
| 236 |
} |
| 237 |
|
| 238 |
void check_element4_connected_to_element3_remotely() |
| 239 |
{ |
| 240 |
expect_element4_connected_to_3_remotely_via_side_3(); |
| 241 |
expect_parallel_info_from_elem4_to_3(); |
| 242 |
} |
| 243 |
|
| 244 |
void check_element3_connected_to_element2_locally_and_element4_remotely() |
| 245 |
{ |
| 246 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 247 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(elem3)); |
| 248 |
expect_element3_connected_to_4_remotely_via_side_5(); |
| 249 |
expect_connected_to_local_elem_id_via_side(elem3, 2, 4); |
| 250 |
} |
| 251 |
|
| 252 |
void expect_element3_connected_to_4_remotely_via_side_5() |
| 253 |
{ |
| 254 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 255 |
expect_connected_to_remote_elem_id_via_side(elem3, 4, 5); |
| 256 |
expect_parallel_info_from_elem3_to_4(); |
| 257 |
} |
| 258 |
|
| 259 |
void expect_parallel_info_from_elem3_to_4() |
| 260 |
{ |
| 261 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 262 |
const stk::mesh::impl::ParallelInfo &parInfo = get_elem_graph().get_parallel_edge_info(elem3, 5, 4, 4); |
| 263 |
expect_otherProc_permutation_chosenId(parInfo, 1, 4); |
| 264 |
} |
| 265 |
|
| 266 |
void expect_element4_connected_to_3_remotely_via_side_3() |
| 267 |
{ |
| 268 |
stk::mesh::Entity elem4 = get_bulk().get_entity(stk::topology::ELEM_RANK, 4); |
| 269 |
ASSERT_EQ(1u, get_elem_graph().get_num_connected_elems(elem4)); |
| 270 |
expect_connected_to_remote_elem_id_via_side(elem4, 3, 4); |
| 271 |
} |
| 272 |
|
| 273 |
void expect_parallel_info_from_elem4_to_3() |
| 274 |
{ |
| 275 |
stk::mesh::Entity elem4 = get_bulk().get_entity(stk::topology::ELEM_RANK, 4); |
| 276 |
const stk::mesh::impl::ParallelInfo &parInfo = get_elem_graph().get_parallel_edge_info(elem4, 4, 3, 5); |
| 277 |
expect_otherProc_permutation_chosenId(parInfo, 0, 4); |
| 278 |
} |
| 279 |
}; |
| 280 |
TEST_F(ElemGraphChangeOwnerMoveFrom1To0, withAura) |
| 281 |
{ |
| 282 |
run_test_on_num_procs(2, stk::mesh::BulkData::AUTO_AURA); |
| 283 |
} |
| 284 |
TEST_F(ElemGraphChangeOwnerMoveFrom1To0, withoutAura) |
| 285 |
{ |
| 286 |
run_test_on_num_procs(2, stk::mesh::BulkData::NO_AUTO_AURA); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
class ElemGraphChangeOwnerMoveEverythingFromProc1 : public ElemGraphChangeOwner |
| 291 |
{ |
| 292 |
protected: |
| 293 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 294 |
{ |
| 295 |
setup_mesh("generated:1x1x4", auraOption); |
| 296 |
expect_graph_correct_after_moving_everything_to_proc0(); |
| 297 |
} |
| 298 |
void expect_graph_correct_after_moving_everything_to_proc0() |
| 299 |
{ |
| 300 |
create_elem_graph(); |
| 301 |
expect_initial_graph_correct(); |
| 302 |
move_elements({stk::mesh::EntityIdProc(3, 0), stk::mesh::EntityIdProc(4, 0)}); |
| 303 |
|
| 304 |
if (get_bulk().parallel_rank() == 0) { |
| 305 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 306 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(elem3)); |
| 307 |
expect_connected_to_local_elem_id_via_side(elem3, 2, 4); |
| 308 |
expect_connected_to_local_elem_id_via_side(elem3, 4, 5); |
| 309 |
} |
| 310 |
else { |
| 311 |
EXPECT_EQ(0u, get_elem_graph().num_edges()); |
| 312 |
EXPECT_EQ(0u, get_elem_graph().num_parallel_edges()); |
| 313 |
} |
| 314 |
} |
| 315 |
}; |
| 316 |
TEST_F(ElemGraphChangeOwnerMoveEverythingFromProc1, withAura) |
| 317 |
{ |
| 318 |
run_test_on_num_procs(2, stk::mesh::BulkData::AUTO_AURA); |
| 319 |
} |
| 320 |
TEST_F(ElemGraphChangeOwnerMoveEverythingFromProc1, withoutAura) |
| 321 |
{ |
| 322 |
run_test_on_num_procs(2, stk::mesh::BulkData::NO_AUTO_AURA); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
class ElemGraphChangeOwnerLeapFrog : public ElemGraphChangeOwner |
| 327 |
{ |
| 328 |
protected: |
| 329 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 330 |
{ |
| 331 |
setup_mesh("generated:1x1x6", auraOption); |
| 332 |
expect_graph_correct_after_leaps(); |
| 333 |
} |
| 334 |
void expect_graph_correct_after_leaps() |
| 335 |
{ |
| 336 |
create_elem_graph(); |
| 337 |
expect_initial_graph_correct(); |
| 338 |
move_elements({stk::mesh::EntityIdProc(2, 1), stk::mesh::EntityIdProc(3, 2)}); |
| 339 |
|
| 340 |
if (get_bulk().parallel_rank() == 1) { |
| 341 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 342 |
expect_connected_to_remote_elem_id_via_side(elem2, 3, 5); |
| 343 |
const stk::mesh::impl::ParallelInfo& parInfo = get_elem_graph().get_const_parallel_edge_info(elem2, 5, 3, 4); |
| 344 |
expect_otherProc_permutation_chosenId(parInfo, 2, 4); |
| 345 |
} |
| 346 |
else if (get_bulk().parallel_rank() == 2) { |
| 347 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 348 |
expect_connected_to_remote_elem_id_via_side(elem3, 2, 4); |
| 349 |
const stk::mesh::impl::ParallelInfo& parInfo = get_elem_graph().get_const_parallel_edge_info(elem3, 4, 2, 5); |
| 350 |
expect_otherProc_permutation_chosenId(parInfo, 1, 4); |
| 351 |
} |
| 352 |
} |
| 353 |
}; |
| 354 |
TEST_F(ElemGraphChangeOwnerLeapFrog, withAura) |
| 355 |
{ |
| 356 |
run_test_on_num_procs(3, stk::mesh::BulkData::AUTO_AURA); |
| 357 |
} |
| 358 |
TEST_F(ElemGraphChangeOwnerLeapFrog, withoutAura) |
| 359 |
{ |
| 360 |
run_test_on_num_procs(3, stk::mesh::BulkData::NO_AUTO_AURA); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
class ElemGraphChangeOwnerMoveNeighborsToEnd : public ElemGraphChangeOwner |
| 365 |
{ |
| 366 |
protected: |
| 367 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 368 |
{ |
| 369 |
setup_mesh("generated:1x1x6", auraOption); |
| 370 |
expect_graph_correct_after_moving_neighbors_to_last_proc(); |
| 371 |
} |
| 372 |
void expect_graph_correct_after_moving_neighbors_to_last_proc() |
| 373 |
{ |
| 374 |
create_elem_graph(); |
| 375 |
expect_initial_graph_correct(); |
| 376 |
move_elements({stk::mesh::EntityIdProc(2, 2), stk::mesh::EntityIdProc(3, 2)}); |
| 377 |
|
| 378 |
if (get_bulk().parallel_rank() == 2) { |
| 379 |
stk::mesh::Entity elem2 = get_bulk().get_entity(stk::topology::ELEM_RANK, 2); |
| 380 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 381 |
expect_connected_to_local_elem_id_via_side(elem2, 3, 5); |
| 382 |
expect_connected_to_local_elem_id_via_side(elem3, 2, 4); |
| 383 |
} |
| 384 |
} |
| 385 |
}; |
| 386 |
TEST_F(ElemGraphChangeOwnerMoveNeighborsToEnd, withAura) |
| 387 |
{ |
| 388 |
run_test_on_num_procs(3, stk::mesh::BulkData::AUTO_AURA); |
| 389 |
} |
| 390 |
TEST_F(ElemGraphChangeOwnerMoveNeighborsToEnd, withoutAura) |
| 391 |
{ |
| 392 |
run_test_on_num_procs(3, stk::mesh::BulkData::NO_AUTO_AURA); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
class ElemGraphChangeOwnerMoveNeighborsToDifferentProcs : public ElemGraphChangeOwner |
| 397 |
{ |
| 398 |
protected: |
| 399 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 400 |
{ |
| 401 |
setup_mesh_with_cyclic_decomp("1x2x2", auraOption); |
| 402 |
expect_mesh_created_correctly(); |
| 403 |
expect_graph_correct_after_moving_neighbors_to_different_procs(); |
| 404 |
} |
| 405 |
void expect_mesh_created_correctly() |
| 406 |
{ |
| 407 |
expect_element_on_proc(1, 0); |
| 408 |
expect_element_on_proc(2, 1); |
| 409 |
expect_element_on_proc(3, 2); |
| 410 |
expect_element_on_proc(4, 3); |
| 411 |
} |
| 412 |
void expect_element_on_proc(stk::mesh::EntityId id, int proc) |
| 413 |
{ |
| 414 |
if(get_bulk().parallel_rank() == proc) |
| 415 |
{ |
| 416 |
EXPECT_TRUE(is_owned_on_this_proc(get_bulk().get_entity(stk::topology::ELEMENT_RANK, id))); |
| 417 |
} |
| 418 |
} |
| 419 |
void expect_graph_correct_after_moving_neighbors_to_different_procs() |
| 420 |
{ |
| 421 |
create_elem_graph(); |
| 422 |
check_initial_graph(); |
| 423 |
move_elements({stk::mesh::EntityIdProc(1, 1), stk::mesh::EntityIdProc(3, 3)}); |
| 424 |
|
| 425 |
if (get_bulk().parallel_rank() == 1) { |
| 426 |
stk::mesh::Entity elem1 = get_bulk().get_entity(stk::topology::ELEM_RANK, 1); |
| 427 |
expect_connected_to_remote_elem_id_via_side(elem1, 3, 5); |
| 428 |
const stk::mesh::impl::ParallelInfo& parInfo = get_elem_graph().get_const_parallel_edge_info(elem1, 5, 3, 4); |
| 429 |
expect_otherProc_permutation_chosenId(parInfo, 3, 4); |
| 430 |
} |
| 431 |
else if (get_bulk().parallel_rank() == 3) { |
| 432 |
stk::mesh::Entity elem3 = get_bulk().get_entity(stk::topology::ELEM_RANK, 3); |
| 433 |
expect_connected_to_remote_elem_id_via_side(elem3, 1, 4); |
| 434 |
const stk::mesh::impl::ParallelInfo& parInfo = get_elem_graph().get_const_parallel_edge_info(elem3, 4, 1, 5); |
| 435 |
expect_otherProc_permutation_chosenId(parInfo, 1, 4); |
| 436 |
} |
| 437 |
} |
| 438 |
void check_initial_graph() |
| 439 |
{ |
| 440 |
expect_element1_connected_correctly(); |
| 441 |
expect_element2_connected_correctly(); |
| 442 |
} |
| 443 |
|
| 444 |
void expect_element1_connected_correctly() |
| 445 |
{ |
| 446 |
stk::mesh::Entity element1 = get_bulk().get_entity(stk::topology::ELEMENT_RANK, 1); |
| 447 |
if(is_owned_on_this_proc(element1)) |
| 448 |
expect_element1_connected_to_2_and_3(element1); |
| 449 |
} |
| 450 |
|
| 451 |
void expect_element1_connected_to_2_and_3(stk::mesh::Entity element1) |
| 452 |
{ |
| 453 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(element1)); |
| 454 |
expect_connected_to_remote_elem_id_on_proc(element1, 0, 2, 0, 1); |
| 455 |
expect_connected_to_remote_elem_id_on_proc(element1, 1, 3, 4, 2); |
| 456 |
} |
| 457 |
|
| 458 |
void expect_element2_connected_correctly() |
| 459 |
{ |
| 460 |
stk::mesh::Entity element2 = get_bulk().get_entity(stk::topology::ELEMENT_RANK, 2); |
| 461 |
if(is_owned_on_this_proc(element2)) |
| 462 |
expect_element2_connected_to_1_and_4(element2); |
| 463 |
} |
| 464 |
|
| 465 |
void expect_element2_connected_to_1_and_4(stk::mesh::Entity element2) |
| 466 |
{ |
| 467 |
ASSERT_EQ(2u, get_elem_graph().get_num_connected_elems(element2)); |
| 468 |
expect_connected_to_remote_elem_id_on_proc(element2, 0, 1, 2, 0); |
| 469 |
expect_connected_to_remote_elem_id_on_proc(element2, 1, 4, 4, 3); |
| 470 |
} |
| 471 |
|
| 472 |
void expect_connected_to_remote_elem_id_on_proc(stk::mesh::Entity elem, |
| 473 |
size_t connectedIndex, |
| 474 |
stk::mesh::EntityId connectedId, |
| 475 |
int side2, |
| 476 |
int expectedProc) |
| 477 |
{ |
| 478 |
expect_connected_to_remote_elem_id(elem, connectedIndex, connectedId); |
| 479 |
int side1 = get_elem_graph().get_connected_remote_id_and_via_side(elem, connectedIndex).side; |
| 480 |
const stk::mesh::impl::ParallelInfo &parInfo = get_elem_graph().get_parallel_edge_info(elem, side1, connectedId, side2); |
| 481 |
EXPECT_EQ(expectedProc, parInfo.get_proc_rank_of_neighbor()); |
| 482 |
} |
| 483 |
}; |
| 484 |
TEST_F(ElemGraphChangeOwnerMoveNeighborsToDifferentProcs, withAura) |
| 485 |
{ |
| 486 |
run_test_on_num_procs(4, stk::mesh::BulkData::AUTO_AURA); |
| 487 |
} |
| 488 |
TEST_F(ElemGraphChangeOwnerMoveNeighborsToDifferentProcs, withoutAura) |
| 489 |
{ |
| 490 |
run_test_on_num_procs(4, stk::mesh::BulkData::NO_AUTO_AURA); |
| 491 |
} |
| 492 |
|
| 493 |
std::shared_ptr<stk::mesh::BulkData> build_mesh(stk::ParallelMachine comm, |
| 494 |
stk::mesh::BulkData::AutomaticAuraOption auraOption, |
| 495 |
unsigned spatialDim = 0, |
| 496 |
const std::vector<std::string>& entityRankNames = std::vector<std::string>()) |
| 497 |
{ |
| 498 |
stk::mesh::MeshBuilder builder(comm); |
| 499 |
builder.set_spatial_dimension(spatialDim); |
| 500 |
builder.set_entity_rank_names(entityRankNames); |
| 501 |
builder.set_aura_option(auraOption); |
| 502 |
std::shared_ptr<stk::mesh::BulkData> bulk = builder.create(); |
| 503 |
return bulk; |
| 504 |
} |
| 505 |
|
| 506 |
void change_entity_owner_hex_test_2_procs(bool aura_on) |
| 507 |
{ |
| 508 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 509 |
int proc = stk::parallel_machine_rank(comm); |
| 510 |
|
| 511 |
if(stk::parallel_machine_size(comm) == 2) |
| 512 |
{ |
| 513 |
stk::mesh::BulkData::AutomaticAuraOption aura_option = stk::mesh::BulkData::AUTO_AURA; |
| 514 |
if (!aura_on) |
| 515 |
{ |
| 516 |
aura_option = stk::mesh::BulkData::NO_AUTO_AURA; |
| 517 |
} |
| 518 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(comm, aura_option); |
| 519 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 520 |
|
| 521 |
stk::io::fill_mesh("generated:1x1x4", bulkData); |
| 522 |
|
| 523 |
std::vector<size_t> counts; |
| 524 |
stk::mesh::count_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData, counts); |
| 525 |
int numLocallyOwnedElems = counts[stk::topology::ELEM_RANK]; |
| 526 |
EXPECT_EQ(2, numLocallyOwnedElems); |
| 527 |
|
| 528 |
ElemElemGraphTester elem_graph(bulkData); |
| 529 |
bulkData.register_observer(std::make_shared<stk::mesh::ElemElemGraphUpdater>(bulkData, elem_graph)); |
| 530 |
|
| 531 |
// Create a vector of the elements to be moved |
| 532 |
std::vector <stk::mesh::Entity> elems_to_move; |
| 533 |
|
| 534 |
stk::mesh::EntityId elem_2_id = 2; |
| 535 |
std::vector< std::pair< stk::mesh::Entity, int > > elem_proc_pairs_to_move; |
| 536 |
stk::mesh::Entity elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, elem_2_id); |
| 537 |
|
| 538 |
if (proc == 0) |
| 539 |
{ |
| 540 |
elems_to_move.push_back(elem_2); |
| 541 |
|
| 542 |
int other_proc = 1; |
| 543 |
for (unsigned i=0; i<elems_to_move.size(); i++) |
| 544 |
{ |
| 545 |
EXPECT_TRUE(bulkData.is_valid(elems_to_move[i])); |
| 546 |
EXPECT_EQ(0, bulkData.parallel_owner_rank(elems_to_move[i])); |
| 547 |
elem_proc_pairs_to_move.push_back(std::make_pair(elems_to_move[i], other_proc)); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
bulkData.change_entity_owner(elem_proc_pairs_to_move); |
| 552 |
|
| 553 |
elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, elem_2_id); |
| 554 |
|
| 555 |
if (proc == 0) |
| 556 |
{ |
| 557 |
ASSERT_THROW(elem_graph.get_parallel_edge_info(elem_2, 5, stk::mesh::EntityId(3), 4), std::logic_error); |
| 558 |
} |
| 559 |
|
| 560 |
if (proc == 1) |
| 561 |
{ |
| 562 |
EXPECT_TRUE(bulkData.is_valid(elem_2)); |
| 563 |
EXPECT_EQ(1, bulkData.parallel_owner_rank(elem_2)); |
| 564 |
|
| 565 |
EXPECT_EQ(2u, elem_graph.get_num_connected_elems(elem_2)); |
| 566 |
|
| 567 |
expect_elem_connected_to_remote_elem_id_via_side(bulkData, elem_graph, elem_2, 1, 4); |
| 568 |
expect_elem_connected_to_local_elem_id_via_side(bulkData, elem_graph, elem_2, 3, 5); |
| 569 |
|
| 570 |
stk::mesh::Entity elem_3 = bulkData.get_entity(stk::topology::ELEM_RANK, 3); |
| 571 |
ASSERT_THROW(elem_graph.get_parallel_edge_info(elem_3, 4, stk::mesh::EntityId(2), 5), std::logic_error); |
| 572 |
} |
| 573 |
|
| 574 |
EXPECT_EQ(1u, elem_graph.num_parallel_edges()); |
| 575 |
} |
| 576 |
} |
| 577 |
|
| 578 |
TEST(ElementGraph, test_change_entity_owner_2_procs_hex_mesh_with_aura) |
| 579 |
{ |
| 580 |
bool aura_on = true; |
| 581 |
change_entity_owner_hex_test_2_procs(aura_on); |
| 582 |
} |
| 583 |
|
| 584 |
TEST(ElementGraph, test_change_entity_owner_2_procs_hex_mesh_without_aura) |
| 585 |
{ |
| 586 |
bool aura_on = false; |
| 587 |
change_entity_owner_hex_test_2_procs(aura_on); |
| 588 |
} |
| 589 |
|
| 590 |
void change_entity_owner_then_death_hex_test_2_procs(bool aura_on) |
| 591 |
{ |
| 592 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 593 |
int proc = stk::parallel_machine_rank(comm); |
| 594 |
|
| 595 |
if(stk::parallel_machine_size(comm) == 2) |
| 596 |
{ |
| 597 |
unsigned spatial_dim = 3; |
| 598 |
stk::mesh::BulkData::AutomaticAuraOption aura_option = stk::mesh::BulkData::AUTO_AURA; |
| 599 |
if (!aura_on) |
| 600 |
{ |
| 601 |
aura_option = stk::mesh::BulkData::NO_AUTO_AURA; |
| 602 |
} |
| 603 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(comm, aura_option, spatial_dim, stk::mesh::entity_rank_names()); |
| 604 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 605 |
stk::mesh::MetaData& meta = bulkData.mesh_meta_data(); |
| 606 |
|
| 607 |
stk::mesh::Part& faces_part = meta.declare_part_with_topology("surface_5", stk::topology::QUAD_4); |
| 608 |
stk::mesh::Part& active = meta.declare_part("active", stk::topology::ELEMENT_RANK); |
| 609 |
stk::mesh::PartVector boundary_mesh_parts { &faces_part }; |
| 610 |
|
| 611 |
stk::io::fill_mesh("generated:1x1x4", bulkData); |
| 612 |
|
| 613 |
stk::unit_test_util::put_mesh_into_part(bulkData, active); |
| 614 |
|
| 615 |
std::vector<size_t> counts; |
| 616 |
stk::mesh::count_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData, counts); |
| 617 |
int numLocallyOwnedElems = counts[stk::topology::ELEM_RANK]; |
| 618 |
EXPECT_EQ(2, numLocallyOwnedElems); |
| 619 |
|
| 620 |
stk::mesh::ElemElemGraph &elem_graph = bulkData.get_face_adjacent_element_graph(); |
| 621 |
|
| 622 |
// Create a vector of the elements to be moved |
| 623 |
std::vector <stk::mesh::Entity> elems_to_move; |
| 624 |
|
| 625 |
stk::mesh::EntityId elem_2_id = 2; |
| 626 |
std::vector< std::pair< stk::mesh::Entity, int > > elem_proc_pairs_to_move; |
| 627 |
stk::mesh::Entity elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, elem_2_id); |
| 628 |
|
| 629 |
if (proc == 0) |
| 630 |
{ |
| 631 |
elems_to_move.push_back(elem_2); |
| 632 |
|
| 633 |
int other_proc = 1; |
| 634 |
for (unsigned i=0; i<elems_to_move.size(); i++) |
| 635 |
{ |
| 636 |
EXPECT_TRUE(bulkData.is_valid(elems_to_move[i])); |
| 637 |
EXPECT_EQ(0, bulkData.parallel_owner_rank(elems_to_move[i])); |
| 638 |
elem_proc_pairs_to_move.push_back(std::make_pair(elems_to_move[i], other_proc)); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
bulkData.change_entity_owner(elem_proc_pairs_to_move); |
| 643 |
|
| 644 |
elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, elem_2_id); |
| 645 |
|
| 646 |
stk::mesh::EntityVector killedElements; |
| 647 |
std::vector<stk::mesh::PartVector> add_parts, remove_parts; |
| 648 |
if (proc == 1) |
| 649 |
{ |
| 650 |
killedElements.push_back(elem_2); |
| 651 |
add_parts.push_back(stk::mesh::PartVector()); |
| 652 |
remove_parts.push_back(stk::mesh::PartVector{&active}); |
| 653 |
} |
| 654 |
|
| 655 |
bulkData.batch_change_entity_parts(killedElements, add_parts, remove_parts); |
| 656 |
boundary_mesh_parts.push_back(&active); |
| 657 |
|
| 658 |
stk::mesh::impl::ParallelSelectedInfo remoteActiveSelector; |
| 659 |
stk::mesh::impl::populate_selected_value_for_remote_elements(bulkData, elem_graph, bulkData.mesh_meta_data().universal_part(), remoteActiveSelector); |
| 660 |
|
| 661 |
process_killed_elements(bulkData, killedElements, active, remoteActiveSelector, boundary_mesh_parts, &boundary_mesh_parts); |
| 662 |
|
| 663 |
if (proc == 1) |
| 664 |
{ |
| 665 |
EXPECT_TRUE(bulkData.is_valid(elem_2)); |
| 666 |
EXPECT_EQ(1, bulkData.parallel_owner_rank(elem_2)); |
| 667 |
EXPECT_FALSE(bulkData.bucket(elem_2).member(active)); |
| 668 |
|
| 669 |
EXPECT_EQ(2u, elem_graph.get_num_connected_elems(elem_2)); |
| 670 |
|
| 671 |
expect_elem_connected_to_remote_elem_id_via_side(bulkData, elem_graph, elem_2, 1, 4); |
| 672 |
expect_elem_connected_to_local_elem_id_via_side(bulkData, elem_graph, elem_2, 3, 5); |
| 673 |
} |
| 674 |
if (proc == 0) |
| 675 |
{ |
| 676 |
EXPECT_FALSE(remoteActiveSelector[-2]); |
| 677 |
|
| 678 |
ASSERT_THROW(elem_graph.get_parallel_edge_info(elem_2, 5, stk::mesh::EntityId(3), 4), std::logic_error); |
| 679 |
} |
| 680 |
|
| 681 |
EXPECT_EQ(1u, elem_graph.num_parallel_edges()); |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
TEST(ElementGraph, test_change_entity_owner_and_death_hex_mesh_2_procs_with_aura) |
| 686 |
{ |
| 687 |
bool aura_on = true; |
| 688 |
change_entity_owner_then_death_hex_test_2_procs(aura_on); |
| 689 |
} |
| 690 |
|
| 691 |
TEST(ElementGraph, test_change_entity_owner_and_death_hex_mesh_2_procs_without_aura) |
| 692 |
{ |
| 693 |
bool aura_on = false; |
| 694 |
change_entity_owner_then_death_hex_test_2_procs(aura_on); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
void setup_hex_shell_hex_mesh(stk::mesh::BulkData& bulkData) |
| 699 |
{ |
| 700 |
// |
| 701 |
// proc 0 proc 1 proc 2 |
| 702 |
// |
| 703 |
// block_1 | block_2 | block_3 |
| 704 |
// |
| 705 |
// 3---------------7 7 7-------------11 |
| 706 |
// /| /| /| /| /| |
| 707 |
// / | / | / | / | / | |
| 708 |
// / | / | / | / | / | |
| 709 |
// 4--------------8 | 8 | 8--------------12 | |
| 710 |
// | | | | | | | | | | |
| 711 |
// | | 1 | | | 2 | | | 3 | | |
| 712 |
// | | | | | | | | | | |
| 713 |
// | 2----------|---6 | 6 | 6----------|---10 |
| 714 |
// | / | / | / | / | / |
| 715 |
// | / | / | / | / | / |
| 716 |
// |/ |/ |/ |/ |/ |
| 717 |
// 1--------------5 5 5--------------9 |
| 718 |
|
| 719 |
stk::mesh::MetaData& meta = bulkData.mesh_meta_data(); |
| 720 |
unsigned spatial_dimension = 3; |
| 721 |
meta.initialize(spatial_dimension, stk::mesh::entity_rank_names()); |
| 722 |
|
| 723 |
stk::mesh::Field<double>& field = meta.declare_field<double>(stk::topology::NODE_RANK, "field1"); |
| 724 |
stk::mesh::put_field_on_mesh(field, meta.universal_part(), nullptr); |
| 725 |
|
| 726 |
stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::HEX_8); |
| 727 |
stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", stk::topology::SHELL_QUAD_4); |
| 728 |
stk::mesh::Part& block_3 = meta.declare_part_with_topology("block_3", stk::topology::HEX_8); |
| 729 |
meta.commit(); |
| 730 |
|
| 731 |
bulkData.modification_begin(); |
| 732 |
|
| 733 |
stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4, 5, 6, 7, 8}; |
| 734 |
stk::mesh::EntityIdVector elem2_nodes {5, 6, 7, 8}; |
| 735 |
stk::mesh::EntityIdVector elem3_nodes {5, 6, 7, 8, 9, 10, 11, 12}; |
| 736 |
|
| 737 |
stk::mesh::EntityId elemId = 1; |
| 738 |
if (bulkData.parallel_rank() == 0) { |
| 739 |
stk::mesh::declare_element(bulkData, block_1, elemId, elem1_nodes); |
| 740 |
stk::mesh::Entity node5 = bulkData.get_entity(stk::topology::NODE_RANK, 5); |
| 741 |
stk::mesh::Entity node6 = bulkData.get_entity(stk::topology::NODE_RANK, 6); |
| 742 |
stk::mesh::Entity node7 = bulkData.get_entity(stk::topology::NODE_RANK, 7); |
| 743 |
stk::mesh::Entity node8 = bulkData.get_entity(stk::topology::NODE_RANK, 8); |
| 744 |
bulkData.add_node_sharing(node5, 1); |
| 745 |
bulkData.add_node_sharing(node6, 1); |
| 746 |
bulkData.add_node_sharing(node7, 1); |
| 747 |
bulkData.add_node_sharing(node8, 1); |
| 748 |
bulkData.add_node_sharing(node5, 2); |
| 749 |
bulkData.add_node_sharing(node6, 2); |
| 750 |
bulkData.add_node_sharing(node7, 2); |
| 751 |
bulkData.add_node_sharing(node8, 2); |
| 752 |
} |
| 753 |
else if (bulkData.parallel_rank() == 1) { |
| 754 |
elemId = 2; |
| 755 |
stk::mesh::declare_element(bulkData, block_2, elemId, elem2_nodes); |
| 756 |
stk::mesh::Entity node5 = bulkData.get_entity(stk::topology::NODE_RANK, 5); |
| 757 |
stk::mesh::Entity node6 = bulkData.get_entity(stk::topology::NODE_RANK, 6); |
| 758 |
stk::mesh::Entity node7 = bulkData.get_entity(stk::topology::NODE_RANK, 7); |
| 759 |
stk::mesh::Entity node8 = bulkData.get_entity(stk::topology::NODE_RANK, 8); |
| 760 |
bulkData.add_node_sharing(node5, 0); |
| 761 |
bulkData.add_node_sharing(node6, 0); |
| 762 |
bulkData.add_node_sharing(node7, 0); |
| 763 |
bulkData.add_node_sharing(node8, 0); |
| 764 |
bulkData.add_node_sharing(node5, 2); |
| 765 |
bulkData.add_node_sharing(node6, 2); |
| 766 |
bulkData.add_node_sharing(node7, 2); |
| 767 |
bulkData.add_node_sharing(node8, 2); |
| 768 |
} |
| 769 |
else if (bulkData.parallel_rank() == 2) { |
| 770 |
elemId = 3; |
| 771 |
stk::mesh::declare_element(bulkData, block_3, elemId, elem3_nodes); |
| 772 |
stk::mesh::Entity node5 = bulkData.get_entity(stk::topology::NODE_RANK, 5); |
| 773 |
stk::mesh::Entity node6 = bulkData.get_entity(stk::topology::NODE_RANK, 6); |
| 774 |
stk::mesh::Entity node7 = bulkData.get_entity(stk::topology::NODE_RANK, 7); |
| 775 |
stk::mesh::Entity node8 = bulkData.get_entity(stk::topology::NODE_RANK, 8); |
| 776 |
bulkData.add_node_sharing(node5, 0); |
| 777 |
bulkData.add_node_sharing(node6, 0); |
| 778 |
bulkData.add_node_sharing(node7, 0); |
| 779 |
bulkData.add_node_sharing(node8, 0); |
| 780 |
bulkData.add_node_sharing(node5, 1); |
| 781 |
bulkData.add_node_sharing(node6, 1); |
| 782 |
bulkData.add_node_sharing(node7, 1); |
| 783 |
bulkData.add_node_sharing(node8, 1); |
| 784 |
} |
| 785 |
|
| 786 |
bulkData.modification_end(); |
| 787 |
} |
| 788 |
|
| 789 |
void change_entity_owner_hex_shell_hex_test_3_procs(bool aura_on) |
| 790 |
{ |
| 791 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 792 |
int proc = stk::parallel_machine_rank(comm); |
| 793 |
if(stk::parallel_machine_size(comm) == 3) |
| 794 |
{ |
| 795 |
stk::mesh::BulkData::AutomaticAuraOption aura_option = stk::mesh::BulkData::AUTO_AURA; |
| 796 |
if (!aura_on) |
| 797 |
{ |
| 798 |
aura_option = stk::mesh::BulkData::NO_AUTO_AURA; |
| 799 |
} |
| 800 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(comm, aura_option); |
| 801 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 802 |
|
| 803 |
setup_hex_shell_hex_mesh(bulkData); |
| 804 |
|
| 805 |
bulkData.initialize_face_adjacent_element_graph(); |
| 806 |
stk::mesh::ElemElemGraph &elementGraph = bulkData.get_face_adjacent_element_graph(); |
| 807 |
|
| 808 |
const stk::mesh::Entity hex1 = bulkData.get_entity(stk::topology::ELEM_RANK, 1); |
| 809 |
const stk::mesh::Entity hex3 = bulkData.get_entity(stk::topology::ELEM_RANK, 3); |
| 810 |
const stk::mesh::Entity shell2 = bulkData.get_entity(stk::topology::ELEM_RANK, 2); |
| 811 |
|
| 812 |
if (proc == 0) { |
| 813 |
// Connectivity for Hex Element 1 |
| 814 |
EXPECT_EQ(1u, elementGraph.get_num_connected_elems(hex1)); |
| 815 |
EXPECT_EQ(5, elementGraph.get_connected_remote_id_and_via_side(hex1, 0).side); |
| 816 |
EXPECT_EQ(2u, elementGraph.get_connected_remote_id_and_via_side(hex1, 0).id); |
| 817 |
EXPECT_FALSE(elementGraph.is_connected_elem_locally_owned(hex1, 0)); |
| 818 |
EXPECT_EQ(1u, elementGraph.num_edges()); |
| 819 |
EXPECT_EQ(1u, elementGraph.num_parallel_edges()); |
| 820 |
} |
| 821 |
else if (proc == 1) { |
| 822 |
// Connectivity for Shell Element 2 |
| 823 |
unsigned hex1Index = 0; |
| 824 |
unsigned hex3Index = 1; |
| 825 |
EXPECT_EQ(2u, elementGraph.get_num_connected_elems(shell2)); |
| 826 |
EXPECT_EQ(0, elementGraph.get_connected_remote_id_and_via_side(shell2, hex3Index).side); |
| 827 |
EXPECT_EQ(1, elementGraph.get_connected_remote_id_and_via_side(shell2, hex1Index).side); |
| 828 |
EXPECT_EQ(3u, elementGraph.get_connected_remote_id_and_via_side(shell2, hex3Index).id); |
| 829 |
EXPECT_EQ(1u, elementGraph.get_connected_remote_id_and_via_side(shell2, hex1Index).id); |
| 830 |
EXPECT_FALSE(elementGraph.is_connected_elem_locally_owned(shell2, hex3Index)); |
| 831 |
EXPECT_FALSE(elementGraph.is_connected_elem_locally_owned(shell2, hex1Index)); |
| 832 |
EXPECT_EQ(2u, elementGraph.num_edges()); |
| 833 |
EXPECT_EQ(2u, elementGraph.num_parallel_edges()); |
| 834 |
} |
| 835 |
else if (proc == 2) { |
| 836 |
// Connectivity for Hex Element 3 |
| 837 |
EXPECT_EQ(1u, elementGraph.get_num_connected_elems(hex3)); |
| 838 |
EXPECT_EQ(4, elementGraph.get_connected_remote_id_and_via_side(hex3, 0).side); |
| 839 |
EXPECT_EQ(2u, elementGraph.get_connected_remote_id_and_via_side(hex3, 0).id); |
| 840 |
EXPECT_FALSE(elementGraph.is_connected_elem_locally_owned(hex3, 0)); |
| 841 |
EXPECT_EQ(1u, elementGraph.num_edges()); |
| 842 |
EXPECT_EQ(1u, elementGraph.num_parallel_edges()); |
| 843 |
} |
| 844 |
|
| 845 |
stk::mesh::EntityId elem_to_move_global_id = 2; |
| 846 |
std::vector< std::pair< stk::mesh::Entity, int > > elem_proc_pairs_to_move; |
| 847 |
stk::mesh::Entity elem_to_move = bulkData.get_entity(stk::topology::ELEM_RANK, elem_to_move_global_id); |
| 848 |
|
| 849 |
if (proc == 1) |
| 850 |
{ |
| 851 |
int destination_proc = 2; |
| 852 |
elem_proc_pairs_to_move.push_back(std::make_pair(elem_to_move, destination_proc)); |
| 853 |
} |
| 854 |
|
| 855 |
bulkData.change_entity_owner(elem_proc_pairs_to_move); |
| 856 |
|
| 857 |
std::vector<size_t> counts; |
| 858 |
stk::mesh::count_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData, counts); |
| 859 |
int numLocallyOwnedElemsInMesh = counts[stk::topology::ELEM_RANK]; |
| 860 |
|
| 861 |
size_t size_of_elem_graph = elementGraph.size(); |
| 862 |
|
| 863 |
if (proc == 0) |
| 864 |
{ |
| 865 |
EXPECT_EQ(1, numLocallyOwnedElemsInMesh); |
| 866 |
EXPECT_EQ(1u, size_of_elem_graph); |
| 867 |
|
| 868 |
stk::mesh::Entity elem_1 = bulkData.get_entity(stk::topology::ELEM_RANK, 1); |
| 869 |
stk::mesh::impl::ParallelInfo& elem1_to_elem2_info = elementGraph.get_parallel_edge_info(elem_1, 5, stk::mesh::EntityId(2), 1); |
| 870 |
EXPECT_EQ(2, elem1_to_elem2_info.get_proc_rank_of_neighbor()); |
| 871 |
EXPECT_EQ(1u, elementGraph.num_edges()); |
| 872 |
EXPECT_EQ(1u, elementGraph.num_parallel_edges()); |
| 873 |
} |
| 874 |
if (proc == 1) |
| 875 |
{ |
| 876 |
EXPECT_EQ(0, numLocallyOwnedElemsInMesh); |
| 877 |
EXPECT_EQ(0u, size_of_elem_graph); |
| 878 |
|
| 879 |
stk::mesh::Entity elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, 2); |
| 880 |
ASSERT_THROW(elementGraph.get_parallel_edge_info(elem_2, 1, stk::mesh::EntityId(1), 5), std::logic_error); |
| 881 |
|
| 882 |
ASSERT_THROW(elementGraph.get_parallel_edge_info(elem_2, 0, stk::mesh::EntityId(3), 4), std::logic_error); |
| 883 |
EXPECT_EQ(0u, elementGraph.num_edges()); |
| 884 |
EXPECT_EQ(0u, elementGraph.num_parallel_edges()); |
| 885 |
} |
| 886 |
if (proc == 2) |
| 887 |
{ |
| 888 |
EXPECT_EQ(2, numLocallyOwnedElemsInMesh); |
| 889 |
EXPECT_EQ(2u, size_of_elem_graph); |
| 890 |
|
| 891 |
stk::mesh::Entity elem_2 = bulkData.get_entity(stk::topology::ELEM_RANK, 2); |
| 892 |
stk::mesh::impl::ParallelInfo& elem2_to_elem1_info = elementGraph.get_parallel_edge_info(elem_2, 1, stk::mesh::EntityId(1), 5); |
| 893 |
EXPECT_EQ(0, elem2_to_elem1_info.get_proc_rank_of_neighbor()); |
| 894 |
EXPECT_EQ(3u, elementGraph.num_edges()); |
| 895 |
EXPECT_EQ(1u, elementGraph.num_parallel_edges()); |
| 896 |
} |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
TEST(ElementGraph, test_change_entity_owner_3_procs_hex_shell_hex_mesh_with_aura) |
| 901 |
{ |
| 902 |
bool aura_on = true; |
| 903 |
change_entity_owner_hex_shell_hex_test_3_procs(aura_on); |
| 904 |
} |
| 905 |
|
| 906 |
TEST(ElementGraph, test_change_entity_owner_3_procs_hex_shell_hex_mesh_without_aura) |
| 907 |
{ |
| 908 |
bool aura_on = false; |
| 909 |
change_entity_owner_hex_shell_hex_test_3_procs(aura_on); |
| 910 |
} |
| 911 |
|
| 912 |
void change_entity_owner_hex_test_4_procs(bool aura_on) |
| 913 |
{ |
| 914 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 915 |
int proc = stk::parallel_machine_rank(comm); |
| 916 |
std::vector<double> wall_times; |
| 917 |
wall_times.reserve(10); |
| 918 |
std::vector<std::string> msgs; |
| 919 |
msgs.reserve(10); |
| 920 |
|
| 921 |
std::vector<size_t> mem_usage; |
| 922 |
|
| 923 |
wall_times.push_back(stk::wall_time()); |
| 924 |
msgs.push_back("program-start"); |
| 925 |
mem_usage.push_back(stk::get_memory_usage_now()); |
| 926 |
|
| 927 |
if(stk::parallel_machine_size(comm) == 4) |
| 928 |
{ |
| 929 |
stk::mesh::BulkData::AutomaticAuraOption aura_option = stk::mesh::BulkData::AUTO_AURA; |
| 930 |
if (!aura_on) |
| 931 |
{ |
| 932 |
aura_option = stk::mesh::BulkData::NO_AUTO_AURA; |
| 933 |
} |
| 934 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(comm, aura_option); |
| 935 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 936 |
|
| 937 |
stk::io::fill_mesh("generated:1x1x4", bulkData); |
| 938 |
|
| 939 |
wall_times.push_back(stk::wall_time()); |
| 940 |
msgs.push_back("after mesh-read"); |
| 941 |
mem_usage.push_back(stk::get_memory_usage_now()); |
| 942 |
|
| 943 |
std::vector<size_t> counts; |
| 944 |
stk::mesh::count_entities(bulkData.mesh_meta_data().locally_owned_part(), bulkData, counts); |
| 945 |
int numLocallyOwnedElems = counts[stk::topology::ELEM_RANK]; |
| 946 |
EXPECT_EQ(1, numLocallyOwnedElems); |
| 947 |
|
| 948 |
stk::mesh::ElemElemGraph &elem_graph = bulkData.get_face_adjacent_element_graph(); |
| 949 |
|
| 950 |
wall_times.push_back(stk::wall_time()); |
| 951 |
msgs.push_back("after fill-graph"); |
| 952 |
mem_usage.push_back(stk::get_memory_usage_now()); |
| 953 |
|
| 954 |
// Create a vector of the elements to be moved |
| 955 |
std::vector <stk::mesh::Entity> elems_to_move; |
| 956 |
|
| 957 |
stk::mesh::EntityId elem_global_id = 2; |
| 958 |
std::vector< std::pair< stk::mesh::Entity, int > > elem_proc_pairs_to_move; |
| 959 |
stk::mesh::Entity elem_to_move = bulkData.get_entity(stk::topology::ELEM_RANK, elem_global_id); |
| 960 |
if (proc == 1) |
| 961 |
{ |
| 962 |
elems_to_move.push_back(elem_to_move); |
| 963 |
|
| 964 |
int other_proc = 2; |
| 965 |
for (unsigned i=0; i<elems_to_move.size(); i++) |
| 966 |
{ |
| 967 |
EXPECT_TRUE(bulkData.is_valid(elems_to_move[i])); |
| 968 |
EXPECT_EQ(1, bulkData.parallel_owner_rank(elems_to_move[i])); |
| 969 |
elem_proc_pairs_to_move.push_back(std::make_pair(elems_to_move[i], other_proc)); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
bulkData.change_entity_owner(elem_proc_pairs_to_move); |
| 974 |
|
| 975 |
elem_to_move = bulkData.get_entity(stk::topology::ELEM_RANK, elem_global_id); |
| 976 |
|
| 977 |
if (proc == 2) |
| 978 |
{ |
| 979 |
EXPECT_TRUE(bulkData.is_valid(elem_to_move)); |
| 980 |
EXPECT_EQ(2, bulkData.parallel_owner_rank(elem_to_move)); |
| 981 |
|
| 982 |
EXPECT_EQ(2u, elem_graph.get_num_connected_elems(elem_to_move)); |
| 983 |
|
| 984 |
expect_elem_connected_to_remote_elem_id_via_side(bulkData, elem_graph, elem_to_move, 1, 4); |
| 985 |
expect_elem_connected_to_local_elem_id_via_side(bulkData, elem_graph, elem_to_move, 3, 5); |
| 986 |
|
| 987 |
stk::mesh::Entity elem_3 = bulkData.get_entity(stk::topology::ELEM_RANK, 3); |
| 988 |
ASSERT_THROW(elem_graph.get_parallel_edge_info(elem_3, 4, stk::mesh::EntityId(2), 5), std::logic_error); |
| 989 |
|
| 990 |
EXPECT_EQ(2u, elem_graph.num_parallel_edges()); |
| 991 |
} |
| 992 |
else if (proc == 0) |
| 993 |
{ |
| 994 |
stk::mesh::Entity elem_1 = bulkData.get_entity(stk::topology::ELEM_RANK, 1); |
| 995 |
stk::mesh::impl::ParallelInfo &elem_1_to_2_p_info = elem_graph.get_parallel_edge_info(elem_1, 5, stk::mesh::EntityId(2), 4); |
| 996 |
EXPECT_EQ(2, elem_1_to_2_p_info.get_proc_rank_of_neighbor()); |
| 997 |
EXPECT_EQ(1u, elem_graph.num_parallel_edges()); |
| 998 |
} |
| 999 |
else if (proc == 1) |
| 1000 |
{ |
| 1001 |
EXPECT_EQ(0u, elem_graph.size()); |
| 1002 |
EXPECT_EQ(0u, elem_graph.num_edges()); |
| 1003 |
EXPECT_EQ(0u, elem_graph.num_parallel_edges()); |
| 1004 |
} |
| 1005 |
else if (proc == 3) |
| 1006 |
{ |
| 1007 |
EXPECT_EQ(1u, elem_graph.num_parallel_edges()); |
| 1008 |
} |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
TEST(ElementGraph, test_change_entity_owner_4_procs_hex_mesh_with_aura) |
| 1013 |
{ |
| 1014 |
bool aura_on = true; |
| 1015 |
change_entity_owner_hex_test_4_procs(aura_on); |
| 1016 |
} |
| 1017 |
|
| 1018 |
TEST(ElementGraph, test_change_entity_owner_4_procs_hex_mesh_without_aura) |
| 1019 |
{ |
| 1020 |
bool aura_on = false; |
| 1021 |
change_entity_owner_hex_test_4_procs(aura_on); |
| 1022 |
} |
| 1023 |
|
| 1024 |
} //namespace |