Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/SetupKeyholeMesh.hpp

raw
1 #ifndef setupkeyholemeshhpp
2 #define setupkeyholemeshhpp
3 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
4 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
5 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
6 // in this software.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials provided
18 // with the distribution.
19 //
20 // * Neither the name of NTESS nor the names of its contributors
21 // may be used to endorse or promote products derived from this
22 // software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36
37 #include <stddef.h> // for size_t
38 #include <stdlib.h> // for exit
39 #include <exception> // for exception
40 #include <iostream> // for ostringstream, etc
41 #include <iterator> // for distance
42 #include <map> // for _Rb_tree_const_iterator, etc
43 #include <stdexcept> // for logic_error, runtime_error
44 #include <stk_mesh/base/BulkData.hpp> // for BulkData, etc
45 #include <stk_mesh/base/FEMHelpers.hpp>
46 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc
47 #include <string> // for string, basic_string, etc
48 #include <utility> // for pair
49 #include <vector> // for vector, etc
50 #include "stk_mesh/base/Bucket.hpp" // for Bucket, has_superset
51 #include "stk_mesh/base/Entity.hpp" // for Entity
52 #include "stk_mesh/base/EntityKey.hpp" // for EntityKey
53 #include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names, etc
54 #include "stk_mesh/base/Part.hpp" // for Part
55 #include "stk_mesh/base/Types.hpp" // for EntityProc, EntityVector, etc
56 #include "stk_topology/topology.hpp" // for topology, etc
57 #include <stk_unit_test_utils/ioUtils.hpp>
58
59
60 namespace stk { namespace mesh { namespace unit_test {
61
62 inline
63 void setupKeyholeMesh2D_case1(stk::mesh::BulkData& bulk)
64 {
65 //
66 // proc 0 proc 1
67 // |
68 // | block_2 block_3
69 // |
70 // block_1 | 10---9 9----12
71 // | | 3 | | 4 |
72 // 4----3 | 3----8 8----11
73 // | 1 | |
74 // 1----2 | 2----7
75 // | | 2 |
76 // | 5----6
77 // |
78 //
79 //shared nodes 2 and 3 should be members of block_1 and block_2 on both procs
80 //nodes 8 and 9 are ghosts on proc 0, and should be members of block_2 and block_3
81 //
82 //if edges are added, the edge between nodes 2 and 3 should be a member of block_1 not block_2.
83 //
84 //also, the edge between nodes 8 and 9 should be a member of block_2 and block_3 on both procs.
85
86 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
87
88 stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D);
89 stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", stk::topology::QUAD_4_2D);
90 stk::mesh::Part& block_3 = meta.declare_part_with_topology("block_3", stk::topology::QUAD_4_2D);
91 meta.commit();
92
93 bulk.modification_begin();
94
95 stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4};
96 stk::mesh::EntityIdVector elem2_nodes {5, 6, 7, 2};
97 stk::mesh::EntityIdVector elem3_nodes {3, 8, 9, 10};
98 stk::mesh::EntityIdVector elem4_nodes {8, 11, 12, 9};
99
100 stk::mesh::EntityId elemId = 1;
101 if (bulk.parallel_rank() == 0) {
102 stk::mesh::declare_element(bulk, block_1, elemId, elem1_nodes);
103 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
104 stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3);
105 bulk.add_node_sharing(node2, 1);
106 bulk.add_node_sharing(node3, 1);
107 }
108 else if (bulk.parallel_rank() == 1) {
109 elemId = 2;
110 stk::mesh::declare_element(bulk, block_2, elemId, elem2_nodes);
111 elemId = 3;
112 stk::mesh::declare_element(bulk, block_2, elemId, elem3_nodes);
113 elemId = 4;
114 stk::mesh::declare_element(bulk, block_3, elemId, elem4_nodes);
115 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
116 stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3);
117 bulk.add_node_sharing(node2, 0);
118 bulk.add_node_sharing(node3, 0);
119 }
120
121 bulk.modification_end();
122 }
123
124 inline
125 void setupKeyholeMesh2D_case2(stk::mesh::BulkData& bulk)
126 {
127 //
128 // proc 0 proc 1
129 // |
130 // | block_2 block_3
131 // |
132 // block_1 | 12---11
133 // | | 4 |
134 // 4----3 | 3----6 6----10
135 // | 1 | | | 2 |
136 // 1----2 | 2----5 5----9
137 // | | 3 |
138 // | 7----8
139 // |
140 //
141 //nodes 5 and 6 are ghosts (aura) on proc 0,
142 //and should be members of block_2 and block_3 on proc 0
143 //if edges are added, the edge between nodes 5 and 6 should
144 //be a member of block_2 not block_3.
145 //
146
147 stk::mesh::MetaData& meta = bulk.mesh_meta_data();
148
149 stk::mesh::Part& block_1 = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D);
150 stk::mesh::Part& block_2 = meta.declare_part_with_topology("block_2", stk::topology::QUAD_4_2D);
151 stk::mesh::Part& block_3 = meta.declare_part_with_topology("block_3", stk::topology::QUAD_4_2D);
152 meta.commit();
153
154 bulk.modification_begin();
155
156 stk::mesh::EntityIdVector elem1_nodes {1, 2, 3, 4};
157 stk::mesh::EntityIdVector elem2_nodes {2, 5, 6, 3};
158 stk::mesh::EntityIdVector elem3_nodes {7, 8, 9, 5};
159 stk::mesh::EntityIdVector elem4_nodes {6, 10, 11, 12};
160
161 stk::mesh::EntityId elemId = 1;
162 if (bulk.parallel_rank() == 0) {
163 stk::mesh::declare_element(bulk, block_1, elemId, elem1_nodes);
164 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
165 stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3);
166 bulk.add_node_sharing(node2, 1);
167 bulk.add_node_sharing(node3, 1);
168 }
169 else if (bulk.parallel_rank() == 1) {
170 elemId = 2;
171 stk::mesh::declare_element(bulk, block_2, elemId, elem2_nodes);
172 elemId = 3;
173 stk::mesh::declare_element(bulk, block_3, elemId, elem3_nodes);
174 elemId = 4;
175 stk::mesh::declare_element(bulk, block_3, elemId, elem4_nodes);
176 stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, 2);
177 stk::mesh::Entity node3 = bulk.get_entity(stk::topology::NODE_RANK, 3);
178 bulk.add_node_sharing(node2, 0);
179 bulk.add_node_sharing(node3, 0);
180 }
181
182 bulk.modification_end();
183 }
184
185
186 // element ids / proc_id:
187 // |-------|-------|-------|
188 // | | | |
189 // | 1/0 | 4/2 | 7/2 |
190 // | | | |
191 // |-------|-------|-------|
192 // | | | |
193 // | 2/0 | 5/1 | 8/2 |
194 // | | | |
195 // |-------|-------|-------|
196 // | | | |
197 // | 3/0 | 6/2 | 9/2 |
198 // | | | |
199 // |-------|-------|-------|
200 inline
201 void setupKeyholeMesh3D_case1(stk::mesh::BulkData& bulk)
202 {
203 STK_ThrowRequire(bulk.parallel_size() == 3);
204 stk::io::fill_mesh("generated:3x1x3", bulk);
205
206 stk::mesh::EntityProcVec elementProcChanges;
207 if (bulk.parallel_rank() == 1) {
208 elementProcChanges.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK,4u),2));
209 elementProcChanges.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK,6u),2));
210 }
211 bulk.change_entity_owner(elementProcChanges);
212 }
213
214 // element ids / proc_id:
215 // |-------|-------|-------|
216 // | | | |
217 // | 1/0 | 4/2 | 7/2 |
218 // | | | |
219 // |-------|-------|-------|
220 // | | | |
221 // | 2/0 | n/a | 8/2 |
222 // | | | |
223 // |-------|-------|-------|
224 // | | | |
225 // | 3/0 | 6/2 | 9/2 |
226 // | | | |
227 // |-------|-------|-------|
228 // The element in the middle has been deleted
229
230 inline
231 void setupKeyholeMesh3D_case2(stk::mesh::BulkData& bulk)
232 {
233 STK_ThrowRequire(bulk.parallel_size() == 3);
234 stk::io::fill_mesh("generated:3x1x3", bulk);
235
236 stk::mesh::EntityProcVec elementProcChanges;
237 if (bulk.parallel_rank() == 1) {
238 elementProcChanges.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK,4),2));
239 elementProcChanges.push_back(stk::mesh::EntityProc(bulk.get_entity(stk::topology::ELEM_RANK,6),2));
240 }
241 bulk.change_entity_owner(elementProcChanges);
242 bulk.modification_begin();
243 if (bulk.parallel_rank() == 1) {
244 stk::mesh::Entity local_element5 = bulk.get_entity(stk::topology::ELEM_RANK,5);
245 const bool delete_success = bulk.destroy_entity(local_element5);
246 STK_ThrowRequire(delete_success);
247 }
248 bulk.modification_end();
249 }
250
251 } } } // namespace stk mesh unit_test
252
253 #endif