Debian Codegraph @

packages/stk/stk_doc_tests/stk_io/howToCreateAssemblies.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 <gtest/gtest.h> // for AssertHelper, EXPECT_NE, etc
36 #include <stddef.h> // for size_t, NULL
37 #include <unistd.h> // for unlink
38 #include <stk_util/stk_config.h>
39 #include <stk_io/IossBridge.hpp>
40 #include <stk_io/FillMesh.hpp>
41 #include <stk_io/WriteMesh.hpp>
42 #include <stk_mesh/base/MetaData.hpp> // for MetaData
43 #include <stk_mesh/base/MeshBuilder.hpp>
44 #include <stk_mesh/base/Part.hpp>
45 #include <string> // for string
46 #include "stk_util/parallel/Parallel.hpp"
47
48 TEST(Assemblies, createAssemblyWithElementBlocks)
49 {
50 const unsigned spatialDim = 2;
51 stk::mesh::MetaData meta(spatialDim);
52
53 stk::mesh::Part& block1Part = meta.declare_part_with_topology("block_1", stk::topology::QUAD_4_2D);
54 stk::mesh::Part& block2Part = meta.declare_part_with_topology("block_2", stk::topology::TRI_3_2D);
55
56 stk::io::put_io_part_attribute(block1Part);
57 stk::io::put_io_part_attribute(block2Part);
58
59 stk::mesh::Part& assemblyPart = meta.declare_part("myAssembly");
60
61 EXPECT_FALSE(stk::io::is_part_assembly_io_part(assemblyPart));
62 EXPECT_FALSE(stk::io::is_part_io_part(assemblyPart));
63
64 stk::io::put_assembly_io_part_attribute(assemblyPart);
65 meta.set_part_id(assemblyPart, 100);
66
67 EXPECT_TRUE(stk::io::is_part_assembly_io_part(assemblyPart));
68 EXPECT_TRUE(stk::io::is_part_io_part(assemblyPart));
69
70 meta.declare_part_subset(assemblyPart, block1Part);
71 meta.declare_part_subset(assemblyPart, block2Part);
72
73 EXPECT_TRUE(assemblyPart.contains(block1Part));
74 EXPECT_TRUE(assemblyPart.contains(block2Part));
75 }
76
77 TEST(Assemblies, createAssemblyWithElementBlocksAndSurfaces)
78 {
79 const unsigned spatialDim = 3;
80 stk::mesh::MetaData meta(spatialDim);
81
82 stk::mesh::Part& block1Part = meta.declare_part_with_topology("block_1", stk::topology::HEX_8);
83 stk::mesh::Part& block2Part = meta.declare_part_with_topology("block_2", stk::topology::WEDGE_6);
84 stk::mesh::Part& block3Part = meta.declare_part_with_topology("block_3", stk::topology::TET_4);
85
86 stk::mesh::Part& surface1Part = meta.declare_part_with_topology("surface_1", stk::topology::QUAD_4);
87 stk::mesh::Part& surface2Part = meta.declare_part_with_topology("surface_2", stk::topology::TRI_3);
88
89 stk::io::put_io_part_attribute(block1Part);
90 stk::io::put_io_part_attribute(block2Part);
91 stk::io::put_io_part_attribute(block3Part);
92 stk::io::put_io_part_attribute(surface1Part);
93 stk::io::put_io_part_attribute(surface2Part);
94
95 std::string parentAssemblyName("parentAssembly");
96 std::string subAssembly1Name("subAssembly1");
97 std::string subAssembly2Name("subAssembly2");
98
99 stk::mesh::Part& parentAssemblyPart = meta.declare_part(parentAssemblyName);
100 stk::mesh::Part& subAssembly1Part = meta.declare_part(subAssembly1Name);
101 stk::mesh::Part& subAssembly2Part = meta.declare_part(subAssembly2Name);
102
103 stk::io::put_assembly_io_part_attribute(parentAssemblyPart);
104 stk::io::put_assembly_io_part_attribute(subAssembly1Part);
105 stk::io::put_assembly_io_part_attribute(subAssembly2Part);
106
107 meta.declare_part_subset(parentAssemblyPart, subAssembly1Part);
108 meta.declare_part_subset(parentAssemblyPart, subAssembly2Part);
109
110 meta.declare_part_subset(subAssembly1Part, block1Part);
111 meta.declare_part_subset(subAssembly1Part, block2Part);
112 meta.declare_part_subset(subAssembly1Part, block3Part);
113
114 meta.declare_part_subset(subAssembly2Part, surface1Part);
115 meta.declare_part_subset(subAssembly2Part, surface2Part);
116
117 EXPECT_TRUE(stk::io::has_sub_assemblies(meta, parentAssemblyName));
118
119 stk::mesh::PartVector allLeafParts = stk::io::get_unique_leaf_parts(meta, parentAssemblyName);
120 EXPECT_EQ(5u, allLeafParts.size());
121
122 stk::mesh::PartVector subAssembly1LeafParts = stk::io::get_unique_leaf_parts(meta, subAssembly1Name);
123 EXPECT_EQ(3u, subAssembly1LeafParts.size());
124
125 stk::mesh::PartVector subAssembly2LeafParts = stk::io::get_unique_leaf_parts(meta, subAssembly2Name);
126 EXPECT_EQ(2u, subAssembly2LeafParts.size());
127
128 for(const stk::mesh::Part* subAssemblyPart : subAssembly1LeafParts) {
129 EXPECT_TRUE(stk::mesh::contains(allLeafParts, *subAssemblyPart));
130 }
131
132 for(const stk::mesh::Part* subAssemblyPart : subAssembly2LeafParts) {
133 EXPECT_TRUE(stk::mesh::contains(allLeafParts, *subAssemblyPart));
134 }
135 }
136
137 TEST(Assemblies, cannotCreateAssemblyWithMixedRanks)
138 {
139 stk::mesh::MeshBuilder builder(MPI_COMM_WORLD);
140 builder.set_spatial_dimension(3);
141 std::shared_ptr<stk::mesh::BulkData> bulk = builder.create();
142 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
143
144 stk::mesh::Part& block1Part = meta.declare_part_with_topology("block_1", stk::topology::HEX_8);
145 stk::mesh::Part& surface1Part = meta.declare_part_with_topology("surface_1", stk::topology::QUAD_4);
146
147 stk::io::put_io_part_attribute(block1Part);
148 stk::io::put_io_part_attribute(surface1Part);
149
150 std::string assemblyName("assembly");
151
152 stk::mesh::Part& assemblyPart = meta.declare_part(assemblyName);
153 stk::io::put_assembly_io_part_attribute(assemblyPart);
154
155 meta.declare_part_subset(assemblyPart, block1Part);
156 meta.declare_part_subset(assemblyPart, surface1Part);
157
158 stk::io::fill_mesh("generated:2x2x2|sideset:x", *bulk);
159
160 EXPECT_THROW(stk::io::write_mesh("outputFile.g", *bulk), std::runtime_error);
161 }
162