| 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 "SetupKeyholeMesh.hpp" |
| 36 |
#include "mpi.h" // for MPI_COMM_WORLD, etc |
| 37 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 38 |
#include "stk_mesh/base/CreateEdges.hpp" // for create_edges |
| 39 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 40 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 41 |
#include "stk_mesh/base/Types.hpp" // for PartVector, BucketVector, etc |
| 42 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 43 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_TRUE, etc |
| 44 |
#include <iostream> // for operator<<, basic_ostream, etc |
| 45 |
#include <stddef.h> // for size_t |
| 46 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 47 |
#include <stk_util/parallel/Parallel.hpp> // for parallel_machine_size, etc |
| 48 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 49 |
#include <string> // for operator<<, char_traits |
| 50 |
namespace stk { namespace mesh { class Part; } } |
| 51 |
|
| 52 |
using stk::unit_test_util::build_mesh; |
| 53 |
|
| 54 |
TEST(UnitTestKeyhole, NodeParts_case1) |
| 55 |
{ |
| 56 |
stk::ParallelMachine communicator = MPI_COMM_WORLD; |
| 57 |
|
| 58 |
int numProcs = stk::parallel_machine_size(communicator); |
| 59 |
if (numProcs != 2) { |
| 60 |
return; |
| 61 |
} |
| 62 |
|
| 63 |
const unsigned spatialDim = 2; |
| 64 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 65 |
stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data(); |
| 66 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 67 |
|
| 68 |
stk::mesh::unit_test::setupKeyholeMesh2D_case1(bulk); |
| 69 |
|
| 70 |
stk::mesh::Part& shared = meta.globally_shared_part(); |
| 71 |
const stk::mesh::BucketVector& shared_node_buckets = bulk.get_buckets(stk::topology::NODE_RANK, shared); |
| 72 |
stk::mesh::PartVector blocksA(2); |
| 73 |
blocksA[0] = meta.get_part("block_1"); |
| 74 |
blocksA[1] = meta.get_part("block_2"); |
| 75 |
unsigned num_shared_nodes = 0; |
| 76 |
for(size_t i=0; i<shared_node_buckets.size(); ++i) { |
| 77 |
num_shared_nodes += shared_node_buckets[i]->size(); |
| 78 |
const stk::mesh::Bucket& bucket = *shared_node_buckets[i]; |
| 79 |
std::ostringstream oss; |
| 80 |
oss<<"proc "<<bulk.parallel_rank()<<", shared node ids: "; |
| 81 |
for(size_t j=0; j<bucket.size(); ++j) oss <<bulk.identifier(bucket[j])<<" "; |
| 82 |
std::cerr<<oss.str()<<std::endl; |
| 83 |
bool in_both_blocks = bucket.member_all(blocksA); |
| 84 |
EXPECT_TRUE(in_both_blocks); |
| 85 |
} |
| 86 |
|
| 87 |
const unsigned expected_num_shared_nodes = 2; |
| 88 |
EXPECT_EQ(expected_num_shared_nodes, num_shared_nodes); |
| 89 |
|
| 90 |
if (bulk.parallel_rank() == 0) { |
| 91 |
stk::mesh::Entity node8 = bulk.get_entity(stk::topology::NODE_RANK, stk::mesh::EntityId(8)); |
| 92 |
stk::mesh::Entity node9 = bulk.get_entity(stk::topology::NODE_RANK, stk::mesh::EntityId(9)); |
| 93 |
|
| 94 |
EXPECT_TRUE(bulk.is_valid(node8)); |
| 95 |
EXPECT_TRUE(bulk.is_valid(node9)); |
| 96 |
|
| 97 |
const stk::mesh::Part& aura_part = meta.aura_part(); |
| 98 |
EXPECT_TRUE(bulk.bucket(node8).member(aura_part)); |
| 99 |
EXPECT_TRUE(bulk.bucket(node9).member(aura_part)); |
| 100 |
|
| 101 |
stk::mesh::Part& block_2 = *meta.get_part("block_2"); |
| 102 |
stk::mesh::Part& block_3 = *meta.get_part("block_3"); |
| 103 |
stk::mesh::PartVector blocksB(2); |
| 104 |
blocksB[0] = &block_2; |
| 105 |
blocksB[1] = &block_3; |
| 106 |
EXPECT_TRUE(bulk.bucket(node8).member_all(blocksB)); |
| 107 |
EXPECT_TRUE(bulk.bucket(node9).member_all(blocksB)); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
TEST(UnitTestKeyhole, NodeParts_case2) |
| 112 |
{ |
| 113 |
stk::ParallelMachine communicator = MPI_COMM_WORLD; |
| 114 |
|
| 115 |
int numProcs = stk::parallel_machine_size(communicator); |
| 116 |
if (numProcs != 2) { |
| 117 |
return; |
| 118 |
} |
| 119 |
|
| 120 |
const unsigned spatialDim = 2; |
| 121 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 122 |
stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data(); |
| 123 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 124 |
|
| 125 |
stk::mesh::unit_test::setupKeyholeMesh2D_case2(bulk); |
| 126 |
|
| 127 |
if (bulk.parallel_rank() == 0) { |
| 128 |
stk::mesh::Part& aura = meta.aura_part(); |
| 129 |
const stk::mesh::BucketVector& aura_node_buckets = bulk.get_buckets(stk::topology::NODE_RANK, aura); |
| 130 |
stk::mesh::PartVector blocks(2); |
| 131 |
blocks[0] = meta.get_part("block_2"); |
| 132 |
blocks[1] = meta.get_part("block_3"); |
| 133 |
unsigned num_aura_nodes = 0; |
| 134 |
for(size_t i=0; i<aura_node_buckets.size(); ++i) { |
| 135 |
num_aura_nodes += aura_node_buckets[i]->size(); |
| 136 |
const stk::mesh::Bucket& bucket = *aura_node_buckets[i]; |
| 137 |
std::cerr<<"proc 0, aura node ids: "; |
| 138 |
for(size_t j=0; j<bucket.size(); ++j) std::cerr<<bulk.identifier(bucket[j])<<" "; |
| 139 |
std::cerr<<std::endl; |
| 140 |
bool in_both_blocks = bucket.member_all(blocks); |
| 141 |
EXPECT_TRUE(in_both_blocks); |
| 142 |
} |
| 143 |
|
| 144 |
const unsigned expected_num_aura_nodes = 2; |
| 145 |
EXPECT_EQ(expected_num_aura_nodes, num_aura_nodes); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
TEST(UnitTestKeyhole, EdgeParts_case1) |
| 150 |
{ |
| 151 |
stk::ParallelMachine communicator = MPI_COMM_WORLD; |
| 152 |
|
| 153 |
int numProcs = stk::parallel_machine_size(communicator); |
| 154 |
if (numProcs != 2) { |
| 155 |
return; |
| 156 |
} |
| 157 |
|
| 158 |
const unsigned spatialDim = 2; |
| 159 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 160 |
stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data(); |
| 161 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 162 |
|
| 163 |
stk::mesh::unit_test::setupKeyholeMesh2D_case1(bulk); |
| 164 |
|
| 165 |
stk::mesh::create_edges(bulk); |
| 166 |
|
| 167 |
//find the edge between nodes 2 and 3. |
| 168 |
stk::mesh::Entity edge = stk::mesh::Entity(); |
| 169 |
stk::mesh::EntityId nodeId2 = 2; |
| 170 |
stk::mesh::Entity node2 = bulk.get_entity(stk::topology::NODE_RANK, nodeId2); |
| 171 |
unsigned num_edges = bulk.num_edges(node2); |
| 172 |
const stk::mesh::Entity* edges = bulk.begin_edges(node2); |
| 173 |
for(unsigned i=0; i<num_edges; ++i) { |
| 174 |
stk::mesh::Entity this_edge = edges[i]; |
| 175 |
const stk::mesh::Entity* edge_nodes = bulk.begin_nodes(this_edge); |
| 176 |
if (bulk.identifier(edge_nodes[0])==2 && bulk.identifier(edge_nodes[1])==3) { |
| 177 |
edge = this_edge; |
| 178 |
break; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
EXPECT_TRUE(bulk.is_valid(edge)); |
| 183 |
std::cerr<<"proc "<<bulk.parallel_rank()<<" found edge id="<<bulk.identifier(edge)<<" between nodes 2 and 3"<<std::endl; |
| 184 |
|
| 185 |
const stk::mesh::Part& block_1 = *meta.get_part("block_1"); |
| 186 |
const stk::mesh::Part& block_2 = *meta.get_part("block_2"); |
| 187 |
const stk::mesh::Bucket& edge_bucket = bulk.bucket(edge); |
| 188 |
EXPECT_TRUE(edge_bucket.member(block_1)); |
| 189 |
EXPECT_FALSE(edge_bucket.member(block_2)); |
| 190 |
|
| 191 |
//find the edge between nodes 8 and 9. |
| 192 |
edge = stk::mesh::Entity(); |
| 193 |
stk::mesh::EntityId nodeId8 = 8; |
| 194 |
stk::mesh::Entity node8 = bulk.get_entity(stk::topology::NODE_RANK, nodeId8); |
| 195 |
num_edges = bulk.num_edges(node8); |
| 196 |
edges = bulk.begin_edges(node8); |
| 197 |
for(unsigned i=0; i<num_edges; ++i) { |
| 198 |
stk::mesh::Entity this_edge = edges[i]; |
| 199 |
const stk::mesh::Entity* edge_nodes = bulk.begin_nodes(this_edge); |
| 200 |
if (bulk.identifier(edge_nodes[0])==8 && bulk.identifier(edge_nodes[1])==9) { |
| 201 |
edge = this_edge; |
| 202 |
break; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
EXPECT_TRUE(bulk.is_valid(edge)); |
| 207 |
std::cerr<<"proc "<<bulk.parallel_rank()<<" found edge id="<<bulk.identifier(edge)<<" between nodes 8 and 9"<<std::endl; |
| 208 |
|
| 209 |
const stk::mesh::Part& block_3 = *meta.get_part("block_3"); |
| 210 |
EXPECT_TRUE(bulk.bucket(edge).member(block_2)); |
| 211 |
EXPECT_TRUE(bulk.bucket(edge).member(block_3)); |
| 212 |
} |
| 213 |
|
| 214 |
TEST(UnitTestKeyhole, EdgeParts_case2) |
| 215 |
{ |
| 216 |
stk::ParallelMachine communicator = MPI_COMM_WORLD; |
| 217 |
|
| 218 |
int numProcs = stk::parallel_machine_size(communicator); |
| 219 |
if (numProcs != 2) { |
| 220 |
return; |
| 221 |
} |
| 222 |
|
| 223 |
const unsigned spatialDim = 2; |
| 224 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 225 |
stk::mesh::MetaData& meta = bulkPtr->mesh_meta_data(); |
| 226 |
stk::mesh::BulkData& bulk = *bulkPtr; |
| 227 |
bulk.initialize_face_adjacent_element_graph(); |
| 228 |
|
| 229 |
stk::mesh::unit_test::setupKeyholeMesh2D_case2(bulk); |
| 230 |
|
| 231 |
stk::mesh::create_edges(bulk); |
| 232 |
|
| 233 |
//find the edge between nodes 5 and 6. |
| 234 |
stk::mesh::Entity edge = stk::mesh::Entity(); |
| 235 |
stk::mesh::EntityId nodeId5 = 5; |
| 236 |
stk::mesh::Entity node5 = bulk.get_entity(stk::topology::NODE_RANK, nodeId5); |
| 237 |
unsigned num_edges = bulk.num_edges(node5); |
| 238 |
const stk::mesh::Entity* edges = bulk.begin_edges(node5); |
| 239 |
for(unsigned i=0; i<num_edges; ++i) { |
| 240 |
stk::mesh::Entity this_edge = edges[i]; |
| 241 |
const stk::mesh::Entity* edge_nodes = bulk.begin_nodes(this_edge); |
| 242 |
if (bulk.identifier(edge_nodes[0])==5 && bulk.identifier(edge_nodes[1])==6) { |
| 243 |
edge = this_edge; |
| 244 |
break; |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
EXPECT_TRUE(bulk.is_valid(edge)); |
| 249 |
std::cerr<<"proc "<<bulk.parallel_rank()<<" found edge id="<<bulk.identifier(edge)<<" between nodes 5 and 6"<<std::endl; |
| 250 |
|
| 251 |
const stk::mesh::Part& block_2 = *meta.get_part("block_2"); |
| 252 |
const stk::mesh::Part& block_3 = *meta.get_part("block_3"); |
| 253 |
const stk::mesh::Bucket& edge_bucket = bulk.bucket(edge); |
| 254 |
EXPECT_TRUE(edge_bucket.member(block_2)); |
| 255 |
EXPECT_FALSE(edge_bucket.member(block_3)); |
| 256 |
} |
| 257 |
|