| 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_mesh/base/BulkData.hpp> // for BulkData |
| 37 |
#include <stk_mesh/base/MeshBuilder.hpp> // for MeshBuilder |
| 38 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, entity_rank_names |
| 39 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 40 |
#include "stk_mesh/base/Types.hpp" // for EntityId |
| 41 |
#include "stk_mesh/base/Comm.hpp" // for comm_mesh_counts |
| 42 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 43 |
#include "stkMeshTestUtils.hpp" |
| 44 |
|
| 45 |
namespace { |
| 46 |
|
| 47 |
void verify_global_node_count(size_t expectedTotalNumNodes, const stk::mesh::BulkData &mesh) |
| 48 |
{ |
| 49 |
std::vector<size_t> entity_counts; |
| 50 |
stk::mesh::comm_mesh_counts(mesh, entity_counts); |
| 51 |
EXPECT_EQ(expectedTotalNumNodes, entity_counts[stk::topology::NODE_RANK]); |
| 52 |
} |
| 53 |
|
| 54 |
void verify_nodes_2_and_3_are_no_longer_shared(const stk::mesh::BulkData &mesh, const stk::mesh::EntityVector &nodes) |
| 55 |
{ |
| 56 |
EXPECT_TRUE(mesh.is_valid(nodes[0])); |
| 57 |
ASSERT_TRUE(mesh.is_valid(nodes[1])); |
| 58 |
ASSERT_TRUE(mesh.is_valid(nodes[2])); |
| 59 |
EXPECT_FALSE(mesh.bucket(nodes[1]).shared()); |
| 60 |
EXPECT_FALSE(mesh.bucket(nodes[2]).shared()); |
| 61 |
} |
| 62 |
|
| 63 |
void verify_nodes_2_and_3_are_removed(const stk::mesh::BulkData &mesh, const stk::mesh::EntityVector &nodes) |
| 64 |
{ |
| 65 |
EXPECT_TRUE(mesh.is_valid(nodes[0])); |
| 66 |
// These nodes were deleted because the special marking for "independent" |
| 67 |
// nodes was removed when the nodes became connected to the element and |
| 68 |
// now that the element is deleted, these nodes are no longer needed on |
| 69 |
// proc 1. |
| 70 |
EXPECT_FALSE(mesh.is_valid(nodes[1])); |
| 71 |
EXPECT_FALSE(mesh.is_valid(nodes[2])); |
| 72 |
} |
| 73 |
|
| 74 |
//BEGIN |
| 75 |
TEST(stkMeshHowTo, createSharedNodes) |
| 76 |
{ |
| 77 |
const unsigned spatialDimension = 2; |
| 78 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 79 |
builder.set_spatial_dimension(spatialDimension); |
| 80 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 81 |
stk::mesh::MetaData& metaData = bulkPtr->mesh_meta_data(); |
| 82 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 83 |
stk::mesh::Part &triPart = metaData.declare_part_with_topology("tri_part", stk::topology::TRIANGLE_3_2D); |
| 84 |
metaData.commit(); |
| 85 |
|
| 86 |
if (bulkData.parallel_size() == 2) |
| 87 |
{ |
| 88 |
bulkData.modification_begin(); |
| 89 |
|
| 90 |
const unsigned nodesPerElem = 3; |
| 91 |
stk::mesh::EntityIdVector elemIds = {1, 2};//one elemId for each proc |
| 92 |
std::vector<stk::mesh::EntityIdVector> elemNodeIds = { {1, 3, 2}, {4, 2, 3} }; |
| 93 |
const int myproc = bulkData.parallel_rank(); |
| 94 |
|
| 95 |
stk::mesh::Entity elem = bulkData.declare_element(elemIds[myproc], stk::mesh::ConstPartVector{&triPart}); |
| 96 |
stk::mesh::EntityVector elemNodes(nodesPerElem); |
| 97 |
elemNodes[0] = bulkData.declare_node(elemNodeIds[myproc][0]); |
| 98 |
elemNodes[1] = bulkData.declare_node(elemNodeIds[myproc][1]); |
| 99 |
elemNodes[2] = bulkData.declare_node(elemNodeIds[myproc][2]); |
| 100 |
|
| 101 |
bulkData.declare_relation(elem, elemNodes[0], 0); |
| 102 |
bulkData.declare_relation(elem, elemNodes[1], 1); |
| 103 |
bulkData.declare_relation(elem, elemNodes[2], 2); |
| 104 |
|
| 105 |
int otherproc = testUtils::get_other_proc(myproc); |
| 106 |
bulkData.add_node_sharing(elemNodes[1], otherproc); |
| 107 |
bulkData.add_node_sharing(elemNodes[2], otherproc); |
| 108 |
|
| 109 |
bulkData.modification_end(); |
| 110 |
|
| 111 |
const size_t expectedTotalNumNodes = 4; |
| 112 |
verify_global_node_count(expectedTotalNumNodes, bulkData); |
| 113 |
} |
| 114 |
} |
| 115 |
//END |
| 116 |
|
| 117 |
//BEGININDEP |
| 118 |
TEST(stkMeshHowTo, createIndependentSharedNodes) |
| 119 |
{ |
| 120 |
const unsigned spatialDimension = 2; |
| 121 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 122 |
builder.set_spatial_dimension(spatialDimension); |
| 123 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 124 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 125 |
stk::mesh::MetaData& metaData = bulkPtr->mesh_meta_data(); |
| 126 |
metaData.commit(); |
| 127 |
|
| 128 |
if (bulkData.parallel_size() == 2) |
| 129 |
{ |
| 130 |
bulkData.modification_begin(); |
| 131 |
|
| 132 |
const unsigned nodesPerProc = 3; |
| 133 |
std::vector<stk::mesh::EntityIdVector> nodeIds = { {1, 3, 2}, {4, 2, 3} }; |
| 134 |
const int myproc = bulkData.parallel_rank(); |
| 135 |
stk::mesh::EntityVector nodes(nodesPerProc); |
| 136 |
nodes[0] = bulkData.declare_node(nodeIds[myproc][0]); |
| 137 |
nodes[1] = bulkData.declare_node(nodeIds[myproc][1]); |
| 138 |
nodes[2] = bulkData.declare_node(nodeIds[myproc][2]); |
| 139 |
|
| 140 |
int otherproc = testUtils::get_other_proc(myproc); |
| 141 |
bulkData.add_node_sharing(nodes[1], otherproc); |
| 142 |
bulkData.add_node_sharing(nodes[2], otherproc); |
| 143 |
|
| 144 |
bulkData.modification_end(); |
| 145 |
|
| 146 |
const size_t expectedTotalNumNodes = 4; |
| 147 |
verify_global_node_count(expectedTotalNumNodes, bulkData); |
| 148 |
} |
| 149 |
} |
| 150 |
//ENDINDEP |
| 151 |
|
| 152 |
//BEGIN_INDEP_DEP |
| 153 |
TEST(stkMeshHowTo, createIndependentSharedNodesThenAddDependence) |
| 154 |
{ |
| 155 |
const unsigned spatialDimension = 2; |
| 156 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 157 |
builder.set_spatial_dimension(spatialDimension); |
| 158 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = builder.create(); |
| 159 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 160 |
stk::mesh::MetaData& metaData = bulkPtr->mesh_meta_data(); |
| 161 |
stk::mesh::Part &triPart = metaData.declare_part_with_topology("triPart", stk::topology::TRIANGLE_3_2D); |
| 162 |
metaData.commit(); |
| 163 |
|
| 164 |
if(bulkData.parallel_size() == 2) |
| 165 |
{ |
| 166 |
bulkData.modification_begin(); |
| 167 |
|
| 168 |
const unsigned nodesPerProc = 3; |
| 169 |
std::vector<stk::mesh::EntityIdVector> nodeIds = { {1, 3, 2}, {4, 2, 3}}; |
| 170 |
const int myproc = bulkData.parallel_rank(); |
| 171 |
|
| 172 |
stk::mesh::EntityVector nodes(nodesPerProc); |
| 173 |
nodes[0] = bulkData.declare_node(nodeIds[myproc][0]); |
| 174 |
nodes[1] = bulkData.declare_node(nodeIds[myproc][1]); |
| 175 |
nodes[2] = bulkData.declare_node(nodeIds[myproc][2]); |
| 176 |
|
| 177 |
int otherproc = testUtils::get_other_proc(myproc); |
| 178 |
bulkData.add_node_sharing(nodes[1], otherproc); |
| 179 |
bulkData.add_node_sharing(nodes[2], otherproc); |
| 180 |
|
| 181 |
const size_t expectedNumNodesPriorToModEnd = 6; |
| 182 |
verify_global_node_count(expectedNumNodesPriorToModEnd, bulkData); |
| 183 |
|
| 184 |
bulkData.modification_end(); |
| 185 |
|
| 186 |
const size_t expectedNumNodesAfterModEnd = 4; // nodes 2 and 3 are shared |
| 187 |
verify_global_node_count(expectedNumNodesAfterModEnd, bulkData); |
| 188 |
|
| 189 |
const unsigned elemsPerProc = 1; |
| 190 |
stk::mesh::EntityId elemIds[][elemsPerProc] = { {1}, {2}}; |
| 191 |
|
| 192 |
bulkData.modification_begin(); |
| 193 |
stk::mesh::Entity elem = bulkData.declare_element(elemIds[myproc][0], stk::mesh::ConstPartVector{&triPart}); |
| 194 |
bulkData.declare_relation(elem, nodes[0], 0); |
| 195 |
bulkData.declare_relation(elem, nodes[1], 1); |
| 196 |
bulkData.declare_relation(elem, nodes[2], 2); |
| 197 |
EXPECT_NO_THROW(bulkData.modification_end()); |
| 198 |
|
| 199 |
bulkData.modification_begin(); |
| 200 |
bulkData.destroy_entity(elem); |
| 201 |
bulkData.modification_end(); |
| 202 |
|
| 203 |
if(myproc == 0) |
| 204 |
verify_nodes_2_and_3_are_no_longer_shared(bulkData, nodes); |
| 205 |
|
| 206 |
else // myproc == 1 |
| 207 |
verify_nodes_2_and_3_are_removed(bulkData, nodes); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
//END_INDEP_DEP |
| 212 |
} |