Debian Codegraph @

packages/stk/stk_unit_tests/stk_io/IOMeshFixture.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 STK_UNIT_TESTS_STK_IO_IOMeshFixture_hpp
35 #define STK_UNIT_TESTS_STK_IO_IOMeshFixture_hpp
36
37 #include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc
38
39 #include <algorithm>
40 #include <stk_io/FillMesh.hpp>
41 #include <stk_io/IossBridge.hpp>
42 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
43 #include <stk_mesh/base/ExodusTranslator.hpp>
44 #include <stk_mesh/base/Part.hpp>
45 #include <stk_mesh/base/Selector.hpp>
46 #include <stk_topology/topology.hpp>
47 #include <stk_unit_test_utils/MeshFixture.hpp>
48 #include <string>
49 #include <vector>
50
51 namespace stk
52 {
53 namespace io
54 {
55 namespace unit_test
56 {
57
58 class IOMeshFixture : public stk::unit_test_util::MeshFixture
59 {
60 protected:
61 stk::mesh::Part& create_io_part(const std::string& partName,
62 int id = -1,
63 stk::topology topo = stk::topology::HEX_8)
64 {
65 stk::mesh::Part& part = get_meta().declare_part_with_topology(partName, topo);
66 if (id != -1) {
67 get_meta().set_part_id(part, id);
68 }
69 stk::io::put_io_part_attribute(part);
70 return part;
71 }
72
73 void move_element(const stk::mesh::EntityId elemId,
74 stk::mesh::Part& sourcePart,
75 stk::mesh::Part& destPart)
76 {
77 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemId);
78 get_bulk().batch_change_entity_parts({elem}, {&destPart}, {&sourcePart});
79 }
80
81 void move_face(const stk::mesh::EntityId faceId, stk::mesh::Part& sourcePart, stk::mesh::Part& destPart)
82 {
83 stk::mesh::Entity face = get_bulk().get_entity(get_meta().side_rank(), faceId);
84 get_bulk().batch_change_entity_parts({face}, {&destPart}, {&sourcePart});
85 }
86
87 void add_nodes(const stk::mesh::EntityIdVector nodeIds, stk::mesh::Part& destPart)
88 {
89 stk::mesh::EntityVector nodes;
90 nodes.reserve(nodeIds.size());
91
92 for (stk::mesh::EntityId nodeId : nodeIds) {
93 stk::mesh::Entity node = get_bulk().get_entity(stk::topology::NODE_RANK, nodeId);
94 STK_ThrowRequire(get_bulk().is_valid(node));
95 nodes.push_back(node);
96 }
97
98 get_bulk().batch_change_entity_parts(nodes, {&destPart}, {});
99 }
100
101 void add_node(const stk::mesh::EntityId nodeId, stk::mesh::Part& destPart) { add_nodes({nodeId}, destPart); }
102
103 void create_side(const stk::mesh::EntityId elemId,
104 stk::mesh::ConnectivityOrdinal sideOrd,
105 stk::mesh::Part& sidePart)
106 {
107 stk::mesh::Entity elem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemId);
108 ASSERT_TRUE(get_bulk().is_valid(elem));
109 get_bulk().modification_begin();
110 get_bulk().declare_element_side(elem, sideOrd, stk::mesh::PartVector{&sidePart});
111 get_bulk().modification_end();
112 }
113
114 stk::mesh::Selector create_block_subset_selector(const stk::mesh::PartVector& blocksToExclude)
115 {
116 stk::mesh::Selector meshSubsetSelector = get_meta().universal_part();
117 if (!blocksToExclude.empty()) {
118 stk::mesh::PartVector elemBlocks;
119 stk::mesh::fill_element_block_parts(get_meta(), stk::topology::INVALID_TOPOLOGY, elemBlocks);
120 for(const stk::mesh::Part* excludedBlock : blocksToExclude) {
121 auto foundBlock = std::find(elemBlocks.begin(), elemBlocks.end(), excludedBlock);
122 STK_ThrowRequire(foundBlock != elemBlocks.end());
123 elemBlocks.erase(foundBlock);
124 }
125 meshSubsetSelector = stk::mesh::selectUnion(elemBlocks);
126 }
127
128 return meshSubsetSelector;
129 }
130 };
131
132 } // namespace unit_test
133 } // namespace io
134 } // namespace stk
135 #endif
136