| 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 ASSERT_TRUE, AssertHelper, etc |
| 36 |
#include <stddef.h> // for size_t |
| 37 |
#include <iostream> // for operator<<, basic_ostream, etc |
| 38 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 39 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 40 |
#include <stk_util/parallel/Parallel.hpp> // for ParallelMachine |
| 41 |
#include <string> // for string, allocator, etc |
| 42 |
#include <vector> // for vector |
| 43 |
#include "mpi.h" // for MPI_Barrier, MPI_COMM_WORLD, etc |
| 44 |
|
| 45 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 46 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names |
| 47 |
#include "stk_mesh/base/Types.hpp" // for EntityProc, EntityId, etc |
| 48 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 49 |
#include "stk_unit_test_utils/stk_mesh_fixtures/FixtureNodeSharing.hpp" |
| 50 |
|
| 51 |
using stk::mesh::Part; |
| 52 |
using stk::mesh::MetaData; |
| 53 |
using stk::mesh::BulkData; |
| 54 |
using stk::mesh::MeshBuilder; |
| 55 |
using stk::mesh::PartVector; |
| 56 |
using stk::mesh::EntityProc; |
| 57 |
using stk::mesh::Entity; |
| 58 |
using stk::mesh::EntityId; |
| 59 |
using stk::mesh::EntityVector; |
| 60 |
|
| 61 |
TEST(UnitTestingOfBulkData, aura1DRing_RestoreDeletedAuraEntity) |
| 62 |
{ |
| 63 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != 3) { GTEST_SKIP(); } |
| 64 |
|
| 65 |
// |
| 66 |
// testing if modification flags propagate properly for ghosted entities |
| 67 |
// |
| 68 |
// To test this, we focus on a single node shared on 2 procs, ghosted on others |
| 69 |
// |
| 70 |
|
| 71 |
/** |
| 72 |
* 1D Mesh (node,owner)--[elem,owner]---(...) |
| 73 |
* |
| 74 |
* <---(70,0)--[500,0]--(41,1)--[301,1]---(42,2)---[402,2]---(70,0)---> |
| 75 |
* |
| 76 |
* <---(50,0)--[100,0]--(21,1)--[201,1]---(32,2)---[302,2]---(50,0)---> |
| 77 |
* |
| 78 |
*/ |
| 79 |
|
| 80 |
// elem, node0, node1, owner |
| 81 |
EntityId elems_0[][4] = { {100, 21, 50, 0}, {201, 21, 32, 1}, {302, 32, 50, 2}, |
| 82 |
{500, 41, 70, 0}, {301, 41, 42, 1}, {402, 42, 70, 2} }; |
| 83 |
// node, owner |
| 84 |
EntityId nodes_0[][2] = { {21,1}, {50,0}, {32, 2}, {41, 1}, {42, 1}, {70, 0} }; |
| 85 |
|
| 86 |
unsigned nelems = sizeof(elems_0)/4/sizeof(EntityId); |
| 87 |
unsigned nnodes = sizeof(nodes_0)/2/sizeof(EntityId); |
| 88 |
|
| 89 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 90 |
|
| 91 |
// Set up meta and bulk data |
| 92 |
const unsigned spatial_dim = 1; |
| 93 |
|
| 94 |
std::vector<std::string> entity_rank_names = stk::mesh::entity_rank_names(); |
| 95 |
entity_rank_names.push_back("FAMILY_TREE"); |
| 96 |
|
| 97 |
MeshBuilder builder(pm); |
| 98 |
builder.set_spatial_dimension(spatial_dim); |
| 99 |
builder.set_entity_rank_names(entity_rank_names); |
| 100 |
std::shared_ptr<BulkData> bulkPtr = builder.create(); |
| 101 |
BulkData& mesh = *bulkPtr; |
| 102 |
MetaData& meta_data = mesh.mesh_meta_data(); |
| 103 |
Part & elem_part = meta_data.declare_part_with_topology("elem_part", stk::topology::LINE_2_1D); |
| 104 |
Part & node_part = meta_data.declare_part_with_topology("node_part", stk::topology::NODE); |
| 105 |
|
| 106 |
meta_data.commit(); |
| 107 |
|
| 108 |
int p_rank = mesh.parallel_rank(); |
| 109 |
|
| 110 |
// Build map for node sharing |
| 111 |
stk::mesh::fixtures::NodeToProcsMMap nodes_to_procs; |
| 112 |
{ |
| 113 |
for (unsigned ielem=0; ielem < nelems; ielem++) { |
| 114 |
int e_owner = static_cast<int>(elems_0[ielem][3]); |
| 115 |
stk::mesh::fixtures::AddToNodeProcsMMap(nodes_to_procs, elems_0[ielem][2], e_owner); |
| 116 |
stk::mesh::fixtures::AddToNodeProcsMMap(nodes_to_procs, elems_0[ielem][1], e_owner); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
// |
| 121 |
// Begin modification cycle so we can create the entities and relations |
| 122 |
// |
| 123 |
|
| 124 |
// Create elements |
| 125 |
Entity elem = Entity(); |
| 126 |
|
| 127 |
mesh.modification_begin(); |
| 128 |
|
| 129 |
for (unsigned ielem=0; ielem < nelems; ielem++) |
| 130 |
{ |
| 131 |
if (static_cast<int>(elems_0[ielem][3]) == p_rank) |
| 132 |
{ |
| 133 |
elem = mesh.declare_element(elems_0[ielem][0], stk::mesh::ConstPartVector{&elem_part}); |
| 134 |
|
| 135 |
EntityVector nodes; |
| 136 |
// Create node on all procs |
| 137 |
nodes.push_back( mesh.declare_node(elems_0[ielem][2], stk::mesh::ConstPartVector{&node_part}) ); |
| 138 |
nodes.push_back( mesh.declare_node(elems_0[ielem][1], stk::mesh::ConstPartVector{&node_part}) ); |
| 139 |
|
| 140 |
// Add relations to nodes |
| 141 |
mesh.declare_relation( elem, nodes[0], 0 ); |
| 142 |
mesh.declare_relation( elem, nodes[1], 1 ); |
| 143 |
|
| 144 |
// Node sharing |
| 145 |
stk::mesh::fixtures::DoAddNodeSharings(mesh, nodes_to_procs, mesh.identifier(nodes[0]), nodes[0]); |
| 146 |
stk::mesh::fixtures::DoAddNodeSharings(mesh, nodes_to_procs, mesh.identifier(nodes[1]), nodes[1]); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
mesh.modification_end(); |
| 151 |
|
| 152 |
Entity node1 = Entity(); |
| 153 |
|
| 154 |
// change node owners |
| 155 |
std::vector<EntityProc> change; |
| 156 |
|
| 157 |
for (unsigned inode=0; inode < nnodes; inode++) |
| 158 |
{ |
| 159 |
node1 = mesh.get_entity(stk::topology::NODE_RANK, nodes_0[inode][0]); |
| 160 |
if (mesh.is_valid(node1) && mesh.parallel_owner_rank(node1) == p_rank) |
| 161 |
{ |
| 162 |
int dest = nodes_0[inode][1]; |
| 163 |
EntityProc eproc(node1, dest); |
| 164 |
change.push_back(eproc); |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
mesh.change_entity_owner( change ); |
| 169 |
|
| 170 |
// attempt to delete a node and its elems but on a ghosted proc |
| 171 |
mesh.modification_begin(); |
| 172 |
|
| 173 |
if (p_rank == 2) |
| 174 |
{ |
| 175 |
node1 = mesh.get_entity(stk::topology::NODE_RANK, 21); |
| 176 |
Entity elem1 = mesh.get_entity(stk::topology::ELEMENT_RANK, 201); |
| 177 |
Entity elem2 = mesh.get_entity(stk::topology::ELEMENT_RANK, 100); |
| 178 |
|
| 179 |
bool did_it_elem = mesh.destroy_entity(elem1); |
| 180 |
did_it_elem = did_it_elem & mesh.destroy_entity(elem2); |
| 181 |
ASSERT_TRUE(did_it_elem); |
| 182 |
bool did_it = mesh.destroy_entity(node1); |
| 183 |
ASSERT_TRUE(did_it); |
| 184 |
} |
| 185 |
|
| 186 |
mesh.modification_end(); |
| 187 |
|
| 188 |
// The node that we deleted on proc 2 was an aura node. so modification_end |
| 189 |
// should have restored the node (and also restored the aura elements we deleted). |
| 190 |
// The way this mesh is arranged, every proc has every element. |
| 191 |
node1 = mesh.get_entity(stk::topology::NODE_RANK, 21); |
| 192 |
ASSERT_TRUE(mesh.is_valid(node1)); |
| 193 |
elem = mesh.get_entity(stk::topology::ELEM_RANK, 201); |
| 194 |
ASSERT_TRUE(mesh.is_valid(elem)); |
| 195 |
elem = mesh.get_entity(stk::topology::ELEM_RANK, 100); |
| 196 |
ASSERT_TRUE(mesh.is_valid(elem)); |
| 197 |
} |
| 198 |
|