Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/face_creation/skin_mesh/UnitTestSkinning.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_TRUE, etc
36 #include <map> // for map, operator==, etc
37 #include <set> // for set, operator==
38 #include <stk_mesh/base/BulkData.hpp> // for BulkData
39 #include <stk_mesh/base/Entity.hpp> // for Entity
40 #include <stk_mesh/base/GetEntities.hpp> // for count_entities, etc
41 #include <stk_mesh/base/MetaData.hpp> // for MetaData
42 #include <stk_mesh/base/Selector.hpp> // for Selector
43 #include <stk_mesh/base/SkinMesh.hpp> // for skin_mesh
44 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc
45 #include <vector> // for vector, etc
46 #include "mpi.h" // for ompi_communicator_t, etc
47
48 #include "stk_mesh/base/Types.hpp" // for PartVector, BucketVector, etc
49 #include "stk_topology/topology.hpp" // for topology, topology::rank_t, etc
50 #include "stk_unit_test_utils/stk_mesh_fixtures/GridFixture.hpp" // for GridFixture
51 namespace stk { namespace mesh { class Part; } }
52 namespace stk { namespace mesh { class Bucket; } }
53
54 static const stk::topology::rank_t NODE_RANK = stk::topology::NODE_RANK;
55
56 using stk::mesh::MetaData;
57
58 class UnitTestStkMeshSkinning {
59 public:
60 UnitTestStkMeshSkinning(stk::ParallelMachine pm) : m_comm(pm), m_num_procs(0), m_rank(0)
61 {
62 m_num_procs = stk::parallel_machine_size( m_comm );
63 m_rank = stk::parallel_machine_rank( m_comm );
64 }
65
66 void test_skinning();
67
68 stk::ParallelMachine m_comm;
69 int m_num_procs;
70 int m_rank;
71 };
72
73 void UnitTestStkMeshSkinning::test_skinning()
74 {
75 // This test will only work for np=1
76 if (m_num_procs > 1) {
77 return;
78 }
79
80 stk::mesh::fixtures::GridFixture grid_mesh(MPI_COMM_WORLD);
81
82 stk::mesh::BulkData& bulk_data = grid_mesh.bulk_data();
83 stk::mesh::MetaData& fem_meta = grid_mesh.fem_meta();
84 const stk::mesh::EntityRank element_rank = stk::topology::ELEMENT_RANK;
85
86 // Create a part for the skin and the shells
87 stk::mesh::Part & skin_part = fem_meta.declare_part("skin_part");
88 stk::mesh::Part & shell_part = fem_meta.declare_part_with_topology("shell_part", stk::topology::SHELL_LINE_2);
89 fem_meta.commit();
90
91 // Begin modification cycle
92 grid_mesh.bulk_data().modification_begin();
93
94 // Generate the plain grid
95 grid_mesh.generate_grid();
96
97 // Add the shells
98 std::vector<size_t> count;
99 stk::mesh::Selector locally_owned(fem_meta.locally_owned_part());
100 stk::mesh::count_entities(locally_owned, bulk_data, count);
101 const unsigned num_shell_1_faces = 4;
102 const unsigned num_shell_2_faces = 2;
103 const unsigned num_shell_faces = num_shell_1_faces + num_shell_2_faces;
104 const unsigned num_entities = count[NODE_RANK] +
105 count[element_rank];
106
107 stk::mesh::PartVector shell_parts;
108 shell_parts.push_back(&shell_part);
109
110 std::vector<stk::mesh::Entity> shell_faces;
111 for (unsigned i = 1; i <= num_shell_faces; ++i) {
112 stk::mesh::Entity new_shell = bulk_data.declare_element(num_entities + i,
113 shell_parts);
114 shell_faces.push_back(new_shell);
115 }
116
117 // Set up relationships for shells
118
119 // declare shell relationships for first shell
120 unsigned node_list_1[5] = {21, 26, 31, 36, 41};
121 for (unsigned i = 0; i < num_shell_1_faces; ++i) {
122 stk::mesh::Entity shell = shell_faces[i];
123 stk::mesh::Entity node1 = bulk_data.get_entity(NODE_RANK, node_list_1[i]);
124 stk::mesh::Entity node2 = bulk_data.get_entity(NODE_RANK, node_list_1[i+1]);
125 bulk_data.declare_relation(shell, node1, 0);
126 bulk_data.declare_relation(shell, node2, 1);
127 }
128
129 // declare shell relationships for second shell
130 unsigned node_list_2[3] = {31, 36, 41};
131 for (unsigned i = 0; i < num_shell_2_faces; ++i) {
132 stk::mesh::Entity shell = shell_faces[i + num_shell_1_faces];
133 stk::mesh::Entity node1 = bulk_data.get_entity(NODE_RANK, node_list_2[i]);
134 stk::mesh::Entity node2 = bulk_data.get_entity(NODE_RANK, node_list_2[i+1]);
135 bulk_data.declare_relation(shell, node1, 0);
136 bulk_data.declare_relation(shell, node2, 1);
137 }
138
139 grid_mesh.bulk_data().modification_end();
140
141 // skin the boundary
142 {
143 stk::mesh::PartVector add_parts(1,&skin_part);
144 stk::mesh::skin_mesh(bulk_data, add_parts);
145 }
146
147 // Grab the skin entities
148 stk::mesh::Selector skin_selector(skin_part);
149 const stk::mesh::BucketVector& edge_buckets = bulk_data.buckets(stk::topology::EDGE_RANK);
150 std::vector<stk::mesh::Entity> skin_entities;
151 stk::mesh::get_selected_entities(skin_selector, edge_buckets, skin_entities);
152
153 unsigned num_expected_skin_entites = 16;
154 EXPECT_EQ(num_expected_skin_entites, skin_entities.size());
155
156 // Map the element id to the number of skins associated with that element
157
158 std::map<unsigned, unsigned> results;
159 std::map<unsigned, unsigned> expected_results;
160
161 expected_results[1] = 2;
162 expected_results[2] = 1;
163 expected_results[3] = 1;
164 expected_results[4] = 1;
165 expected_results[5] = 1;
166 expected_results[9] = 1;
167 expected_results[13] = 2;
168 expected_results[14] = 1;
169 expected_results[15] = 1;
170 expected_results[16] = 1;
171 expected_results[42] = 1;
172 expected_results[43] = 1;
173 expected_results[44] = 1;
174 expected_results[45] = 1;
175 expected_results[46] = 1;
176 expected_results[47] = 1;
177
178 // Vector of of vector of entities (shells) that are expected to share a skin
179
180 std::set<std::set<unsigned> > sharing;
181 std::set<std::set<unsigned> > expected_sharing;
182
183 std::set<unsigned> temp;
184 temp.insert(44);
185 temp.insert(46);
186 expected_sharing.insert(temp);
187
188 temp.clear();
189 temp.insert(45);
190 temp.insert(47);
191 expected_sharing.insert(temp);
192
193 // map skin-id to ids of elements it is attached to; we will use this to
194 // compute sharing
195 for (std::vector<stk::mesh::Entity>::const_iterator
196 itr = skin_entities.begin(); itr != skin_entities.end(); ++itr)
197 {
198 stk::mesh::Entity const *elem_itr = bulk_data.begin_elements(*itr);
199 stk::mesh::Entity const *elem_end = bulk_data.end_elements(*itr);
200 bool has_multiple = bulk_data.num_elements(*itr) > 1;
201 std::set<unsigned> sharing_elements;
202 for ( ; elem_itr != elem_end ; ++elem_itr )
203 {
204 unsigned elem_id = bulk_data.identifier(*elem_itr);
205
206 if (results.find(elem_id) != results.end()) {
207 ++results[elem_id];
208 }
209 else {
210 results[elem_id] = 1;
211 }
212
213 if (has_multiple) {
214 sharing_elements.insert(elem_id);
215 }
216 }
217 if (has_multiple) {
218 sharing.insert(sharing_elements);
219 }
220 }
221
222 EXPECT_TRUE(results == expected_results);
223 EXPECT_TRUE(sharing == expected_sharing);
224 }
225