| 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 <stk_ngp_test/ngp_test.hpp> |
| 37 |
#include <stk_mesh/base/MetaData.hpp> |
| 38 |
#include <stk_mesh/base/Part.hpp> |
| 39 |
#include <stk_topology/topology.hpp> |
| 40 |
#include <stk_io/IossBridge.hpp> |
| 41 |
#include "Assembly.hpp" |
| 42 |
|
| 43 |
namespace stk |
| 44 |
{ |
| 45 |
namespace io |
| 46 |
{ |
| 47 |
namespace unit_test |
| 48 |
{ |
| 49 |
|
| 50 |
TEST_F(Assembly, ioPartIsNotAssembly) |
| 51 |
{ |
| 52 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 53 |
stk::mesh::Part& part = create_io_part("myPart"); |
| 54 |
|
| 55 |
EXPECT_FALSE(stk::io::is_part_assembly_io_part(part)); |
| 56 |
} |
| 57 |
|
| 58 |
TEST_F(Assembly, createAssembly) |
| 59 |
{ |
| 60 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 61 |
const std::string assemblyName("myAssembly"); |
| 62 |
stk::mesh::Part& assemblyPart = create_assembly(assemblyName, 100); |
| 63 |
|
| 64 |
test_assembly_part_attributes(assemblyPart); |
| 65 |
|
| 66 |
EXPECT_TRUE(stk::io::get_unique_leaf_parts(get_meta(), assemblyName).empty()); |
| 67 |
} |
| 68 |
|
| 69 |
TEST_F(Assembly, getAssemblyNames_empty) |
| 70 |
{ |
| 71 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 72 |
std::vector<std::string> assemblyNames = stk::io::get_assembly_names(get_meta()); |
| 73 |
EXPECT_TRUE(assemblyNames.empty()); |
| 74 |
} |
| 75 |
|
| 76 |
TEST_F(Assembly, getAssemblyNames_singleAssembly) |
| 77 |
{ |
| 78 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 79 |
std::string assemblyName("myAssembly"); |
| 80 |
create_assembly(assemblyName, 100); |
| 81 |
|
| 82 |
create_io_part("myPart"); |
| 83 |
|
| 84 |
std::vector<std::string> assemblyNames = stk::io::get_assembly_names(get_meta()); |
| 85 |
ASSERT_EQ(1u, assemblyNames.size()); |
| 86 |
EXPECT_EQ(assemblyName, assemblyNames[0]); |
| 87 |
} |
| 88 |
|
| 89 |
TEST_F(Assembly, getAssemblyNames_multipleAssemblies_inOrderOfCreation) |
| 90 |
{ |
| 91 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 92 |
std::string assemblyBBB("BBB_assembly"); |
| 93 |
create_assembly(assemblyBBB, 100); |
| 94 |
|
| 95 |
std::string assemblyZZZ("ZZZ_assembly"); |
| 96 |
create_assembly(assemblyZZZ, 200); |
| 97 |
|
| 98 |
std::string assemblyAAA("AAA_assembly"); |
| 99 |
create_assembly(assemblyAAA, 300); |
| 100 |
|
| 101 |
std::vector<std::string> assemblyNames = stk::io::get_assembly_names(get_meta()); |
| 102 |
ASSERT_EQ(3u, assemblyNames.size()); |
| 103 |
EXPECT_EQ(assemblyBBB, assemblyNames[0]); |
| 104 |
EXPECT_EQ(assemblyZZZ, assemblyNames[1]); |
| 105 |
EXPECT_EQ(assemblyAAA, assemblyNames[2]); |
| 106 |
} |
| 107 |
|
| 108 |
TEST_F(Assembly, createAssemblyWithSubAssemblies) |
| 109 |
{ |
| 110 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 111 |
std::string parentAssemblyName("myParentAssembly"); |
| 112 |
std::string subAssembly1Name("mySubAssembly1"); |
| 113 |
std::string subAssembly2Name("mySubAssembly2"); |
| 114 |
|
| 115 |
stk::mesh::Part* parentAssemblyPart; |
| 116 |
stk::mesh::PartVector subAssemblyParts; |
| 117 |
std::tie(parentAssemblyPart, subAssemblyParts) = create_assembly_hierarchy(parentAssemblyName, 100, |
| 118 |
{subAssembly1Name, subAssembly2Name}, |
| 119 |
{200, 201}); |
| 120 |
|
| 121 |
EXPECT_TRUE(stk::io::has_sub_assemblies(get_meta(), parentAssemblyName)); |
| 122 |
|
| 123 |
test_assembly_part_attributes(*parentAssemblyPart); |
| 124 |
test_assembly_part_attributes(subAssemblyParts); |
| 125 |
} |
| 126 |
|
| 127 |
TEST_F(Assembly, createAssemblyWithSubAssemblies_getAssemblyNames) |
| 128 |
{ |
| 129 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 130 |
std::string parentAssemblyName("myParentAssembly"); |
| 131 |
std::string subAssembly1Name("mySubAssembly1"); |
| 132 |
std::string subAssembly2Name("mySubAssembly2"); |
| 133 |
|
| 134 |
create_assembly_hierarchy(parentAssemblyName, 100, {subAssembly1Name, subAssembly2Name}, {200, 201}); |
| 135 |
|
| 136 |
std::vector<std::string> assemblyNames = stk::io::get_assembly_names(get_meta()); |
| 137 |
ASSERT_EQ(3u, assemblyNames.size()); |
| 138 |
EXPECT_EQ(parentAssemblyName, assemblyNames[0]); |
| 139 |
EXPECT_EQ(subAssembly1Name, assemblyNames[1]); |
| 140 |
EXPECT_EQ(subAssembly2Name, assemblyNames[2]); |
| 141 |
} |
| 142 |
|
| 143 |
TEST_F(Assembly, createAssemblyWithSubAssemblies_getSubAssemblyNames) |
| 144 |
{ |
| 145 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 146 |
std::string parentAssemblyName("myParentAssembly"); |
| 147 |
std::string subAssembly1Name("mySubAssembly1"); |
| 148 |
std::string subAssembly2Name("mySubAssembly2"); |
| 149 |
|
| 150 |
create_assembly_hierarchy(parentAssemblyName, 100, {subAssembly1Name, subAssembly2Name}, {200, 201}); |
| 151 |
|
| 152 |
std::vector<std::string> subAssemblyNames = stk::io::get_sub_assembly_names(get_meta(), parentAssemblyName); |
| 153 |
ASSERT_EQ(2u, subAssemblyNames.size()); |
| 154 |
EXPECT_EQ(subAssembly1Name, subAssemblyNames[0]); |
| 155 |
EXPECT_EQ(subAssembly2Name, subAssemblyNames[1]); |
| 156 |
|
| 157 |
EXPECT_TRUE(stk::io::get_sub_assembly_names(get_meta(), subAssembly1Name).empty()); |
| 158 |
EXPECT_TRUE(stk::io::get_sub_assembly_names(get_meta(), subAssembly2Name).empty()); |
| 159 |
} |
| 160 |
|
| 161 |
TEST_F(Assembly, createAssemblyWithSubAssemblies_leafParts) |
| 162 |
{ |
| 163 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 164 |
std::string parentAssemblyName("myParentAssembly"); |
| 165 |
std::string subAssembly1Name("mySubAssembly1"); |
| 166 |
std::string subAssembly2Name("mySubAssembly2"); |
| 167 |
|
| 168 |
stk::mesh::Part* parentAssemblyPart; |
| 169 |
stk::mesh::PartVector subAssemblyParts; |
| 170 |
std::tie(parentAssemblyPart, subAssemblyParts) = create_assembly_hierarchy(parentAssemblyName, 100, |
| 171 |
{subAssembly1Name, subAssembly2Name}, {200, 201}); |
| 172 |
stk::mesh::Part& block1Part = create_io_part("block_1"); |
| 173 |
stk::mesh::Part& block2Part = create_io_part("block_2"); |
| 174 |
stk::mesh::Part& block3Part = create_io_part("block_3"); |
| 175 |
|
| 176 |
ASSERT_EQ(2u, subAssemblyParts.size()); |
| 177 |
declare_subsets(*subAssemblyParts[0], {&block1Part, &block2Part}); |
| 178 |
declare_subsets(*subAssemblyParts[1], {&block2Part, &block3Part}); |
| 179 |
|
| 180 |
EXPECT_FALSE(stk::io::has_sub_assemblies(get_meta(), subAssembly1Name)); |
| 181 |
EXPECT_FALSE(stk::io::has_sub_assemblies(get_meta(), subAssembly2Name)); |
| 182 |
|
| 183 |
EXPECT_TRUE(subAssemblyParts[0]->contains(block1Part)); |
| 184 |
EXPECT_TRUE(subAssemblyParts[0]->contains(block2Part)); |
| 185 |
EXPECT_TRUE(subAssemblyParts[1]->contains(block2Part)); |
| 186 |
EXPECT_TRUE(subAssemblyParts[1]->contains(block3Part)); |
| 187 |
|
| 188 |
EXPECT_EQ(5u, parentAssemblyPart->subsets().size()); |
| 189 |
|
| 190 |
stk::mesh::PartVector leafParts = stk::io::get_unique_leaf_parts(get_meta(), parentAssemblyName); |
| 191 |
|
| 192 |
ASSERT_EQ(3u, leafParts.size()); |
| 193 |
EXPECT_EQ(block1Part.mesh_meta_data_ordinal(), leafParts[0]->mesh_meta_data_ordinal()); |
| 194 |
EXPECT_EQ(block2Part.mesh_meta_data_ordinal(), leafParts[1]->mesh_meta_data_ordinal()); |
| 195 |
EXPECT_EQ(block3Part.mesh_meta_data_ordinal(), leafParts[2]->mesh_meta_data_ordinal()); |
| 196 |
} |
| 197 |
|
| 198 |
TEST_F(Assembly, deeperHierarchy_names) |
| 199 |
{ |
| 200 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 201 |
create_deep_assembly_hierarchy(); |
| 202 |
|
| 203 |
std::string parentAssemblyName("myParentAssembly"); |
| 204 |
std::string subAssembly1Name("mySubAssembly1"); |
| 205 |
std::string subAssembly2Name("mySubAssembly2"); |
| 206 |
std::string subSubAssemblyName("mySubSubAssembly"); |
| 207 |
std::string subSubSubAssembly1Name("mySubSubSubAssembly1"); |
| 208 |
std::string subSubSubAssembly2Name("mySubSubSubAssembly2"); |
| 209 |
|
| 210 |
std::vector<std::string> assemblyNames = stk::io::get_assembly_names(get_meta()); |
| 211 |
ASSERT_EQ(6u, assemblyNames.size()); |
| 212 |
EXPECT_EQ(parentAssemblyName, assemblyNames[0]); |
| 213 |
EXPECT_EQ(subAssembly1Name, assemblyNames[1]); |
| 214 |
EXPECT_EQ(subAssembly2Name, assemblyNames[2]); |
| 215 |
EXPECT_EQ(subSubAssemblyName, assemblyNames[3]); |
| 216 |
EXPECT_EQ(subSubSubAssembly1Name, assemblyNames[4]); |
| 217 |
EXPECT_EQ(subSubSubAssembly2Name, assemblyNames[5]); |
| 218 |
|
| 219 |
test_sub_assembly_names(parentAssemblyName, {subAssembly1Name, subAssembly2Name}); |
| 220 |
test_sub_assembly_names(subAssembly1Name, {subSubAssemblyName}); |
| 221 |
test_sub_assembly_names(subAssembly2Name, {}); |
| 222 |
test_sub_assembly_names(subSubAssemblyName, {subSubSubAssembly1Name, subSubSubAssembly2Name}); |
| 223 |
test_sub_assembly_names(subSubSubAssembly1Name, {}); |
| 224 |
test_sub_assembly_names(subSubSubAssembly2Name, {}); |
| 225 |
} |
| 226 |
|
| 227 |
TEST_F(Assembly, deeperHierarchy_parts) |
| 228 |
{ |
| 229 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 230 |
create_deep_assembly_hierarchy(); |
| 231 |
|
| 232 |
stk::mesh::PartVector leafParts = stk::io::get_unique_leaf_parts(get_meta(), "myParentAssembly"); |
| 233 |
ASSERT_EQ(3u, leafParts.size()); |
| 234 |
EXPECT_EQ("block_1", leafParts[0]->name()); |
| 235 |
EXPECT_EQ("block_2", leafParts[1]->name()); |
| 236 |
EXPECT_EQ("block_3", leafParts[2]->name()); |
| 237 |
} |
| 238 |
|
| 239 |
} // namespace unit_test |
| 240 |
} // namespace io |
| 241 |
} // namespace stk |