| 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> |
| 36 |
#include <stk_mesh/base/Types.hpp> |
| 37 |
#include <stk_mesh/base/MetaData.hpp> |
| 38 |
#include <stk_mesh/base/BulkData.hpp> |
| 39 |
#include <stk_mesh/base/MeshBuilder.hpp> |
| 40 |
#include <stk_topology/topology.hpp> |
| 41 |
#include <stk_util/parallel/Parallel.hpp> |
| 42 |
|
| 43 |
|
| 44 |
class ParticleCustomGhostTester : public ::testing::Test |
| 45 |
{ |
| 46 |
public: |
| 47 |
ParticleCustomGhostTester() |
| 48 |
: meta(nullptr), bulk() |
| 49 |
{} |
| 50 |
|
| 51 |
void initialize(stk::ParallelMachine pm, stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 52 |
{ |
| 53 |
stk::mesh::MeshBuilder builder(pm); |
| 54 |
builder.set_spatial_dimension(3); |
| 55 |
builder.set_aura_option(auraOption); |
| 56 |
bulk = builder.create(); |
| 57 |
meta = &(bulk->mesh_meta_data()); |
| 58 |
createParts(); |
| 59 |
} |
| 60 |
|
| 61 |
void createParticleOnProc0AndGhostToProc1() |
| 62 |
{ |
| 63 |
bulk->modification_begin(); |
| 64 |
createParticleOnProc0(); |
| 65 |
ghostParticleToProc1(); |
| 66 |
bulk->modification_end(); |
| 67 |
} |
| 68 |
|
| 69 |
void createBeamOnProc1AndUpdateSharingOnProc0() |
| 70 |
{ |
| 71 |
bulk->modification_begin(); |
| 72 |
createBeamOnProc1(); |
| 73 |
addNode1Sharing(); |
| 74 |
bulk->modification_end(); |
| 75 |
} |
| 76 |
|
| 77 |
void destroyBeamOnProc1AndVerifyParticleIsStillOnProc1() |
| 78 |
{ |
| 79 |
destroyBeamOnProc1(); |
| 80 |
verifyParticleIsStillOnProc1(); |
| 81 |
verifyNode1IsSendGhostAndNotSharedOnProc0(); |
| 82 |
verifyNode1IsGhostedAndNotSharedOnProc1(); |
| 83 |
} |
| 84 |
|
| 85 |
void verifyNode1NotShared() |
| 86 |
{ |
| 87 |
EXPECT_FALSE(bulk->bucket(node1).shared()); |
| 88 |
EXPECT_FALSE(bulk->in_shared(bulk->entity_key(node1))); |
| 89 |
} |
| 90 |
|
| 91 |
void verifyNode1IsSendGhostAndNotSharedOnProc0() |
| 92 |
{ |
| 93 |
if (bulk->parallel_rank() == 0) |
| 94 |
{ |
| 95 |
verifyNode1NotShared(); |
| 96 |
EXPECT_TRUE(bulk->in_send_ghost(bulk->entity_key(node1))); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
void verifyNode1IsGhostedAndNotSharedOnProc1() |
| 101 |
{ |
| 102 |
if (bulk->parallel_rank() == 1) |
| 103 |
{ |
| 104 |
verifyNode1NotShared(); |
| 105 |
EXPECT_TRUE(bulk->in_receive_custom_ghost(bulk->entity_key(node1))); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
void verifyParticleIsStillOnProc1() |
| 110 |
{ |
| 111 |
if (bulk->parallel_rank() == 1) |
| 112 |
{ |
| 113 |
particle = bulk->get_entity(stk::topology::ELEMENT_RANK,1); |
| 114 |
EXPECT_TRUE(bulk->is_valid(particle)); |
| 115 |
EXPECT_TRUE(bulk->is_valid(node1)); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
~ParticleCustomGhostTester() |
| 120 |
{ |
| 121 |
} |
| 122 |
private: |
| 123 |
void destroyBeamOnProc1() |
| 124 |
{ |
| 125 |
bulk->modification_begin(); |
| 126 |
if (bulk->parallel_rank() == 1) |
| 127 |
{ |
| 128 |
destroyBeam(); |
| 129 |
} |
| 130 |
bulk->modification_end(); |
| 131 |
} |
| 132 |
|
| 133 |
void ghostParticleToProc1() |
| 134 |
{ |
| 135 |
stk::mesh::Ghosting & my_ghosting = bulk->create_ghosting("My Custom Ghosting"); |
| 136 |
stk::mesh::EntityProcVec ghost_entities; |
| 137 |
if (bulk->parallel_rank() == 0) |
| 138 |
ghost_entities.push_back(stk::mesh::EntityProc(particle,1)); |
| 139 |
bulk->change_ghosting(my_ghosting,ghost_entities,{}); |
| 140 |
} |
| 141 |
|
| 142 |
void createParticleOnProc0() |
| 143 |
{ |
| 144 |
if (bulk->parallel_rank() == 0) |
| 145 |
{ |
| 146 |
particle = bulk->declare_element(1, stk::mesh::ConstPartVector{particle_part}); |
| 147 |
node1 = bulk->declare_node(1, stk::mesh::ConstPartVector{node_part}); |
| 148 |
bulk->declare_relation(particle,node1,0); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
void createParts() |
| 153 |
{ |
| 154 |
node_part = &meta->get_topology_root_part(stk::topology::NODE); |
| 155 |
particle_part = &meta->get_topology_root_part(stk::topology::PARTICLE); |
| 156 |
beam_part = &meta->get_topology_root_part(stk::topology::BEAM_2); |
| 157 |
} |
| 158 |
|
| 159 |
void createBeamOnProc1() |
| 160 |
{ |
| 161 |
if (bulk->parallel_rank() == 1) |
| 162 |
createBeam(); |
| 163 |
} |
| 164 |
|
| 165 |
void declareBeamRelationsToNodes() |
| 166 |
{ |
| 167 |
node1 = bulk->get_entity(stk::topology::NODE_RANK,1); |
| 168 |
node2 = bulk->declare_node(2, stk::mesh::ConstPartVector{node_part}); |
| 169 |
bulk->declare_relation(beam,node1,0); |
| 170 |
bulk->declare_relation(beam,node2,1); |
| 171 |
} |
| 172 |
|
| 173 |
void createBeam() |
| 174 |
{ |
| 175 |
beam = bulk->declare_element(2, stk::mesh::ConstPartVector{beam_part}); |
| 176 |
declareBeamRelationsToNodes(); |
| 177 |
} |
| 178 |
|
| 179 |
void addNode1Sharing() |
| 180 |
{ |
| 181 |
addNode1SharingOnProc0(); |
| 182 |
addNode1SharingOnProc1(); |
| 183 |
} |
| 184 |
|
| 185 |
void addNode1SharingOnProc1() |
| 186 |
{ |
| 187 |
if (bulk->parallel_rank() == 1) |
| 188 |
{ |
| 189 |
node1 = bulk->get_entity(stk::topology::NODE_RANK,1); |
| 190 |
bulk->add_node_sharing(node1,0); |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
void addNode1SharingOnProc0() |
| 195 |
{ |
| 196 |
if (bulk->parallel_rank() == 0) |
| 197 |
{ |
| 198 |
bulk->add_node_sharing(node1,1); |
| 199 |
} |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
void destroyBeam() |
| 204 |
{ |
| 205 |
EXPECT_TRUE(bulk->is_valid(beam)); |
| 206 |
EXPECT_TRUE(bulk->destroy_entity(beam)); |
| 207 |
EXPECT_FALSE(bulk->is_valid(beam)); |
| 208 |
} |
| 209 |
|
| 210 |
stk::mesh::MetaData* meta = nullptr; |
| 211 |
std::shared_ptr<stk::mesh::BulkData> bulk; |
| 212 |
stk::mesh::Part * node_part; |
| 213 |
stk::mesh::Part * beam_part; |
| 214 |
stk::mesh::Part * particle_part; |
| 215 |
stk::mesh::Entity beam; |
| 216 |
stk::mesh::Entity particle; |
| 217 |
stk::mesh::Entity node1; |
| 218 |
stk::mesh::Entity node2; |
| 219 |
|
| 220 |
}; |
| 221 |
|
| 222 |
TEST_F(ParticleCustomGhostTester, KeepCustomGhostAfterLossOfSharing_ticket_14261) |
| 223 |
{ |
| 224 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) == 2) |
| 225 |
{ |
| 226 |
initialize(MPI_COMM_WORLD,stk::mesh::BulkData::NO_AUTO_AURA); |
| 227 |
createParticleOnProc0AndGhostToProc1(); |
| 228 |
createBeamOnProc1AndUpdateSharingOnProc0(); |
| 229 |
destroyBeamOnProc1AndVerifyParticleIsStillOnProc1(); |
| 230 |
} |
| 231 |
} |
| 232 |
|