Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestEntity.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> // for ASSERT_TRUE, AssertHelper, etc
36 #include <stk_mesh/base/EntityKey.hpp> // for EntityKey
37 #include <stk_mesh/base/Types.hpp> // for PartVector
38 #include <stk_mesh/base/HashEntityAndEntityKey.hpp>
39 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine
40 #include "stk_topology/topology.hpp" // for topology, etc
41 #include <stdexcept>
42 #include <unordered_set>
43
44 namespace stk { namespace mesh { class Bucket; } }
45 namespace stk { namespace mesh { class BulkData; } }
46 namespace stk { namespace mesh { class MetaData; } }
47 namespace stk { namespace mesh { class Part; } }
48 namespace stk { namespace mesh { namespace impl { class PartRepository; } } }
49 namespace stk { namespace mesh { struct Entity; } }
50
51 using stk::ParallelMachine;
52 using stk::mesh::MetaData;
53 using stk::mesh::BulkData;
54 using stk::mesh::Part;
55 using stk::mesh::PartVector;
56 using stk::mesh::EntityKey;
57 using stk::mesh::Entity;
58 using stk::mesh::Bucket;
59 using stk::mesh::impl::PartRepository;
60
61 namespace {
62
63 //----------------------------------------------------------------------
64
65 TEST(UnitTestEntity, testHashEntity)
66 {
67 std::unordered_set<stk::mesh::Entity, std::hash<stk::mesh::Entity>> set_of_entities;
68 stk::mesh::Entity entity1, entity2, entity3, entity4;
69 entity1.set_local_offset(1);
70 entity2.set_local_offset(2);
71 entity3.set_local_offset(3);
72 entity4.set_local_offset(4);
73 set_of_entities.insert(entity2);
74 set_of_entities.insert(entity3);
75 set_of_entities.insert(entity1);
76 set_of_entities.insert(entity2);//insert entity2 redundantly
77 EXPECT_EQ(3u, set_of_entities.size());
78 EXPECT_FALSE(set_of_entities.find(entity1) == set_of_entities.end());
79 EXPECT_TRUE(set_of_entities.find(entity4) == set_of_entities.end());//entity4 not in set
80 }
81
82 TEST(UnitTestEntity, testHashEntityKey)
83 {
84 std::unordered_set<stk::mesh::EntityKey, std::hash<stk::mesh::EntityKey>> set_of_keys;
85 stk::mesh::EntityKey
86 key1(stk::topology::NODE_RANK,1),
87 key2(stk::topology::EDGE_RANK,1),
88 key3(stk::topology::FACE_RANK,1),
89 key4(stk::topology::ELEM_RANK,1);
90 set_of_keys.insert(key2);
91 set_of_keys.insert(key3);
92 set_of_keys.insert(key1);
93 set_of_keys.insert(key2);//insert key2 redundantly
94 EXPECT_EQ(3u, set_of_keys.size());
95 EXPECT_FALSE(set_of_keys.find(key1) == set_of_keys.end());
96 EXPECT_TRUE(set_of_keys.find(key4) == set_of_keys.end());//key4 not in set
97 }
98
99 TEST(UnitTestEntity,testEntityKey)
100 {
101 EntityKey key_bad_zero = EntityKey();
102 EntityKey key_good_0_1 = EntityKey( stk::topology::NODE_RANK , 1 );
103 EntityKey key_good_1_1 = EntityKey( stk::topology::EDGE_RANK , 1 );
104 EntityKey key_good_2_10 = EntityKey( stk::topology::FACE_RANK , 10);
105 EntityKey key_order_1_12 = EntityKey( stk::topology::EDGE_RANK , 12 );
106 EntityKey key_order_2_10 = EntityKey( stk::topology::FACE_RANK , 10 );
107
108 ASSERT_TRUE( ! key_bad_zero.is_valid() );
109 ASSERT_TRUE( key_good_0_1.is_valid() );
110 ASSERT_TRUE( key_good_1_1.is_valid() );
111 ASSERT_TRUE( key_good_2_10.is_valid() );
112
113 ASSERT_TRUE( stk::topology::NODE_RANK == key_good_0_1.rank());
114 ASSERT_TRUE( stk::topology::EDGE_RANK == key_good_1_1.rank() );
115 ASSERT_TRUE( stk::topology::FACE_RANK == key_good_2_10.rank() );
116 ASSERT_TRUE( 1 == key_good_0_1.id() );
117 ASSERT_TRUE( 1 == key_good_1_1.id() );
118 ASSERT_TRUE( 10 == key_good_2_10.id() );
119
120 ASSERT_TRUE( key_order_1_12 < key_order_2_10);
121 ASSERT_TRUE( !( key_order_1_12 > key_order_2_10));
122
123 #ifndef NDEBUG
124 ASSERT_THROW( EntityKey( stk::topology::INVALID_RANK, 1 ) , std::logic_error );
125 ASSERT_THROW( EntityKey( stk::topology::NODE_RANK , ~0ull ) , std::logic_error );
126 #endif // NDEBUG
127 }
128
129 //----------------------------------------------------------------------
130 }//namespace <anonymous>
131