| 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_unit_test_utils/MeshFixture.hpp> |
| 37 |
#include <stk_mesh/base/BulkData.hpp> |
| 38 |
#include <stk_mesh/base/Entity.hpp> |
| 39 |
#include <stk_mesh/base/MetaData.hpp> |
| 40 |
#include <stk_mesh/base/Types.hpp> |
| 41 |
#include <stk_mesh/base/Comm.hpp> |
| 42 |
#include <stk_mesh/baseImpl/Visitors.hpp> |
| 43 |
#include <stk_topology/topology.hpp> |
| 44 |
|
| 45 |
namespace |
| 46 |
{ |
| 47 |
|
| 48 |
using EntitySet = std::set<stk::mesh::Entity>; |
| 49 |
|
| 50 |
class VisitAura : public stk::unit_test_util::MeshFixture |
| 51 |
{ |
| 52 |
public: |
| 53 |
VisitAura() |
| 54 |
: MeshFixture(3, {"node","edge","face","elem","constraint"}), |
| 55 |
thisProc(stk::parallel_machine_rank(MPI_COMM_WORLD)) {} |
| 56 |
|
| 57 |
void check_for_expected_entities(const EntitySet& entities, |
| 58 |
stk::mesh::EntityRank rank, |
| 59 |
const stk::mesh::EntityIdVector& expected) |
| 60 |
{ |
| 61 |
for(stk::mesh::EntityId id : expected) { |
| 62 |
stk::mesh::Entity expectedEntity = get_bulk().get_entity(rank, id); |
| 63 |
EXPECT_TRUE(get_bulk().is_valid(expectedEntity)); |
| 64 |
EXPECT_TRUE(entities.find(expectedEntity) != entities.end())<<"Failed to find "<<get_bulk().entity_key(expectedEntity); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
EntitySet visit_aura_closure(stk::mesh::EntityRank rank, stk::mesh::EntityId id) |
| 69 |
{ |
| 70 |
stk::mesh::Entity entity = get_bulk().get_entity(rank, id); |
| 71 |
EXPECT_TRUE(get_bulk().is_valid(entity)); |
| 72 |
|
| 73 |
stk::mesh::impl::OnlyVisitGhostsOnce onlyVisitGhostsOnce(get_bulk()); |
| 74 |
EntitySet entities; |
| 75 |
stk::mesh::impl::StoreInSet<EntitySet> storeInSet(entities); |
| 76 |
stk::mesh::impl::VisitAuraClosureGeneral(get_bulk(), entity, storeInSet, onlyVisitGhostsOnce); |
| 77 |
return entities; |
| 78 |
} |
| 79 |
|
| 80 |
stk::mesh::Entity create_constraint_entity(stk::mesh::EntityId constraintId, |
| 81 |
const stk::mesh::EntityVector& connectedEntities) |
| 82 |
{ |
| 83 |
get_bulk().modification_begin(); |
| 84 |
stk::mesh::Entity constraintEntity = get_bulk().declare_entity(stk::topology::CONSTRAINT_RANK, constraintId, stk::mesh::ConstPartVector{}); |
| 85 |
for(unsigned i=0; i<connectedEntities.size(); ++i) { |
| 86 |
get_bulk().declare_relation(constraintEntity, connectedEntities[i], i); |
| 87 |
} |
| 88 |
get_bulk().modification_end(); |
| 89 |
return constraintEntity; |
| 90 |
} |
| 91 |
|
| 92 |
const int thisProc; |
| 93 |
}; |
| 94 |
|
| 95 |
static constexpr int numProcs = 2; |
| 96 |
|
| 97 |
TEST_F(VisitAura, auraClosureOfOwnedNode_isEmpty) |
| 98 |
{ |
| 99 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 100 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 101 |
|
| 102 |
stk::mesh::EntityId ownedNodeId[numProcs] = {1, 12}; |
| 103 |
|
| 104 |
EntitySet entities = visit_aura_closure(stk::topology::NODE_RANK, ownedNodeId[thisProc]); |
| 105 |
|
| 106 |
EXPECT_EQ(0u, entities.size()); |
| 107 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, {}); |
| 108 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, {}); |
| 109 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, {}); |
| 110 |
} |
| 111 |
|
| 112 |
TEST_F(VisitAura, auraClosureOfSharedNode) |
| 113 |
{ |
| 114 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 115 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 116 |
|
| 117 |
stk::mesh::EntityId sharedNodeId[numProcs] = {5, 5}; |
| 118 |
|
| 119 |
EntitySet entities = visit_aura_closure(stk::topology::NODE_RANK, sharedNodeId[thisProc]); |
| 120 |
|
| 121 |
stk::mesh::EntityIdVector expectedElems[numProcs] = {{2}, {1}}; |
| 122 |
stk::mesh::EntityIdVector expectedFaces[numProcs] = {{21,22,23,24,26}, {11,12,13,14,15}}; |
| 123 |
stk::mesh::EntityIdVector expectedNodes[numProcs] = {{9,10,11,12}, {1,2,3,4}}; |
| 124 |
|
| 125 |
EXPECT_EQ(10u, entities.size()); |
| 126 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, expectedElems[thisProc]); |
| 127 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, expectedFaces[thisProc]); |
| 128 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, expectedNodes[thisProc]); |
| 129 |
} |
| 130 |
|
| 131 |
TEST_F(VisitAura, auraClosureOfAuraElem) |
| 132 |
{ |
| 133 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 134 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 135 |
|
| 136 |
stk::mesh::EntityId recvAuraElemId[numProcs] = {2, 1}; |
| 137 |
|
| 138 |
EntitySet entities = visit_aura_closure(stk::topology::ELEM_RANK, recvAuraElemId[thisProc]); |
| 139 |
|
| 140 |
stk::mesh::EntityIdVector expectedElems[numProcs] = {{2}, {1}}; |
| 141 |
stk::mesh::EntityIdVector expectedFaces[numProcs] = {{21,22,23,24,26}, {11,12,13,14,15}}; |
| 142 |
stk::mesh::EntityIdVector expectedNodes[numProcs] = {{9,10,11,12}, {1,2,3,4}}; |
| 143 |
|
| 144 |
EXPECT_EQ(10u, entities.size()); |
| 145 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, expectedElems[thisProc]); |
| 146 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, expectedFaces[thisProc]); |
| 147 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, expectedNodes[thisProc]); |
| 148 |
} |
| 149 |
|
| 150 |
TEST_F(VisitAura, auraClosureOfAuraFace) |
| 151 |
{ |
| 152 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 153 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 154 |
|
| 155 |
stk::mesh::EntityId recvAuraFaceId[numProcs] = {22, 13}; |
| 156 |
|
| 157 |
EntitySet entities = visit_aura_closure(stk::topology::FACE_RANK, recvAuraFaceId[thisProc]); |
| 158 |
|
| 159 |
stk::mesh::EntityIdVector expectedElems[numProcs] = {{2}, {1}}; |
| 160 |
stk::mesh::EntityIdVector expectedFaces[numProcs] = {{21,22,23,24,26}, {11,12,13,14,15}}; |
| 161 |
stk::mesh::EntityIdVector expectedNodes[numProcs] = {{9,10,11,12}, {1,2,3,4}}; |
| 162 |
|
| 163 |
EXPECT_EQ(10u, entities.size()); |
| 164 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, expectedElems[thisProc]); |
| 165 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, expectedFaces[thisProc]); |
| 166 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, expectedNodes[thisProc]); |
| 167 |
} |
| 168 |
|
| 169 |
TEST_F(VisitAura, auraClosureOfOwnedConstraintWithElem) |
| 170 |
{ |
| 171 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 172 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 173 |
stk::mesh::EntityId constraintIds[numProcs] = {1, 2}; |
| 174 |
stk::mesh::EntityId elemIds[numProcs] = {1, 2}; |
| 175 |
stk::mesh::Entity ownedElem = get_bulk().get_entity(stk::topology::ELEM_RANK, elemIds[thisProc]); |
| 176 |
create_constraint_entity(constraintIds[thisProc], {ownedElem}); |
| 177 |
EntitySet entities = visit_aura_closure(stk::topology::CONSTRAINT_RANK, constraintIds[thisProc]); |
| 178 |
|
| 179 |
stk::mesh::EntityIdVector expectedConstraints[numProcs] = {{2}, {1}}; |
| 180 |
stk::mesh::EntityIdVector expectedElems[numProcs] = {{2}, {1}}; |
| 181 |
stk::mesh::EntityIdVector expectedFaces[numProcs] = {{21,22,23,24,26}, {11,12,13,14,15}}; |
| 182 |
stk::mesh::EntityIdVector expectedNodes[numProcs] = {{9,10,11,12}, {1,2,3,4}}; |
| 183 |
|
| 184 |
EXPECT_EQ(11u, entities.size()); |
| 185 |
check_for_expected_entities(entities, stk::topology::CONSTRAINT_RANK, expectedConstraints[thisProc]); |
| 186 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, expectedElems[thisProc]); |
| 187 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, expectedFaces[thisProc]); |
| 188 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, expectedNodes[thisProc]); |
| 189 |
} |
| 190 |
|
| 191 |
TEST_F(VisitAura, auraClosureOfOwnedConstraintWithNodes) |
| 192 |
{ |
| 193 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != numProcs) { return; } |
| 194 |
setup_mesh("generated:1x1x2|sideset:xXyYzZ", stk::mesh::BulkData::AUTO_AURA); |
| 195 |
stk::mesh::EntityId constraintIds[numProcs] = {1, 2}; |
| 196 |
stk::mesh::EntityId ownedNodeIds[numProcs] = {1, 12}; |
| 197 |
stk::mesh::EntityId sharedNodeIds[numProcs] = {5, 5}; |
| 198 |
stk::mesh::Entity ownedNode = get_bulk().get_entity(stk::topology::NODE_RANK, ownedNodeIds[thisProc]); |
| 199 |
stk::mesh::Entity sharedNode = get_bulk().get_entity(stk::topology::NODE_RANK, sharedNodeIds[thisProc]); |
| 200 |
create_constraint_entity(constraintIds[thisProc], {ownedNode, sharedNode}); |
| 201 |
EntitySet entities = visit_aura_closure(stk::topology::CONSTRAINT_RANK, constraintIds[thisProc]); |
| 202 |
|
| 203 |
stk::mesh::EntityIdVector expectedConstraints[numProcs] = {{2}, {1}}; |
| 204 |
stk::mesh::EntityIdVector expectedElems[numProcs] = {{2}, {1}}; |
| 205 |
stk::mesh::EntityIdVector expectedFaces[numProcs] = {{21,22,23,24,26}, {11,12,13,14,15}}; |
| 206 |
stk::mesh::EntityIdVector expectedNodes[numProcs] = {{9,10,11,12}, {1,2,3,4}}; |
| 207 |
|
| 208 |
EXPECT_EQ(11u, entities.size()); |
| 209 |
check_for_expected_entities(entities, stk::topology::CONSTRAINT_RANK, expectedConstraints[thisProc]); |
| 210 |
check_for_expected_entities(entities, stk::topology::ELEM_RANK, expectedElems[thisProc]); |
| 211 |
check_for_expected_entities(entities, stk::topology::FACE_RANK, expectedFaces[thisProc]); |
| 212 |
check_for_expected_entities(entities, stk::topology::NODE_RANK, expectedNodes[thisProc]); |
| 213 |
} |
| 214 |
|
| 215 |
} // empty namespace |
| 216 |
|