| 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, EXPECT_TRUE, etc |
| 36 |
#include <stk_util/parallel/Parallel.hpp> |
| 37 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 38 |
#include "stk_mesh/base/Types.hpp" // for PartVector, EntityId, etc |
| 39 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 40 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData |
| 41 |
#include <stk_mesh/base/GetEntities.hpp> |
| 42 |
#include <stk_mesh/base/ForEachEntity.hpp> |
| 43 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 44 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 45 |
#include "stk_mesh/base/SkinBoundary.hpp" |
| 46 |
#include "stk_mesh/base/CreateEdges.hpp" |
| 47 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 48 |
#include "stk_io/FillMesh.hpp" |
| 49 |
#include "stk_mesh/base/MeshBuilder.hpp" |
| 50 |
#include "stk_unit_test_utils/BuildMesh.hpp" |
| 51 |
#include "UnitTestTextMeshFixture.hpp" |
| 52 |
|
| 53 |
namespace |
| 54 |
{ |
| 55 |
|
| 56 |
void verify_shared_nodes_ownership(const stk::mesh::BulkData& bulk, int expectedOwnerProc) |
| 57 |
{ |
| 58 |
stk::mesh::for_each_entity_run(bulk, stk::topology::NODE_RANK, bulk.mesh_meta_data().globally_shared_part(), |
| 59 |
[&expectedOwnerProc](const stk::mesh::BulkData& mesh, stk::mesh::Entity entity) |
| 60 |
{ |
| 61 |
EXPECT_EQ(expectedOwnerProc, mesh.parallel_owner_rank(entity)); |
| 62 |
}); |
| 63 |
} |
| 64 |
|
| 65 |
void ceo_shared_nodes(stk::mesh::BulkData& bulk) |
| 66 |
{ |
| 67 |
stk::mesh::EntityProcVec entityProcs; |
| 68 |
const int currentOwnerProc = 0; |
| 69 |
const int newOwnerProc = 1; |
| 70 |
if (bulk.parallel_rank() == 0) { |
| 71 |
stk::mesh::for_each_entity_run(bulk, stk::topology::NODE_RANK, bulk.mesh_meta_data().globally_shared_part(), |
| 72 |
[¤tOwnerProc, &newOwnerProc, &entityProcs](const stk::mesh::BulkData& mesh, stk::mesh::Entity entity) |
| 73 |
{ |
| 74 |
EXPECT_EQ(currentOwnerProc, mesh.parallel_owner_rank(entity)); |
| 75 |
entityProcs.emplace_back(entity, newOwnerProc); |
| 76 |
}); |
| 77 |
} |
| 78 |
|
| 79 |
bulk.change_entity_owner(entityProcs); |
| 80 |
} |
| 81 |
|
| 82 |
class TestCEONodesAura2d : public TestTextMeshAura2d |
| 83 |
{ |
| 84 |
public: |
| 85 |
TestCEONodesAura2d() {} |
| 86 |
}; |
| 87 |
|
| 88 |
TEST_F(TestCEONodesAura2d, quadSharedNodes) |
| 89 |
{ |
| 90 |
if (get_parallel_size() != 2) { GTEST_SKIP(); } |
| 91 |
|
| 92 |
std::string meshDesc = "0, 1, QUAD_4_2D, 1,2,5,4\n" |
| 93 |
"0, 2, QUAD_4_2D, 2,3,6,5\n" |
| 94 |
"1, 3, QUAD_4_2D, 4,5,8,7\n" |
| 95 |
"1, 4, QUAD_4_2D, 5,6,9,8\n"; |
| 96 |
|
| 97 |
setup_text_mesh(meshDesc); |
| 98 |
|
| 99 |
stk::mesh::create_all_sides(get_bulk(), get_meta().universal_part()); |
| 100 |
|
| 101 |
int ownerProc = 0; |
| 102 |
verify_shared_nodes_ownership(get_bulk(), ownerProc); |
| 103 |
|
| 104 |
ceo_shared_nodes(get_bulk()); |
| 105 |
|
| 106 |
ownerProc = 1; |
| 107 |
verify_shared_nodes_ownership(get_bulk(), ownerProc); |
| 108 |
} |
| 109 |
|
| 110 |
class TestCEONodesAura : public TestTextMeshAura |
| 111 |
{ |
| 112 |
public: |
| 113 |
TestCEONodesAura() {} |
| 114 |
}; |
| 115 |
|
| 116 |
TEST_F(TestCEONodesAura, hexSharedNodes) |
| 117 |
{ |
| 118 |
if (get_parallel_size() != 2) { GTEST_SKIP(); } |
| 119 |
|
| 120 |
std::string meshDesc = "generated:1x1x2"; |
| 121 |
|
| 122 |
stk::io::fill_mesh(meshDesc, get_bulk()); |
| 123 |
|
| 124 |
stk::mesh::create_edges(get_bulk()); |
| 125 |
|
| 126 |
int ownerProc = 0; |
| 127 |
verify_shared_nodes_ownership(get_bulk(), ownerProc); |
| 128 |
|
| 129 |
ceo_shared_nodes(get_bulk()); |
| 130 |
|
| 131 |
ownerProc = 1; |
| 132 |
verify_shared_nodes_ownership(get_bulk(), ownerProc); |
| 133 |
} |
| 134 |
|
| 135 |
} // empty namespace |
| 136 |
|