Debian Codegraph @

packages/stk/stk_unit_tests/stk_io/UnitTestReadWriteUtils.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 #ifndef UNIT_TEST_READ_WRITE_UTILS_HPP
35 #define UNIT_TEST_READ_WRITE_UTILS_HPP
36
37 #include <stk_topology/topology.hpp>
38 #include <stk_mesh/base/BulkData.hpp>
39 #include <stk_mesh/base/MetaData.hpp>
40 #include <stk_mesh/base/GetEntities.hpp>
41 #include <stk_mesh/baseImpl/MeshImplUtils.hpp>
42 #include <stk_mesh/baseImpl/ConnectEdgesImpl.hpp>
43 #include <stk_mesh/base/Types.hpp>
44 #include <stk_mesh/base/Comm.hpp>
45 #include <stk_mesh/base/Field.hpp>
46 #include <stk_mesh/base/FEMHelpers.hpp>
47 #include <stk_mesh/base/SkinBoundary.hpp>
48 #include <stk_unit_test_utils/GetMeshSpec.hpp>
49 #include <stk_unit_test_utils/TextMesh.hpp>
50 #include <stk_unit_test_utils/MeshFixture.hpp>
51 #include <stk_io/FillMesh.hpp>
52 #include <stk_io/IossBridge.hpp>
53 #include <stk_io/StkMeshIoBroker.hpp>
54 #include <stk_util/parallel/Parallel.hpp>
55
56 namespace io_test_utils {
57
58 struct ExpectedValues
59 {
60 ExpectedValues()
61 : numConnectedEdges(0),
62 globalEdgeCount(0),
63 globalElemCount(0)
64 {}
65
66 ExpectedValues(std::vector<unsigned> numLocalEdgesPerProc_, unsigned /*numFaces_*/,
67 unsigned numConnectedEdges_, unsigned globalEdgeCount_, unsigned globalElemCount_)
68 : numLocalEdgesPerProc(numLocalEdgesPerProc_),
69 numConnectedEdges(numConnectedEdges_),
70 globalEdgeCount(globalEdgeCount_),
71 globalElemCount(globalElemCount_)
72 {}
73
74 std::vector<unsigned> numEdgesPerProc;
75 std::vector<unsigned> numLocalEdgesPerProc;
76 std::vector<unsigned> numFacesPerProc;
77 std::vector<unsigned> numLocalFacesPerProc;
78 unsigned numConnectedEdges;
79 unsigned globalEdgeCount;
80 unsigned globalElemCount;
81 };
82
83 inline bool is_entity1_connected_to_entity2(const stk::mesh::BulkData& bulk, const stk::mesh::Entity entity1, const stk::mesh::Entity entity2)
84 {
85 stk::mesh::EntityRank entityRank = bulk.entity_rank(entity2);
86
87 unsigned numConnection = bulk.num_connectivity(entity1, entityRank);
88
89 const stk::mesh::Entity* connectedEntities = bulk.begin(entity1, entityRank);
90 for(unsigned i = 0; i < numConnection; i++) {
91 if(connectedEntities[i] == entity2) {
92 return true;
93 }
94 }
95 return false;
96 }
97
98 inline bool is_fully_connected(const stk::mesh::BulkData& bulk, const stk::mesh::Entity entity1, const stk::mesh::Entity entity2)
99 {
100 bool entity1IsConnectedToEntity2 = is_entity1_connected_to_entity2(bulk, entity1, entity2);
101 bool entity2IsConnectedToEntity1 = is_entity1_connected_to_entity2(bulk, entity2, entity1);
102
103 return entity1IsConnectedToEntity2 && entity2IsConnectedToEntity1;
104 }
105
106 }//io_test_utils
107
108 #endif