Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/change_parts/CustomGhostEntities.cpp

raw
1 #include "gtest/gtest.h"
2 #include "mpi.h"
3 #include <stk_mesh/base/Part.hpp>
4 #include <stk_mesh/base/MetaData.hpp>
5 #include <stk_mesh/base/BulkData.hpp>
6 #include <stk_mesh/base/GetEntities.hpp>
7 #include <stk_unit_test_utils/MeshFixture.hpp>
8 #include <stk_unit_test_utils/getOption.h>
9 #include <stk_util/parallel/CommSparse.hpp>
10 #include <stk_util/parallel/Parallel.hpp>
11
12 namespace
13 {
14
15 class CustomGhostEntities: public stk::unit_test_util::MeshFixture
16 {
17 protected:
18 CustomGhostEntities()
19 : stk::unit_test_util::MeshFixture(),
20 myPart(nullptr)
21 {
22 setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA);
23 myPart = &(get_meta().declare_part("myPart",stk::topology::FACE_RANK));
24 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
25 stk::io::fill_mesh("generated:2x1x2|sideset:z", get_bulk());
26 get_face_entities();
27 add_myPart_to_both_faces();
28 }
29 }
30
31 void get_face_entities()
32 {
33 face15 = get_bulk().get_entity(stk::topology::FACE_RANK, 15);
34 face25 = get_bulk().get_entity(stk::topology::FACE_RANK, 25);
35 }
36
37 void add_myPart_to_face15_and_face25()
38 {
39 if (get_bulk().is_valid(face15)) {
40 get_bulk().change_entity_parts(face15, stk::mesh::ConstPartVector{myPart});
41 }
42 if (get_bulk().is_valid(face25)) {
43 get_bulk().change_entity_parts(face25, stk::mesh::ConstPartVector{myPart});
44 }
45 }
46
47 void add_myPart_to_both_faces()
48 {
49 get_bulk().modification_begin();
50 add_myPart_to_face15_and_face25();
51 get_bulk().modification_end();
52 }
53
54 void send_face_15_from_proc_0_to_proc_1(stk::mesh::Ghosting& ghosting)
55 {
56 stk::mesh::EntityProcVec entitiesToGhost;
57 if (get_bulk().parallel_rank() == 0) {
58 entitiesToGhost.push_back(stk::mesh::EntityProc(face15, proc1));
59 }
60 get_bulk().change_ghosting(ghosting, entitiesToGhost);
61 }
62
63 void custom_ghost_face_15_from_proc_0_to_proc_1()
64 {
65 get_bulk().modification_begin();
66 stk::mesh::Ghosting& ghosting = get_bulk().create_ghosting("myCustomGhosting");
67 send_face_15_from_proc_0_to_proc_1(ghosting);
68 get_bulk().modification_end();
69 }
70
71 void remove_face_15_from_myPart_on_proc_0()
72 {
73 get_bulk().modification_begin();
74 if (get_bulk().parallel_rank() == 0) {
75 get_bulk().change_entity_parts(face15, stk::mesh::ConstPartVector{}, stk::mesh::ConstPartVector{myPart});
76 }
77 get_bulk().modification_end();
78 }
79
80 void expect_face15_not_in_myPart_on_any_proc()
81 {
82 face15 = get_bulk().get_entity(stk::topology::FACE_RANK, 15);
83 EXPECT_FALSE(get_bulk().bucket(face15).member(*myPart));
84 }
85
86 void expect_proc_0_has_4_nodes_in_myPart()
87 {
88 if (get_bulk().parallel_rank() == 0) {
89 EXPECT_EQ(4u, stk::mesh::count_selected_entities(*myPart, get_bulk().buckets(stk::topology::NODE_RANK)));
90 }
91 }
92
93 void expect_proc_1_has_2_nodes_in_myPart()
94 {
95 if (get_bulk().parallel_rank() == 1) {
96 EXPECT_EQ(2u, stk::mesh::count_selected_entities(*myPart, get_bulk().buckets(stk::topology::NODE_RANK)));
97 }
98 }
99
100 void check_results()
101 {
102 expect_face15_not_in_myPart_on_any_proc();
103 expect_proc_0_has_4_nodes_in_myPart();
104 expect_proc_1_has_2_nodes_in_myPart();
105 }
106
107 private:
108 stk::mesh::Part* myPart;
109 stk::mesh::Entity face15, face25;
110 int proc1 = 1;
111 };
112
113 TEST_F(CustomGhostEntities, removePart)
114 {
115 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) {
116 custom_ghost_face_15_from_proc_0_to_proc_1();
117 remove_face_15_from_myPart_on_proc_0();
118 check_results();
119 }
120 }
121
122 }