| 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, ASSERT_TRUE, etc |
| 36 |
#include <map> // for map, map<>::mapped_type |
| 37 |
#include <ostream> // for basic_ostream::operator<< |
| 38 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 39 |
#include <stk_mesh/base/CreateEdges.hpp> // for create_edges |
| 40 |
#include <stk_topology/topology.hpp> // for topology, etc |
| 41 |
#include <vector> // for vector |
| 42 |
#include "mpi.h" // for MPI_COMM_WORLD |
| 43 |
|
| 44 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 45 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 46 |
#include "stk_mesh/base/Types.hpp" // for EntityId, EntityRank |
| 47 |
#include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture |
| 48 |
#include "stk_util/parallel/Parallel.hpp" // for parallel_machine_rank, etc |
| 49 |
|
| 50 |
using stk::mesh::MetaData; |
| 51 |
using stk::mesh::BulkData; |
| 52 |
using stk::mesh::Entity; |
| 53 |
using stk::mesh::EntityRank; |
| 54 |
using stk::mesh::EntityId; |
| 55 |
|
| 56 |
TEST( UnitTestGloballyShared, DISABLED_keyhole_3x1 ) |
| 57 |
{ |
| 58 |
// layout: |
| 59 |
// [ e_1, e_2, e_3 ] elements |
| 60 |
// [ p_0, p_1, p_0 ] processors |
| 61 |
// |
| 62 |
const unsigned p_rank = stk::parallel_machine_rank(MPI_COMM_WORLD); |
| 63 |
const unsigned p_size = stk::parallel_machine_size(MPI_COMM_WORLD); |
| 64 |
|
| 65 |
// Skip unless p_size is at least 2 |
| 66 |
if (p_size < 2) |
| 67 |
return; |
| 68 |
|
| 69 |
const unsigned NX = 3; |
| 70 |
const unsigned NY = 1; |
| 71 |
|
| 72 |
// map< processor, vector of element ids >, this is our custom parallel |
| 73 |
// distribution. Assign 1,5 to proc 0, all the rest to proc 1. The other |
| 74 |
// procs get nothing. |
| 75 |
std::map<unsigned,std::vector<EntityId> > parallel_distribution; |
| 76 |
{ |
| 77 |
std::vector< EntityId> element_ids; |
| 78 |
element_ids.push_back(1); |
| 79 |
element_ids.push_back(3); |
| 80 |
parallel_distribution[0] = element_ids; |
| 81 |
element_ids.clear(); |
| 82 |
element_ids.push_back(2); |
| 83 |
parallel_distribution[1] = element_ids; |
| 84 |
} |
| 85 |
|
| 86 |
// Create the fixture |
| 87 |
stk::mesh::fixtures::QuadFixture qf(MPI_COMM_WORLD,NX,NY); |
| 88 |
qf.m_meta.commit(); |
| 89 |
if (p_rank <= 1) { |
| 90 |
qf.generate_mesh(parallel_distribution[p_rank]); |
| 91 |
} |
| 92 |
else { |
| 93 |
std::vector<EntityId> empty_vector; |
| 94 |
qf.generate_mesh( empty_vector ) ; |
| 95 |
} |
| 96 |
|
| 97 |
BulkData & mesh = qf.m_bulk_data; |
| 98 |
|
| 99 |
stk::mesh::create_edges(mesh); |
| 100 |
|
| 101 |
// Quad edge ordinals: |
| 102 |
// 2 |
| 103 |
// ----- |
| 104 |
// | | |
| 105 |
// 3 | | 1 |
| 106 |
// | | |
| 107 |
// ----- |
| 108 |
// 0 |
| 109 |
|
| 110 |
// Verify that the entities and known and owned by the appropriate procs |
| 111 |
const EntityRank element_rank = stk::topology::ELEMENT_RANK; |
| 112 |
Entity element_1 = mesh.get_entity(element_rank, 1); |
| 113 |
Entity element_2 = mesh.get_entity(element_rank, 2); |
| 114 |
Entity element_3 = mesh.get_entity(element_rank, 3); |
| 115 |
if (p_rank == 0) { |
| 116 |
ASSERT_TRUE( mesh.is_valid(element_1) ); |
| 117 |
ASSERT_TRUE( mesh.is_valid(element_2) ); |
| 118 |
ASSERT_TRUE( mesh.is_valid(element_3) ); |
| 119 |
EXPECT_EQ( 0, mesh.parallel_owner_rank(element_1) ); |
| 120 |
EXPECT_EQ( 1, mesh.parallel_owner_rank(element_2) ); |
| 121 |
EXPECT_EQ( 0, mesh.parallel_owner_rank(element_3) ); |
| 122 |
// Verify global sharing of edges on element_1 and element_3 |
| 123 |
// element_1: edge_1 should be globally shared |
| 124 |
// element_3: edge_3 should be globally shared |
| 125 |
stk::mesh::Entity const* element_1_edge_relations = mesh.begin_edges(element_1); |
| 126 |
const int num_element_1_edges = mesh.num_edges(element_1); |
| 127 |
ASSERT_EQ( 4, num_element_1_edges ); |
| 128 |
Entity element_1_edge_1 = element_1_edge_relations[1]; |
| 129 |
ASSERT_TRUE( mesh.is_valid(element_1_edge_1) ); |
| 130 |
EXPECT_TRUE( mesh.in_shared(mesh.entity_key(element_1_edge_1)) ); |
| 131 |
|
| 132 |
stk::mesh::Entity const* element_3_edge_relations = mesh.begin_edges(element_3); |
| 133 |
const int num_element_3_edges = mesh.num_edges(element_3); |
| 134 |
ASSERT_EQ( 4, num_element_3_edges ); |
| 135 |
Entity element_3_edge_3 = element_3_edge_relations[3]; |
| 136 |
ASSERT_TRUE( mesh.is_valid(element_3_edge_3) ); |
| 137 |
EXPECT_TRUE( mesh.in_shared(mesh.entity_key(element_3_edge_3)) ); |
| 138 |
|
| 139 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_1)) ); |
| 140 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_2)) ); |
| 141 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_3)) ); |
| 142 |
} |
| 143 |
else if (p_rank == 1) { |
| 144 |
ASSERT_TRUE( mesh.is_valid(element_1) ); |
| 145 |
ASSERT_TRUE( mesh.is_valid(element_2) ); |
| 146 |
ASSERT_TRUE( mesh.is_valid(element_3) ); |
| 147 |
EXPECT_EQ( 0, mesh.parallel_owner_rank(element_1) ); |
| 148 |
EXPECT_EQ( 1, mesh.parallel_owner_rank(element_2) ); |
| 149 |
EXPECT_EQ( 0, mesh.parallel_owner_rank(element_3) ); |
| 150 |
// Verify global sharing of edges on element_2 |
| 151 |
// element_2: edge_0 and edge_2 should _not be_ globally shared |
| 152 |
// edge_1 and edge_3 should _be_ globally shared |
| 153 |
stk::mesh::Entity const* element_2_edge_relations = mesh.begin_edges(element_2); |
| 154 |
const int num_element_2_edges = mesh.num_edges(element_2); |
| 155 |
ASSERT_EQ( 4, num_element_2_edges ); |
| 156 |
|
| 157 |
Entity element_2_edge_0 = element_2_edge_relations[0]; |
| 158 |
ASSERT_TRUE( mesh.is_valid(element_2_edge_0) ); |
| 159 |
|
| 160 |
Entity element_2_edge_2 = element_2_edge_relations[2]; |
| 161 |
ASSERT_TRUE( mesh.is_valid(element_2_edge_2) ); |
| 162 |
|
| 163 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_2_edge_0)) ); |
| 164 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_2_edge_2)) ); |
| 165 |
|
| 166 |
Entity element_2_edge_1 = element_2_edge_relations[1]; |
| 167 |
ASSERT_TRUE( mesh.is_valid(element_2_edge_1) ); |
| 168 |
Entity element_2_edge_3 = element_2_edge_relations[3]; |
| 169 |
ASSERT_TRUE( mesh.is_valid(element_2_edge_3) ); |
| 170 |
|
| 171 |
EXPECT_TRUE( mesh.in_shared(mesh.entity_key(element_2_edge_1)) ); |
| 172 |
EXPECT_TRUE( mesh.in_shared(mesh.entity_key(element_2_edge_3)) ); |
| 173 |
|
| 174 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_1)) ); |
| 175 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_2)) ); |
| 176 |
EXPECT_FALSE( mesh.in_shared(mesh.entity_key(element_3)) ); |
| 177 |
} |
| 178 |
else { |
| 179 |
EXPECT_TRUE( !mesh.is_valid(element_1) ); |
| 180 |
EXPECT_TRUE( !mesh.is_valid(element_2) ); |
| 181 |
EXPECT_TRUE( !mesh.is_valid(element_3) ); |
| 182 |
} |
| 183 |
} |
| 184 |
|