Debian Codegraph @

packages/stk/stk_unit_tests/stk_mesh/TestElemElemGraphUtils.hpp

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 #ifndef stk_unit_tests_elem_elem_graph_utils_hpp
36 #define stk_unit_tests_elem_elem_graph_utils_hpp
37
38 #include "stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp"
39 #include "stk_mesh/base/ForEachEntity.hpp"
40
41 namespace stk {
42 namespace unit_test {
43
44 inline
45 void verify_no_graph_edges(const stk::mesh::BulkData& bulk)
46 {
47 const stk::mesh::ElemElemGraph& eeGraph = bulk.get_face_adjacent_element_graph();
48 stk::mesh::for_each_entity_run(bulk, stk::topology::ELEM_RANK, bulk.mesh_meta_data().locally_owned_part(),
49 [&eeGraph](const stk::mesh::BulkData& /*mesh*/, stk::mesh::Entity elem) {
50 stk::mesh::impl::LocalId elemLocalId = eeGraph.get_local_element_id(elem);
51 stk::mesh::GraphEdgesForElement graphEdges = eeGraph.get_edges_for_element(elemLocalId);
52 EXPECT_EQ(0u, graphEdges.size());
53 });
54 }
55
56 inline
57 void verify_graph_edge_exists(const stk::mesh::ElemElemGraph& eeGraph,
58 stk::mesh::impl::LocalId elem1LocalId,
59 stk::mesh::impl::LocalId elem2LocalId)
60 {
61 stk::mesh::GraphEdgesForElement graphEdges = eeGraph.get_edges_for_element(elem1LocalId);
62 bool foundIt = false;
63 for(const stk::mesh::GraphEdge& graphEdge : graphEdges) {
64 if (graphEdge.elem2() == elem2LocalId) {
65 foundIt = true;
66 break;
67 }
68 }
69 EXPECT_TRUE(foundIt);
70 }
71
72 inline
73 void verify_graph_edge_between_elems(const stk::mesh::BulkData& bulk,
74 stk::mesh::Entity elem1, stk::mesh::Entity elem2)
75 {
76 const stk::mesh::ElemElemGraph& eeGraph = bulk.get_face_adjacent_element_graph();
77 stk::mesh::impl::LocalId elem1LocalId = eeGraph.get_local_element_id(elem1);
78 stk::mesh::impl::LocalId elem2LocalId = eeGraph.get_local_element_id(elem2);
79
80 verify_graph_edge_exists(eeGraph, elem1LocalId, elem2LocalId);
81 verify_graph_edge_exists(eeGraph, elem2LocalId, elem1LocalId);
82 }
83
84 } // namespace unit_test
85 } // namespace stk
86
87 #endif