Debian Codegraph @

packages/stk/stk_doc_tests/stk_mesh/howToSkinMesh.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_EQ, etc
36 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
37 #include <stk_mesh/base/GetEntities.hpp> // for count_entities
38 #include <stk_mesh/base/MeshBuilder.hpp>
39 #include <stk_mesh/base/MetaData.hpp> // for MetaData
40 #include <stk_mesh/base/Selector.hpp> // for Selector
41 #include <stk_mesh/base/SkinBoundary.hpp> // for Selector
42 #include <stk_topology/topology.hpp> // for topology, etc
43 #include <string> // for string
44 #include <vector> // for vector
45 #include "stk_io/DatabasePurpose.hpp" // for DatabasePurpose::READ_MESH
46 #include "stk_io/FillMesh.hpp"
47 namespace stk { namespace mesh { class BulkData; } }
48
49 namespace
50 {
51 //BEGIN_CREATE_EXPOSED_BOUNDARY
52 TEST(StkMeshHowTo, SkinExposedHex)
53 {
54 // ============================================================
55 // INITIALIZATION
56 MPI_Comm communicator = MPI_COMM_WORLD;
57 if (stk::parallel_machine_size(communicator) != 1) { return; }
58
59 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(communicator).create();
60 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
61
62 const std::string generatedFileName = "generated:1x1x1";
63 stk::io::fill_mesh(generatedFileName, *bulk);
64
65 // ============================================================
66 //+ EXAMPLE
67 //+ Skin the mesh and create the exposed boundary sides..
68 stk::mesh::Selector allEntities = meta.universal_part();
69 stk::mesh::Part &skinPart = meta.declare_part("skin", meta.side_rank());
70 stk::io::put_io_part_attribute(skinPart);
71
72 stk::mesh::create_exposed_block_boundary_sides(*bulk, allEntities, {&skinPart});
73
74 // ==================================================
75 // VERIFICATION
76 EXPECT_TRUE(stk::mesh::check_exposed_block_boundary_sides(*bulk, allEntities, skinPart));
77 stk::mesh::Selector skin(skinPart & meta.locally_owned_part());
78 unsigned numSkinnedSides = stk::mesh::count_entities(*bulk, meta.side_rank(), skin);
79 EXPECT_EQ(6u, numSkinnedSides) << "in part " << skinPart.name();
80 }
81 //END_CREATE_EXPOSED_BOUNDARY
82
83 //BEGIN_CREATE_INTERIOR_BOUNDARY
84 TEST(StkMeshHowTo, SkinInteriorHex)
85 {
86 // ============================================================
87 // INITIALIZATION
88 MPI_Comm communicator = MPI_COMM_WORLD;
89 if (stk::parallel_machine_size(communicator) != 1) { return; }
90
91 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(communicator).create();
92 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
93
94 const std::string generatedFileName = "generated:1x1x2";
95 stk::io::fill_mesh(generatedFileName, *bulk);
96
97 // ============================================================
98 //+ EXAMPLE
99 //+ Skin the mesh and create the exposed boundary sides..
100 stk::mesh::Selector allEntities = meta.universal_part();
101 stk::mesh::Part &skinPart = meta.declare_part("skin", meta.side_rank());
102 stk::io::put_io_part_attribute(skinPart);
103
104 stk::mesh::Entity elem2 = bulk->get_entity(stk::topology::ELEM_RANK, 2u);
105 stk::mesh::Part *block_1 = meta.get_part("block_1");
106
107 bulk->modification_begin();
108 stk::mesh::Part &block_2 = meta.declare_part("block_2", stk::topology::ELEM_RANK);
109 stk::io::put_io_part_attribute(block_2);
110 bulk->change_entity_parts(elem2, stk::mesh::ConstPartVector{&block_2}, stk::mesh::ConstPartVector{block_1});
111 bulk->modification_end();
112
113 stk::mesh::create_interior_block_boundary_sides(*bulk, allEntities, {&skinPart});
114
115 // ==================================================
116 // VERIFICATION
117 EXPECT_TRUE(stk::mesh::check_interior_block_boundary_sides(*bulk, allEntities, skinPart));
118 stk::mesh::Selector skin(skinPart & meta.locally_owned_part());
119 unsigned numSkinnedSides = stk::mesh::count_entities(*bulk, meta.side_rank(), skin);
120 EXPECT_EQ(1u, numSkinnedSides) << "in part " << skinPart.name();
121 }
122 //END_CREATE_INTERIOR_BOUNDARY
123
124 //BEGIN_CREATE_ALL_BLOCK_BOUNDARY
125 TEST(StkMeshHowTo, SkinAllHexBlocks)
126 {
127 // ============================================================
128 // INITIALIZATION
129 MPI_Comm communicator = MPI_COMM_WORLD;
130 if (stk::parallel_machine_size(communicator) != 1) { return; }
131
132 std::shared_ptr<stk::mesh::BulkData> bulk = stk::mesh::MeshBuilder(communicator).create();
133 stk::mesh::MetaData& meta = bulk->mesh_meta_data();
134
135 const std::string generatedFileName = "generated:1x1x2";
136 stk::io::fill_mesh(generatedFileName, *bulk);
137
138 // ============================================================
139 //+ EXAMPLE
140 //+ Skin the mesh and create all boundary sides..
141 stk::mesh::Selector allEntities = meta.universal_part();
142 stk::mesh::Part &skinPart = meta.declare_part("skin", meta.side_rank());
143 stk::io::put_io_part_attribute(skinPart);
144
145 stk::mesh::Entity elem2 = bulk->get_entity(stk::topology::ELEM_RANK, 2u);
146 stk::mesh::Part *block_1 = meta.get_part("block_1");
147
148 bulk->modification_begin();
149 stk::mesh::Part &block_2 = meta.declare_part("block_2", stk::topology::ELEM_RANK);
150 stk::io::put_io_part_attribute(block_2);
151 bulk->change_entity_parts(elem2, stk::mesh::ConstPartVector{&block_2}, stk::mesh::ConstPartVector{block_1});
152 bulk->modification_end();
153
154 stk::mesh::create_all_block_boundary_sides(*bulk, allEntities, {&skinPart});
155
156 // ==================================================
157 // VERIFICATION
158 stk::mesh::Selector skin(skinPart & meta.locally_owned_part());
159 unsigned numSkinnedSides = stk::mesh::count_entities(*bulk, meta.side_rank(), skin);
160 EXPECT_EQ(11u, numSkinnedSides) << "in part " << skinPart.name();
161 }
162 //END_CREATE_ALL_BLOCK_BOUNDARY
163 }