| 1 |
/*--------------------------------------------------------------------*/ |
| 2 |
/* Copyright 2002 - 2008, 2010, 2011 National Technology & */ |
| 3 |
/* Engineering Solutions of Sandia, LLC (NTESS). Under the terms */ |
| 4 |
/* of Contract DE-NA0003525 with NTESS, there is a */ |
| 5 |
/* non-exclusive license for use of this work by or on behalf */ |
| 6 |
/* of the U.S. Government. Export of this program may require */ |
| 7 |
/* a license from the United States Government. */ |
| 8 |
/*--------------------------------------------------------------------*/ |
| 9 |
|
| 10 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 11 |
#include "mpi.h" // for MPI_COMM_WORLD |
| 12 |
#include <stddef.h> // for size_t, nullptr |
| 13 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphUpdater.hpp> |
| 14 |
#include <stk_mesh/base/FaceCreator.hpp> |
| 15 |
#include <stk_mesh/base/SideSetEntry.hpp> |
| 16 |
#include <stk_mesh/base/SkinMeshUtil.hpp> |
| 17 |
#include <string> // for string |
| 18 |
#include <Ionit_Initializer.h> // for Initializer |
| 19 |
#include "stk_io/DatabasePurpose.hpp" |
| 20 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 21 |
#include <stk_mesh/base/GetEntities.hpp> |
| 22 |
#include <stk_mesh/base/Comm.hpp> |
| 23 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 24 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 25 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 26 |
#include <stk_util/util/SortAndUnique.hpp> |
| 27 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 28 |
#include <stk_unit_test_utils/MeshFixture.hpp> // for MeshTestFixture |
| 29 |
#include <stk_unit_test_utils/FaceCreationTestUtils.hpp> |
| 30 |
|
| 31 |
namespace |
| 32 |
{ |
| 33 |
|
| 34 |
class SkinWithModification : public stk::unit_test_util::MeshFixture |
| 35 |
{ |
| 36 |
protected: |
| 37 |
SkinWithModification() : boundaryPart(nullptr) |
| 38 |
{ |
| 39 |
} |
| 40 |
void setup_for_skinning() |
| 41 |
{ |
| 42 |
boundaryPart = &get_meta().declare_part("boundary", get_meta().side_rank()); |
| 43 |
|
| 44 |
thingsToSkin = get_meta().universal_part(); |
| 45 |
} |
| 46 |
~SkinWithModification() |
| 47 |
{ |
| 48 |
} |
| 49 |
void test_skinning(const SideTestUtil::TestCase& exteriorTestCase, |
| 50 |
const SideTestUtil::TestCase& interiorTestCase) |
| 51 |
{ |
| 52 |
test_exposed_boundary(exteriorTestCase); |
| 53 |
test_interior_block_boundary(interiorTestCase); |
| 54 |
} |
| 55 |
void destroy_element(stk::mesh::Entity elem) |
| 56 |
{ |
| 57 |
get_bulk().modification_begin(); |
| 58 |
if(get_bulk().parallel_rank() == 0) |
| 59 |
get_bulk().destroy_entity(elem); |
| 60 |
get_bulk().modification_end(); |
| 61 |
} |
| 62 |
|
| 63 |
void delete_shells_13_and_14() |
| 64 |
{ |
| 65 |
get_bulk().modification_begin(); |
| 66 |
if(get_bulk().parallel_rank() == 0) |
| 67 |
{ |
| 68 |
get_bulk().destroy_entity(shell13); |
| 69 |
get_bulk().destroy_entity(shell14); |
| 70 |
} |
| 71 |
get_bulk().modification_end(); |
| 72 |
} |
| 73 |
|
| 74 |
void create_shells_13_and_14() |
| 75 |
{ |
| 76 |
create_shell_13(); |
| 77 |
create_shell_14(); |
| 78 |
} |
| 79 |
|
| 80 |
void create_shell_13() |
| 81 |
{ |
| 82 |
shell13 = create_shell_with_id(shellId1); |
| 83 |
} |
| 84 |
|
| 85 |
void create_shell_14() |
| 86 |
{ |
| 87 |
shell14 = create_shell_with_id(shellId2); |
| 88 |
} |
| 89 |
stk::mesh::Entity create_shell_with_id(const stk::mesh::EntityId shellId) |
| 90 |
{ |
| 91 |
stk::mesh::Entity shell; |
| 92 |
get_bulk().modification_begin(); |
| 93 |
if(get_bulk().parallel_rank() == 0) |
| 94 |
shell = stk::mesh::declare_element(get_bulk(), get_meta().get_topology_root_part(stk::topology::SHELL_QUAD_4), shellId, {5, 6, 7, 8}); |
| 95 |
get_bulk().modification_end(); |
| 96 |
return shell; |
| 97 |
} |
| 98 |
|
| 99 |
private: |
| 100 |
void test_exposed_boundary(const SideTestUtil::TestCase& testCase) |
| 101 |
{ |
| 102 |
make_exterior_sides(); |
| 103 |
SideTestUtil::expect_exposed_sides_connected_as_specified_in_test_case(get_bulk(), testCase, get_things_to_skin(), *boundaryPart); |
| 104 |
destroy_sides_in_boundary_part(); |
| 105 |
} |
| 106 |
void make_exterior_sides() |
| 107 |
{ |
| 108 |
stk::mesh::create_exposed_block_boundary_sides(get_bulk(), get_things_to_skin(), {boundaryPart}); |
| 109 |
} |
| 110 |
|
| 111 |
void destroy_sides_in_boundary_part() |
| 112 |
{ |
| 113 |
stk::mesh::EntityVector boundarySides; |
| 114 |
stk::mesh::get_selected_entities(*boundaryPart, get_bulk().buckets(get_meta().side_rank()), boundarySides); |
| 115 |
destroy_boundary_part_entities(boundarySides); |
| 116 |
SideTestUtil::expect_global_num_sides_in_part(get_bulk(), 0, get_meta().universal_part()); |
| 117 |
} |
| 118 |
void destroy_entities(const stk::mesh::EntityVector& entities) |
| 119 |
{ |
| 120 |
for(stk::mesh::Entity side : entities) |
| 121 |
destroy_side(side); |
| 122 |
} |
| 123 |
void destroy_side(stk::mesh::Entity side) |
| 124 |
{ |
| 125 |
stk::mesh::EntityVector elements(get_bulk().begin_elements(side), get_bulk().end_elements(side)); |
| 126 |
std::vector<stk::mesh::ConnectivityOrdinal> elementOrdinals(get_bulk().begin_element_ordinals(side), get_bulk().end_element_ordinals(side)); |
| 127 |
for(size_t i = 0; i < elements.size(); i++) |
| 128 |
get_bulk().destroy_relation(elements[i], side, elementOrdinals[i]); |
| 129 |
get_bulk().destroy_entity(side); |
| 130 |
} |
| 131 |
void test_interior_block_boundary(const SideTestUtil::TestCase& testCase) |
| 132 |
{ |
| 133 |
make_interior_block_boundary_sides(); |
| 134 |
SideTestUtil::expect_interior_sides_connected_as_specified_in_test_case(get_bulk(), testCase, get_things_to_skin(), *boundaryPart); |
| 135 |
destroy_sides_in_boundary_part(); |
| 136 |
} |
| 137 |
void make_interior_block_boundary_sides() |
| 138 |
{ |
| 139 |
stk::mesh::create_interior_block_boundary_sides(get_bulk(), get_things_to_skin(), {boundaryPart}); |
| 140 |
} |
| 141 |
|
| 142 |
const stk::mesh::Selector &get_things_to_skin() |
| 143 |
{ |
| 144 |
return thingsToSkin; |
| 145 |
} |
| 146 |
|
| 147 |
void destroy_boundary_part_entities(stk::mesh::EntityVector &boundarySides) |
| 148 |
{ |
| 149 |
get_bulk().modification_begin(); |
| 150 |
destroy_entities(boundarySides); |
| 151 |
get_bulk().modification_end(); |
| 152 |
} |
| 153 |
|
| 154 |
protected: |
| 155 |
const stk::mesh::EntityId shellId1 = 13; |
| 156 |
const stk::mesh::EntityId shellId2 = 14; |
| 157 |
|
| 158 |
stk::mesh::Entity shell13; |
| 159 |
stk::mesh::Entity shell14; |
| 160 |
private: |
| 161 |
stk::mesh::Part *boundaryPart; |
| 162 |
stk::mesh::Selector thingsToSkin; |
| 163 |
}; |
| 164 |
|
| 165 |
class SkinFileWithModification : public SkinWithModification |
| 166 |
{ |
| 167 |
protected: |
| 168 |
void setup_mesh_from_initial_configuration(const std::string &initialConfiguration, |
| 169 |
bool emptyMeshAlreadyCreated = false) |
| 170 |
{ |
| 171 |
if (!emptyMeshAlreadyCreated) { |
| 172 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 173 |
} |
| 174 |
SideTestUtil::read_and_decompose_mesh(initialConfiguration, get_bulk()); |
| 175 |
setup_for_skinning(); |
| 176 |
} |
| 177 |
|
| 178 |
void test_no_mods(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 179 |
{ |
| 180 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 181 |
{ |
| 182 |
setup_mesh_from_initial_configuration (get_filename()); |
| 183 |
test_skinning(exterior, interior); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
void test_adding_one_shell(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 188 |
{ |
| 189 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 190 |
{ |
| 191 |
setup_mesh_from_initial_configuration(get_filename()); |
| 192 |
create_shell_13(); |
| 193 |
test_skinning(exterior, interior); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
void test_adding_two_shell(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 198 |
{ |
| 199 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 200 |
{ |
| 201 |
setup_mesh_from_initial_configuration(get_filename()); |
| 202 |
create_shells_13_and_14(); |
| 203 |
test_skinning(exterior, interior); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
void test_adding_two_shells_then_delete_one(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 208 |
{ |
| 209 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 210 |
{ |
| 211 |
setup_mesh_from_initial_configuration(get_filename()); |
| 212 |
create_shells_13_and_14(); |
| 213 |
destroy_element(shell14); |
| 214 |
test_skinning(exterior, interior); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
void test_adding_two_shells_then_delete_both(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 219 |
{ |
| 220 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 221 |
{ |
| 222 |
setup_mesh_from_initial_configuration(get_filename()); |
| 223 |
create_shells_13_and_14(); |
| 224 |
destroy_element(shell14); |
| 225 |
destroy_element(shell13); |
| 226 |
test_skinning(exterior, interior); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
void test_adding_two_shells_then_delete_both_in_same_mod_cycle(const SideTestUtil::TestCase &exterior, const SideTestUtil::TestCase &interior) |
| 231 |
{ |
| 232 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 233 |
{ |
| 234 |
setup_mesh_from_initial_configuration(get_filename()); |
| 235 |
create_shells_13_and_14(); |
| 236 |
delete_shells_13_and_14(); |
| 237 |
test_skinning(exterior, interior); |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
void test_adding_partial_coincident_hex() |
| 242 |
{ |
| 243 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 244 |
{ |
| 245 |
stk::mesh::EntityId elemId = 30; |
| 246 |
create_partial_coincident_hexes(elemId); |
| 247 |
test_skinning_partial_coincident(elemId); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
stk::mesh::EntityId create_partial_coincident_hexes(stk::mesh::EntityId elemId) |
| 252 |
{ |
| 253 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 254 |
stk::mesh::Part& block2 = create_part_with_id(get_meta(), 2, stk::topology::HEX_8); |
| 255 |
const bool emptyMeshAlreadyCreated = true; |
| 256 |
setup_mesh_from_initial_configuration (get_filename(), emptyMeshAlreadyCreated); |
| 257 |
add_partially_coincident_hex(elemId, block2); |
| 258 |
return elemId; |
| 259 |
} |
| 260 |
|
| 261 |
void add_partially_coincident_hex(stk::mesh::EntityId elemId, stk::mesh::Part& block2) |
| 262 |
{ |
| 263 |
get_bulk().modification_begin(); |
| 264 |
if(get_bulk().parallel_rank() == 0) |
| 265 |
stk::mesh::declare_element(get_bulk(), block2, elemId, stk::mesh::EntityIdVector {31, 32, 33, 34, 5, 6, 7, 8}); |
| 266 |
get_bulk().modification_end(); |
| 267 |
} |
| 268 |
|
| 269 |
void test_skinning_partial_coincident(stk::mesh::EntityId elemId) |
| 270 |
{ |
| 271 |
const SideTestUtil::TestCase exteriorCase = {"AA.e", 2, 15, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, |
| 272 |
{2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 5}, |
| 273 |
{elemId, 0}, {elemId, 1}, {elemId, 2}, {elemId, 3}, {elemId, 4}}}; |
| 274 |
const SideTestUtil::TestCase interiorCase = {"AA.e", 2, 1, {{1, 5}, {elemId, 5}, {2, 4}}}; |
| 275 |
test_skinning(exteriorCase, interiorCase); |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
void create_2_quads_with_partial_coincident_quad_mesh(stk::mesh::Part& block1, stk::mesh::Part& block2) |
| 280 |
{ |
| 281 |
std::string meshDesc; |
| 282 |
if (get_parallel_size() == 1) { |
| 283 |
meshDesc = "0,1,QUAD_4_2D,1,2,3,4\n" |
| 284 |
"0,2,QUAD_4_2D,4,3,5,6\n" |
| 285 |
"0,3,QUAD_4_2D,21,22,3,4"; |
| 286 |
} |
| 287 |
else { |
| 288 |
meshDesc = "0,1,QUAD_4_2D,1,2,3,4\n" |
| 289 |
"1,2,QUAD_4_2D,4,3,5,6\n" |
| 290 |
"0,3,QUAD_4_2D,21,22,3,4"; |
| 291 |
} |
| 292 |
stk::unit_test_util::setup_text_mesh(get_bulk(), meshDesc); |
| 293 |
|
| 294 |
get_bulk().modification_begin(); |
| 295 |
put_entity_into_part(get_bulk(), 1, block1); |
| 296 |
put_entity_into_part(get_bulk(), 2, block2); |
| 297 |
put_entity_into_part(get_bulk(), 3, block1); |
| 298 |
get_bulk().modification_end(); |
| 299 |
} |
| 300 |
|
| 301 |
void put_entity_into_part(stk::mesh::BulkData &bulkDataArg, stk::mesh::EntityId id, stk::mesh::Part& part) |
| 302 |
{ |
| 303 |
stk::mesh::Entity entity = bulkDataArg.get_entity(stk::topology::ELEM_RANK, id); |
| 304 |
if(bulkDataArg.is_valid(entity) && bulkDataArg.bucket(entity).owned()) |
| 305 |
{ |
| 306 |
bulkDataArg.change_entity_parts(entity, stk::mesh::ConstPartVector{&part}); |
| 307 |
} |
| 308 |
} |
| 309 |
stk::mesh::Part& create_part_with_id(stk::mesh::MetaData &metaDataArg, int id, stk::topology topology) |
| 310 |
{ |
| 311 |
stk::mesh::Part& part = metaDataArg.declare_part_with_topology("block_"+std::to_string(id), topology); |
| 312 |
metaDataArg.set_part_id(part, id); |
| 313 |
return part; |
| 314 |
} |
| 315 |
|
| 316 |
virtual const std::string get_filename() = 0; |
| 317 |
}; |
| 318 |
|
| 319 |
class SkinAAWithModification : public SkinFileWithModification |
| 320 |
{ |
| 321 |
protected: |
| 322 |
virtual const std::string get_filename() override { return "AA.e"; } |
| 323 |
const SideTestUtil::TestCase AAExterior = {"AA.e", 2, 10, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 5}}}; |
| 324 |
const SideTestUtil::TestCase AeAExterior = {"AeA.e", 2, 10, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 5}}}; |
| 325 |
const SideTestUtil::TestCase AefAExterior = {"AefA.e", 2, 10, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 5}}}; |
| 326 |
const SideTestUtil::TestCase AAInterior = {"AA.e", 2, 0, {}}; |
| 327 |
const SideTestUtil::TestCase AeAInterior = {"AeA.e", 3, 2, {{1, 5}, {shellId1, 0}, {shellId1, 1}, {2, 4}}}; |
| 328 |
const SideTestUtil::TestCase AefAInterior = {"AefA.e", 3, 2, {{1, 5}, {shellId1, 0}, {shellId1, 1}, {shellId2, 0}, {shellId2, 1}, {2, 4}}}; |
| 329 |
}; |
| 330 |
TEST_F(SkinAAWithModification, TestSkinningWithNoMods) |
| 331 |
{ |
| 332 |
test_no_mods(AAExterior, AAInterior); |
| 333 |
} |
| 334 |
TEST_F(SkinAAWithModification, TestAddingOneShell) |
| 335 |
{ |
| 336 |
test_adding_one_shell(AeAExterior, AeAInterior); |
| 337 |
} |
| 338 |
TEST_F(SkinAAWithModification, TestAddingTwoShells) |
| 339 |
{ |
| 340 |
test_adding_two_shell(AefAExterior, AefAInterior); |
| 341 |
} |
| 342 |
TEST_F(SkinAAWithModification, TestAddTwoShellThenDeleteOne) |
| 343 |
{ |
| 344 |
test_adding_two_shells_then_delete_one(AeAExterior, AeAInterior); |
| 345 |
} |
| 346 |
TEST_F(SkinAAWithModification, TestAddTwoShellThenDeleteBoth) |
| 347 |
{ |
| 348 |
test_adding_two_shells_then_delete_both(AAExterior, AAInterior); |
| 349 |
} |
| 350 |
TEST_F(SkinAAWithModification, TestAddTwoShellThenDeleteBothInSameModCycle) |
| 351 |
{ |
| 352 |
test_adding_two_shells_then_delete_both_in_same_mod_cycle(AAExterior, AAInterior); |
| 353 |
} |
| 354 |
TEST_F(SkinAAWithModification, TestPartialCoincident) |
| 355 |
{ |
| 356 |
test_adding_partial_coincident_hex(); |
| 357 |
} |
| 358 |
TEST_F(SkinAAWithModification, TestPartialCoincident2d) |
| 359 |
{ |
| 360 |
if(stk::parallel_machine_size(get_comm()) <= 2) |
| 361 |
{ |
| 362 |
reset_mesh(); |
| 363 |
set_spatial_dimension(2); |
| 364 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 365 |
stk::mesh::Part& block1 = create_part_with_id(get_meta(), 1, stk::topology::QUAD_4_2D); |
| 366 |
stk::mesh::Part& block2 = create_part_with_id(get_meta(), 2, stk::topology::QUAD_4_2D); |
| 367 |
|
| 368 |
setup_for_skinning(); |
| 369 |
|
| 370 |
create_2_quads_with_partial_coincident_quad_mesh(block1, block2); |
| 371 |
|
| 372 |
const SideTestUtil::TestCase exteriorCase = {"AA.e", 2, 9, {{1, 0}, {1, 1}, {1, 3}, |
| 373 |
{2, 1}, {2, 2}, {2, 3}, |
| 374 |
{3, 0}, {3, 1}, {3, 3}}}; |
| 375 |
const SideTestUtil::TestCase interiorCase = {"AA.e", 2, 1, {{1, 2}, {3, 2}, {2, 0}}}; |
| 376 |
test_skinning(exteriorCase, interiorCase); |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
class SkinAWithModification : public SkinFileWithModification |
| 381 |
{ |
| 382 |
protected: |
| 383 |
virtual const std::string get_filename() override { return "A.e"; } |
| 384 |
const SideTestUtil::TestCase AExterior = {"A.e", 1, 6, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}}}; |
| 385 |
const SideTestUtil::TestCase AeExterior = {"Ae.e", 2, 6, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {shellId1, 0}}}; |
| 386 |
const SideTestUtil::TestCase AefExterior = {"Aef.e", 3, 6, {{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {shellId1, 0}, {shellId2, 0}}}; |
| 387 |
const SideTestUtil::TestCase AInterior = {"A.e", 2, 0, {}}; |
| 388 |
const SideTestUtil::TestCase AeInterior = {"Ae.e", 2, 1, {{1, 5}, {shellId1, 1}}}; |
| 389 |
const SideTestUtil::TestCase AefInterior = {"Aef.e", 3, 1, {{1, 5}, {shellId1, 1}, {shellId2, 1}}}; |
| 390 |
}; |
| 391 |
TEST_F(SkinAWithModification, TestSkinningWithNoMods) |
| 392 |
{ |
| 393 |
test_no_mods(AExterior, AInterior); |
| 394 |
} |
| 395 |
TEST_F(SkinAWithModification, TestAddingOneShell) |
| 396 |
{ |
| 397 |
test_adding_one_shell(AeExterior, AeInterior); |
| 398 |
} |
| 399 |
TEST_F(SkinAWithModification, TestAddingTwoShells) |
| 400 |
{ |
| 401 |
test_adding_two_shell(AefExterior, AefInterior); |
| 402 |
} |
| 403 |
TEST_F(SkinAWithModification, TestAddTwoShellThenDeleteOne) |
| 404 |
{ |
| 405 |
test_adding_two_shells_then_delete_one(AeExterior, AeInterior); |
| 406 |
} |
| 407 |
TEST_F(SkinAWithModification, TestAddTwoShellThenDeleteBoth) |
| 408 |
{ |
| 409 |
test_adding_two_shells_then_delete_both(AExterior, AInterior); |
| 410 |
} |
| 411 |
|
| 412 |
} |