Debian Codegraph @

packages/stk/stk_unit_tests/stk_io/UnitTestMeshGroupingEntity.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 <stddef.h> // for size_t
36 #include <stdlib.h> // for rand, srand, RAND_MAX
37 #include <stk_io/IossBridge.hpp> // for is_part_io_part
38 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
39 #include <stk_mesh/base/BulkData.hpp> // for BulkData
40 #include <stk_mesh/base/MetaData.hpp> // for MetaData
41 #include <gtest/gtest.h>
42 #include <string> // for string
43 #include <vector> // for vector, etc
44 #include "gtest/gtest.h" // for AssertHelper, ASSERT_TRUE
45 #include "stk_io/DatabasePurpose.hpp" // for DatabasePurpose::READ_MESH, etc
46 #include "stk_mesh/base/Bucket.hpp" // for Bucket
47 #include "stk_mesh/base/Entity.hpp" // for Entity
48 #include "stk_mesh/base/Part.hpp" // for Part
49 #include "stk_mesh/base/Selector.hpp" // for Selector, operator&
50 #include "stk_mesh/base/Types.hpp" // for PartVector, BucketVector, etc
51 #include "stk_topology/topology.hpp" // for topology, etc
52 #include "stk_util/parallel/Parallel.hpp" // for ParallelMachine
53 #include "stk_mesh/baseImpl/MeshImplUtils.hpp"
54 #include "stk_mesh/base/FEMHelpers.hpp"
55 #include "stk_mesh/base/Field.hpp"
56 #include <stk_unit_test_utils/MeshFixture.hpp>
57 #include <Ioss_EntityType.h> // for EntityType
58 #include <Ioss_ElementBlock.h>
59 #include <Ioss_SideSet.h>
60 #include <Ioss_SideBlock.h>
61 #include <Ioss_ConcreteVariableType.h>
62 #include <Ionit_Initializer.h>
63 #include <Ioss_IOFactory.h>
64 #include <Ioss_DBUsage.h>
65 #include <stk_unit_test_utils/TextMesh.hpp>
66 #include <stk_unit_test_utils/BuildMesh.hpp>
67
68 using stk::unit_test_util::build_mesh;
69 using stk::unit_test_util::build_mesh_no_simple_fields;
70
71 TEST(MeshGroupingEntity, universalSideset_get_entity_rank)
72 {
73 Ioss::Init::Initializer init;
74 Ioss::PropertyManager properties;
75 Ioss::DatabaseIO *db_io = Ioss::IOFactory::create("generated", "1x1x32", Ioss::READ_MODEL, MPI_COMM_WORLD, properties);
76 Ioss::Region* ioRegion = new Ioss::Region(db_io, "IO_Region");
77
78 Ioss::SideSet* usideset = new Ioss::SideSet(db_io, "universal_sideset");
79 Ioss::SideBlock* usideblk = new Ioss::SideBlock(db_io, "universal_sideset", "unknown", "unknown", 1);
80 usideset->add(usideblk);
81 stk::mesh::MetaData meta(3);
82 EXPECT_EQ(stk::topology::FACE_RANK, stk::io::get_entity_rank(usideset, meta));
83 EXPECT_EQ(stk::topology::FACE_RANK, stk::io::get_entity_rank(usideblk, meta));
84 delete usideset;
85 delete ioRegion;
86 }
87
88 TEST(MeshGroupingEntity, getElementBlockFromPart)
89 {
90 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
91 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(MPI_COMM_WORLD);
92 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
93
94 stk::io::StkMeshIoBroker ioBroker;
95 stk::io::fill_mesh_preexisting(ioBroker, "generated:1x1x1", *bulk);
96 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
97
98 stk::mesh::Part* part = meta.get_part("block_1");
99 EXPECT_TRUE(part != nullptr);
100 EXPECT_EQ(stk::topology::ELEMENT_RANK, part->primary_entity_rank());
101
102 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, *part);
103 EXPECT_TRUE(entity != nullptr);
104 EXPECT_EQ(Ioss::ELEMENTBLOCK, entity->type());
105 }
106
107 TEST(MeshGroupingEntity, getElementBlockFromNonIoPart)
108 {
109 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
110 const unsigned spatialDim = 3;
111 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(spatialDim, MPI_COMM_WORLD);
112 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
113
114 stk::io::StkMeshIoBroker ioBroker;
115 stk::mesh::Part& dummyPart = meta.declare_part("dummy", stk::topology::ELEMENT_RANK);
116 EXPECT_FALSE(stk::io::is_part_io_part(dummyPart));
117 stk::io::fill_mesh_preexisting(ioBroker, "generated:1x1x1", *bulk);
118 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
119
120 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, dummyPart);
121 EXPECT_TRUE(entity == nullptr);
122 }
123
124 TEST(MeshGroupingEntity, getSideSetFromPart)
125 {
126 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
127 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(MPI_COMM_WORLD);
128 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
129
130 stk::io::StkMeshIoBroker ioBroker;
131 stk::io::fill_mesh_preexisting(ioBroker, "generated:1x1x1|sideset:x", *bulk);
132 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
133
134 stk::mesh::Part* part = meta.get_part("surface_1");
135 EXPECT_TRUE(part != nullptr);
136 EXPECT_EQ(meta.side_rank(), part->primary_entity_rank());
137
138 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, *part);
139 EXPECT_TRUE(entity != nullptr);
140 EXPECT_EQ(Ioss::SIDESET, entity->type());
141 }
142
143 TEST(MeshGroupingEntity, getNodeSetFromPart)
144 {
145 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
146 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(MPI_COMM_WORLD);
147 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
148
149 stk::io::StkMeshIoBroker ioBroker;
150 stk::io::fill_mesh_preexisting(ioBroker, "generated:1x1x1|nodeset:x", *bulk);
151 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
152
153 stk::mesh::Part* part = meta.get_part("nodelist_1");
154 EXPECT_TRUE(part != nullptr);
155 EXPECT_EQ(stk::topology::NODE_RANK, part->primary_entity_rank());
156
157 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, *part);
158 EXPECT_TRUE(entity != nullptr);
159 EXPECT_EQ(Ioss::NODESET, entity->type());
160 }
161
162 TEST(MeshGroupingEntity, nonInputIoPart)
163 {
164 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
165 const unsigned spatialDim = 3;
166 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(spatialDim, MPI_COMM_WORLD);
167 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
168
169 stk::io::StkMeshIoBroker ioBroker;
170 stk::mesh::Part& dummyPart = meta.declare_part("dummy", stk::topology::ELEMENT_RANK);
171 EXPECT_FALSE(stk::io::is_part_io_part(dummyPart));
172 stk::io::put_io_part_attribute(dummyPart);
173 EXPECT_TRUE(stk::io::is_part_io_part(dummyPart));
174
175 stk::io::fill_mesh_preexisting(ioBroker, "generated:1x1x1", *bulk);
176 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
177
178 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, dummyPart);
179 EXPECT_TRUE(entity == nullptr);
180 }
181
182 void create_2block_quad_mesh(const std::string& fileName)
183 {
184 const unsigned spatialDim = 2;
185 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(spatialDim, MPI_COMM_WORLD);
186 std::string meshDesc = "0,1,QUAD_4_2D,1,2,5,4,block_1\n"
187 "0,2,QUAD_4_2D,2,3,6,5,block_2";
188
189 stk::unit_test_util::setup_text_mesh(*bulk, meshDesc);
190 stk::io::write_mesh(fileName, *bulk);
191 }
192
193 TEST(MeshGroupingEntity, matchhingNameAndType)
194 {
195 if(stk::parallel_machine_size(MPI_COMM_WORLD) > 1) { return; }
196 const unsigned spatialDim = 2;
197 std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(spatialDim, MPI_COMM_WORLD);
198 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
199
200 stk::io::StkMeshIoBroker ioBroker;
201 std::string fileName = "output.g";
202 std::string skippedPartName = "block_2";
203
204 create_2block_quad_mesh(fileName);
205
206 ioBroker.set_bulk_data(bulk);
207 size_t inputIndex = ioBroker.add_mesh_database(fileName, stk::io::READ_MESH);
208 Ioss::DatabaseIO* dbIo = ioBroker.get_input_database(inputIndex);
209 dbIo->set_block_omissions({skippedPartName});
210 ioBroker.create_input_mesh();
211
212 stk::mesh::Part* skippedPart = meta.get_part(skippedPartName);
213 EXPECT_EQ(nullptr, skippedPart);
214
215 skippedPart = &meta.declare_part(skippedPartName, stk::topology::NODE_RANK);
216 EXPECT_FALSE(stk::io::is_part_io_part(*skippedPart));
217 stk::io::put_io_part_attribute(*skippedPart);
218 EXPECT_TRUE(stk::io::is_part_io_part(*skippedPart));
219
220 ioBroker.add_all_mesh_fields_as_input_fields();
221 ioBroker.populate_bulk_data();
222
223 std::shared_ptr<Ioss::Region> ioRegion = ioBroker.get_input_ioss_region();
224
225 Ioss::GroupingEntity* entity = stk::io::get_grouping_entity(*ioRegion, *skippedPart);
226 EXPECT_TRUE(entity == nullptr);
227 }
228
229 TEST(MeshGroupingEntity, iossEntityTypesForElementRank)
230 {
231 stk::mesh::MetaData meta(2);
232
233 std::vector<Ioss::EntityType> entityTypeVec = stk::io::get_ioss_entity_types(meta, stk::topology::ELEMENT_RANK);
234
235 EXPECT_EQ(2u, entityTypeVec.size());
236 EXPECT_TRUE(entityTypeVec[0] == Ioss::ELEMENTBLOCK || entityTypeVec[1] == Ioss::ELEMENTBLOCK);
237 EXPECT_TRUE(entityTypeVec[0] == Ioss::SUPERELEMENT || entityTypeVec[1] == Ioss::SUPERELEMENT);
238 }
239
240 TEST(MeshGroupingEntity, iossEntityTypesForFaceRank)
241 {
242 stk::mesh::MetaData meta2D(2);
243 stk::mesh::MetaData meta3D(3);
244
245 std::vector<Ioss::EntityType> entityTypeVec = stk::io::get_ioss_entity_types(meta2D, stk::topology::FACE_RANK);
246
247 EXPECT_EQ(0u, entityTypeVec.size());
248
249 entityTypeVec = stk::io::get_ioss_entity_types(meta2D, stk::topology::EDGE_RANK);
250
251 EXPECT_EQ(2u, entityTypeVec.size());
252 EXPECT_TRUE(entityTypeVec[0] == Ioss::SIDESET || entityTypeVec[1] == Ioss::SIDESET);
253 EXPECT_TRUE(entityTypeVec[0] == Ioss::SIDEBLOCK || entityTypeVec[1] == Ioss::SIDEBLOCK);
254
255 entityTypeVec = stk::io::get_ioss_entity_types(meta3D, stk::topology::FACE_RANK);
256
257 EXPECT_EQ(2u, entityTypeVec.size());
258 EXPECT_TRUE(entityTypeVec[0] == Ioss::SIDESET || entityTypeVec[1] == Ioss::SIDESET);
259 EXPECT_TRUE(entityTypeVec[0] == Ioss::SIDEBLOCK || entityTypeVec[1] == Ioss::SIDEBLOCK);
260
261 entityTypeVec = stk::io::get_ioss_entity_types(meta3D, stk::topology::EDGE_RANK);
262 EXPECT_EQ(0u, entityTypeVec.size());
263 }
264
265 TEST(MeshGroupingEntity, iossEntityTypesForConstraintRank)
266 {
267 stk::mesh::MetaData meta(2);
268
269 std::vector<Ioss::EntityType> entityTypeVec = stk::io::get_ioss_entity_types(meta, stk::topology::CONSTRAINT_RANK);
270
271 EXPECT_EQ(0u, entityTypeVec.size());
272 }
273
274 TEST(MeshGroupingEntity, iossEntityTypesForNodeRank)
275 {
276 stk::mesh::MetaData meta;
277
278 std::vector<Ioss::EntityType> entityTypeVec = stk::io::get_ioss_entity_types(meta, stk::topology::NODE_RANK);
279
280 EXPECT_EQ(2u, entityTypeVec.size());
281 EXPECT_TRUE(entityTypeVec[0] == Ioss::NODESET || entityTypeVec[1] == Ioss::NODESET);
282 EXPECT_TRUE(entityTypeVec[0] == Ioss::NODEBLOCK || entityTypeVec[1] == Ioss::NODEBLOCK);
283 }