| 1 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 2 |
#include <stk_mesh/base/MetaData.hpp> // for get_cell_topology, MetaData |
| 3 |
#include <stk_util/parallel/Parallel.hpp> // for ParallelMachine |
| 4 |
#include <gtest/gtest.h> |
| 5 |
#include <stk_io/WriteMesh.hpp> |
| 6 |
|
| 7 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 8 |
#include <stk_io/WriteMesh.hpp> |
| 9 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 10 |
|
| 11 |
#include <stk_mesh/base/GetEntities.hpp> |
| 12 |
|
| 13 |
|
| 14 |
namespace |
| 15 |
{ |
| 16 |
|
| 17 |
class TwoHexWithInternalSideset : public stk::unit_test_util::MeshFixture |
| 18 |
{ |
| 19 |
protected: |
| 20 |
void create_mesh_with_internal_side() |
| 21 |
{ |
| 22 |
setup_mesh("generated:1x1x2", stk::mesh::BulkData::NO_AUTO_AURA); |
| 23 |
get_bulk().set_use_entity_ids_for_resolving_sharing(true); |
| 24 |
|
| 25 |
get_bulk().modification_begin(); |
| 26 |
stk::mesh::Entity element1 = get_bulk().get_entity(stk::topology::ELEM_RANK,1); |
| 27 |
stk::mesh::Entity element2 = get_bulk().get_entity(stk::topology::ELEM_RANK,2); |
| 28 |
|
| 29 |
if(get_bulk().is_valid(element1) && get_bulk().bucket(element1).owned()) |
| 30 |
get_bulk().declare_element_side(element1, 5, stk::mesh::ConstPartVector{}); |
| 31 |
|
| 32 |
if(get_bulk().is_valid(element2) && get_bulk().bucket(element2).owned()) |
| 33 |
get_bulk().declare_element_side(element2, 4, stk::mesh::ConstPartVector{}); |
| 34 |
|
| 35 |
get_bulk().modification_end(); |
| 36 |
verify_side_is_internal_not_shared(); |
| 37 |
} |
| 38 |
|
| 39 |
void verify_side_is_internal_not_shared() |
| 40 |
{ |
| 41 |
stk::mesh::EntityVector sides; |
| 42 |
stk::mesh::Selector shared_owned = get_meta().locally_owned_part() | get_meta().globally_shared_part(); |
| 43 |
stk::mesh::get_selected_entities(shared_owned, get_bulk().buckets(get_meta().side_rank()), sides); |
| 44 |
|
| 45 |
std::vector<size_t> numGoldSidesPerProc = { 1, 1 }; |
| 46 |
ASSERT_EQ(numGoldSidesPerProc[get_bulk().parallel_rank()], sides.size()); |
| 47 |
|
| 48 |
unsigned num_elements = get_bulk().num_elements(sides[0]); |
| 49 |
ASSERT_EQ(1u, num_elements); |
| 50 |
} |
| 51 |
|
| 52 |
void test_throw_on_add_node_sharing(bool use_ids_for_sharing) |
| 53 |
{ |
| 54 |
get_bulk().set_use_entity_ids_for_resolving_sharing(use_ids_for_sharing); |
| 55 |
stk::mesh::EntityId uniqueNodeId = 100; |
| 56 |
get_bulk().modification_begin(); |
| 57 |
stk::mesh::Entity node = get_bulk().declare_node(uniqueNodeId, stk::mesh::ConstPartVector{}); |
| 58 |
int other_proc = 1 - get_bulk().parallel_rank(); |
| 59 |
get_bulk().add_node_sharing(node, other_proc); |
| 60 |
get_bulk().modification_end(); |
| 61 |
} |
| 62 |
}; |
| 63 |
|
| 64 |
TEST_F(TwoHexWithInternalSideset, DISABLED_addNodeSharingClassic) |
| 65 |
{ |
| 66 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) |
| 67 |
{ |
| 68 |
create_mesh_with_internal_side(); |
| 69 |
bool use_ids_for_resolving_sharing = false; |
| 70 |
EXPECT_THROW(test_throw_on_add_node_sharing(use_ids_for_resolving_sharing), std::runtime_error); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
TEST_F(TwoHexWithInternalSideset, addNodeSharingCurrent) |
| 75 |
{ |
| 76 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) |
| 77 |
{ |
| 78 |
create_mesh_with_internal_side(); |
| 79 |
bool use_ids_for_resolving_sharing = true; |
| 80 |
EXPECT_NO_THROW(test_throw_on_add_node_sharing(use_ids_for_resolving_sharing)); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
} |