Debian Codegraph @

packages/stk/stk_doc_tests/stk_mesh/IOSidesetFaceCreation.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 <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
37 #include <stk_mesh/base/GetEntities.hpp> // for count_entities
38 #include <stk_mesh/base/MetaData.hpp> // for MetaData
39 #include <stk_mesh/base/Selector.hpp> // for Selector
40 #include <stk_mesh/base/FEMHelpers.hpp>
41 #include <stk_topology/topology.hpp> // for topology, etc
42 #include <string> // for string
43 #include <vector> // for vector
44 #include "stk_io/DatabasePurpose.hpp" // for DatabasePurpose::READ_MESH
45 #include <stddef.h> // for size_t, NULL
46 #include <stk_mesh/baseImpl/MeshImplUtils.hpp>
47
48 #include <stk_unit_test_utils/MeshFixture.hpp>
49
50 namespace stk { namespace mesh { class BulkData; } }
51
52 namespace
53 {
54
55 //BEGIN2hex1sideset
56 TEST(StkMeshHowTo, StkIO2Hex1SidesetFaceCreation_externalFile)
57 {
58 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
59 // ------- |S ------- ------- |F -------
60 // | | |I | | | | |A | |
61 // |HEX1 5<-|D 4 HEX2| --STK-IO--> |HEX1 5<-|C->4 HEX2|
62 // | | |E | | | | |E | |
63 // ------- |S ------- ------- | -------
64 // |E |----> face is put into
65 // |T part surface_1
66 // |---> orientation points outward
67 // from Hex1 face5
68
69 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
70 stkMeshIoBroker.add_mesh_database("ALA.e", stk::io::READ_MESH);
71 stkMeshIoBroker.create_input_mesh();
72 stkMeshIoBroker.populate_bulk_data();
73
74 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
75 stk::mesh::EntityVector all_faces;
76 stk::mesh::get_entities(mesh, stk::topology::FACE_RANK, all_faces);
77 std::sort(all_faces.begin(),all_faces.end());
78 unsigned expected_num_faces = 1;
79 ASSERT_EQ(expected_num_faces, all_faces.size());
80 size_t face_index = 0;
81 stk::mesh::Entity face = all_faces[face_index];
82 stk::topology faceTopology = mesh.bucket(face).topology();
83 ASSERT_EQ(stk::topology::QUAD_4, faceTopology);
84
85 EXPECT_TRUE(mesh.bucket(face).member(*mesh.mesh_meta_data().get_part("surface_1")));
86
87 unsigned expected_connected_elements = 2;
88 ASSERT_EQ(expected_connected_elements, mesh.num_elements(face));
89
90 const stk::mesh::Entity * connected_elements = mesh.begin_elements(face);
91 const stk::mesh::ConnectivityOrdinal * which_side_of_element = mesh.begin_element_ordinals(face);
92 const stk::mesh::Permutation* face_permutations = mesh.begin_element_permutations(face);
93
94 {
95 int element_count = 0;
96 stk::mesh::Entity hex_2 = connected_elements[element_count];
97 EXPECT_EQ(2u, mesh.identifier(hex_2));
98 unsigned expected_face_ordinal = 4;
99 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
100 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
101 EXPECT_FALSE(is_positive_permutation);
102 }
103
104 {
105 int element_count = 1;
106 stk::mesh::Entity hex_1 = connected_elements[element_count];
107 EXPECT_EQ(1u, mesh.identifier(hex_1));
108 unsigned expected_face_ordinal = 5;
109 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
110 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
111 EXPECT_TRUE(is_positive_permutation);
112 }
113
114 }
115 }
116 //END2hex1sideset
117
118 //BEGIN2hex2shell3sideset
119 TEST(StkMeshHowTo, StkIO2Hex2Shell3SidesetFaceCreation_externalFile)
120 {
121 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
122 // ------- |S |S| |S| |S |S -------
123 // | | |I |H| |H| |I |I | |
124 // |HEX1 5<-|D |E| |E0<-|D |D->4 HEX2|
125 // | | |E |L| |L| |E |E | | |
126 // ------- |S |L| |L| |S |S ------- |
127 // |E 3 4 |E |E |
128 // |T |T |T STK
129 // IO
130 // |
131 // V
132 //
133 // ------- |F |S| |S| |F -------
134 // | | |A--|H|->1H| |A | |
135 // |HEX1 5<-|C->1E| |E0<------------|C->4 HEX2|
136 // | | |E |L0<-|L|-------------|E | |
137 // ------- | |L| |L| | -------
138 // | 3 4 |
139 // |---> orientation |-->orientation
140 // |---> in surface_1 part |-->in surface_2 and
141 // surface_3 parts
142
143
144 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
145 stkMeshIoBroker.add_mesh_database("ALefLRA.e", stk::io::READ_MESH);
146 stkMeshIoBroker.create_input_mesh();
147 stkMeshIoBroker.populate_bulk_data();
148
149 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
150 stk::mesh::EntityVector all_faces;
151 stk::mesh::get_entities(mesh, stk::topology::FACE_RANK, all_faces);
152 std::sort(all_faces.begin(),all_faces.end());
153 unsigned expected_num_faces = 2;
154 ASSERT_EQ(expected_num_faces, all_faces.size());
155
156 stk::topology faceTopology = mesh.bucket(all_faces[0]).topology();
157 ASSERT_EQ(stk::topology::QUAD_4, faceTopology);
158 ASSERT_EQ(faceTopology, mesh.bucket(all_faces[1]).topology());
159
160 size_t face_index = 0;
161 {
162 stk::mesh::Entity face = all_faces[face_index];
163 unsigned expected_connected_elements = 3;
164 ASSERT_EQ(expected_connected_elements, mesh.num_elements(face));
165
166 EXPECT_TRUE(mesh.bucket(face).member(*mesh.mesh_meta_data().get_part("surface_1")));
167
168 const stk::mesh::Entity * connected_elements = mesh.begin_elements(face);
169 const stk::mesh::ConnectivityOrdinal * which_side_of_element = mesh.begin_element_ordinals(face);
170 const stk::mesh::Permutation* face_permutations = mesh.begin_element_permutations(face);
171
172 {
173 int element_count = 0;
174 stk::mesh::Entity shell_3 = connected_elements[element_count];
175 EXPECT_EQ(3u, mesh.identifier(shell_3));
176 unsigned expected_face_ordinal = 1;
177 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
178 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
179 EXPECT_FALSE(is_positive_permutation);
180 }
181 {
182 int element_count = 1;
183 stk::mesh::Entity shell_4 = connected_elements[element_count];
184 EXPECT_EQ(4u, mesh.identifier(shell_4));
185 unsigned expected_face_ordinal = 1;
186 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
187 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
188 EXPECT_FALSE(is_positive_permutation);
189 }
190 {
191 int element_count = 2;
192 stk::mesh::Entity hex_1 = connected_elements[element_count];
193 EXPECT_EQ(1u, mesh.identifier(hex_1));
194 unsigned expected_face_ordinal = 5;
195 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
196 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
197 EXPECT_TRUE(is_positive_permutation);
198 }
199 }
200
201 face_index = 1;
202 {
203 stk::mesh::Entity face = all_faces[face_index];
204 unsigned expected_connected_elements = 3;
205 ASSERT_EQ(expected_connected_elements, mesh.num_elements(face));
206
207 EXPECT_TRUE(mesh.bucket(face).member(*mesh.mesh_meta_data().get_part("surface_2")));
208 EXPECT_TRUE(mesh.bucket(face).member(*mesh.mesh_meta_data().get_part("surface_3")));
209
210 const stk::mesh::Entity * connected_elements = mesh.begin_elements(face);
211 const stk::mesh::ConnectivityOrdinal * which_side_of_element = mesh.begin_element_ordinals(face);
212 const stk::mesh::Permutation* face_permutations = mesh.begin_element_permutations(face);
213
214 {
215 int element_count = 0;
216 stk::mesh::Entity shell_3 = connected_elements[element_count];
217 EXPECT_EQ(3u, mesh.identifier(shell_3));
218 unsigned expected_face_ordinal = 0;
219 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
220 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
221 EXPECT_FALSE(is_positive_permutation);
222 }
223 {
224 int element_count = 1;
225 stk::mesh::Entity shell_4 = connected_elements[element_count];
226 EXPECT_EQ(4u, mesh.identifier(shell_4));
227 unsigned expected_face_ordinal = 0;
228 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
229 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
230 EXPECT_FALSE(is_positive_permutation);
231 }
232 {
233 int element_count = 2;
234 stk::mesh::Entity hex_2 = connected_elements[element_count];
235 EXPECT_EQ(2u, mesh.identifier(hex_2));
236 unsigned expected_face_ordinal = 4;
237 EXPECT_EQ(expected_face_ordinal, which_side_of_element[element_count]);
238 bool is_positive_permutation = faceTopology.is_positive_polarity(face_permutations[element_count]);
239 EXPECT_TRUE(is_positive_permutation);
240 }
241 }
242 }
243 }
244 //END2hex2shell3sideset
245
246 class SideCreationExplanation : public stk::unit_test_util::MeshFixture
247 {
248 protected:
249 void test_face_created_on_elem_side_gets_id_16(stk::mesh::EntityId elemId, int sideOrdinal)
250 {
251 setup_mesh("generated:1x1x4", stk::mesh::BulkData::NO_AUTO_AURA);
252 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemId);
253 get_bulk().modification_begin();
254 if(get_bulk().is_valid(elem))
255 {
256 stk::mesh::Entity side = get_bulk().declare_element_side(elem, sideOrdinal, stk::mesh::ConstPartVector{});
257 EXPECT_EQ(16u, get_bulk().identifier(side));
258 }
259 get_bulk().modification_end();
260 }
261 };
262
263 TEST_F(SideCreationExplanation, IdSelectionWhenCreatingSideOnElement1)
264 {
265 test_face_created_on_elem_side_gets_id_16(1, 5);
266 }
267
268 TEST_F(SideCreationExplanation, IdSelectionWhenCreatingSideOnElement2)
269 {
270 test_face_created_on_elem_side_gets_id_16(2, 4);
271 }
272
273 } //end empty namespace