Debian Codegraph @

packages/stk/stk_doc_tests/stk_mesh/entityState.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>
36 #include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker
37 #include <stk_mesh/base/MetaData.hpp> // for MetaData
38 #include <stk_mesh/base/BulkData.hpp> // for MetaData
39
40 //BEGIN_CREATED
41 TEST(stkMeshHowTo, checkCreatedStateAfterMeshCreation)
42 {
43 MPI_Comm communicator = MPI_COMM_WORLD;
44 const int parallel_size = stk::parallel_machine_size(communicator);
45 if (parallel_size != 1) { return; }
46 const std::string fileName = "generated:1x1x1";
47 stk::io::StkMeshIoBroker meshReader(communicator);
48 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
49 meshReader.create_input_mesh();
50 meshReader.populate_bulk_data();
51 stk::mesh::BulkData & bulk = meshReader.bulk_data();
52 for (size_t n=1 ; n<=8 ; ++n) {
53 stk::mesh::Entity node = bulk.get_entity(stk::topology::NODE_RANK, n);
54 EXPECT_EQ( stk::mesh::Created, bulk.state(node) );
55 }
56 stk::mesh::Entity element = bulk.get_entity(stk::topology::ELEMENT_RANK,1);
57 EXPECT_EQ( stk::mesh::Created, bulk.state(element) );
58 bulk.modification_begin();
59 bulk.modification_end();
60 EXPECT_EQ( stk::mesh::Unchanged, bulk.state(element) );
61 }
62 //END_CREATED
63
64 //BEGIN_DELETED
65 TEST(stkMeshHowTo, checkDeletedState)
66 {
67 MPI_Comm communicator = MPI_COMM_WORLD;
68 const int parallel_size = stk::parallel_machine_size(communicator);
69 if (parallel_size != 1) { return; }
70 const std::string fileName = "generated:1x1x1";
71 stk::io::StkMeshIoBroker meshReader(communicator);
72 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
73 meshReader.create_input_mesh();
74 meshReader.populate_bulk_data();
75 stk::mesh::BulkData & bulk = meshReader.bulk_data();
76 stk::mesh::Entity element = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
77 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
78 bulk.modification_begin();
79 bulk.destroy_relation(element, node1, 0);
80 EXPECT_TRUE(bulk.destroy_entity(node1));
81 // Elements must have all their nodes defined:
82 stk::mesh::Entity new_node = bulk.declare_node(25);
83 bulk.declare_relation(element,new_node, 0);
84 bulk.modification_end();
85 EXPECT_FALSE( bulk.is_valid(node1) ); // deleted makes it not valid
86 EXPECT_TRUE( bulk.in_index_range(node1));
87 EXPECT_EQ( stk::mesh::Deleted, bulk.state(node1) );
88 bulk.modification_begin();
89 bulk.modification_end();
90 EXPECT_FALSE( bulk.is_valid(node1) );
91 }
92 //END_DELETED
93
94 //BEGIN_MODIFIED
95 TEST(stkMeshHowTo, checkModifiedState)
96 {
97 MPI_Comm communicator = MPI_COMM_WORLD;
98 const int parallel_size = stk::parallel_machine_size(communicator);
99 if (parallel_size != 1) { return; }
100 const std::string fileName = "generated:1x1x1";
101 stk::io::StkMeshIoBroker meshReader(communicator);
102 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
103 meshReader.create_input_mesh();
104 meshReader.populate_bulk_data();
105 stk::mesh::BulkData & bulk = meshReader.bulk_data();
106 stk::mesh::Entity element = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
107 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
108 bulk.modification_begin();
109 bulk.destroy_relation(element, node1, 0);
110 // Elements must have all their nodes defined:
111 stk::mesh::Entity new_node = bulk.declare_node(25);
112 bulk.declare_relation(element, new_node, 0);
113 bulk.modification_end();
114 EXPECT_EQ( stk::mesh::Modified, bulk.state(node1) );
115 EXPECT_EQ( stk::mesh::Modified, bulk.state(element) );
116 }
117 //END_MODIFIED
118
119
120 //BEGIN_AURA_MODIFIED
121 TEST(stkMeshHowTo, checkAuraCreatedState)
122 {
123 MPI_Comm communicator = MPI_COMM_WORLD;
124 const int parallel_size = stk::parallel_machine_size(communicator);
125 if (parallel_size != 2) { GTEST_SKIP(); }
126 const std::string fileName = "generated:1x1x2";
127 stk::io::StkMeshIoBroker meshReader(communicator);
128 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
129 meshReader.create_input_mesh();
130 meshReader.populate_bulk_data();
131 stk::mesh::BulkData & bulk = meshReader.bulk_data();
132 stk::mesh::Entity element1 = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
133 stk::mesh::Entity element2 = bulk.get_entity(stk::topology::ELEMENT_RANK, 2);
134 if (bulk.parallel_rank() == 0) {
135 EXPECT_EQ( stk::mesh::Created, bulk.state(element1) );
136 EXPECT_TRUE( bulk.in_receive_ghost(bulk.entity_key(element2)) );
137 EXPECT_EQ( stk::mesh::Created, bulk.state(element2) );
138 } else { // parallel_rank == 1
139 EXPECT_TRUE( bulk.in_receive_ghost(bulk.entity_key(element1)) );
140 EXPECT_EQ( stk::mesh::Created, bulk.state(element1) );
141 EXPECT_EQ( stk::mesh::Created, bulk.state(element2) );
142 }
143 }
144 //END_AURA_MODIFIED
145
146 //BEGIN_CEO_MODIFIED
147 TEST(stkMeshHowTo, checkCEOModifiedState)
148 {
149 MPI_Comm communicator = MPI_COMM_WORLD;
150 const int parallel_size = stk::parallel_machine_size(communicator);
151 if (parallel_size != 2) { GTEST_SKIP(); }
152 const std::string fileName = "generated:1x1x2";
153 stk::io::StkMeshIoBroker meshReader(communicator);
154 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
155 meshReader.create_input_mesh();
156 meshReader.populate_bulk_data();
157 stk::mesh::BulkData & bulk = meshReader.bulk_data();
158 stk::mesh::Entity node5 = bulk.get_entity(stk::topology::NODE_RANK, 5);
159 std::vector<stk::mesh::EntityProc> ceo_vector;
160 if (bulk.parallel_rank() == 0) {
161 ceo_vector.push_back(stk::mesh::EntityProc(node5,1));
162 }
163 bulk.change_entity_owner(ceo_vector);
164 stk::mesh::Entity element1 = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
165 stk::mesh::Entity element2 = bulk.get_entity(stk::topology::ELEMENT_RANK, 2);
166 if (bulk.parallel_rank() == 0) {
167 EXPECT_EQ( stk::mesh::Modified, bulk.state(element1) );
168 EXPECT_EQ( stk::mesh::Created, bulk.state(element2) );
169 }
170 else {
171 EXPECT_EQ( stk::mesh::Created, bulk.state(element1) );
172 EXPECT_EQ( stk::mesh::Modified, bulk.state(element2) );
173 }
174 }
175 //END_CEO_MODIFIED
176
177 //BEGIN_PARALLEL_MODIFIED
178 TEST(stkMeshHowTo, checkParallelConsistencyModifiedState)
179 {
180 MPI_Comm communicator = MPI_COMM_WORLD;
181 const int parallel_size = stk::parallel_machine_size(communicator);
182 if (parallel_size != 2) { GTEST_SKIP(); }
183 const std::string fileName = "generated:1x1x2";
184 stk::io::StkMeshIoBroker meshReader(communicator);
185 meshReader.add_mesh_database(fileName, stk::io::READ_MESH);
186 meshReader.create_input_mesh();
187 meshReader.populate_bulk_data();
188 stk::mesh::BulkData & bulk = meshReader.bulk_data();
189 stk::mesh::Entity element1 = bulk.get_entity(stk::topology::ELEMENT_RANK, 1);
190 stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1);
191 bulk.modification_begin();
192 bulk.modification_end();
193 if (bulk.parallel_rank() == 0) {
194 EXPECT_EQ( stk::mesh::Unchanged, bulk.state(element1) );
195 } else { // parallel_rank == 1
196 EXPECT_EQ( stk::mesh::Unchanged, bulk.state(element1) );
197 }
198 bulk.modification_begin();
199 if (bulk.parallel_rank() == 0) {
200 bulk.destroy_relation(element1, node1, 0);
201 stk::mesh::Entity new_node = bulk.declare_node(15);
202 bulk.declare_relation(element1,new_node,0);
203 }
204 if (bulk.parallel_rank() == 0) {
205 EXPECT_EQ( stk::mesh::Modified, bulk.state(element1) );
206 } else { // parallel_rank == 1
207 EXPECT_EQ( stk::mesh::Unchanged, bulk.state(element1) );
208 }
209 bulk.modification_end();
210 if (bulk.parallel_rank() == 0) {
211 EXPECT_EQ( stk::mesh::Modified, bulk.state(element1) );
212 } else { // parallel_rank == 1
213 EXPECT_EQ( stk::mesh::Created, bulk.state(element1) );
214 }
215 }
216 //END_PARALLEL_MODIFIED
217