Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/custom_ghosting/UnitTestChangeEntityOwnerKeepUnaffectedCustomGhost.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include <gtest/gtest.h>
36 #include <stk_mesh/base/Types.hpp>
37 #include <stk_mesh/base/MetaData.hpp>
38 #include <stk_mesh/base/BulkData.hpp>
39 #include <stk_mesh/base/MeshBuilder.hpp>
40 #include <stk_topology/topology.hpp>
41 #include <stk_util/parallel/Parallel.hpp>
42
43
44 class ChangeEntityOwnerTest : public ::testing::Test
45 {
46 public:
47 ChangeEntityOwnerTest()
48 : meta(nullptr), bulk(), customGhosting(nullptr)
49 {
50 }
51
52 virtual ~ChangeEntityOwnerTest()
53 {
54 }
55
56 void setup_mesh(stk::ParallelMachine pm)
57 {
58 stk::mesh::MeshBuilder builder(pm);
59 builder.set_spatial_dimension(2);
60 builder.set_aura_option(stk::mesh::BulkData::NO_AUTO_AURA);
61 bulk = builder.create();
62 meta = &(bulk->mesh_meta_data());
63 create_1_beam_per_proc();
64 custom_ghost_node2_to_proc2();
65 }
66
67 void create_1_beam_per_proc()
68 {
69 const int myProc = stk::parallel_machine_rank(bulk->parallel());
70 stk::mesh::Part& beamPart = meta->get_topology_root_part(stk::topology::BEAM_2);
71
72 bulk->modification_begin();
73
74 stk::mesh::EntityId firstNodeId = myProc + 1;
75 stk::mesh::Entity node1 = bulk->declare_node(firstNodeId);
76 stk::mesh::Entity node2 = bulk->declare_node(firstNodeId+1);
77 if (bulk->parallel_rank()==0) {
78 int otherProc = 1;
79 bulk->add_node_sharing(node2, otherProc);
80 }
81 if (bulk->parallel_rank()==1) {
82 int otherProc = 0;
83 bulk->add_node_sharing(node1, otherProc);
84 otherProc = 2;
85 bulk->add_node_sharing(node2, otherProc);
86 }
87 if (bulk->parallel_rank()==2) {
88 int otherProc = 1;
89 bulk->add_node_sharing(node1, otherProc);
90 }
91
92 stk::mesh::EntityId beamId = myProc + 1;
93
94 stk::mesh::Entity beam = bulk->declare_element(beamId, stk::mesh::ConstPartVector{&beamPart});
95 bulk->declare_relation(beam, node1, 0);
96 bulk->declare_relation(beam, node2, 1);
97
98 bulk->modification_end();
99 }
100
101 void custom_ghost_node2_to_proc2()
102 {
103 bulk->modification_begin();
104 customGhosting = &bulk->create_ghosting("customGhosting");
105 std::vector<stk::mesh::EntityProc> sendGhost;
106 if (bulk->parallel_rank() == 0) {
107 stk::mesh::EntityId nodeId = 2;
108 const int otherProc = 2;
109 sendGhost.push_back(stk::mesh::EntityProc(bulk->get_entity(stk::topology::NODE_RANK, nodeId), otherProc));
110 }
111 bulk->change_ghosting(*customGhosting, sendGhost);
112 bulk->modification_end();
113 }
114
115 void move_beam2_to_proc0()
116 {
117 std::vector<stk::mesh::EntityProc> elemToMove;
118
119 if (bulk->parallel_rank()==1) {
120 const int otherProc = 0;
121 stk::mesh::EntityId beamId = 2;
122 elemToMove.push_back(stk::mesh::EntityProc(bulk->get_entity(stk::topology::ELEM_RANK, beamId), otherProc));
123 }
124
125 bulk->change_entity_owner(elemToMove);
126 }
127
128 protected:
129 stk::mesh::MetaData* meta = nullptr;
130 std::shared_ptr<stk::mesh::BulkData> bulk;
131 stk::mesh::Ghosting * customGhosting;
132 };
133
134 TEST_F(ChangeEntityOwnerTest, keepUnaffectedCustomGhost)
135 {
136 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); }
137
138 setup_mesh(MPI_COMM_WORLD);
139
140 stk::mesh::EntityKey node2key(stk::topology::NODE_RANK, 2);
141 stk::mesh::Entity node2 = bulk->get_entity(node2key);
142 EXPECT_TRUE(bulk->is_valid(node2));
143
144 if (bulk->parallel_rank() == 0) {
145 EXPECT_TRUE(bulk->in_send_ghost(*customGhosting, node2key, 2));
146 }
147
148 move_beam2_to_proc0();
149
150 if (bulk->parallel_rank() == 0) {
151 EXPECT_TRUE(bulk->in_send_ghost(*customGhosting, node2key, 2));
152 }
153 }
154