| 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 "mpi.h" // for MPI_Barrier, MPI_COMM_WORLD, etc |
| 36 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 37 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 38 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData |
| 39 |
#include "stk_mesh/base/Part.hpp" // for Part |
| 40 |
#include "stk_mesh/base/Types.hpp" // for PartVector |
| 41 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 42 |
#include "stk_unit_test_utils/stk_mesh_fixtures/RingFixture.hpp" // for RingFixture |
| 43 |
#include <gtest/gtest.h> // for ASSERT_TRUE, AssertHelper, etc |
| 44 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData, etc |
| 45 |
#include <stk_unit_test_utils/BulkDataTester.hpp> |
| 46 |
#include <stk_util/parallel/Parallel.hpp> // for parallel_machine_rank, etc |
| 47 |
#include <vector> // for vector |
| 48 |
namespace stk { namespace mesh { class Selector; } } |
| 49 |
|
| 50 |
using stk::mesh::Part; |
| 51 |
using stk::mesh::MetaData; |
| 52 |
using stk::mesh::BulkData; |
| 53 |
using stk::mesh::Entity; |
| 54 |
using stk::mesh::Selector; |
| 55 |
using stk::mesh::PartVector; |
| 56 |
using stk::mesh::fixtures::RingFixture; |
| 57 |
|
| 58 |
//---------------------------------------------------------------------- |
| 59 |
|
| 60 |
TEST(UnitTestingOfBulkData, testChangeParts_ringmesh) |
| 61 |
{ |
| 62 |
// This unit test tests part operations and verifies operations |
| 63 |
// by looking at bucket supersets. |
| 64 |
|
| 65 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 66 |
MPI_Barrier( pm ); |
| 67 |
|
| 68 |
const unsigned nPerProc = 10; |
| 69 |
const int p_rank = stk::parallel_machine_rank( pm ); |
| 70 |
const int p_size = stk::parallel_machine_size( pm ); |
| 71 |
const unsigned nLocalNode = nPerProc + ( 1 < p_size ? 1 : 0 ); |
| 72 |
const unsigned nLocalElement = nPerProc ; |
| 73 |
|
| 74 |
// Create the ring mesh |
| 75 |
|
| 76 |
RingFixture ring_mesh( pm , nPerProc , true /* generate parts */, stk::mesh::BulkData::NO_AUTO_AURA); |
| 77 |
ring_mesh.m_meta_data.commit(); |
| 78 |
BulkData& bulk = ring_mesh.m_bulk_data; |
| 79 |
|
| 80 |
bulk.modification_begin(); |
| 81 |
ring_mesh.generate_mesh( ); |
| 82 |
ASSERT_TRUE(bulk.modification_end()); |
| 83 |
|
| 84 |
ring_mesh.fixup_node_ownership(); |
| 85 |
|
| 86 |
Part & part_owns = ring_mesh.m_meta_data.locally_owned_part(); |
| 87 |
Part & part_univ = ring_mesh.m_meta_data.universal_part(); |
| 88 |
|
| 89 |
// Check that local elements are in the expected parts. Note that the |
| 90 |
// RingMesh puts each element in its own part. |
| 91 |
for ( unsigned i = 0 ; i < nLocalElement ; ++i ) { |
| 92 |
const unsigned n = i + nPerProc * p_rank ; |
| 93 |
Entity const element = bulk.get_entity( stk::topology::ELEMENT_RANK /*entity rank*/, |
| 94 |
ring_mesh.m_element_ids[n] ); |
| 95 |
ASSERT_TRUE( bulk.is_valid(element) ); |
| 96 |
ASSERT_TRUE( bulk.bucket(element).member( part_univ ) ); |
| 97 |
ASSERT_TRUE( bulk.bucket(element).member( part_owns ) ); |
| 98 |
ASSERT_TRUE( bulk.bucket(element).member( * ring_mesh.m_element_parts[ n % ring_mesh.m_element_parts.size() ] ) ); |
| 99 |
} |
| 100 |
|
| 101 |
// Check that local nodes are in the expected parts. Note that the relations |
| 102 |
// that nodes have to elements should cause induced membership of the node |
| 103 |
// in the parts of both elements it touches. |
| 104 |
for ( unsigned i = 0 ; i < nLocalNode ; ++i ) { |
| 105 |
const unsigned n = ( i + nPerProc * p_rank ) % ring_mesh.m_node_ids.size(); |
| 106 |
const unsigned e0 = n ; |
| 107 |
const unsigned e1 = ( n + ring_mesh.m_element_ids.size() - 1 ) % ring_mesh.m_element_ids.size(); |
| 108 |
const unsigned ns = ring_mesh.m_element_parts.size(); |
| 109 |
const unsigned n0 = e0 % ns ; |
| 110 |
const unsigned n1 = e1 % ns ; |
| 111 |
Part * const epart_0 = ring_mesh.m_element_parts[ n0 < n1 ? n0 : n1 ]; |
| 112 |
Part * const epart_1 = ring_mesh.m_element_parts[ n0 < n1 ? n1 : n0 ]; |
| 113 |
|
| 114 |
Entity const node = bulk.get_entity( stk::topology::NODE_RANK , ring_mesh.m_node_ids[n] ); |
| 115 |
ASSERT_TRUE( bulk.is_valid(node) ); |
| 116 |
if ( bulk.parallel_owner_rank(node) == p_rank ) { |
| 117 |
ASSERT_TRUE( bulk.bucket(node).member( part_univ ) ); |
| 118 |
ASSERT_TRUE( bulk.bucket(node).member( part_owns ) ); |
| 119 |
ASSERT_TRUE( bulk.bucket(node).member( *epart_0 ) ); |
| 120 |
ASSERT_TRUE( bulk.bucket(node).member( *epart_1 ) ); |
| 121 |
} |
| 122 |
else { |
| 123 |
ASSERT_TRUE( bulk.bucket(node).member( part_univ ) ); |
| 124 |
ASSERT_TRUE( ! bulk.bucket(node).member( part_owns ) ); |
| 125 |
ASSERT_TRUE( bulk.bucket(node).member( * epart_0 ) ); |
| 126 |
ASSERT_TRUE( bulk.bucket(node).member( * epart_1 ) ); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
bulk.modification_begin(); |
| 131 |
|
| 132 |
// On rank 0, change all locally owned elements to the extra-part then check |
| 133 |
// for correct part membership |
| 134 |
if ( 0 == p_rank ) { |
| 135 |
for ( unsigned i = 0 ; i < nLocalElement ; ++i ) { |
| 136 |
const unsigned n = i + nPerProc * p_rank ; |
| 137 |
|
| 138 |
PartVector add(1); add[0] = & ring_mesh.m_element_part_extra ; |
| 139 |
PartVector rem(1); rem[0] = ring_mesh.m_element_parts[ n % ring_mesh.m_element_parts.size() ]; |
| 140 |
|
| 141 |
Entity const element = bulk.get_entity( stk::topology::ELEMENT_RANK , ring_mesh.m_element_ids[n] ); |
| 142 |
bulk.change_entity_parts( element , add , rem ); |
| 143 |
ASSERT_TRUE( bulk.bucket(element).member( part_univ ) ); |
| 144 |
ASSERT_TRUE( bulk.bucket(element).member( part_owns ) ); |
| 145 |
ASSERT_TRUE( bulk.bucket(element).member(ring_mesh.m_element_part_extra ) ); |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
bulk.modification_end(); |
| 150 |
|
| 151 |
// Modification end has been called, check that the part changes made |
| 152 |
// in the previous step are reflected across the other procs. |
| 153 |
for ( unsigned i = 0 ; i < nLocalNode ; ++i ) { |
| 154 |
const unsigned n = ( i + nPerProc * p_rank ) % ring_mesh.m_node_ids.size(); |
| 155 |
const unsigned e0 = n ; |
| 156 |
const unsigned e1 = ( n + ring_mesh.m_element_ids.size() - 1 ) % ring_mesh.m_element_ids.size(); |
| 157 |
const unsigned ns = ring_mesh.m_element_parts.size(); |
| 158 |
const unsigned n0 = e0 % ns ; |
| 159 |
const unsigned n1 = e1 % ns ; |
| 160 |
Part * ep_0 = e0 < nLocalElement ? & ring_mesh.m_element_part_extra : ring_mesh.m_element_parts[n0] ; |
| 161 |
Part * ep_1 = e1 < nLocalElement ? & ring_mesh.m_element_part_extra : ring_mesh.m_element_parts[n1] ; |
| 162 |
|
| 163 |
Part * epart_0 = ep_0->mesh_meta_data_ordinal() < ep_1->mesh_meta_data_ordinal() ? ep_0 : ep_1 ; |
| 164 |
Part * epart_1 = ep_0->mesh_meta_data_ordinal() < ep_1->mesh_meta_data_ordinal() ? ep_1 : ep_0 ; |
| 165 |
|
| 166 |
Entity const node = bulk.get_entity( stk::topology::NODE_RANK , ring_mesh.m_node_ids[n] ); |
| 167 |
ASSERT_TRUE( bulk.is_valid(node) ); |
| 168 |
if ( bulk.parallel_owner_rank(node) == p_rank ) { |
| 169 |
ASSERT_TRUE( bulk.bucket(node).member( part_owns ) ); |
| 170 |
} |
| 171 |
else { |
| 172 |
ASSERT_TRUE( ! bulk.bucket(node).member( part_owns ) ); |
| 173 |
} |
| 174 |
|
| 175 |
ASSERT_TRUE( bulk.bucket(node).member( part_univ ) ); |
| 176 |
ASSERT_TRUE( bulk.bucket(node).member( *epart_0 ) ); |
| 177 |
ASSERT_TRUE( bulk.bucket(node).member( *epart_1 ) ); |
| 178 |
} |
| 179 |
} |