Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/UnitTestFEMHelper.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>
36 #include <vector> // for vector
37 #include <stk_mesh/base/BulkData.hpp> // for BulkData
38 #include <stk_util/parallel/Parallel.hpp> // for ParallelMachine
39 #include "stk_mesh/base/Selector.hpp" // for Selector
40 #include <stk_mesh/base/CreateEdges.hpp> // for create_edges
41 #include <stk_mesh/base/CreateFaces.hpp> // for create_edges
42 #include "stk_mesh/base/Entity.hpp" // for Entity
43 #include <stk_mesh/base/FEMHelpers.hpp> // for declare_element
44 #include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names
45 #include "stk_mesh/base/Types.hpp" // for EntityProc, EntityId, etc
46 #include "stk_topology/topology.hpp" // for topology, etc
47 #include "stk_mesh/base/GetEntities.hpp" // for count_entities
48 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
49 #include <stk_mesh/base/Comm.hpp>
50 #include <array>
51 #include <stk_unit_test_utils/FaceTestingUtils.hpp>
52 #include <stk_unit_test_utils/BuildMesh.hpp>
53
54 using stk::mesh::MetaData;
55 using stk::mesh::BulkData;
56 using stk::mesh::Selector;
57 using stk::mesh::PartVector;
58 using stk::mesh::Entity;
59 using stk::mesh::EntityId;
60 using stk::mesh::EntityKey;
61 using stk::mesh::EntityVector;
62 using stk::mesh::EntityRank;
63 using stk::unit_test_util::build_mesh;
64
65 TEST(FEMHelper, get_ordinal_and_permutation)
66 {
67 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2)
68 {
69 unsigned gold_side_node_ids[4] = {5,6,8,7};
70 unsigned gold_num_nodes = 4;
71
72 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
73 std::string name = "generated:1x1x2";
74 stkMeshIoBroker.add_mesh_database(name, stk::io::READ_MESH);
75 stkMeshIoBroker.create_input_mesh();
76 stkMeshIoBroker.populate_bulk_data();
77
78 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
79
80 unsigned elem_id = 0;
81 unsigned gold_local_side_id = 0;
82 unsigned perm_value = 0;
83
84 if (mesh.parallel_rank()==0)
85 {
86 gold_local_side_id=5;
87 elem_id = 1;
88 perm_value = 0;
89 }
90 else
91 {
92 gold_local_side_id=4;
93 elem_id = 2;
94 perm_value = 4;
95 }
96
97 stk::mesh::Permutation gold_permutation = static_cast<stk::mesh::Permutation>(perm_value);
98
99 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEM_RANK, elem_id);
100 EXPECT_TRUE(mesh.bucket(elem).owned());
101
102 stk::mesh::EntityVector side_nodes(gold_num_nodes);
103 for(unsigned i = 0; i < gold_num_nodes; ++i)
104 {
105 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i]);
106 side_nodes[i] = node;
107 }
108
109 stk::mesh::EntityRank to_rank = stk::topology::FACE_RANK;
110 std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation
111 = stk::mesh::get_ordinal_and_permutation(mesh, elem, to_rank, side_nodes);
112
113 ASSERT_TRUE(ordinalAndPermutation.first != stk::mesh::INVALID_CONNECTIVITY_ORDINAL);
114 ASSERT_TRUE(ordinalAndPermutation.second != stk::mesh::INVALID_PERMUTATION);
115
116 EXPECT_EQ(gold_local_side_id, ordinalAndPermutation.first);
117 EXPECT_EQ(gold_permutation, ordinalAndPermutation.second);
118 }
119 }
120
121 TEST(FEMHelper, check_permutation_consistency_using_FEMHelper_parallel)
122 {
123 if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2)
124 {
125 stk::mesh::EntityId global_side_id = 1;
126 unsigned gold_side_node_ids[4] = {5,6,8,7};
127 unsigned gold_num_nodes = 4;
128
129 stk::io::StkMeshIoBroker stkMeshIoBroker(MPI_COMM_WORLD);
130 std::string name = "generated:1x1x2";
131 stkMeshIoBroker.add_mesh_database(name, stk::io::READ_MESH);
132 stkMeshIoBroker.create_input_mesh();
133 stkMeshIoBroker.populate_bulk_data();
134
135 stk::mesh::BulkData &mesh = stkMeshIoBroker.bulk_data();
136
137 unsigned elem_id = 0;
138 if (mesh.parallel_rank()==0)
139 elem_id = 1;
140 else
141 elem_id = 2;
142
143 stk::mesh::Entity elem = mesh.get_entity(stk::topology::ELEM_RANK, elem_id);
144 EXPECT_TRUE(mesh.bucket(elem).owned());
145
146 stk::mesh::EntityVector side_nodes(gold_num_nodes);
147 for(unsigned i = 0; i < gold_num_nodes; ++i) {
148 stk::mesh::Entity node = mesh.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i]);
149 side_nodes[i] = node;
150 }
151
152 stk::mesh::Part &part = mesh.mesh_meta_data().get_topology_root_part(stk::topology::QUAD_4);
153 mesh.modification_begin();
154 stk::mesh::Entity side = stk::unit_test_util::declare_element_side_with_nodes(mesh, elem, side_nodes, global_side_id, part);
155 EXPECT_NO_THROW(mesh.modification_end());
156
157 std::vector<size_t> mesh_counts;
158 stk::mesh::comm_mesh_counts(mesh, mesh_counts);
159 size_t numFacesGlobal = 1u;
160 EXPECT_EQ(numFacesGlobal, mesh_counts[stk::topology::FACE_RANK]);
161 EXPECT_TRUE(mesh.is_valid(side));
162 }
163 }
164
165 template <typename DATATYPE, size_t IDIM, size_t JDIM>
166 std::vector <std::vector<DATATYPE> > build_2D_vector(std::array< std::array <DATATYPE, JDIM>, IDIM> inputarray)
167 {
168 std::vector <std::vector<DATATYPE> > retval(IDIM);
169
170 for (unsigned i = 0; i < IDIM; ++i) {
171 retval[i].resize(JDIM);
172 for (unsigned j = 0; j < JDIM; ++j) {
173 retval[i][j] = inputarray[i][j];
174 }
175 }
176
177 return retval;
178 }
179
180 void build_element_from_topology_verify_ordinals_and_permutations(stk::mesh::BulkData &bulk,
181 const stk::topology topo,
182 const stk::mesh::EntityIdVector & elem_node_ids,
183 const stk::mesh::EntityIdVector & edge_ids,
184 const std::vector < std::vector < unsigned > > &gold_side_node_ids,
185 const unsigned * gold_side_permutations,
186 const std::vector < std::vector < unsigned > > &gold_edge_node_ids,
187 const unsigned * gold_edge_permutations)
188 {
189 stk::mesh::EntityId element_id[1] = {1};
190 stk::mesh::MetaData &meta = bulk.mesh_meta_data();
191 stk::mesh::Part &elem_part = meta.declare_part_with_topology("elem_part", topo);
192
193 meta.commit();
194 bulk.modification_begin();
195
196 stk::mesh::Entity elem = stk::mesh::declare_element(bulk, elem_part, element_id[0], elem_node_ids);
197
198 stk::mesh::EntityVector side_nodes;
199 uint num_sides = topo.num_sides();
200 stk::topology::rank_t sub_topo_rank = topo.side_rank();
201
202 for(uint i = 0; i < num_sides; ++i)
203 {
204 // FIXME SHELL_SIDE_TOPO
205 if (topo.is_shell() && topo.side_rank() == stk::topology::FACE_RANK && i >= topo.num_faces()) { continue; }
206
207 stk::topology sub_topo = topo.side_topology(i);
208 bulk.declare_element_side(elem, i, stk::mesh::ConstPartVector{&meta.get_topology_root_part(sub_topo)});
209
210 side_nodes.clear();
211
212 for (uint j = 0; j < sub_topo.num_nodes(); ++j)
213 {
214 stk::mesh::Entity side_node = bulk.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i][j]);
215 side_nodes.push_back(side_node);
216 }
217
218 stk::mesh::OrdinalAndPermutation ordinalAndPermutation = stk::mesh::get_ordinal_and_permutation(bulk, elem, sub_topo_rank, side_nodes);
219
220 EXPECT_EQ(ordinalAndPermutation.second, gold_side_permutations[i]) << topo;
221 EXPECT_EQ(ordinalAndPermutation.first, i) << topo;
222 }
223
224 if (edge_ids.empty()) {
225 bulk.modification_end();
226 return;
227 }
228
229 stk::mesh::EntityVector edge_nodes;
230 uint num_edges = topo.num_edges();
231
232 for(uint i = 0; i < num_edges; ++i)
233 {
234 edge_nodes.clear();
235
236 stk::mesh::Entity edge = bulk.declare_edge(edge_ids[i], stk::mesh::ConstPartVector{&meta.get_topology_root_part(topo.edge_topology(i))});
237
238 for (uint j = 0; j < topo.edge_topology(i).num_nodes(); ++j)
239 {
240 stk::mesh::Entity edge_node = bulk.get_entity(stk::topology::NODE_RANK, gold_edge_node_ids[i][j]);
241 edge_nodes.push_back(edge_node);
242 bulk.declare_relation(edge, edge_node, j);
243 }
244
245 std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation
246 = stk::mesh::get_ordinal_and_permutation(bulk, elem, stk::topology::EDGE_RANK, edge_nodes);
247
248 EXPECT_EQ(ordinalAndPermutation.second, gold_edge_permutations[i]) << topo;
249 EXPECT_EQ(ordinalAndPermutation.first, i) << topo;
250 }
251
252 bulk.modification_end();
253 }
254
255 void verify_unbuildable_element(stk::mesh::BulkData &bulk,
256 const stk::topology topo,
257 const stk::mesh::EntityIdVector & elem_node_ids,
258 const stk::mesh::EntityIdVector & side_ids,
259 const std::vector < std::vector < unsigned > > &gold_side_node_ids,
260 bool *sides_connectibility_check,
261 const stk::mesh::EntityIdVector & edge_ids,
262 const std::vector < std::vector < unsigned > > &gold_edge_node_ids,
263 bool *edges_connectibility_check)
264 {
265 stk::mesh::EntityId element_id[1] = {1};
266 stk::mesh::MetaData &meta = bulk.mesh_meta_data();
267 stk::mesh::Part &elem_part = meta.declare_part_with_topology("elem_part", topo);
268
269 meta.commit();
270 bulk.modification_begin();
271
272 stk::mesh::Entity elem = stk::mesh::declare_element(bulk, elem_part, element_id[0], elem_node_ids);
273
274 stk::mesh::EntityVector side_nodes;
275 uint num_sides = topo.num_sides();
276 stk::topology::rank_t sub_topo_rank = topo.side_rank();
277
278 for(uint i = 0; i < num_sides; ++i)
279 {
280 stk::topology sub_topo = topo.side_topology(i);
281 side_nodes.clear();
282
283 stk::mesh::Entity side = bulk.declare_solo_side(side_ids[i], {&meta.get_topology_root_part(sub_topo)});
284
285 for (uint j = 0; j < sub_topo.num_nodes(); ++j)
286 {
287 stk::mesh::Entity side_node = bulk.get_entity(stk::topology::NODE_RANK, gold_side_node_ids[i][j]);
288 side_nodes.push_back(side_node);
289 bulk.declare_relation(side, side_node, j);
290 }
291
292 std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation
293 = stk::mesh::get_ordinal_and_permutation(bulk, elem, sub_topo_rank, side_nodes);
294
295 if (sides_connectibility_check[i])
296 {
297 EXPECT_NE(ordinalAndPermutation.first, stk::mesh::INVALID_CONNECTIVITY_ORDINAL);
298 EXPECT_NE(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION);
299 }
300 else
301 {
302 EXPECT_EQ(ordinalAndPermutation.first, stk::mesh::INVALID_CONNECTIVITY_ORDINAL);
303 EXPECT_EQ(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION);
304 }
305 }
306
307 if (edge_ids.empty()) {
308 bulk.modification_end();
309 return;
310 }
311
312 stk::mesh::EntityVector edge_nodes;
313 uint num_edges = topo.num_edges();
314
315 for(uint i = 0; i < num_edges; ++i)
316 {
317 edge_nodes.clear();
318
319 stk::mesh::Entity edge = bulk.declare_edge(edge_ids[i], stk::mesh::ConstPartVector{&meta.get_topology_root_part(topo.edge_topology(i))});
320
321 for (uint j = 0; j < topo.edge_topology(i).num_nodes(); ++j)
322 {
323 stk::mesh::Entity edge_node = bulk.get_entity(stk::topology::NODE_RANK, gold_edge_node_ids[i][j]);
324 edge_nodes.push_back(edge_node);
325 bulk.declare_relation(edge, edge_node, j);
326 }
327
328 std::pair<stk::mesh::ConnectivityOrdinal, stk::mesh::Permutation> ordinalAndPermutation
329 = stk::mesh::get_ordinal_and_permutation(bulk, elem, stk::topology::EDGE_RANK, edge_nodes);
330
331 if (edges_connectibility_check[i])
332 {
333 EXPECT_NE(ordinalAndPermutation.first, stk::mesh::INVALID_CONNECTIVITY_ORDINAL);
334 EXPECT_NE(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION);
335 }
336 else
337 {
338 EXPECT_EQ(ordinalAndPermutation.first, stk::mesh::INVALID_CONNECTIVITY_ORDINAL);
339 EXPECT_EQ(ordinalAndPermutation.second, stk::mesh::Permutation::INVALID_PERMUTATION);
340 }
341 }
342
343 bulk.modification_end();
344 }
345
346 TEST(FEMHelper, test_permutations_for_key_topologies)
347 {
348 stk::ParallelMachine pm = MPI_COMM_WORLD;
349 const int p_size = stk::parallel_machine_size(pm);
350
351 if (p_size != 1) {
352 return;
353 }
354
355 int spatial_dimension;
356 stk::topology topo;
357
358 const unsigned num_test_topologies = 10;
359 stk::topology test_topologies[num_test_topologies] = {stk::topology::TRI_3_2D,
360 stk::topology::QUAD_4_2D,
361 stk::topology::SHELL_TRI_3,
362 stk::topology::SHELL_QUAD_4,
363 stk::topology::TET_4,
364 stk::topology::PYRAMID_5,
365 stk::topology::WEDGE_6,
366 stk::topology::HEX_8,
367 stk::topology::TRI_6_2D,
368 stk::topology::TET_10};
369
370 // check that the permutations define the same sides
371 for (size_t index = 0; index < num_test_topologies; ++index)
372 {
373 topo = test_topologies[index];
374
375 if(topo.rank() == stk::topology::ELEMENT_RANK)
376 {
377 spatial_dimension = topo.dimension();
378 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatial_dimension, pm);
379 stk::mesh::BulkData& bulk = *bulkPtr;
380
381 //specific to topology
382 switch (topo)
383 {
384 case stk::topology::TRI_3_2D:
385 {
386 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3};
387
388 std::array < std::array <unsigned, 2>, 3 > gold_side_node_ids_data = {{{{1,2}},{{3,2}},{{3,1}}}};
389 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
390 unsigned gold_side_permutations[3] = { 0, 1, 0 };
391 stk::mesh::EntityIdVector edge_ids;
392 std::vector < std::vector < unsigned > > gold_edge_node_ids;
393 unsigned * gold_edge_permutations = NULL;
394
395 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
396 edge_ids, gold_side_node_ids,
397 &gold_side_permutations[0], gold_edge_node_ids,
398 gold_edge_permutations);
399 break;
400 }
401 case stk::topology::QUAD_4_2D:
402 {
403 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4};
404
405 std::array < std::array <unsigned, 2>, 4 > gold_side_node_ids_data = {{ {{1,2}}, {{2,3}}, {{4,3}}, {{4,1}} }};
406 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
407 unsigned gold_side_permutations[4] = { 0, 0, 1, 0 };
408 stk::mesh::EntityIdVector edge_ids;
409 std::vector < std::vector < unsigned > > gold_edge_node_ids;
410 unsigned * gold_edge_permutations = NULL;
411
412 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
413 edge_ids, gold_side_node_ids,
414 &gold_side_permutations[0], gold_edge_node_ids,
415 gold_edge_permutations);
416
417 break;
418 }
419 case stk::topology::SHELL_TRI_3:
420 {
421 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3};
422 stk::mesh::EntityIdVector edge_ids {1, 2, 3};
423
424 std::vector<std::vector<unsigned>> gold_face_node_ids = { {1,2,3}, {3,2,1} };
425 unsigned gold_face_permutations[5] = { 0, 1 };
426
427 std::array < std::array <unsigned, 2>, 3 > gold_edge_node_ids_data = {{ {{1,2}}, {{3,2}}, {{3,1}} }};
428 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
429 unsigned gold_edge_permutations[4] = { 0, 1, 0 };
430
431 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
432 edge_ids, gold_face_node_ids,
433 &gold_face_permutations[0], gold_edge_node_ids,
434 &gold_edge_permutations[0]);
435
436 break;
437 }
438 case stk::topology::SHELL_QUAD_4:
439 {
440 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4};
441 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4};
442
443 std::vector<std::vector<unsigned>> gold_face_node_ids = { {1,2,3,4}, {4,3,2,1} };
444 unsigned gold_face_permutations[6] = { 0, 1 };
445
446 std::array < std::array <unsigned, 2>, 4 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{4,3}}, {{4,1}} }};
447 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
448 unsigned gold_edge_permutations[4] = { 0, 0, 1, 0 };
449
450 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
451 edge_ids, gold_face_node_ids,
452 &gold_face_permutations[0], gold_edge_node_ids,
453 &gold_edge_permutations[0]);
454
455 break;
456 }
457 case stk::topology::TET_4:
458 {
459 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4};
460 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6};
461
462 std::array < std::array <unsigned, 3>, 4 > gold_side_node_ids_data = {{ {{1,2,4}}, {{2,3,4}},
463 {{1,3,4}}, {{3,2,1}} }};
464 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
465 unsigned gold_side_permutations[4] = { 0, 0, 3, 1 };
466
467 std::array < std::array <unsigned, 2>, 6 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{3,1}},
468 {{1,4}}, {{4,2}}, {{3,4}} }};
469 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
470 unsigned gold_edge_permutations[6] = { 0, 0, 0, 0, 1, 0 };
471
472 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
473 edge_ids, gold_side_node_ids,
474 &gold_side_permutations[0], gold_edge_node_ids,
475 &gold_edge_permutations[0]);
476 break;
477 }
478 case stk::topology::PYRAMID_5:
479 {
480 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5};
481 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6, 7, 8};
482
483 std::array < std::array <unsigned, 4>, 5 > gold_side_node_ids_data = {{ {{1,2,5,0}}, {{2,3,5,0}},
484 {{3,4,5,0}}, {{4,5,1,0}},
485 {{1,4,3,2}} }};
486 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
487 unsigned gold_side_permutations[5] = { 0, 0, 0, 4, 0 };
488
489 std::array < std::array <unsigned, 2>, 8 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{3,4}}, {{4,1}},
490 {{1,5}}, {{2,5}}, {{5,3}}, {{4,5}} }};
491 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
492 unsigned gold_edge_permutations[8] = { 0, 0, 0, 0, 0, 0, 1, 0 };
493
494 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
495 edge_ids, gold_side_node_ids,
496 &gold_side_permutations[0], gold_edge_node_ids,
497 &gold_edge_permutations[0]);
498
499 break;
500 }
501 case stk::topology::WEDGE_6:
502 {
503 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5, 6};
504 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6, 7, 8, 9};
505
506 std::array < std::array <unsigned, 4>, 5 > gold_side_node_ids_data = {{ {{1,2,5,4}}, {{3,6,5,2}},
507 {{1,4,6,3}}, {{1,2,3,0}},
508 {{4,5,6,0}} }};
509 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
510 unsigned gold_side_permutations[5] = { 0, 1, 0, 3, 0 };
511
512 std::array < std::array <unsigned, 2>, 9 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{3,1}},
513 {{4,5}}, {{5,6}}, {{6,4}},
514 {{1,4}}, {{5,2}}, {{3,6}} }};
515 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
516 unsigned gold_edge_permutations[9] = { 0, 0, 0, 0, 0, 0, 0, 1, 0 };
517
518 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
519 edge_ids, gold_side_node_ids,
520 &gold_side_permutations[0], gold_edge_node_ids,
521 &gold_edge_permutations[0]);
522
523 break;
524 }
525 case stk::topology::HEX_8:
526 {
527 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5, 6, 7, 8};
528 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
529
530 std::array < std::array <unsigned, 4>, 6 > gold_side_node_ids_data = {{ {{1,2,6,5}}, {{2,3,7,6}}, {{3,4,8,7}},
531 {{1,5,8,4}}, {{1,2,3,4}}, {{5,6,7,8}} }};
532 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
533 unsigned gold_side_permutations[6] = { 0, 0, 0, 0, 4, 0 };
534
535 std::array < std::array <unsigned, 2>, 12 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{3,4}}, {{4,1}},
536 {{5,6}}, {{6,7}}, {{7,8}}, {{8,5}},
537 {{1,5}}, {{2,6}}, {{7,3}}, {{4,8}} }};
538 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
539 unsigned gold_edge_permutations[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 };
540
541 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
542 edge_ids, gold_side_node_ids,
543 &gold_side_permutations[0], gold_edge_node_ids,
544 &gold_edge_permutations[0]);
545
546 break;
547 }
548 case stk::topology::TRI_6_2D:
549 {
550 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5, 6};
551
552 std::array < std::array <unsigned, 3>, 3 > gold_side_node_ids_data = {{ {{1,2,4}}, {{3,2,5}}, {{3,1,6}} }};
553 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
554 unsigned gold_side_permutations[3] = { 0, 1, 0};
555
556 stk::mesh::EntityIdVector edge_ids;
557 std::vector < std::vector < unsigned > > gold_edge_node_ids;
558 unsigned * gold_edge_permutations = NULL;
559
560 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
561 edge_ids, gold_side_node_ids,
562 &gold_side_permutations[0], gold_edge_node_ids,
563 gold_edge_permutations);
564
565 break;
566 }
567 case stk::topology::TET_10:
568 {
569 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
570 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6};
571
572 std::array < std::array <unsigned, 6>, 4 > gold_side_node_ids_data = {{ {{1,2,4, 5,9,8}},
573 {{4,2,3, 9,6,10}},
574 {{1,4,3, 8,10,7}},
575 {{1,3,2, 7,6,5}} }};
576 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
577 unsigned gold_side_permutations[4] = { 0, 2, 0, 0 };
578
579 std::array < std::array <unsigned, 3>, 6 > gold_edge_node_ids_data = {{ {{1,2, 5}}, {{2,3, 6}}, {{3,1, 7}},
580 {{1,4, 8}}, {{4,2, 9}}, {{3,4, 10}} }};
581 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
582 unsigned gold_edge_permutations[6] = { 0, 0, 0, 0, 1, 0 };
583
584 build_element_from_topology_verify_ordinals_and_permutations(bulk, topo, elem_node_ids,
585 edge_ids, gold_side_node_ids,
586 &gold_side_permutations[0], gold_edge_node_ids,
587 &gold_edge_permutations[0]);
588
589 break;
590 }
591 default :
592 {
593 throw std::runtime_error("Invalid Topology\n");
594 }
595 }
596 }
597 }
598 }
599
600 TEST(FEMHelper, verify_connectibility_failure)
601 {
602 stk::ParallelMachine pm = MPI_COMM_WORLD;
603 const int p_size = stk::parallel_machine_size(pm);
604
605 if (p_size != 1) {
606 return;
607 }
608
609 int spatial_dimension;
610 stk::topology topo;
611
612 const unsigned num_test_topologies = 2;
613 stk::topology test_topologies[num_test_topologies] = { stk::topology::PYRAMID_5, stk::topology::TET_10};
614
615 // check that the permutations define the same sides
616 for (size_t index = 0; index < num_test_topologies; ++index)
617 {
618 topo = test_topologies[index];
619
620 if(topo.rank() == stk::topology::ELEMENT_RANK)
621 {
622 spatial_dimension = topo.dimension();
623
624 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatial_dimension, pm);
625 stk::mesh::BulkData& bulk = *bulkPtr;
626
627 //specific to topology
628 switch (topo)
629 {
630 case stk::topology::PYRAMID_5:
631 {
632 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5};
633 stk::mesh::EntityIdVector side_ids {7, 8, 9, 10, 17};
634 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6, 7, 8};
635
636 std::array < std::array <unsigned, 4>, 5 > gold_side_node_ids_data = {{ {{1,2,5,0}}, {{2,3,5,0}},
637 {{3,4,5,0}}, {{4,5,1,0}},
638 {{1,3,4,2}} }};
639 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
640
641 std::array < std::array <unsigned, 2>, 8 > gold_edge_node_ids_data = {{ {{1,2}}, {{2,3}}, {{3,4}}, {{4,1}},
642 {{1,5}}, {{2,5}}, {{5,3}}, {{4,5}} }};
643 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
644
645 bool sides_connectibility_check[5] = { 1, 1, 1, 1, 0 };
646 bool edges_connectibility_check[8] = { 1, 1, 1, 1, 1, 1, 1, 1 };
647 verify_unbuildable_element(bulk, topo, elem_node_ids, side_ids, gold_side_node_ids,
648 sides_connectibility_check, edge_ids, gold_edge_node_ids,
649 edges_connectibility_check);
650 break;
651 }
652 case stk::topology::TET_10:
653 {
654 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
655 stk::mesh::EntityIdVector side_ids {7, 8, 9, 10};
656 stk::mesh::EntityIdVector edge_ids {1, 2, 3, 4, 5, 6};
657
658 std::array < std::array <unsigned, 6>, 4 > gold_side_node_ids_data = {{ {{1,2,4, 5,9,8}},
659 {{4,2,3, 9,6,10}},
660 {{1,4,3, 8,10,7}},
661 {{1,3,2, 7,6,5}} }};
662 std::vector < std::vector < unsigned > > gold_side_node_ids = build_2D_vector(gold_side_node_ids_data);
663
664 std::array < std::array <unsigned, 3>, 6 > gold_edge_node_ids_data = {{ {{1,2, 5}}, {{2,3, 6}}, {{3,1, 7}},
665 {{1,4, 8}}, {{4,9, 2}}, {{3,4, 10}} }};
666 std::vector < std::vector < unsigned > > gold_edge_node_ids = build_2D_vector(gold_edge_node_ids_data);
667
668 bool sides_connectibility_check[4] = { 1, 1, 1, 1 };
669 bool edges_connectibility_check[6] = { 1, 1, 1, 1, 0, 1 };
670 verify_unbuildable_element(bulk, topo, elem_node_ids, side_ids, gold_side_node_ids,
671 sides_connectibility_check, edge_ids, gold_edge_node_ids,
672 edges_connectibility_check);
673 break;
674 }
675 default:
676 {
677 throw std::runtime_error("Invalid Topology\n");
678 }
679 }
680 }
681 }
682 }
683
684 TEST(FEMHelper, shell_edge_equivalent_and_positive)
685 {
686 stk::ParallelMachine pm = MPI_COMM_WORLD;
687 int p_size = stk::parallel_machine_size(pm);
688
689 if (p_size > 1) {
690 return;
691 }
692
693 const unsigned spatialDim = 3;
694 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
695 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
696 stk::mesh::BulkData& mesh = *bulkPtr;
697
698 stk::mesh::Part * shellPart = &meta.declare_part_with_topology("shell_part", stk::topology::SHELL_QUAD_4);
699
700 meta.commit();
701
702 mesh.modification_begin();
703
704 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3, 4};
705 stk::mesh::Entity elem = stk::mesh::declare_element(mesh, *shellPart, 1, elem_node_ids);
706 const stk::mesh::Entity* nodes = mesh.begin_nodes(elem);
707 unsigned numNodes = mesh.num_nodes(elem);
708
709 stk::mesh::Part& quadPart = meta.get_topology_root_part(stk::topology::QUAD_4);
710 stk::mesh::EntityId quadSideId = 11;
711 stk::mesh::Entity quadSide = mesh.declare_solo_side(quadSideId, {&quadPart});
712 mesh.declare_relation(elem, quadSide, 0);
713
714 for(unsigned i=0; i<numNodes; ++i) {
715 mesh.declare_relation(quadSide, nodes[i], i);
716 }
717 stk::mesh::Part& linePart = meta.get_topology_root_part(stk::topology::LINE_2);
718 stk::mesh::EntityId lineSideId = 13;
719 stk::mesh::Entity lineSide = mesh.declare_edge(lineSideId, stk::mesh::ConstPartVector{&linePart});
720 mesh.declare_relation(elem, lineSide, 2);
721 mesh.declare_relation(lineSide, nodes[0], 0);
722 mesh.declare_relation(lineSide, nodes[1], 1);
723
724 mesh.modification_end();
725
726 nodes = mesh.begin_nodes(elem);
727 unsigned quadSideOrdinal = 0;
728 stk::mesh::EntityVector quadNodes(nodes, nodes+numNodes);
729 stk::mesh::EquivAndPositive result = stk::mesh::is_side_equivalent_and_positive(mesh, elem, quadSideOrdinal, quadNodes);
730 EXPECT_TRUE(result.is_positive);
731 EXPECT_TRUE(result.is_equiv);
732
733 unsigned lineSideOrdinal = 2;
734 stk::mesh::EntityVector lineNodes(nodes, nodes+2);
735 result = stk::mesh::is_side_equivalent_and_positive(mesh, elem, lineSideOrdinal, lineNodes);
736 EXPECT_TRUE(result.is_positive);
737 EXPECT_TRUE(result.is_equiv);
738 }
739
740 // Hide this entire test in release to prevent Valgrind errors
741 // related to an array bounds overrun.
742 #ifndef NDEBUG
743 TEST(FEMHelper, test_incorrect_nodes)
744 {
745 stk::ParallelMachine pm = MPI_COMM_WORLD;
746 int p_size = stk::parallel_machine_size(pm);
747
748 if (p_size > 1) {
749 return;
750 }
751
752 const unsigned spatialDim = 2;
753 std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, pm);
754 stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data();
755 stk::mesh::BulkData& mesh = *bulkPtr;
756
757 stk::mesh::Part * quadPart = &meta.declare_part_with_topology("quad_part", stk::topology::QUAD_4_2D);
758 meta.commit();
759
760 mesh.modification_begin();
761
762 stk::mesh::EntityIdVector elem_node_ids {1, 2, 3}; // Not enough!!
763 EXPECT_THROW(stk::mesh::declare_element(mesh, *quadPart, 1, elem_node_ids), std::logic_error);
764
765 mesh.modification_end();
766 }
767 #endif