| 1 |
#include <gtest/gtest.h> |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
#include <algorithm> |
| 5 |
#include <functional> |
| 6 |
#include <numeric> |
| 7 |
#include <stdlib.h> |
| 8 |
|
| 9 |
#include <stk_topology/topology.hpp> |
| 10 |
#include <stk_mesh/base/BulkData.hpp> |
| 11 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 12 |
#include <stk_mesh/base/MetaData.hpp> |
| 13 |
#include <stk_mesh/base/Comm.hpp> |
| 14 |
#include <stk_mesh/base/GetEntities.hpp> |
| 15 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 16 |
#include <stk_mesh/baseImpl/MeshImplUtils.hpp> |
| 17 |
#include <stk_mesh/base/Field.hpp> |
| 18 |
#include <stk_mesh/base/SideSetEntry.hpp> |
| 19 |
#include <stk_mesh/base/SidesetUpdater.hpp> |
| 20 |
#include <stk_mesh/base/SkinMesh.hpp> |
| 21 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 22 |
#include <stk_mesh/base/CreateFaces.hpp> |
| 23 |
#include <stk_mesh/base/SkinMeshUtil.hpp> |
| 24 |
#include "stk_mesh/base/DestroyElements.hpp" // for destroy_elements_no_mod... |
| 25 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> |
| 26 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp> |
| 27 |
|
| 28 |
#include <stk_util/environment/memory_util.hpp> |
| 29 |
#include <stk_util/util/ReportHandler.hpp> |
| 30 |
|
| 31 |
#include <stk_io/IossBridge.hpp> |
| 32 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 33 |
|
| 34 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 35 |
#include <stk_unit_test_utils/getOption.h> |
| 36 |
|
| 37 |
#include "stk_unit_test_utils/ElemGraphTestUtils.hpp" |
| 38 |
#include "stk_unit_test_utils/unittestMeshUtils.hpp" |
| 39 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 40 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 41 |
|
| 42 |
namespace { |
| 43 |
|
| 44 |
using namespace stk::mesh::impl; |
| 45 |
using namespace stk::mesh; |
| 46 |
using stk::unit_test_util::build_mesh; |
| 47 |
|
| 48 |
struct ElementConnectivityInfo { |
| 49 |
ElementConnectivityInfo() |
| 50 |
: element(Entity()), ordinal(INVALID_CONNECTIVITY_ORDINAL), permutation(INVALID_PERMUTATION) |
| 51 |
{ }; |
| 52 |
ElementConnectivityInfo(Entity element_) |
| 53 |
: element(element_), ordinal(INVALID_CONNECTIVITY_ORDINAL), permutation(INVALID_PERMUTATION) |
| 54 |
{ } |
| 55 |
ElementConnectivityInfo(Entity element_, ConnectivityOrdinal ordinal_) |
| 56 |
: element(element_), ordinal(ordinal_), permutation(INVALID_PERMUTATION) |
| 57 |
{ } |
| 58 |
ElementConnectivityInfo(Entity element_, int ordinal_) |
| 59 |
: ElementConnectivityInfo(element_, static_cast<stk::mesh::ConnectivityOrdinal>(ordinal_)) |
| 60 |
{ } |
| 61 |
ElementConnectivityInfo(Entity element_, stk::mesh::ConnectivityOrdinal ordinal_, stk::mesh::Permutation permutation_) |
| 62 |
: element(element_), ordinal(ordinal_), permutation(permutation_) |
| 63 |
{ } |
| 64 |
ElementConnectivityInfo(Entity element_, stk::mesh::ConnectivityOrdinal ordinal_, int permutation_) |
| 65 |
: ElementConnectivityInfo(element_, ordinal_, static_cast<stk::mesh::Permutation>(permutation_)) |
| 66 |
{ } |
| 67 |
ElementConnectivityInfo(Entity element_, int ordinal_, int permutation_) |
| 68 |
: ElementConnectivityInfo(element_, static_cast<stk::mesh::ConnectivityOrdinal>(ordinal_), static_cast<stk::mesh::Permutation>(permutation_)) |
| 69 |
{ } |
| 70 |
|
| 71 |
stk::mesh::Entity element; |
| 72 |
stk::mesh::ConnectivityOrdinal ordinal; |
| 73 |
stk::mesh::Permutation permutation; |
| 74 |
}; |
| 75 |
|
| 76 |
using ConnectionTesterBeforeElementCreation = std::function<void(const stk::mesh::BulkData& bulk, |
| 77 |
const ElementConnectivityInfo& eci, |
| 78 |
stk::mesh::Entity face)>; |
| 79 |
using ConnectionTesterAfterElementCreation = std::function<void(const stk::mesh::BulkData& bulk, |
| 80 |
const ElementConnectivityInfo& eci1, |
| 81 |
const ElementConnectivityInfo& eci2, |
| 82 |
stk::mesh::Entity face)>; |
| 83 |
|
| 84 |
|
| 85 |
std::shared_ptr<stk::mesh::BulkData> |
| 86 |
setup_bulk_for_testing_connectivity_after_new_element_creation(unsigned spatialDimension, |
| 87 |
stk::ParallelMachine comm, |
| 88 |
stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::AUTO_AURA) |
| 89 |
{ |
| 90 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = stk::unit_test_util::build_mesh(spatialDimension, comm, auraOption); |
| 91 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 92 |
stk::mesh::MetaData& meta = bulk.mesh_meta_data(); |
| 93 |
|
| 94 |
if (!bulk.has_observer_type<stk::mesh::SidesetUpdater>()) { |
| 95 |
stk::mesh::Selector activeSelector = meta.universal_part(); |
| 96 |
|
| 97 |
bulk.register_observer(std::make_shared<stk::mesh::IncrementalSidesetUpdater>(bulk, activeSelector)); |
| 98 |
} |
| 99 |
|
| 100 |
return bulkPtr; |
| 101 |
} |
| 102 |
|
| 103 |
TEST(ElementFaceConnectivity, test_get_ordinals_without_connected_sides) |
| 104 |
{ |
| 105 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 106 |
if(stk::parallel_machine_size(comm) != 1) { |
| 107 |
GTEST_SKIP(); |
| 108 |
} |
| 109 |
|
| 110 |
const unsigned spatialDimension = 3; |
| 111 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 112 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 113 |
|
| 114 |
bulk.initialize_face_adjacent_element_graph(); |
| 115 |
|
| 116 |
stk::topology hex = stk::topology::HEX_8; |
| 117 |
stk::mesh::Part& block_1 = bulk.mesh_meta_data().declare_part_with_topology("block_1", hex); |
| 118 |
|
| 119 |
bulk.modification_begin(); |
| 120 |
stk::mesh::EntityIdVector elem1Nodes {1, 2, 3, 4, 5, 6, 7, 8}; |
| 121 |
stk::mesh::EntityId elem1Id = 1; |
| 122 |
stk::mesh::Entity elem1 = stk::mesh::declare_element(bulk, block_1, elem1Id, elem1Nodes); |
| 123 |
bulk.modification_end(); |
| 124 |
|
| 125 |
bulk.modification_begin(); |
| 126 |
stk::mesh::Entity face = bulk.declare_element_side(elem1, 5, stk::mesh::PartVector{}); |
| 127 |
bulk.modification_end(); |
| 128 |
|
| 129 |
EXPECT_TRUE(bulk.is_valid(face)); |
| 130 |
|
| 131 |
std::vector<stk::mesh::ConnectivityOrdinal> goldOrdinals{0, 1, 2, 3, 4}; |
| 132 |
auto ordinals = stk::mesh::impl::get_ordinals_without_connected_sides(bulk, elem1); |
| 133 |
|
| 134 |
EXPECT_EQ(goldOrdinals, ordinals); |
| 135 |
} |
| 136 |
|
| 137 |
void test_side_connectivity_before_new_element_creation(const stk::mesh::BulkData& mesh, |
| 138 |
const ElementConnectivityInfo& eci, |
| 139 |
stk::mesh::Entity face) |
| 140 |
{ |
| 141 |
const unsigned numSideElements = mesh.num_elements(face); |
| 142 |
const stk::mesh::Entity* sideElements = mesh.begin_elements(face); |
| 143 |
const stk::mesh::ConnectivityOrdinal * sideOrdinals = mesh.begin_element_ordinals(face); |
| 144 |
const stk::mesh::Permutation * sidePermutations = mesh.begin_element_permutations(face); |
| 145 |
|
| 146 |
EXPECT_EQ(1u, numSideElements); |
| 147 |
EXPECT_EQ(eci.element, sideElements[0]); |
| 148 |
|
| 149 |
stk::topology elemTopo = mesh.bucket(sideElements[0]).topology(); |
| 150 |
stk::mesh::EntityRank rank = mesh.entity_rank(face); |
| 151 |
|
| 152 |
unsigned ordinal = elemTopo.side_ordinal(sideOrdinals[0], rank); |
| 153 |
|
| 154 |
EXPECT_EQ(eci.ordinal, ordinal); |
| 155 |
EXPECT_EQ(eci.permutation, sidePermutations[0]); |
| 156 |
} |
| 157 |
|
| 158 |
void test_side_connectivity_after_new_element_creation(const stk::mesh::BulkData& mesh, |
| 159 |
const ElementConnectivityInfo& eci1, |
| 160 |
const ElementConnectivityInfo& eci2, |
| 161 |
stk::mesh::Entity face) |
| 162 |
{ |
| 163 |
const unsigned numSideElements = mesh.num_elements(face); |
| 164 |
const stk::mesh::Entity* sideElements = mesh.begin_elements(face); |
| 165 |
const stk::mesh::ConnectivityOrdinal * sideOrdinals = mesh.begin_element_ordinals(face); |
| 166 |
const stk::mesh::Permutation * sidePermutations = mesh.begin_element_permutations(face); |
| 167 |
|
| 168 |
EXPECT_EQ(2u, numSideElements); |
| 169 |
|
| 170 |
EXPECT_TRUE(eci1.element == sideElements[0] || eci2.element == sideElements[0]); |
| 171 |
EXPECT_TRUE(eci1.element == sideElements[1] || eci2.element == sideElements[1]); |
| 172 |
|
| 173 |
unsigned index1 = 0; |
| 174 |
unsigned index2 = 1; |
| 175 |
|
| 176 |
if(eci1.element == sideElements[1]) { |
| 177 |
index1 = 1; |
| 178 |
index2 = 0; |
| 179 |
} |
| 180 |
|
| 181 |
EXPECT_EQ(eci1.element, sideElements[index1]); |
| 182 |
EXPECT_EQ(eci2.element, sideElements[index2]); |
| 183 |
|
| 184 |
stk::topology elemTopo1 = mesh.bucket(sideElements[index1]).topology(); |
| 185 |
stk::topology elemTopo2 = mesh.bucket(sideElements[index2]).topology(); |
| 186 |
|
| 187 |
stk::mesh::EntityRank rank = mesh.entity_rank(face); |
| 188 |
|
| 189 |
unsigned ordinal1 = elemTopo1.side_ordinal(sideOrdinals[index1], rank); |
| 190 |
unsigned ordinal2 = elemTopo2.side_ordinal(sideOrdinals[index2], rank); |
| 191 |
|
| 192 |
EXPECT_EQ(eci1.ordinal, ordinal1); |
| 193 |
EXPECT_EQ(eci2.ordinal, ordinal2); |
| 194 |
|
| 195 |
EXPECT_EQ(eci1.permutation, sidePermutations[index1]); |
| 196 |
EXPECT_EQ(eci2.permutation, sidePermutations[index2]); |
| 197 |
} |
| 198 |
|
| 199 |
void run_hex_face_connectivity_after_new_element_creation(stk::mesh::BulkData& bulk, |
| 200 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation, |
| 201 |
ConnectionTesterAfterElementCreation testAfterElementCreation) |
| 202 |
{ |
| 203 |
stk::topology hex = stk::topology::HEX_8; |
| 204 |
stk::mesh::Part& block_1 = bulk.mesh_meta_data().declare_part_with_topology("block_1", hex); |
| 205 |
|
| 206 |
bulk.modification_begin(); |
| 207 |
stk::mesh::EntityIdVector elem1Nodes {1, 2, 3, 4, 5, 6, 7, 8}; |
| 208 |
stk::mesh::EntityId elem1Id = 1; |
| 209 |
stk::mesh::Entity elem1 = stk::mesh::declare_element(bulk, block_1, elem1Id, elem1Nodes); |
| 210 |
bulk.modification_end(); |
| 211 |
|
| 212 |
bulk.modification_begin(); |
| 213 |
stk::mesh::Entity face = bulk.declare_element_side(elem1, 5, stk::mesh::PartVector{}); |
| 214 |
bulk.modification_end(); |
| 215 |
|
| 216 |
EXPECT_EQ(stk::topology::FACE_RANK, bulk.entity_rank(face)); |
| 217 |
|
| 218 |
int ordinal1 = 5; |
| 219 |
int permutation1 = 0; |
| 220 |
ElementConnectivityInfo eci1(elem1, ordinal1, permutation1); |
| 221 |
testBeforeElementCreation(bulk, eci1, face); |
| 222 |
|
| 223 |
bulk.modification_begin(); |
| 224 |
stk::mesh::EntityIdVector elem2Nodes {5, 6, 7, 8, 9, 10, 11, 12}; |
| 225 |
stk::mesh::EntityId elem2Id = 2; |
| 226 |
stk::mesh::Entity elem2 = stk::mesh::declare_element(bulk, block_1, elem2Id, elem2Nodes); |
| 227 |
bulk.modification_end(); |
| 228 |
|
| 229 |
bulk.modification_begin(); |
| 230 |
// Do this in different mod cycle so that the element has chance to be in the graph |
| 231 |
stk::mesh::impl::connect_element_to_existing_sides(bulk, elem2); |
| 232 |
bulk.modification_end(); |
| 233 |
|
| 234 |
int ordinal2 = 4; |
| 235 |
int permutation2 = 4; |
| 236 |
ElementConnectivityInfo eci2(elem2, ordinal2, permutation2); |
| 237 |
testAfterElementCreation(bulk, eci1, eci2, face); |
| 238 |
} |
| 239 |
|
| 240 |
TEST(ElementFaceConnectivity, test_hex_face_connectivity_after_new_element_creation_with_graph) |
| 241 |
{ |
| 242 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 243 |
if(stk::parallel_machine_size(comm) != 1) { |
| 244 |
GTEST_SKIP(); |
| 245 |
} |
| 246 |
|
| 247 |
const unsigned spatialDimension = 3; |
| 248 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 249 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 250 |
|
| 251 |
bulk.initialize_face_adjacent_element_graph(); |
| 252 |
const stk::mesh::ElemElemGraph& graph = bulk.get_face_adjacent_element_graph(); |
| 253 |
|
| 254 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation = |
| 255 |
[&graph](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci, stk::mesh::Entity face) { |
| 256 |
test_side_connectivity_before_new_element_creation(mesh, eci, face); |
| 257 |
ASSERT_EQ(1u, graph.size()); |
| 258 |
ASSERT_EQ(0u, graph.get_num_connected_elems(eci.element)); |
| 259 |
}; |
| 260 |
|
| 261 |
ConnectionTesterAfterElementCreation testAfterElementCreation = |
| 262 |
[&graph](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci1, const ElementConnectivityInfo& eci2, stk::mesh::Entity face) { |
| 263 |
test_side_connectivity_after_new_element_creation(mesh, eci1, eci2, face); |
| 264 |
ASSERT_EQ(2u, graph.size()); |
| 265 |
ASSERT_EQ(1u, graph.get_num_connected_elems(eci1.element)); |
| 266 |
ASSERT_EQ(1u, graph.get_num_connected_elems(eci2.element)); |
| 267 |
}; |
| 268 |
|
| 269 |
run_hex_face_connectivity_after_new_element_creation(bulk, testBeforeElementCreation, testAfterElementCreation); |
| 270 |
} |
| 271 |
|
| 272 |
TEST(ElementFaceConnectivity, test_hex_face_connectivity_after_new_element_creation_no_graph) |
| 273 |
{ |
| 274 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 275 |
if(stk::parallel_machine_size(comm) != 1) { |
| 276 |
GTEST_SKIP(); |
| 277 |
} |
| 278 |
|
| 279 |
const unsigned spatialDimension = 3; |
| 280 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 281 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 282 |
|
| 283 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation = |
| 284 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci, stk::mesh::Entity face) { |
| 285 |
test_side_connectivity_before_new_element_creation(mesh, eci, face); |
| 286 |
}; |
| 287 |
|
| 288 |
ConnectionTesterAfterElementCreation testAfterElementCreation = |
| 289 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci1, const ElementConnectivityInfo& eci2, stk::mesh::Entity face) { |
| 290 |
test_side_connectivity_after_new_element_creation(mesh, eci1, eci2, face); |
| 291 |
}; |
| 292 |
|
| 293 |
run_hex_face_connectivity_after_new_element_creation(bulk, testBeforeElementCreation, testAfterElementCreation); |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
void run_shell_face_connectivity_after_new_element_creation(stk::mesh::BulkData& bulk, |
| 298 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation, |
| 299 |
ConnectionTesterAfterElementCreation testAfterElementCreation) |
| 300 |
{ |
| 301 |
/* shell-quad-4 mesh: */ |
| 302 |
/* */ |
| 303 |
/* */ |
| 304 |
/* 4*-----*3----*6 */ |
| 305 |
/* | | | */ |
| 306 |
/* | | | */ |
| 307 |
/* 1*-----*2----*5 */ |
| 308 |
/* */ |
| 309 |
|
| 310 |
stk::topology shell4 = stk::topology::SHELL_QUAD_4_ALL_FACE_SIDES; |
| 311 |
stk::mesh::Part& block_1 = bulk.mesh_meta_data().declare_part_with_topology("block_1", shell4); |
| 312 |
|
| 313 |
bulk.modification_begin(); |
| 314 |
stk::mesh::EntityIdVector elem1Nodes {1, 2, 3, 4}; |
| 315 |
stk::mesh::EntityId elem1Id = 1; |
| 316 |
stk::mesh::Entity elem1 = stk::mesh::declare_element(bulk, block_1, elem1Id, elem1Nodes); |
| 317 |
bulk.modification_end(); |
| 318 |
|
| 319 |
bulk.modification_begin(); |
| 320 |
stk::mesh::Entity face = bulk.declare_element_side(elem1, 3, stk::mesh::PartVector{}); |
| 321 |
bulk.modification_end(); |
| 322 |
|
| 323 |
EXPECT_EQ(stk::topology::FACE_RANK, bulk.entity_rank(face)); |
| 324 |
|
| 325 |
int ordinal1 = 3; |
| 326 |
int permutation1 = 0; |
| 327 |
ElementConnectivityInfo eci1(elem1, ordinal1, permutation1); |
| 328 |
testBeforeElementCreation(bulk, eci1, face); |
| 329 |
|
| 330 |
bulk.modification_begin(); |
| 331 |
stk::mesh::EntityIdVector elem2Nodes {2, 5, 6, 3}; |
| 332 |
stk::mesh::EntityId elem2Id = 2; |
| 333 |
stk::mesh::Entity elem2 = stk::mesh::declare_element(bulk, block_1, elem2Id, elem2Nodes); |
| 334 |
bulk.modification_end(); |
| 335 |
|
| 336 |
bulk.modification_begin(); |
| 337 |
// Do this in different mod cycle so that the element has chance to be in the graph |
| 338 |
stk::mesh::impl::connect_element_to_existing_sides(bulk, elem2); |
| 339 |
bulk.modification_end(); |
| 340 |
|
| 341 |
int ordinal2 = 5; |
| 342 |
int permutation2 = 1; |
| 343 |
ElementConnectivityInfo eci2(elem2, ordinal2, permutation2); |
| 344 |
testAfterElementCreation(bulk, eci1, eci2, face); |
| 345 |
} |
| 346 |
|
| 347 |
TEST(ElementFaceConnectivity, test_paved_shell_face_connectivity_after_new_element_creation_no_graph) |
| 348 |
{ |
| 349 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 350 |
if(stk::parallel_machine_size(comm) != 1) { |
| 351 |
GTEST_SKIP(); |
| 352 |
} |
| 353 |
|
| 354 |
const unsigned spatialDimension = 3; |
| 355 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 356 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 357 |
|
| 358 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation = |
| 359 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci, stk::mesh::Entity face) { |
| 360 |
test_side_connectivity_before_new_element_creation(mesh, eci, face); |
| 361 |
}; |
| 362 |
|
| 363 |
ConnectionTesterAfterElementCreation testAfterElementCreation = |
| 364 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci1, const ElementConnectivityInfo& eci2, stk::mesh::Entity face) { |
| 365 |
test_side_connectivity_after_new_element_creation(mesh, eci1, eci2, face); |
| 366 |
}; |
| 367 |
|
| 368 |
run_shell_face_connectivity_after_new_element_creation(bulk, testBeforeElementCreation, testAfterElementCreation); |
| 369 |
} |
| 370 |
|
| 371 |
void run_shell_edge_connectivity_after_new_element_creation(stk::mesh::BulkData& bulk, |
| 372 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation, |
| 373 |
ConnectionTesterAfterElementCreation testAfterElementCreation) |
| 374 |
{ |
| 375 |
/* shell-quad-4 mesh: */ |
| 376 |
/* */ |
| 377 |
/* */ |
| 378 |
/* 4*-----*3----*6 */ |
| 379 |
/* | | | */ |
| 380 |
/* | | | */ |
| 381 |
/* 1*-----*2----*5 */ |
| 382 |
/* */ |
| 383 |
|
| 384 |
stk::topology shell4 = stk::topology::SHELL_QUAD_4; |
| 385 |
stk::mesh::Part& block_1 = bulk.mesh_meta_data().declare_part_with_topology("block_1", shell4); |
| 386 |
|
| 387 |
bulk.modification_begin(); |
| 388 |
stk::mesh::EntityIdVector elem1Nodes {1, 2, 3, 4}; |
| 389 |
stk::mesh::EntityId elem1Id = 1; |
| 390 |
stk::mesh::Entity elem1 = stk::mesh::declare_element(bulk, block_1, elem1Id, elem1Nodes); |
| 391 |
bulk.modification_end(); |
| 392 |
|
| 393 |
bulk.modification_begin(); |
| 394 |
stk::mesh::Entity edge = bulk.declare_element_side(elem1, 3, stk::mesh::PartVector{}); |
| 395 |
bulk.modification_end(); |
| 396 |
|
| 397 |
EXPECT_EQ(stk::topology::EDGE_RANK, bulk.entity_rank(edge)); |
| 398 |
|
| 399 |
int ordinal1 = 3; |
| 400 |
int permutation1 = 0; |
| 401 |
ElementConnectivityInfo eci1(elem1, ordinal1, permutation1); |
| 402 |
testBeforeElementCreation(bulk, eci1, edge); |
| 403 |
|
| 404 |
bulk.modification_begin(); |
| 405 |
stk::mesh::EntityIdVector elem2Nodes {2, 5, 6, 3}; |
| 406 |
stk::mesh::EntityId elem2Id = 2; |
| 407 |
stk::mesh::Entity elem2 = stk::mesh::declare_element(bulk, block_1, elem2Id, elem2Nodes); |
| 408 |
bulk.modification_end(); |
| 409 |
|
| 410 |
bulk.modification_begin(); |
| 411 |
// Do this in different mod cycle so that the element has chance to be in the graph |
| 412 |
stk::mesh::impl::connect_element_to_existing_sides(bulk, elem2); |
| 413 |
bulk.modification_end(); |
| 414 |
|
| 415 |
int ordinal2 = 5; |
| 416 |
int permutation2 = 1; |
| 417 |
ElementConnectivityInfo eci2(elem2, ordinal2, permutation2); |
| 418 |
testAfterElementCreation(bulk, eci1, eci2, edge); |
| 419 |
} |
| 420 |
|
| 421 |
TEST(ElementFaceConnectivity, test_paved_shell_edge_connectivity_after_new_element_creation_no_graph) |
| 422 |
{ |
| 423 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 424 |
if(stk::parallel_machine_size(comm) != 1) { |
| 425 |
GTEST_SKIP(); |
| 426 |
} |
| 427 |
|
| 428 |
const unsigned spatialDimension = 3; |
| 429 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 430 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 431 |
|
| 432 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation = |
| 433 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci, stk::mesh::Entity side) { |
| 434 |
test_side_connectivity_before_new_element_creation(mesh, eci, side); |
| 435 |
}; |
| 436 |
|
| 437 |
ConnectionTesterAfterElementCreation testAfterElementCreation = |
| 438 |
[](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci1, const ElementConnectivityInfo& eci2, stk::mesh::Entity side) { |
| 439 |
test_side_connectivity_after_new_element_creation(mesh, eci1, eci2, side); |
| 440 |
}; |
| 441 |
|
| 442 |
run_shell_edge_connectivity_after_new_element_creation(bulk, testBeforeElementCreation, testAfterElementCreation); |
| 443 |
} |
| 444 |
|
| 445 |
TEST(ElementFaceConnectivity, test_paved_shell_edge_connectivity_after_new_element_creation_with_graph) |
| 446 |
{ |
| 447 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 448 |
if(stk::parallel_machine_size(comm) != 1) { |
| 449 |
GTEST_SKIP(); |
| 450 |
} |
| 451 |
|
| 452 |
const unsigned spatialDimension = 3; |
| 453 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm); |
| 454 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 455 |
|
| 456 |
bulk.initialize_face_adjacent_element_graph(); |
| 457 |
const stk::mesh::ElemElemGraph& graph = bulk.get_face_adjacent_element_graph(); |
| 458 |
|
| 459 |
ConnectionTesterBeforeElementCreation testBeforeElementCreation = |
| 460 |
[&graph](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci, stk::mesh::Entity side) { |
| 461 |
test_side_connectivity_before_new_element_creation(mesh, eci, side); |
| 462 |
ASSERT_EQ(1u, graph.size()); |
| 463 |
ASSERT_EQ(0u, graph.get_num_connected_elems(eci.element)); |
| 464 |
}; |
| 465 |
|
| 466 |
ConnectionTesterAfterElementCreation testAfterElementCreation = |
| 467 |
[&graph](const stk::mesh::BulkData& mesh, const ElementConnectivityInfo& eci1, const ElementConnectivityInfo& eci2, stk::mesh::Entity side) { |
| 468 |
test_side_connectivity_after_new_element_creation(mesh, eci1, eci2, side); |
| 469 |
ASSERT_EQ(2u, graph.size()); |
| 470 |
ASSERT_EQ(1u, graph.get_num_connected_elems(eci1.element)); |
| 471 |
ASSERT_EQ(1u, graph.get_num_connected_elems(eci2.element)); |
| 472 |
}; |
| 473 |
|
| 474 |
run_shell_edge_connectivity_after_new_element_creation(bulk, testBeforeElementCreation, testAfterElementCreation); |
| 475 |
} |
| 476 |
|
| 477 |
bool element_external_faces(const stk::mesh::BulkData& mesh, const stk::mesh::Selector& selector, |
| 478 |
const stk::mesh::Entity elem, std::vector<bool>& faceIsExternal) |
| 479 |
{ |
| 480 |
// SM code to figure out external faces to create shell contact elements on |
| 481 |
faceIsExternal.clear(); |
| 482 |
const stk::topology elemTopology = mesh.bucket(elem).topology(); |
| 483 |
const unsigned num_node = elemTopology.num_nodes(); |
| 484 |
const unsigned num_face = elemTopology.num_faces(); |
| 485 |
stk::mesh::Entity const* nodes = mesh.begin_nodes(elem); |
| 486 |
std::vector<std::set<stk::mesh::EntityId> > connElems(num_node); |
| 487 |
bool hasExternal = false; |
| 488 |
|
| 489 |
for (unsigned n = 0; n < num_node; ++n) { |
| 490 |
stk::mesh::Entity node = nodes[n]; |
| 491 |
stk::mesh::Entity const* conn_elems = mesh.begin_elements(node); |
| 492 |
unsigned num_conn_elems = mesh.num_elements(node); |
| 493 |
std::set<stk::mesh::EntityId> conn_elem_ids; |
| 494 |
for (unsigned ie = 0; ie < num_conn_elems; ++ie) { |
| 495 |
if (selector(mesh.bucket(elem))) { |
| 496 |
conn_elem_ids.insert(mesh.identifier(conn_elems[ie])); |
| 497 |
} |
| 498 |
} |
| 499 |
connElems[n] = conn_elem_ids; |
| 500 |
} |
| 501 |
for (unsigned iface = 0; iface < num_face; ++iface) { |
| 502 |
stk::topology face_topology = elemTopology.face_topology(iface); |
| 503 |
const unsigned num_nodes_per_face = face_topology.num_nodes(); |
| 504 |
STK_ThrowAssert(num_nodes_per_face <= 4); |
| 505 |
unsigned faceNodeIndex[4]; |
| 506 |
elemTopology.face_node_ordinals(iface, faceNodeIndex); |
| 507 |
std::map<stk::mesh::EntityId, unsigned> elemIdFoundCount; |
| 508 |
for (unsigned inode = 0; inode < num_nodes_per_face; ++inode) { |
| 509 |
std::set<stk::mesh::EntityId>& connElemIDs = connElems[faceNodeIndex[inode]]; |
| 510 |
for (stk::mesh::EntityId gid : connElemIDs) { |
| 511 |
if (elemIdFoundCount.find(gid) != elemIdFoundCount.end()) { |
| 512 |
elemIdFoundCount[gid] += 1; |
| 513 |
} else { |
| 514 |
elemIdFoundCount[gid] = 1; |
| 515 |
} |
| 516 |
} |
| 517 |
} |
| 518 |
unsigned numCommon = 0; |
| 519 |
for (auto& m : elemIdFoundCount) { |
| 520 |
if (m.second == num_nodes_per_face) { |
| 521 |
numCommon += 1; |
| 522 |
} |
| 523 |
} |
| 524 |
if (numCommon == 1) { |
| 525 |
faceIsExternal.push_back(true); |
| 526 |
hasExternal = true; |
| 527 |
} else { |
| 528 |
faceIsExternal.push_back(false); |
| 529 |
} |
| 530 |
} |
| 531 |
return hasExternal; |
| 532 |
} |
| 533 |
|
| 534 |
void delete_created_external_shells(stk::mesh::BulkData& bulk, std::vector<stk::mesh::Entity>& createdElems) |
| 535 |
{ |
| 536 |
stk::mesh::Selector orphansToDelete; |
| 537 |
bulk.modification_begin(); |
| 538 |
stk::mesh::destroy_elements_no_mod_cycle(bulk, createdElems, orphansToDelete); |
| 539 |
bulk.modification_end(); |
| 540 |
} |
| 541 |
|
| 542 |
// map the nodes of a tri3 to degenerated quad4 |
| 543 |
constexpr unsigned subQuadToTriNodeMap[] = {0, 1, 2, 2}; |
| 544 |
|
| 545 |
void create_external_shell(stk::mesh::BulkData& bulk, |
| 546 |
const stk::mesh::Entity elem, |
| 547 |
const std::vector<bool>& faceExternal, |
| 548 |
stk::mesh::Part& blockPart, |
| 549 |
const std::vector<unsigned>& shellElemIds, |
| 550 |
std::vector<stk::mesh::Entity>& createdElems) |
| 551 |
{ |
| 552 |
stk::topology const elemTopology = bulk.bucket(elem).topology(); |
| 553 |
|
| 554 |
std::vector<stk::mesh::Relation> nodeRelations; |
| 555 |
stk::mesh::EntityIdVector nodeIds; |
| 556 |
|
| 557 |
const stk::mesh::Entity* const elemNodes = bulk.begin_nodes(elem); |
| 558 |
const unsigned num_face = elemTopology.num_faces(); |
| 559 |
for (unsigned iface = 0; iface < num_face; ++iface) { |
| 560 |
stk::topology faceTopology = elemTopology.face_topology(iface); |
| 561 |
STK_ThrowRequire(faceTopology == stk::topology::TRI_3 || faceTopology == stk::topology::QUAD_4); |
| 562 |
|
| 563 |
const unsigned numContSurfNodes = faceTopology.num_nodes(); |
| 564 |
nodeRelations.reserve(numContSurfNodes); |
| 565 |
|
| 566 |
unsigned faceNodeIndex[4]; |
| 567 |
elemTopology.face_node_ordinals(iface, faceNodeIndex); |
| 568 |
if (faceExternal[iface]) { |
| 569 |
nodeRelations.clear(); |
| 570 |
nodeIds.clear(); |
| 571 |
if (faceTopology == stk::topology::TRI_3) { |
| 572 |
for (unsigned inod = 0; inod < numContSurfNodes; ++inod) { |
| 573 |
auto node = elemNodes[faceNodeIndex[subQuadToTriNodeMap[inod]]]; |
| 574 |
nodeRelations.emplace_back(stk::topology::NODE_RANK, node, stk::mesh::RelationType::USES, inod); |
| 575 |
nodeIds.push_back(bulk.identifier(node)); |
| 576 |
} |
| 577 |
} else { |
| 578 |
for (unsigned inod = 0; inod < numContSurfNodes; ++inod) { |
| 579 |
auto node = elemNodes[faceNodeIndex[inod]]; |
| 580 |
nodeRelations.emplace_back(stk::topology::NODE_RANK, node, stk::mesh::RelationType::USES, inod); |
| 581 |
nodeIds.push_back(bulk.identifier(node)); |
| 582 |
} |
| 583 |
} |
| 584 |
std::cout << "P" << bulk.parallel_rank() << ": Creating external shell with id: " |
| 585 |
<< shellElemIds[iface] << " on face: " << iface << " of element: " << bulk.identifier(elem) << std::endl; |
| 586 |
|
| 587 |
auto elem = stk::mesh::declare_element(bulk, blockPart, shellElemIds[iface], nodeIds); |
| 588 |
createdElems.push_back(elem); |
| 589 |
} |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
TEST(ElementFaceConnectivity, test_SM_create_shell_and_delete_on_external_side) |
| 594 |
{ |
| 595 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 596 |
if(stk::parallel_machine_size(comm) != 2) { |
| 597 |
GTEST_SKIP(); |
| 598 |
} |
| 599 |
|
| 600 |
const unsigned spatialDimension = 3; |
| 601 |
auto auraOption = stk::mesh::BulkData::NO_AUTO_AURA; |
| 602 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = setup_bulk_for_testing_connectivity_after_new_element_creation(spatialDimension, comm, auraOption); |
| 603 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 604 |
|
| 605 |
stk::mesh::Part& block_2 = bulk.mesh_meta_data().declare_part_with_topology("block_2", stk::topology::SHELL_QUAD_4); |
| 606 |
stk::mesh::Part& block_3 = bulk.mesh_meta_data().declare_part_with_topology("block_3", stk::topology::SHELL_QUAD_4); |
| 607 |
stk::io::put_io_part_attribute(block_2); |
| 608 |
stk::io::put_io_part_attribute(block_3); |
| 609 |
|
| 610 |
stk::mesh::PartVector blocks{&block_2, &block_3}; |
| 611 |
|
| 612 |
stk::io::fill_mesh("textmesh:0,1,HEX_8, 1, 2, 3, 4, 5, 6, 7, 8, block_1\n\ |
| 613 |
1,2,HEX_8, 5, 6, 7, 8, 9,10,11,12, block_1\n\ |
| 614 |
|coordinates:0,0,0, 1,0,0, 1,1,0, 0,1,0,\n\ |
| 615 |
0,0,1, 1,0,1, 1,1,1, 0,1,1,\n\ |
| 616 |
0,0,2, 1,0,2, 1,1,2, 0,1,2", bulk); |
| 617 |
|
| 618 |
bulk.initialize_face_adjacent_element_graph(); |
| 619 |
|
| 620 |
stk::mesh::EntityVector elems, createdElems; |
| 621 |
stk::mesh::get_entities(bulk, stk::topology::ELEM_RANK, elems); |
| 622 |
|
| 623 |
unsigned numElem = elems.size(); |
| 624 |
EXPECT_EQ(1u, numElem); |
| 625 |
|
| 626 |
std::vector<unsigned> shellElemIds(6); |
| 627 |
std::iota(shellElemIds.begin(), shellElemIds.end(), 3 + bulk.parallel_rank()*6*numElem); |
| 628 |
|
| 629 |
stk::mesh::Selector selector = bulk.mesh_meta_data().universal_part(); |
| 630 |
for (unsigned ielem = 0; ielem < numElem; ielem++) { |
| 631 |
stk::mesh::Entity const elem = elems[ielem]; |
| 632 |
std::vector<bool> faceExternal; |
| 633 |
bool hasExternal = element_external_faces(bulk, selector, elem, faceExternal); |
| 634 |
EXPECT_TRUE(hasExternal); |
| 635 |
EXPECT_EQ(6u, faceExternal.size()); |
| 636 |
for(bool faceStatus : faceExternal) { |
| 637 |
EXPECT_TRUE(faceStatus); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
bulk.modification_begin(); |
| 642 |
for (unsigned ielem = 0; ielem < numElem; ielem++) { |
| 643 |
stk::mesh::Entity const elem = elems[ielem]; |
| 644 |
|
| 645 |
// Side 0 only to create parallel paved configuration |
| 646 |
std::vector<bool> faceExternal(6, false); |
| 647 |
faceExternal[0] = true; |
| 648 |
|
| 649 |
create_external_shell(bulk, elem, faceExternal, *blocks[bulk.parallel_rank()], shellElemIds, createdElems); |
| 650 |
} |
| 651 |
bulk.modification_end(); |
| 652 |
|
| 653 |
EXPECT_NO_THROW(delete_created_external_shells(bulk, createdElems)); |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
} // namespace |