Debian Codegraph @

packages/stk/stk_doc_tests/stk_mesh/CreateFacesHexesShells.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/SkinBoundary.hpp>
38 #include <stk_mesh/base/GetEntities.hpp> // for count_entities
39 #include <stk_mesh/base/MetaData.hpp> // for MetaData
40 #include <stk_mesh/base/Selector.hpp> // for Selector
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
46 namespace stk { namespace mesh { class BulkData; } }
47
48 namespace
49 {
50
51
52 //BEGIN2hex
53 TEST(StkMeshHowTo, CreateFacesTwoHexes_externalFile)
54 {
55 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
56 // -----------
57 // | | |
58 // |HEX1|HEX2|
59 // | | |
60 // -----------
61 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
62 stkMeshIoBroker.add_mesh_database("AA.e", stk::io::READ_MESH);
63 stkMeshIoBroker.create_input_mesh();
64 stkMeshIoBroker.populate_bulk_data();
65 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
66
67 stk::mesh::create_all_sides(mesh, mesh.mesh_meta_data().universal_part());
68
69 // ------ F ------
70 // | | A | |
71 // |HEX1|<-C->|HEX2| Also external faces!
72 // | | E | |
73 // ------ ! ------
74
75 unsigned first_bucket = 0;
76 unsigned first_element_in_bucket = 0;
77 stk::mesh::Entity first_element = (*mesh.buckets(stk::topology::ELEMENT_RANK)[first_bucket])[first_element_in_bucket];
78 stk::mesh::Entity internal_face = mesh.begin_faces(first_element)[5];
79
80 unsigned num_elements_connected_to_single_face = 2;
81 EXPECT_EQ(num_elements_connected_to_single_face, mesh.num_elements(internal_face));
82
83 unsigned num_expected_external_faces = 10u;
84 unsigned num_expected_internal_faces = 1u;
85 unsigned num_expected_faces = num_expected_external_faces + num_expected_internal_faces;
86 stk::mesh::Selector all_entities = mesh.mesh_meta_data().universal_part();
87 std::vector<size_t> entity_counts;
88 stk::mesh::count_entities(all_entities, mesh, entity_counts);
89 EXPECT_EQ(num_expected_faces, entity_counts[stk::topology::FACE_RANK]);
90 }
91 }
92 //END2hex
93
94 //BEGINshell
95 TEST(StkMeshHowTo, CreateFacesSingleShell_externalFile)
96 {
97 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
98 // S
99 // H
100 // E
101 // L
102 // L
103 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
104 stkMeshIoBroker.add_mesh_database("e.e", stk::io::READ_MESH);
105 stkMeshIoBroker.create_input_mesh();
106 stkMeshIoBroker.populate_bulk_data();
107 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
108
109 stk::mesh::create_all_sides(mesh, mesh.mesh_meta_data().universal_part());
110
111 // F S F
112 // A H A
113 // C->E<-C
114 // E L E
115 // 1 L 2
116
117 unsigned first_bucket = 0;
118 unsigned first_element_in_bucket = 0;
119 stk::mesh::Entity first_element = (*mesh.buckets(stk::topology::ELEMENT_RANK)[first_bucket])[first_element_in_bucket];
120 stk::mesh::Entity face_one = mesh.begin_faces(first_element)[0];
121 unsigned num_elements_connected_to_face_one = 1;
122 EXPECT_EQ(num_elements_connected_to_face_one, mesh.num_elements(face_one));
123
124 stk::mesh::Entity face_two = mesh.begin_faces(first_element)[1];
125 unsigned num_elements_connected_to_face_two = 1;
126 EXPECT_EQ(num_elements_connected_to_face_two, mesh.num_elements(face_two));
127
128 EXPECT_NE(face_one, face_two);
129
130 unsigned num_expected_faces = 2u;
131 stk::mesh::Selector all_entities = mesh.mesh_meta_data().universal_part();
132 std::vector<size_t> entity_counts;
133 stk::mesh::count_entities(all_entities, mesh, entity_counts);
134 EXPECT_EQ(num_expected_faces, entity_counts[stk::topology::FACE_RANK]);
135 }
136 }
137 //ENDshell
138
139 //BEGINhexshellhex
140 TEST(StkMeshHowTo, CreateFacesTwoHexesInternalShell_externalFile)
141 {
142 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 1) {
143 // ------S------
144 // | |H| |
145 // |HEX1|E|HEX2|
146 // | |L| |
147 // ------L------
148 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
149 stkMeshIoBroker.add_mesh_database("AeA.e", stk::io::READ_MESH);
150 stkMeshIoBroker.create_input_mesh();
151 stkMeshIoBroker.populate_bulk_data();
152 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
153
154 stk::mesh::create_all_sides(mesh, mesh.mesh_meta_data().universal_part());
155
156 // ------ F S F ------
157 // | | A H A | |
158 // |HEX1|<-C->E<-C->|HEX2| Also external faces!
159 // | | E L E | |
160 // ------ 1 L 2 ------
161
162 unsigned first_bucket = 0;
163 unsigned first_element_in_bucket = 0;
164 stk::mesh::Entity first_element = (*mesh.buckets(stk::topology::ELEMENT_RANK)[first_bucket])[first_element_in_bucket];
165 stk::mesh::Entity internal_face_one = mesh.begin_faces(first_element)[5];
166 unsigned num_elements_connected_to_face_one = 2;
167 EXPECT_EQ(num_elements_connected_to_face_one, mesh.num_elements(internal_face_one));
168
169 unsigned second_element_in_bucket = 1;
170 stk::mesh::Entity second_element = (*mesh.buckets(stk::topology::ELEMENT_RANK)[first_bucket])[second_element_in_bucket];
171 stk::mesh::Entity internal_face_two = mesh.begin_faces(second_element)[4];
172 unsigned num_elements_connected_to_face_two = 2;
173 EXPECT_EQ(num_elements_connected_to_face_two, mesh.num_elements(internal_face_two));
174
175 EXPECT_NE(internal_face_one, internal_face_two);
176
177 unsigned num_expected_external_faces = 10u;
178 unsigned num_expected_internal_faces = 2u;
179 unsigned num_expected_faces = num_expected_external_faces + num_expected_internal_faces;
180 stk::mesh::Selector all_entities = mesh.mesh_meta_data().universal_part();
181 std::vector<size_t> entity_counts;
182 stk::mesh::count_entities(all_entities, mesh, entity_counts);
183 EXPECT_EQ(num_expected_faces, entity_counts[stk::topology::FACE_RANK]);
184 }
185 }
186 //ENDhexshellhex
187
188
189 } //end empty namespace