Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestEntityCommDatabase.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 #include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
35 #include <stk_mesh/base/CommListUpdater.hpp> // for CommListUpdater
36 #include <stk_mesh/base/EntityCommDatabase.hpp> // for EntityCommDatabase
37 #include <stk_mesh/base/EntityCommListInfo.hpp>
38 #include <stk_topology/topology.hpp> // for topology, etc
39 #include "stk_mesh/base/Entity.hpp" // for Entity
40 #include "stk_mesh/base/EntityKey.hpp" // for EntityKey
41 #include "stk_mesh/base/Types.hpp" // for EntityCommInfo
42 #include "stk_util/util/NamedPair.hpp"
43
44 TEST(EntityCommDatabase, testCommMapChangeListener)
45 {
46 stk::mesh::EntityCommDatabase commDB;
47 stk::mesh::EntityCommListInfoVector comm_list;
48 std::vector<int> entityCommIndices(200, -1);
49 std::vector<std::pair<stk::mesh::EntityKey,stk::mesh::EntityCommInfo>> removedGhosts;
50 stk::mesh::CommListUpdater comm_list_updater(comm_list, entityCommIndices, removedGhosts);
51 commDB.setCommMapChangeListener(&comm_list_updater);
52
53 int owner = 0;
54 stk::mesh::EntityKey key(stk::topology::NODE_RANK, 99);
55 unsigned ghost_id = 3;
56 commDB.insert(key, stk::mesh::EntityCommInfo(ghost_id, 2), owner);
57 commDB.insert(key, stk::mesh::EntityCommInfo(ghost_id, 3), owner);
58 commDB.insert(key, stk::mesh::EntityCommInfo(ghost_id, 4), owner);
59
60 EXPECT_FALSE(commDB.erase(key, stk::mesh::EntityCommInfo(ghost_id, 1)));
61 EXPECT_TRUE(commDB.erase(key, stk::mesh::EntityCommInfo(ghost_id, 3)));
62 EXPECT_EQ(1u, removedGhosts.size());
63 EXPECT_TRUE(commDB.erase(key, stk::mesh::EntityCommInfo(ghost_id, 2)));
64 EXPECT_EQ(2u, removedGhosts.size());
65
66 //CommListUpdater only manages removing entries from comm-list,
67 //so we must add an entry manually to set up the test.
68 stk::mesh::EntityCommListInfo comm_list_info =
69 {key, stk::mesh::Entity(), commDB.entity_comm(key)};
70 comm_list.push_back(comm_list_info);
71
72 EXPECT_EQ(1u, comm_list.size());
73
74 //now clear an entry from commDB and expect that it also
75 //set the entity_comm value in comm_list to -1.
76 commDB.comm_clear(key);
77
78 EXPECT_EQ(1u, comm_list.size());
79 comm_list_info = comm_list[0];
80 EXPECT_EQ(-1, comm_list_info.entity_comm);
81 }
82
83 TEST(EntityCommDatabase, insertAndErase)
84 {
85 stk::mesh::EntityCommDatabase commDB;
86 std::vector<int> entityCommIndices(2, -1);
87 std::vector<stk::mesh::EntityKey> entityKeys =
88 {stk::mesh::EntityKey(stk::topology::NODE_RANK, 1),
89 stk::mesh::EntityKey(stk::topology::NODE_RANK, 2)};
90 int owner = 0;
91
92 const unsigned SHARED = 0;
93 const unsigned GHOSTED = 1;
94 const int otherProc = 1;
95
96 for (unsigned i=0; i<entityKeys.size(); ++i) {
97 std::pair<int, bool> result =
98 commDB.insert(entityKeys[i], stk::mesh::EntityCommInfo(SHARED, otherProc), owner);
99 EXPECT_TRUE(result.second);
100 EXPECT_FALSE(result.first == -1);
101 entityCommIndices[i] = result.first;
102 }
103
104 for (unsigned i=0; i<entityKeys.size(); ++i) {
105 std::pair<int, bool> result =
106 commDB.insert(entityKeys[i], stk::mesh::EntityCommInfo(GHOSTED, otherProc), owner);
107 EXPECT_TRUE(result.second);
108 }
109
110 commDB.erase(entityKeys[0], stk::mesh::EntityCommInfo(SHARED, otherProc));
111 commDB.erase(entityKeys[1], stk::mesh::EntityCommInfo(GHOSTED, otherProc));
112
113 commDB.erase(entityKeys[0], stk::mesh::EntityCommInfo(GHOSTED, otherProc));
114 EXPECT_TRUE(commDB.entity_comm(entityKeys[0]) == -1);
115
116 commDB.erase(entityKeys[1], stk::mesh::EntityCommInfo(SHARED, otherProc));
117 EXPECT_TRUE(commDB.entity_comm(entityKeys[1]) == -1);
118 }
119