Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestRootTopology.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 AssertHelper, EXPECT_EQ, etc
36 #include <algorithm> // for find
37 #include <stk_mesh/base/MetaData.hpp> // for MetaData, get_cell_topology
38 #include <string> // for allocator, operator+, etc
39 #include <vector> // for vector
40 #include "stk_mesh/base/Part.hpp" // for Part
41 #include "stk_mesh/base/Types.hpp" // for PartVector
42 #include "stk_topology/topology.hpp" // for topology, etc
43
44 namespace {
45 static const unsigned num_test_topologies = 30;
46 static const stk::topology test_topologies[num_test_topologies] = {
47 stk::topology::NODE,
48 //EDGE_RANK
49 stk::topology::LINE_2,
50 stk::topology::LINE_3,
51 //FACE_RANK
52 stk::topology::TRI_3,
53 stk::topology::TRI_4,
54 stk::topology::TRI_6,
55 stk::topology::QUAD_4,
56 stk::topology::QUAD_8,
57 stk::topology::QUAD_9,
58 //ELEMENT_RANK
59 stk::topology::PARTICLE,
60 stk::topology::BEAM_2,
61 stk::topology::BEAM_3,
62 stk::topology::SHELL_TRI_3,
63 // Cannot create SHELL_TRI_4 entities because Shards does not support!
64 // , stk::topology::SHELL_TRI_4
65 stk::topology::SHELL_TRI_6,
66 stk::topology::SHELL_QUAD_4,
67 stk::topology::SHELL_QUAD_8,
68 stk::topology::SHELL_QUAD_9,
69 stk::topology::TET_4,
70 stk::topology::TET_8,
71 stk::topology::TET_10,
72 stk::topology::TET_11,
73 stk::topology::PYRAMID_5,
74 stk::topology::PYRAMID_13,
75 stk::topology::PYRAMID_14,
76 stk::topology::WEDGE_6,
77 stk::topology::WEDGE_15,
78 stk::topology::WEDGE_18,
79 stk::topology::HEX_8,
80 stk::topology::HEX_20,
81 stk::topology::HEX_27};
82 }
83
84 TEST(UnitTestRootTopology, TestRootTopologyPartGetters)
85 {
86 const int spatial_dim = 3;
87 stk::mesh::MetaData meta(spatial_dim);
88 meta.commit();
89
90 for (unsigned i = 0; i < num_test_topologies; ++i)
91 {
92 stk::mesh::Part &root_part1 = meta.get_topology_root_part(test_topologies[i]);
93 stk::topology root_topo = root_part1.topology();
94
95 // The root_topology_part has the same topology information as the original topology.
96 EXPECT_TRUE(test_topologies[i] == root_topo);
97
98 const stk::mesh::PartVector &subsets = root_part1.subsets();
99 const stk::mesh::PartVector &supersets = root_part1.supersets();
100
101 EXPECT_TRUE(subsets.empty());
102 EXPECT_EQ(1u, supersets.size());
103 EXPECT_EQ(&meta.universal_part(), supersets[0]);
104
105 stk::mesh::Part &root_part2 = meta.get_part(root_part1.mesh_meta_data_ordinal());
106 EXPECT_TRUE(root_part1 == root_part2);
107
108 stk::mesh::Part *root_part3 = meta.get_part(root_part1.name());
109 EXPECT_TRUE(root_part1 == *root_part3);
110
111 const stk::mesh::PartVector &all_parts = meta.get_parts();
112 const stk::mesh::PartVector non_internal_parts = meta.get_mesh_parts();
113
114 EXPECT_TRUE(std::find(all_parts.begin(), all_parts.end(), &root_part1) != all_parts.end());
115 EXPECT_TRUE(std::find(non_internal_parts.begin(), non_internal_parts.end(), &root_part1)
116 == non_internal_parts.end());
117 }
118 }
119
120 TEST(UnitTestRootTopology, TestRootTopologySubsets)
121 {
122 const int spatial_dim = 3;
123 stk::mesh::MetaData meta(spatial_dim);
124
125 for (unsigned i = 0; i < num_test_topologies; ++i)
126 {
127 stk::mesh::Part &root_part1 = meta.get_topology_root_part(test_topologies[i]);
128 stk::topology root_topo = root_part1.topology();
129
130 EXPECT_FALSE(root_part1.force_no_induce());
131
132 // The root_topology_part has the same topology information as the original topology.
133 EXPECT_TRUE(test_topologies[i] == root_topo);
134
135 const stk::mesh::PartVector &rootTopoPartSubsets = root_part1.subsets();
136 const stk::mesh::PartVector &rootTopoPartSupersets = root_part1.supersets();
137
138 EXPECT_TRUE(rootTopoPartSubsets.empty());
139 EXPECT_EQ(1u, rootTopoPartSupersets.size());
140 EXPECT_EQ(&meta.universal_part(), rootTopoPartSupersets[0]);
141
142 stk::mesh::Part & newPart = meta.declare_part_with_topology( std::string("topo_part") + root_part1.name(), root_topo );
143
144 EXPECT_EQ(1u, rootTopoPartSubsets.size());
145 EXPECT_EQ(&newPart, rootTopoPartSubsets[0]);
146
147 const stk::mesh::PartVector & newPartSupersets = newPart.supersets();
148
149 EXPECT_EQ(2u, newPartSupersets.size());
150 EXPECT_EQ(&meta.universal_part(), newPartSupersets[0]);
151 EXPECT_EQ(&root_part1, newPartSupersets[1]);
152 }
153
154
155 meta.commit();
156
157 }