Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/custom_ghosting/UnitTestRemoveNeededRecvGhost.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 CustomGhostTest : public ::testing::Test
45 {
46 public:
47 CustomGhostTest()
48 : meta(nullptr), bulk(), customGhosting(nullptr)
49 {
50 }
51
52 virtual ~CustomGhostTest()
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_2_beams_per_proc();
64 custom_ghost_beam1_to_proc1();
65 }
66
67 void create_2_beams_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 const unsigned numLocalNodes = 3;
75 stk::mesh::EntityId firstNodeId = myProc*numLocalNodes + 1;
76 stk::mesh::Entity node1 = bulk->declare_node(firstNodeId);
77 stk::mesh::Entity node2 = bulk->declare_node(firstNodeId+1);
78 stk::mesh::Entity node3 = bulk->declare_node(firstNodeId+2);
79
80 const unsigned numLocalBeams = 2;
81 stk::mesh::EntityId firstBeamId = myProc*numLocalBeams + 1;
82
83 stk::mesh::Entity beam1 = bulk->declare_element(firstBeamId, stk::mesh::ConstPartVector{&beamPart});
84 bulk->declare_relation(beam1, node1, 0);
85 bulk->declare_relation(beam1, node2, 1);
86
87 stk::mesh::Entity beam2 = bulk->declare_element(firstBeamId+1, stk::mesh::ConstPartVector{&beamPart});
88 bulk->declare_relation(beam2, node2, 0);
89 bulk->declare_relation(beam2, node3, 1);
90
91 bulk->modification_end();
92 }
93
94 void custom_ghost_beam1_to_proc1()
95 {
96 bulk->modification_begin();
97 customGhosting = &bulk->create_ghosting("customGhosting");
98 std::vector<stk::mesh::EntityProc> sendGhost;
99 if (bulk->parallel_rank() == 0) {
100 const int otherProc = 1;
101 stk::mesh::EntityId beamId = 1;
102 sendGhost.push_back(stk::mesh::EntityProc(bulk->get_entity(stk::topology::ELEM_RANK, beamId), otherProc));
103 }
104 bulk->change_ghosting(*customGhosting, sendGhost);
105 bulk->modification_end();
106 }
107
108 void custom_ghost_rm_beam1_add_beam2()
109 {
110 std::vector<stk::mesh::EntityProc> sendGhost;
111 std::vector<stk::mesh::EntityKey> rmRecvGhost;
112
113 if (bulk->parallel_rank()==0) {
114 const int otherProc = 1;
115 stk::mesh::EntityId beamId = 2;
116 sendGhost.push_back(stk::mesh::EntityProc(bulk->get_entity(stk::topology::ELEM_RANK, beamId), otherProc));
117 }
118 else {
119 stk::mesh::EntityId beamId = 1;
120 rmRecvGhost.push_back(stk::mesh::EntityKey(stk::topology::ELEM_RANK, beamId));
121 stk::mesh::EntityId nodeId = 1;
122 rmRecvGhost.push_back(stk::mesh::EntityKey(stk::topology::NODE_RANK, nodeId));
123 rmRecvGhost.push_back(stk::mesh::EntityKey(stk::topology::NODE_RANK, nodeId+1));
124 }
125
126 bulk->modification_begin();
127 bulk->change_ghosting(*customGhosting, sendGhost, rmRecvGhost);
128 bulk->modification_end();
129 }
130
131 private:
132 stk::mesh::MetaData* meta = nullptr;
133 std::shared_ptr<stk::mesh::BulkData> bulk;
134 stk::mesh::Ghosting * customGhosting;
135 };
136
137 TEST_F(CustomGhostTest, removeNeededRecvGhost)
138 {
139 if (stk::parallel_machine_size(MPI_COMM_WORLD) != 2) { GTEST_SKIP(); }
140
141 setup_mesh(MPI_COMM_WORLD);
142
143 EXPECT_NO_THROW(custom_ghost_rm_beam1_add_beam2());
144 }
145