| 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_TRUE, etc |
| 36 |
#include <stk_util/parallel/Parallel.hpp> |
| 37 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 38 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 39 |
#include <stk_mesh/base/GetEntities.hpp> |
| 40 |
#include <stk_mesh/base/FEMHelpers.hpp> // for declare_element |
| 41 |
#include <stk_mesh/base/GetEntities.hpp> |
| 42 |
#include <stk_mesh/base/DestroyElements.hpp> |
| 43 |
#include <stk_mesh/baseImpl/CommEntityMods.hpp> |
| 44 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 45 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 46 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 47 |
#include "stk_mesh/base/Types.hpp" // for PartVector, EntityId, etc |
| 48 |
#include "stk_mesh/base/Comm.hpp" |
| 49 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 50 |
#include "stk_io/FillMesh.hpp" |
| 51 |
#include "stk_mesh/base/MeshBuilder.hpp" |
| 52 |
#include "stk_unit_test_utils/BuildMesh.hpp" |
| 53 |
#include "UnitTestTextMeshFixture.hpp" |
| 54 |
|
| 55 |
namespace { |
| 56 |
|
| 57 |
TEST(MakeUnique, entityParallelStates_empty) |
| 58 |
{ |
| 59 |
std::vector<stk::mesh::EntityParallelState> empty; |
| 60 |
stk::mesh::impl::make_unique(empty); |
| 61 |
EXPECT_TRUE(empty.empty()); |
| 62 |
} |
| 63 |
|
| 64 |
stk::mesh::EntityKey get_node_key(stk::mesh::EntityId nodeId) |
| 65 |
{ |
| 66 |
return stk::mesh::EntityKey(stk::topology::NODE_RANK, nodeId); |
| 67 |
} |
| 68 |
|
| 69 |
stk::mesh::EntityParallelState get_pll_state(stk::mesh::EntityId id, |
| 70 |
int proc, |
| 71 |
stk::mesh::EntityState state) |
| 72 |
{ |
| 73 |
return {proc, state, {get_node_key(id), stk::mesh::Entity(), -1}, false}; |
| 74 |
} |
| 75 |
|
| 76 |
TEST(MakeUnique, entityParallelStates_alreadyUnique) |
| 77 |
{ |
| 78 |
std::vector<stk::mesh::EntityParallelState> pllStates; |
| 79 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Modified)); |
| 80 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Modified)); |
| 81 |
pllStates.push_back(get_pll_state(3, 2, stk::mesh::Modified)); |
| 82 |
|
| 83 |
stk::mesh::impl::make_unique(pllStates); |
| 84 |
EXPECT_EQ(3u, pllStates.size()); |
| 85 |
} |
| 86 |
|
| 87 |
TEST(MakeUnique, entityParallelStates_duplicate) |
| 88 |
{ |
| 89 |
std::vector<stk::mesh::EntityParallelState> pllStates; |
| 90 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Modified)); |
| 91 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Modified)); |
| 92 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Deleted)); |
| 93 |
pllStates.push_back(get_pll_state(3, 2, stk::mesh::Modified)); |
| 94 |
|
| 95 |
stk::mesh::impl::make_unique(pllStates); |
| 96 |
EXPECT_EQ(3u, pllStates.size()); |
| 97 |
EXPECT_EQ(stk::mesh::Deleted, pllStates[1].state); |
| 98 |
} |
| 99 |
|
| 100 |
TEST(MakeUnique, entityParallelStates_duplicate_sort_then_unique) |
| 101 |
{ |
| 102 |
std::vector<stk::mesh::EntityParallelState> pllStates; |
| 103 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Deleted)); |
| 104 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Modified)); |
| 105 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Modified)); |
| 106 |
pllStates.push_back(get_pll_state(3, 2, stk::mesh::Modified)); |
| 107 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Deleted)); |
| 108 |
|
| 109 |
std::sort(pllStates.begin(), pllStates.end()); |
| 110 |
stk::mesh::impl::make_unique(pllStates); |
| 111 |
EXPECT_EQ(3u, pllStates.size()); |
| 112 |
EXPECT_EQ(stk::mesh::Deleted, pllStates[0].state); |
| 113 |
EXPECT_EQ(stk::mesh::Deleted, pllStates[1].state); |
| 114 |
} |
| 115 |
|
| 116 |
TEST(MakeUnique, entityParallelStates_3duplicates_sort_then_unique) |
| 117 |
{ |
| 118 |
std::vector<stk::mesh::EntityParallelState> pllStates; |
| 119 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Deleted)); |
| 120 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Modified)); |
| 121 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Modified)); |
| 122 |
pllStates.push_back(get_pll_state(3, 2, stk::mesh::Modified)); |
| 123 |
pllStates.push_back(get_pll_state(2, 1, stk::mesh::Created)); |
| 124 |
pllStates.push_back(get_pll_state(1, 0, stk::mesh::Deleted)); |
| 125 |
|
| 126 |
std::sort(pllStates.begin(), pllStates.end()); |
| 127 |
stk::mesh::impl::make_unique(pllStates); |
| 128 |
EXPECT_EQ(3u, pllStates.size()); |
| 129 |
EXPECT_EQ(stk::mesh::Deleted, pllStates[0].state); |
| 130 |
EXPECT_EQ(stk::mesh::Deleted, pllStates[1].state); |
| 131 |
} |
| 132 |
|
| 133 |
TEST(ThreeTet4sOn3Procs, deleteMiddleTetOnP1AndRecreateOnP2_works) |
| 134 |
{ |
| 135 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); } |
| 136 |
|
| 137 |
std::string meshDesc = "0,1,TET_4,5,7,2,1\n" |
| 138 |
"1,2,TET_4,6,7,1,4\n" |
| 139 |
"2,3,TET_4,6,8,4,3\n"; |
| 140 |
|
| 141 |
std::vector<double> coordinates { |
| 142 |
0.082356, -0.411779, 0.082356, |
| 143 |
0.082356, -0.247067, 0.082356, |
| 144 |
0.082356, -0.576490, 0.247067, |
| 145 |
0.082356, -0.411779, 0.247067, |
| 146 |
0.164711, -0.329423, 0.000000, |
| 147 |
0.164711, -0.494134, 0.164711, |
| 148 |
0.164711, -0.329423, 0.164711, |
| 149 |
0.164711, -0.494134, 0.329423, |
| 150 |
}; |
| 151 |
|
| 152 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 153 |
builder.set_spatial_dimension(3); |
| 154 |
std::unique_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 155 |
stk::mesh::BulkData &bulk = *bulkPtr; |
| 156 |
|
| 157 |
stk::unit_test_util::setup_text_mesh(bulk, stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coordinates)); |
| 158 |
|
| 159 |
const int proc = bulk.parallel_rank(); |
| 160 |
stk::mesh::Part *partWithTopology = bulk.mesh_meta_data().get_part("block_TETRAHEDRON_4"); |
| 161 |
|
| 162 |
const stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1); |
| 163 |
const stk::mesh::Entity node7 = bulk.get_entity(stk::topology::NODE_RANK, 7); |
| 164 |
|
| 165 |
bulk.modification_begin(); |
| 166 |
stk::mesh::EntityVector elem2Vec; |
| 167 |
if(proc == 0) |
| 168 |
{ |
| 169 |
bulk.add_node_sharing(node1, 2); |
| 170 |
bulk.add_node_sharing(node7, 2); |
| 171 |
} |
| 172 |
else if(proc == 1) |
| 173 |
{ |
| 174 |
elem2Vec = {bulk.get_entity(stk::topology::ELEM_RANK, 2)}; |
| 175 |
} |
| 176 |
else if(proc == 2) |
| 177 |
{ |
| 178 |
stk::mesh::declare_element(bulk, *partWithTopology, 11, {6,7,1,4}); |
| 179 |
bulk.add_node_sharing(node1, 0); |
| 180 |
bulk.add_node_sharing(node7, 0); |
| 181 |
} |
| 182 |
|
| 183 |
stk::mesh::destroy_elements_no_mod_cycle(bulk, elem2Vec, bulk.mesh_meta_data().universal_part()); |
| 184 |
|
| 185 |
EXPECT_NO_THROW(bulk.modification_end()); |
| 186 |
} |
| 187 |
|
| 188 |
TEST(ThreeTet10sOn3Procs, deleteMiddleTetOnP1AndRecreateOnP2_works) |
| 189 |
{ |
| 190 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); } |
| 191 |
|
| 192 |
std::string meshDesc = "0,1,TET_10,5,7,2,1,9,10,11,12,13,14\n" |
| 193 |
"1,2,TET_10,6,7,1,4,15,13,16,17,18,19\n" |
| 194 |
"2,3,TET_10,6,8,4,3,20,21,17,22,23,24\n"; |
| 195 |
|
| 196 |
std::vector<double> coordinates { |
| 197 |
0.082356, -0.411779, 0.082356, |
| 198 |
0.082356, -0.247067, 0.082356, |
| 199 |
0.082356, -0.576490, 0.247067, |
| 200 |
0.082356, -0.411779, 0.247067, |
| 201 |
0.164711, -0.329423, 0.000000, |
| 202 |
0.164711, -0.494134, 0.164711, |
| 203 |
0.164711, -0.329423, 0.164711, |
| 204 |
0.164711, -0.494134, 0.329423, |
| 205 |
0.164711, -0.329423, 0.082356, |
| 206 |
0.123534, -0.288245, 0.123534, |
| 207 |
0.123534, -0.288245, 0.041178, |
| 208 |
0.123534, -0.370601, 0.041178, |
| 209 |
0.123534, -0.370601, 0.123534, |
| 210 |
0.082356, -0.329423, 0.082356, |
| 211 |
0.164711, -0.411779, 0.164711, |
| 212 |
0.123534, -0.452956, 0.123534, |
| 213 |
0.123534, -0.452956, 0.205889, |
| 214 |
0.123534, -0.370601, 0.205889, |
| 215 |
0.082356, -0.411779, 0.164711, |
| 216 |
0.164711, -0.494134, 0.247067, |
| 217 |
0.123534, -0.452956, 0.288245, |
| 218 |
0.123534, -0.535312, 0.205889, |
| 219 |
0.123534, -0.535312, 0.288245, |
| 220 |
0.082356, -0.494134, 0.247067, |
| 221 |
}; |
| 222 |
|
| 223 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 224 |
builder.set_spatial_dimension(3); |
| 225 |
std::unique_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 226 |
stk::mesh::BulkData &bulk = *bulkPtr; |
| 227 |
|
| 228 |
stk::unit_test_util::setup_text_mesh(bulk, stk::unit_test_util::get_full_text_mesh_desc(meshDesc, coordinates)); |
| 229 |
|
| 230 |
const int proc = bulk.parallel_rank(); |
| 231 |
stk::mesh::Part *partWithTopology = bulk.mesh_meta_data().get_part("block_TETRAHEDRON_10"); |
| 232 |
|
| 233 |
const stk::mesh::Entity node1 = bulk.get_entity(stk::topology::NODE_RANK, 1); |
| 234 |
const stk::mesh::Entity node7 = bulk.get_entity(stk::topology::NODE_RANK, 7); |
| 235 |
stk::mesh::Entity node13 = bulk.get_entity(stk::topology::NODE_RANK, 13); |
| 236 |
|
| 237 |
bulk.modification_begin(); |
| 238 |
stk::mesh::EntityVector elem2Vec; |
| 239 |
if(proc == 0) |
| 240 |
{ |
| 241 |
bulk.add_node_sharing(node1, 2); |
| 242 |
bulk.add_node_sharing(node7, 2); |
| 243 |
bulk.add_node_sharing(node13, 2); |
| 244 |
} |
| 245 |
else if(proc == 1) |
| 246 |
{ |
| 247 |
elem2Vec = {bulk.get_entity(stk::topology::ELEM_RANK, 2)}; |
| 248 |
} |
| 249 |
else if(proc == 2) |
| 250 |
{ |
| 251 |
stk::mesh::declare_element(bulk, *partWithTopology, 11, {6,7,1,4,15,13,16,17,18,19}); |
| 252 |
bulk.add_node_sharing(node1, 0); |
| 253 |
bulk.add_node_sharing(node7, 0); |
| 254 |
bulk.add_node_sharing(node13, 0); |
| 255 |
} |
| 256 |
|
| 257 |
stk::mesh::destroy_elements_no_mod_cycle(bulk, elem2Vec, bulk.mesh_meta_data().universal_part()); |
| 258 |
|
| 259 |
EXPECT_NO_THROW(bulk.modification_end()); |
| 260 |
|
| 261 |
node13 = bulk.get_entity(stk::topology::NODE_RANK, 13); |
| 262 |
if (bulk.parallel_rank() != 1) { |
| 263 |
EXPECT_TRUE(bulk.is_valid(node13)); |
| 264 |
EXPECT_TRUE(bulk.bucket(node13).shared()); |
| 265 |
} |
| 266 |
else { |
| 267 |
EXPECT_FALSE(bulk.is_valid(node13)); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
} // empty namespace |
| 272 |
|