| 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_COMM_WORLD, etc |
| 36 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket, Bucket::iterator |
| 37 |
#include "stk_mesh/base/BulkData.hpp" // for BulkData, etc |
| 38 |
#include "stk_mesh/base/MeshBuilder.hpp" |
| 39 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 40 |
#include "stk_mesh/base/EntityCommListInfo.hpp" |
| 41 |
#include "stk_mesh/base/EntityKey.hpp" // for EntityKey, operator<< |
| 42 |
#include "stk_mesh/base/EntityLess.hpp" // for EntityLess |
| 43 |
#include "stk_mesh/base/Field.hpp" // for Field |
| 44 |
#include "stk_mesh/base/FieldBase.hpp" // for field_data |
| 45 |
#include "stk_mesh/base/Ghosting.hpp" // for Ghosting, operator<< |
| 46 |
#include "stk_mesh/base/Types.hpp" // for EntityProc, PartVector, etc |
| 47 |
#include "stk_topology/topology.hpp" // for topology::num_nodes |
| 48 |
#include "stk_unit_test_utils/stk_mesh_fixtures/BoxFixture.hpp" // for BoxFixture |
| 49 |
#include "stk_unit_test_utils/stk_mesh_fixtures/FixtureNodeSharing.hpp" |
| 50 |
#include "stk_unit_test_utils/stk_mesh_fixtures/HexFixture.hpp" // for HexFixture, etc |
| 51 |
#include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture |
| 52 |
#include "stk_util/parallel/CommSparse.hpp" |
| 53 |
#include "stk_util/parallel/Parallel.hpp" // for parallel_machine_size, etc |
| 54 |
#include "stk_util/parallel/ParallelComm.hpp" // for CommBuffer |
| 55 |
#include <gtest/gtest.h> // for AssertHelper, ASSERT_TRUE, etc |
| 56 |
#include <iosfwd> // for ostringstream, ostream |
| 57 |
#include <set> // for set, etc |
| 58 |
#include <stddef.h> // for size_t, NULL |
| 59 |
#include <stdexcept> // for logic_error, runtime_error |
| 60 |
#include <stk_mesh/base/EntityCommDatabase.hpp> // for pack_entity_info, etc |
| 61 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field_on_mesh |
| 62 |
#include <stk_unit_test_utils/BulkDataTester.hpp> |
| 63 |
#include <string> // for string |
| 64 |
#include <utility> // for pair, make_pair |
| 65 |
#include <vector> // for vector, etc |
| 66 |
namespace stk { namespace mesh { class Part; } } |
| 67 |
|
| 68 |
|
| 69 |
using namespace stk::mesh; |
| 70 |
|
| 71 |
// UnitTestBulkData_new is the beginnings of a refactoring of the bulk |
| 72 |
// data unit test. It relies on a customized BoxFixture to rapidly |
| 73 |
// create a mesh for testing. |
| 74 |
|
| 75 |
namespace { |
| 76 |
|
| 77 |
/** |
| 78 |
* The customized box fixture used in this file for testing. This fixture |
| 79 |
* is similar to the BoxFixture it inherits from, with the only difference |
| 80 |
* being the extra parts that this fixture declares for testing purposes. |
| 81 |
*/ |
| 82 |
struct TestBoxFixture : public fixtures::BoxFixture |
| 83 |
{ |
| 84 |
TestBoxFixture(stk::ParallelMachine pm = MPI_COMM_WORLD) |
| 85 |
: BoxFixture(pm, stk::mesh::BulkData::AUTO_AURA), |
| 86 |
m_test_part ( m_fem_meta.declare_part ( "Test Part" ) ), |
| 87 |
m_cell_part ( m_fem_meta.declare_part ( "Cell list" , stk::topology::ELEM_RANK ) ), |
| 88 |
m_part_A_0 ( m_fem_meta.declare_part ( "Part A 0", stk::topology::NODE_RANK ) ), |
| 89 |
m_part_A_1 ( m_fem_meta.declare_part ( "Part A 1", stk::topology::EDGE_RANK ) ), |
| 90 |
m_part_A_2 ( m_fem_meta.declare_part ( "Part A 2", stk::topology::FACE_RANK ) ), |
| 91 |
m_part_A_3 ( m_fem_meta.declare_part ( "Part A 3", stk::topology::ELEM_RANK ) ), |
| 92 |
m_part_A_superset ( m_fem_meta.declare_part ( "Part A superset" ) ), |
| 93 |
m_part_B_0 ( m_fem_meta.declare_part ( "Part B 0", stk::topology::NODE_RANK ) ), |
| 94 |
m_part_B_1 ( m_fem_meta.declare_part ( "Part B 1", stk::topology::EDGE_RANK ) ), |
| 95 |
m_part_B_2 ( m_fem_meta.declare_part ( "Part B 2", stk::topology::FACE_RANK ) ), |
| 96 |
m_part_B_3 ( m_fem_meta.declare_part ( "Part B 3", stk::topology::ELEM_RANK ) ), |
| 97 |
m_part_B_superset ( m_fem_meta.declare_part ( "Part B superset" ) ) |
| 98 |
{ |
| 99 |
m_fem_meta.declare_part_subset ( m_part_A_superset , m_part_A_0 ); |
| 100 |
m_fem_meta.declare_part_subset ( m_part_A_superset , m_part_A_1 ); |
| 101 |
m_fem_meta.declare_part_subset ( m_part_A_superset , m_part_A_2 ); |
| 102 |
m_fem_meta.declare_part_subset ( m_part_A_superset , m_part_A_3 ); |
| 103 |
|
| 104 |
m_fem_meta.declare_part_subset ( m_part_B_superset , m_part_B_0 ); |
| 105 |
m_fem_meta.declare_part_subset ( m_part_B_superset , m_part_B_1 ); |
| 106 |
m_fem_meta.declare_part_subset ( m_part_B_superset , m_part_B_2 ); |
| 107 |
m_fem_meta.declare_part_subset ( m_part_B_superset , m_part_B_3 ); |
| 108 |
|
| 109 |
// None of the tests currently need to make any addtional changes |
| 110 |
// to MetaData; if this changes, the line below will have to be |
| 111 |
// removed. |
| 112 |
m_fem_meta.commit(); |
| 113 |
} |
| 114 |
|
| 115 |
Part & m_test_part; // A simple part |
| 116 |
Part & m_cell_part; // A part to put cells in |
| 117 |
|
| 118 |
Part & m_part_A_0; |
| 119 |
Part & m_part_A_1; |
| 120 |
Part & m_part_A_2; |
| 121 |
Part & m_part_A_3; |
| 122 |
|
| 123 |
Part & m_part_A_superset; |
| 124 |
|
| 125 |
Part & m_part_B_0; |
| 126 |
Part & m_part_B_1; |
| 127 |
Part & m_part_B_2; |
| 128 |
Part & m_part_B_3; |
| 129 |
|
| 130 |
Part & m_part_B_superset; |
| 131 |
}; |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
TEST ( UnitTestBulkData_new , verifyAssertOwnerDeletedEntity ) |
| 136 |
{ |
| 137 |
TestBoxFixture fixture; |
| 138 |
|
| 139 |
BulkData &bulk = fixture.bulk_data(); |
| 140 |
Part &new_part = fixture.m_test_part; |
| 141 |
PartVector add_part; |
| 142 |
add_part.push_back ( &new_part ); |
| 143 |
|
| 144 |
const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } }; |
| 145 |
int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 146 |
|
| 147 |
bulk.modification_begin(); |
| 148 |
fixture.generate_boxes( root_box, local_box ); |
| 149 |
ASSERT_TRUE(bulk.modification_end()); |
| 150 |
|
| 151 |
// Find a cell owned by this process |
| 152 |
Entity cell_to_delete = Entity(); |
| 153 |
BucketVector::const_iterator cur_bucket = bulk.buckets(stk::topology::ELEM_RANK).begin(); |
| 154 |
while ( cur_bucket != bulk.buckets(stk::topology::ELEM_RANK).end() ) |
| 155 |
{ |
| 156 |
Bucket::iterator cur_entity = (*cur_bucket)->begin(); |
| 157 |
while ( cur_entity != (*cur_bucket)->end() ) |
| 158 |
{ |
| 159 |
if ( bulk.parallel_owner_rank(*cur_entity) == fixture.comm_rank() ) |
| 160 |
{ |
| 161 |
cell_to_delete = *cur_entity; |
| 162 |
break; |
| 163 |
} |
| 164 |
++cur_entity; |
| 165 |
} |
| 166 |
++cur_bucket; |
| 167 |
} |
| 168 |
|
| 169 |
ASSERT_TRUE ( bulk.is_valid(cell_to_delete) ); |
| 170 |
bulk.modification_begin(); |
| 171 |
bulk.destroy_entity ( cell_to_delete ); |
| 172 |
bulk.modification_end(); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
TEST ( UnitTestBulkData_new , verifyDetectsBadKey ) |
| 177 |
{ |
| 178 |
TestBoxFixture fixture; |
| 179 |
|
| 180 |
BulkData &bulk = fixture.bulk_data(); |
| 181 |
Part &new_part = fixture.m_test_part; |
| 182 |
PartVector add_part, empty_vector; |
| 183 |
add_part.push_back ( &new_part ); |
| 184 |
|
| 185 |
EntityKey bad_key1 ( static_cast<EntityRank>(45) , 1 ); // Bad entity rank |
| 186 |
EntityKey bad_key2 ( stk::topology::EDGE_RANK , 0 ); // Bad id |
| 187 |
|
| 188 |
ASSERT_THROW ( bulk.declare_entity(bad_key1.rank(), |
| 189 |
bad_key1.id(), |
| 190 |
empty_vector), |
| 191 |
std::logic_error ); |
| 192 |
ASSERT_THROW ( bulk.declare_edge(bad_key2.id(), empty_vector), |
| 193 |
std::logic_error ); |
| 194 |
} |
| 195 |
|
| 196 |
TEST ( UnitTestBulkData_new , verifyDetectsNonOwnerChange ) |
| 197 |
{ |
| 198 |
// Set up a mesh where there are shared nodes. Take one of the nodes, and |
| 199 |
// have the non-owning processes try to make a change to that node; this |
| 200 |
// should cause an exception. |
| 201 |
|
| 202 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 203 |
int p_size = stk::parallel_machine_size(pm); |
| 204 |
int p_rank = stk::parallel_machine_rank(pm); |
| 205 |
|
| 206 |
fixtures::QuadFixture fixture(pm, 1 /*nx*/, p_size /*ny*/); |
| 207 |
fixture.m_meta.commit(); |
| 208 |
fixture.generate_mesh(); |
| 209 |
BulkData & bulk = fixture.m_bulk_data; |
| 210 |
|
| 211 |
PartVector empty_vector; |
| 212 |
|
| 213 |
Entity shared_node = fixture.node(1 /*x*/, 1 /*y*/); |
| 214 |
// Assert that this node is shared |
| 215 |
if ( p_size > 1 && bulk.is_valid(shared_node) && (p_rank == 0 || p_rank == 1) ) { |
| 216 |
std::vector<int> shared_procs; |
| 217 |
bulk.comm_shared_procs(bulk.entity_key(shared_node),shared_procs); |
| 218 |
ASSERT_GE(shared_procs.size(), 1u); |
| 219 |
} |
| 220 |
|
| 221 |
bulk.modification_begin(); |
| 222 |
|
| 223 |
// Non-owners of shared_node will attempt to make a change to it; this should |
| 224 |
// cause an exception |
| 225 |
if (bulk.is_valid(shared_node) && p_rank != bulk.parallel_owner_rank(shared_node)) { |
| 226 |
ASSERT_THROW(bulk.change_entity_parts(shared_node, |
| 227 |
empty_vector, //add parts |
| 228 |
empty_vector), //rem parts |
| 229 |
std::logic_error); |
| 230 |
} |
| 231 |
|
| 232 |
bulk.modification_end(); |
| 233 |
} |
| 234 |
|
| 235 |
TEST ( UnitTestBulkData_new , verifyExplicitAddInducedPart ) |
| 236 |
{ |
| 237 |
TestBoxFixture fixture; |
| 238 |
BulkData &bulk = fixture.bulk_data (); |
| 239 |
PartVector empty_vector; |
| 240 |
PartVector cell_part_vector; |
| 241 |
|
| 242 |
bulk.modification_begin(); |
| 243 |
|
| 244 |
Entity new_cell = bulk.declare_element(fixture.comm_rank()+1 , empty_vector ); |
| 245 |
Entity new_node = bulk.declare_node(fixture.comm_rank()+1 , empty_vector ); |
| 246 |
|
| 247 |
bulk.declare_relation ( new_cell , new_node , 1 ); |
| 248 |
|
| 249 |
cell_part_vector.push_back ( &fixture.m_cell_part ); |
| 250 |
bulk.change_entity_parts ( new_cell , cell_part_vector ); |
| 251 |
bulk.change_entity_parts ( new_node , cell_part_vector ); |
| 252 |
EXPECT_TRUE(bulk.bucket(new_node).member(fixture.m_cell_part)); |
| 253 |
} |
| 254 |
|
| 255 |
TEST ( UnitTestBulkData_new , verifyDefaultPartAddition ) |
| 256 |
{ |
| 257 |
TestBoxFixture fixture; |
| 258 |
BulkData &bulk = fixture.bulk_data (); |
| 259 |
|
| 260 |
bulk.modification_begin(); |
| 261 |
Entity new_cell = bulk.declare_element(1, stk::mesh::ConstPartVector{&fixture.get_elem_part()}); |
| 262 |
unsigned cell_num_nodes = fixture.get_elem_topology().num_nodes(); |
| 263 |
for (unsigned i = 0; i < cell_num_nodes; ++i) |
| 264 |
{ |
| 265 |
Entity new_node = bulk.declare_node(i+1); |
| 266 |
bulk.declare_relation(new_cell, new_node, i); |
| 267 |
} |
| 268 |
bulk.modification_end(); |
| 269 |
|
| 270 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.fem_meta().universal_part() ) ); |
| 271 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.fem_meta().locally_owned_part() ) ); |
| 272 |
} |
| 273 |
|
| 274 |
TEST ( UnitTestBulkData_new , verifyChangePartsSerial ) |
| 275 |
{ |
| 276 |
TestBoxFixture fixture; |
| 277 |
BulkData &bulk = fixture.bulk_data (); |
| 278 |
PartVector create_parts , remove_parts , add_parts, empty_parts; |
| 279 |
|
| 280 |
create_parts.push_back ( &fixture.m_test_part ); |
| 281 |
create_parts.push_back ( &fixture.m_part_A_3 ); |
| 282 |
remove_parts.push_back ( &fixture.m_part_A_3 ); |
| 283 |
add_parts.push_back ( &fixture.m_part_B_superset ); |
| 284 |
add_parts.push_back ( &fixture.m_cell_part ); |
| 285 |
|
| 286 |
bulk.modification_begin(); |
| 287 |
Entity new_cell = bulk.declare_element(1, stk::mesh::ConstPartVector{&fixture.get_elem_part()}); |
| 288 |
unsigned cell_num_nodes = fixture.get_elem_topology().num_nodes(); |
| 289 |
for (unsigned i = 0; i < cell_num_nodes; ++i) |
| 290 |
{ |
| 291 |
Entity new_node = bulk.declare_node(i+1); |
| 292 |
bulk.declare_relation(new_cell, new_node, i); |
| 293 |
} |
| 294 |
bulk.change_entity_parts ( new_cell , create_parts , empty_parts ); |
| 295 |
bulk.modification_end(); |
| 296 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_test_part ) ); |
| 297 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_part_A_3 ) ); |
| 298 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_part_A_superset ) ); |
| 299 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_part_B_superset ) ); |
| 300 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_cell_part ) ); |
| 301 |
|
| 302 |
bulk.modification_begin(); |
| 303 |
bulk.change_entity_parts ( new_cell , add_parts , remove_parts ); |
| 304 |
bulk.modification_end(); |
| 305 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_test_part ) ); |
| 306 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_part_A_3 ) ); |
| 307 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_part_A_superset ) ); |
| 308 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_part_B_superset ) ); |
| 309 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_cell_part ) ); |
| 310 |
|
| 311 |
bulk.modification_begin(); |
| 312 |
bulk.change_entity_parts ( new_cell , empty_parts , add_parts ); |
| 313 |
bulk.modification_end(); |
| 314 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_test_part ) ); |
| 315 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_part_A_3 ) ); |
| 316 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.m_part_A_superset ) ); |
| 317 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_part_B_superset ) ); |
| 318 |
ASSERT_TRUE ( !bulk.bucket(new_cell).member ( fixture.m_cell_part ) ); |
| 319 |
|
| 320 |
//Verify still a member of default parts |
| 321 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.fem_meta().universal_part() ) ); |
| 322 |
ASSERT_TRUE ( bulk.bucket(new_cell).member ( fixture.fem_meta().locally_owned_part() ) ); |
| 323 |
} |
| 324 |
|
| 325 |
TEST ( UnitTestBulkData_new , verifyParallelAddParts ) |
| 326 |
{ |
| 327 |
TestBoxFixture fixture; |
| 328 |
stk::unit_test_util::BulkDataTester &bulk = fixture.bulk_data (); |
| 329 |
ConstPartVector add_part; |
| 330 |
|
| 331 |
const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } }; |
| 332 |
int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 333 |
|
| 334 |
add_part.push_back ( &fixture.m_part_A_0 ); |
| 335 |
|
| 336 |
bulk.modification_begin(); |
| 337 |
fixture.generate_boxes( root_box, local_box ); |
| 338 |
ASSERT_TRUE(bulk.modification_end()); |
| 339 |
|
| 340 |
bulk.modification_begin(); |
| 341 |
|
| 342 |
for ( EntityCommListInfoVector::const_iterator |
| 343 |
i = bulk.my_internal_comm_list().begin(); |
| 344 |
i != bulk.my_internal_comm_list().end() ; ++i ) { |
| 345 |
if ( i->key.rank() == 0 ) { |
| 346 |
if ( bulk.parallel_owner_rank(i->entity) == fixture.comm_rank() ) { |
| 347 |
bulk.change_entity_parts ( i->entity, add_part, ConstPartVector() ); |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
|
| 352 |
bulk.modification_end(); |
| 353 |
|
| 354 |
for ( EntityCommListInfoVector::const_iterator |
| 355 |
i = bulk.my_internal_comm_list().begin(); |
| 356 |
i != bulk.my_internal_comm_list().end() ; ++i ) { |
| 357 |
if ( i->key.rank() == 0 ) { |
| 358 |
ASSERT_TRUE ( bulk.bucket(i->entity).member ( fixture.m_part_A_0 ) ); |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
TEST ( UnitTestBulkData_new , verifyInducedMembership ) |
| 364 |
{ |
| 365 |
TestBoxFixture fixture; |
| 366 |
BulkData &bulk = fixture.bulk_data (); |
| 367 |
PartVector create_node_parts , create_cell_parts , empty_parts; |
| 368 |
|
| 369 |
create_node_parts.push_back ( &fixture.m_part_A_0 ); |
| 370 |
create_cell_parts.push_back ( &fixture.m_cell_part ); |
| 371 |
|
| 372 |
bulk.modification_begin(); |
| 373 |
|
| 374 |
Entity node0 = bulk.declare_node(2); |
| 375 |
Entity node = bulk.declare_node(1); |
| 376 |
Entity cell = bulk.declare_element(1, stk::mesh::ConstPartVector{&fixture.get_elem_part()}); |
| 377 |
bulk.change_entity_parts ( node , create_node_parts , PartVector () ); |
| 378 |
bulk.change_entity_parts ( cell , create_cell_parts , PartVector () ); |
| 379 |
// Add node to cell part |
| 380 |
RelationIdentifier cell_node_rel_id = 0; |
| 381 |
bulk.declare_relation ( cell , node0 , cell_node_rel_id ); |
| 382 |
cell_node_rel_id = 1; |
| 383 |
bulk.declare_relation ( cell , node , cell_node_rel_id ); |
| 384 |
|
| 385 |
unsigned cell_num_nodes = fixture.get_elem_topology().num_nodes(); |
| 386 |
for (unsigned i = 2; i < cell_num_nodes; ++i) |
| 387 |
{ |
| 388 |
Entity another_node = bulk.declare_node(i+1); |
| 389 |
bulk.declare_relation(cell, another_node, i); |
| 390 |
} |
| 391 |
|
| 392 |
bulk.modification_end(); |
| 393 |
|
| 394 |
ASSERT_TRUE ( bulk.bucket(node).member ( fixture.m_cell_part ) ); |
| 395 |
|
| 396 |
bulk.modification_begin(); |
| 397 |
bulk.destroy_relation ( cell , node, cell_node_rel_id ); |
| 398 |
Entity another_node = bulk.declare_node(cell_num_nodes); |
| 399 |
bulk.declare_relation(cell, another_node, cell_node_rel_id); |
| 400 |
bulk.modification_end(); |
| 401 |
|
| 402 |
ASSERT_TRUE ( !bulk.bucket(node).member ( fixture.m_cell_part ) ); |
| 403 |
} |
| 404 |
|
| 405 |
TEST ( UnitTestBulkData_new , verifyCanRemoveFromSetWithDifferentRankSubset ) |
| 406 |
{ |
| 407 |
TestBoxFixture fixture; |
| 408 |
BulkData &bulk = fixture.bulk_data (); |
| 409 |
PartVector add_parts , add_elem_parts, remove_parts, empty_parts; |
| 410 |
|
| 411 |
add_parts.push_back ( &fixture.m_part_B_3 ); |
| 412 |
add_parts.push_back ( &fixture.m_part_A_superset ); |
| 413 |
add_elem_parts = add_parts; |
| 414 |
Part &elem_part = fixture.get_elem_part(); |
| 415 |
add_elem_parts.push_back(&elem_part); |
| 416 |
|
| 417 |
remove_parts.push_back ( &fixture.m_part_A_superset ); |
| 418 |
|
| 419 |
bulk.modification_begin(); |
| 420 |
|
| 421 |
Entity e = bulk.declare_element(fixture.comm_rank()+1, add_elem_parts); |
| 422 |
Entity n = bulk.declare_node(fixture.comm_rank()+1, add_parts); |
| 423 |
bulk.declare_relation(e, n, 0); |
| 424 |
unsigned elem_num_nodes = fixture.get_elem_topology().num_nodes(); |
| 425 |
for (unsigned i = 1; i < elem_num_nodes; ++i) |
| 426 |
{ |
| 427 |
Entity another_node = bulk.declare_node(i+1); |
| 428 |
bulk.declare_relation(e, another_node, i); |
| 429 |
} |
| 430 |
bulk.modification_end(); |
| 431 |
|
| 432 |
bulk.modification_begin(); |
| 433 |
bulk.change_entity_parts ( e , empty_parts , remove_parts ); |
| 434 |
bulk.modification_end(); |
| 435 |
|
| 436 |
ASSERT_TRUE ( bulk.bucket(e).member ( fixture.m_part_B_3 ) ); |
| 437 |
ASSERT_TRUE ( !bulk.bucket(e).member ( fixture.m_part_A_superset ) ); |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
TEST ( UnitTestBulkData_new , verifyCommonGhostingName ) |
| 442 |
{ |
| 443 |
#ifndef NDEBUG |
| 444 |
//the throw for inconsistent name only happens in debug mode. |
| 445 |
TestBoxFixture fixture; |
| 446 |
BulkData &bulk = fixture.bulk_data (); |
| 447 |
|
| 448 |
bulk.modification_begin(); |
| 449 |
|
| 450 |
if ( fixture.comm_size() == 1 ) return; |
| 451 |
|
| 452 |
if ( fixture.comm_rank() == 0 ) |
| 453 |
{ |
| 454 |
ASSERT_THROW ( bulk.create_ghosting ( "Name 1" ) , std::runtime_error ); |
| 455 |
} |
| 456 |
else |
| 457 |
{ |
| 458 |
ASSERT_THROW ( bulk.create_ghosting ( "Name 2" ) , std::runtime_error ); |
| 459 |
} |
| 460 |
#endif |
| 461 |
} |
| 462 |
|
| 463 |
|
| 464 |
TEST ( UnitTestBulkData_new , verifyTrivialDestroyAllGhostings ) |
| 465 |
{ |
| 466 |
TestBoxFixture fixture; |
| 467 |
|
| 468 |
if ( fixture.comm_size() == 1 ) return; |
| 469 |
|
| 470 |
BulkData &bulk = fixture.bulk_data(); |
| 471 |
|
| 472 |
const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } }; |
| 473 |
int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 474 |
|
| 475 |
bulk.modification_begin(); |
| 476 |
fixture.generate_boxes( root_box, local_box ); |
| 477 |
ASSERT_TRUE(bulk.modification_end()); |
| 478 |
|
| 479 |
bulk.modification_begin(); |
| 480 |
|
| 481 |
Ghosting &ghosting = bulk.create_ghosting ( "Ghost 1" ); |
| 482 |
|
| 483 |
// Find a cell owned by this process |
| 484 |
BucketVector::const_iterator cur_bucket = bulk.buckets(stk::topology::ELEM_RANK).begin(); |
| 485 |
int send_rank = 0; |
| 486 |
|
| 487 |
std::vector<EntityProc> to_send; |
| 488 |
std::vector<EntityKey> empty_vector; |
| 489 |
while ( cur_bucket != bulk.buckets(stk::topology::ELEM_RANK).end() ) |
| 490 |
{ |
| 491 |
Bucket::iterator cur_entity = (*cur_bucket)->begin(); |
| 492 |
while ( cur_entity != (*cur_bucket)->end() ) |
| 493 |
{ |
| 494 |
if ( bulk.parallel_owner_rank(*cur_entity) == fixture.comm_rank() ) |
| 495 |
{ |
| 496 |
if ( send_rank == fixture.comm_size() ) send_rank = 0; |
| 497 |
if ( send_rank != fixture.comm_rank() ) |
| 498 |
to_send.push_back ( std::make_pair ( *cur_entity , send_rank ) ); |
| 499 |
send_rank++; |
| 500 |
} |
| 501 |
++cur_entity; |
| 502 |
} |
| 503 |
++cur_bucket; |
| 504 |
} |
| 505 |
bulk.change_ghosting ( ghosting , to_send , empty_vector ); |
| 506 |
bulk.modification_end(); |
| 507 |
|
| 508 |
|
| 509 |
{ |
| 510 |
std::vector<EntityProc> send_list ; |
| 511 |
std::vector<EntityKey> recv_list ; |
| 512 |
ghosting.send_list( send_list ); |
| 513 |
ghosting.receive_list( recv_list ); |
| 514 |
|
| 515 |
ASSERT_TRUE ( ! send_list.empty() ); |
| 516 |
ASSERT_TRUE ( ! recv_list.empty() ); |
| 517 |
} |
| 518 |
|
| 519 |
// Usage of operator << in Ghosting.cpp |
| 520 |
std::ostringstream oss; |
| 521 |
oss << ghosting; |
| 522 |
|
| 523 |
bulk.modification_begin(); |
| 524 |
bulk.destroy_all_ghosting (); |
| 525 |
bulk.modification_end(); |
| 526 |
|
| 527 |
{ |
| 528 |
std::vector<EntityProc> send_list ; |
| 529 |
std::vector<EntityKey> recv_list ; |
| 530 |
ghosting.send_list( send_list ); |
| 531 |
ghosting.receive_list( recv_list ); |
| 532 |
|
| 533 |
ASSERT_TRUE ( send_list.empty() ); |
| 534 |
ASSERT_TRUE ( recv_list.empty() ); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
TEST ( UnitTestBulkData_new , verifyChangeGhostingGuards ) |
| 540 |
{ |
| 541 |
TestBoxFixture fixture1, fixture2; |
| 542 |
BulkData & bulk1 = fixture1.bulk_data (); |
| 543 |
BulkData & bulk2 = fixture2.bulk_data (); |
| 544 |
|
| 545 |
const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } }; |
| 546 |
int local_box1[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 547 |
int local_box2[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 548 |
|
| 549 |
bulk1.modification_begin(); |
| 550 |
fixture1.generate_boxes( root_box, local_box1 ); |
| 551 |
ASSERT_TRUE(bulk1.modification_end()); |
| 552 |
|
| 553 |
bulk2.modification_begin(); |
| 554 |
fixture2.generate_boxes( root_box, local_box2 ); |
| 555 |
ASSERT_TRUE(bulk2.modification_end()); |
| 556 |
|
| 557 |
bulk1.modification_begin(); |
| 558 |
bulk2.modification_begin(); |
| 559 |
|
| 560 |
std::vector<EntityProc> to_send; |
| 561 |
std::vector<EntityKey> empty_vector; |
| 562 |
BucketVector::const_iterator cur_bucket = bulk1.buckets(stk::topology::ELEM_RANK).begin(); |
| 563 |
int send_rank = 0; |
| 564 |
while ( cur_bucket != bulk1.buckets(stk::topology::ELEM_RANK).end() ) |
| 565 |
{ |
| 566 |
Bucket::iterator cur_entity = (*cur_bucket)->begin(); |
| 567 |
while ( cur_entity != (*cur_bucket)->end() ) |
| 568 |
{ |
| 569 |
if ( bulk1.parallel_owner_rank(*cur_entity) == fixture1.comm_rank() ) |
| 570 |
{ |
| 571 |
if ( send_rank == fixture1.comm_size() ) send_rank = 0; |
| 572 |
if ( send_rank != fixture1.comm_rank() ) |
| 573 |
to_send.push_back ( std::make_pair ( *cur_entity , send_rank ) ); |
| 574 |
++send_rank; |
| 575 |
} |
| 576 |
++cur_entity; |
| 577 |
} |
| 578 |
++cur_bucket; |
| 579 |
} |
| 580 |
|
| 581 |
Ghosting &ghosting = bulk1.create_ghosting ( "Ghost 1" ); |
| 582 |
ASSERT_THROW ( bulk1.change_ghosting ( bulk1.aura_ghosting() , to_send , empty_vector ) , std::runtime_error ); |
| 583 |
|
| 584 |
ghosting.receive_list(empty_vector); |
| 585 |
ghosting.send_list(to_send); |
| 586 |
|
| 587 |
bulk1.modification_end(); |
| 588 |
bulk2.modification_end(); |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
TEST ( UnitTestBulkData_new , verifyOtherGhostingGuards ) |
| 593 |
{ |
| 594 |
TestBoxFixture fixture; |
| 595 |
BulkData &bulk = fixture.bulk_data (); |
| 596 |
|
| 597 |
const int root_box[3][2] = { { 0 , 4 } , { 0 , 5 } , { 0 , 6 } }; |
| 598 |
int local_box[3][2] = { { 0 , 0 } , { 0 , 0 } , { 0 , 0 } }; |
| 599 |
|
| 600 |
bulk.modification_begin(); |
| 601 |
fixture.generate_boxes( root_box, local_box ); |
| 602 |
ASSERT_TRUE(bulk.modification_end()); |
| 603 |
|
| 604 |
bulk.modification_begin(); |
| 605 |
|
| 606 |
std::vector<EntityProc> to_send_unowned; |
| 607 |
std::vector<EntityProc> empty_send; |
| 608 |
std::vector<EntityKey> to_remove_not_ghosted; |
| 609 |
std::vector<EntityKey> empty_remove; |
| 610 |
BucketVector::const_iterator cur_bucket = bulk.buckets(stk::topology::ELEM_RANK).begin(); |
| 611 |
int send_rank = 0; |
| 612 |
while ( cur_bucket != bulk.buckets(stk::topology::ELEM_RANK).end() ) |
| 613 |
{ |
| 614 |
Bucket::iterator cur_entity = (*cur_bucket)->begin(); |
| 615 |
while ( cur_entity != (*cur_bucket)->end() ) |
| 616 |
{ |
| 617 |
if ( bulk.parallel_owner_rank(*cur_entity) != fixture.comm_rank() ) |
| 618 |
{ |
| 619 |
if ( send_rank == fixture.comm_size() ) send_rank = 0; |
| 620 |
if ( send_rank != fixture.comm_rank() ) |
| 621 |
to_send_unowned.push_back ( std::make_pair ( *cur_entity , send_rank ) ); |
| 622 |
++send_rank; |
| 623 |
} |
| 624 |
else |
| 625 |
{ |
| 626 |
to_remove_not_ghosted.push_back ( bulk.entity_key(*cur_entity) ); |
| 627 |
} |
| 628 |
++cur_entity; |
| 629 |
} |
| 630 |
++cur_bucket; |
| 631 |
} |
| 632 |
|
| 633 |
Ghosting &ghosting = bulk.create_ghosting ( "Ghost 1" ); |
| 634 |
if ( to_send_unowned.size() > 0 ) |
| 635 |
{ |
| 636 |
ASSERT_THROW ( bulk.change_ghosting ( ghosting , to_send_unowned , empty_remove ) , std::runtime_error ); |
| 637 |
} |
| 638 |
else |
| 639 |
{ |
| 640 |
bulk.change_ghosting ( ghosting , to_send_unowned , empty_remove ); |
| 641 |
} |
| 642 |
|
| 643 |
if ( to_remove_not_ghosted.size() > 0 ) |
| 644 |
{ |
| 645 |
ASSERT_NO_THROW( bulk.change_ghosting ( ghosting , empty_send , to_remove_not_ghosted ) ); |
| 646 |
} |
| 647 |
else |
| 648 |
{ |
| 649 |
bulk.change_ghosting ( ghosting , empty_send , to_remove_not_ghosted ); |
| 650 |
} |
| 651 |
bulk.modification_end(); |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
TEST ( UnitTestBulkData_new , verifyPartsOnCreate ) |
| 656 |
{ |
| 657 |
TestBoxFixture fixture; |
| 658 |
BulkData & bulk = fixture.bulk_data (); |
| 659 |
Part & part_a = fixture.m_part_A_0; |
| 660 |
Part & part_b = fixture.m_part_B_0; |
| 661 |
|
| 662 |
PartVector create_vector; |
| 663 |
create_vector.push_back ( &part_a ); |
| 664 |
|
| 665 |
bulk.modification_begin(); |
| 666 |
|
| 667 |
Entity node = bulk.declare_node(fixture.comm_rank()+1 ,create_vector ); |
| 668 |
bulk.modification_end(); |
| 669 |
|
| 670 |
ASSERT_TRUE ( bulk.bucket(node).member ( part_a ) ); |
| 671 |
|
| 672 |
bulk.modification_begin(); |
| 673 |
create_vector.push_back ( &part_b ); |
| 674 |
Entity node2 = bulk.declare_node(fixture.comm_size() + fixture.comm_rank() + 1 , create_vector ); |
| 675 |
bulk.modification_end(); |
| 676 |
|
| 677 |
ASSERT_TRUE ( bulk.bucket(node2).member ( part_a ) ); |
| 678 |
ASSERT_TRUE ( bulk.bucket(node2).member ( part_b ) ); |
| 679 |
} |
| 680 |
|
| 681 |
//---------------------------------------------------------------------- |
| 682 |
|
| 683 |
TEST ( UnitTestBulkData_new , verifyBoxGhosting ) |
| 684 |
{ |
| 685 |
const int p_size = stk::parallel_machine_size( MPI_COMM_WORLD ); |
| 686 |
if ( 8 < p_size ) { return ; } |
| 687 |
|
| 688 |
fixtures::HexFixture fixture( MPI_COMM_WORLD, 2, 2, 2 ); |
| 689 |
fixture.m_meta.commit(); |
| 690 |
fixture.generate_mesh(); |
| 691 |
const BulkData& mesh = fixture.m_bulk_data; |
| 692 |
|
| 693 |
for ( size_t iz = 0 ; iz < 3 ; ++iz ) { |
| 694 |
for ( size_t iy = 0 ; iy < 3 ; ++iy ) { |
| 695 |
for ( size_t ix = 0 ; ix < 3 ; ++ix ) { |
| 696 |
Entity const node = fixture.node(ix,iy,iz); |
| 697 |
ASSERT_TRUE( mesh.is_valid(node) ); |
| 698 |
|
| 699 |
ASSERT_TRUE( fixture.node_id(ix,iy,iz) == mesh.identifier(node) ); |
| 700 |
fixtures::HexFixture::Scalar * const node_coord = stk::mesh::field_data(*fixture.m_coord_field, node); |
| 701 |
ASSERT_TRUE( node_coord != NULL ); |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
for ( size_t iz = 0 ; iz < 2 ; ++iz ) { |
| 707 |
for ( size_t iy = 0 ; iy < 2 ; ++iy ) { |
| 708 |
for ( size_t ix = 0 ; ix < 2 ; ++ix ) { |
| 709 |
Entity const elem = fixture.elem(ix,iy,iz); |
| 710 |
ASSERT_TRUE( mesh.is_valid(elem) ); |
| 711 |
size_t num_elem_nodes = mesh.num_nodes(elem); |
| 712 |
ASSERT_EQ( 8u , num_elem_nodes ); |
| 713 |
Entity const *elem_nodes = mesh.begin_nodes(elem); |
| 714 |
// ConnectivityOrdinal const *elem_node_ords = mesh.begin_node_ordinals(elem); |
| 715 |
if ( 8u == num_elem_nodes ) { |
| 716 |
ASSERT_TRUE( elem_nodes[0] == fixture.node(ix,iy,iz)); |
| 717 |
ASSERT_TRUE( elem_nodes[1] == fixture.node(ix+1,iy,iz)); |
| 718 |
ASSERT_TRUE( elem_nodes[2] == fixture.node(ix+1,iy+1,iz)); |
| 719 |
ASSERT_TRUE( elem_nodes[3] == fixture.node(ix,iy+1,iz)); |
| 720 |
ASSERT_TRUE( elem_nodes[4] == fixture.node(ix,iy,iz+1)); |
| 721 |
ASSERT_TRUE( elem_nodes[5] == fixture.node(ix+1,iy,iz+1)); |
| 722 |
ASSERT_TRUE( elem_nodes[6] == fixture.node(ix+1,iy+1,iz+1)); |
| 723 |
ASSERT_TRUE( elem_nodes[7] == fixture.node(ix,iy+1,iz+1)); |
| 724 |
} |
| 725 |
// Now check access to field data via the fast rank functions. |
| 726 |
// Node const *eph_elem_nodes = mesh.begin_nodes(elem); |
| 727 |
// for ( size_t j = 0 ; j < num_elem_nodes ; ++j ) |
| 728 |
// { |
| 729 |
// fixtures::HexFixture::Scalar * const node_coord = |
| 730 |
// stk::mesh::field_data( fixture.m_coord_field , eph_elem_nodes[j]); |
| 731 |
// EXPECT_EQ( node_coord, elem_node_coord[ elem_node_ords[j] ] ); |
| 732 |
// } |
| 733 |
|
| 734 |
} |
| 735 |
} |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
TEST ( UnitTestBulkData_new , testUninitializedMetaData ) |
| 740 |
{ |
| 741 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 742 |
|
| 743 |
std::shared_ptr<BulkData> bulk = stk::mesh::MeshBuilder(pm).create(); |
| 744 |
MetaData& meta = bulk->mesh_meta_data(); |
| 745 |
|
| 746 |
meta.initialize(2); |
| 747 |
|
| 748 |
meta.commit(); |
| 749 |
|
| 750 |
bulk->modification_begin(); |
| 751 |
|
| 752 |
ASSERT_THROW( bulk->declare_node(1, PartVector()), std::logic_error); |
| 753 |
} |
| 754 |
|
| 755 |
TEST ( UnitTestBulkData_new , testGhostHandleRemainsValidAfterRefresh ) |
| 756 |
{ |
| 757 |
// |
| 758 |
// Testing if a handle to a ghosted entity remains valid before and after a |
| 759 |
// modification cycle in which the ghost is refreshed. |
| 760 |
// |
| 761 |
// To test this, we focus on a single node shared on 2 procs, ghosted on others |
| 762 |
// |
| 763 |
// |
| 764 |
// 1D Mesh (node,owner)--[elem,owner]---(...) |
| 765 |
// |
| 766 |
// <---(50,0)--[100,0]--(21,1)--[201,1]---(32,2)---[302,2]---(50,0)---> |
| 767 |
// |
| 768 |
|
| 769 |
// elem, node0, node1, owner |
| 770 |
EntityId elems_0[][4] = { {100, 21, 50, 0}, {201, 21, 32, 1}, {302, 32, 50, 2} }; |
| 771 |
// node, owner |
| 772 |
EntityId nodes_0[][2] = { {21,1}, {50,0}, {32, 2} }; |
| 773 |
|
| 774 |
const unsigned nelems = sizeof(elems_0)/4/sizeof(EntityId); |
| 775 |
const unsigned nnodes = sizeof(nodes_0)/2/sizeof(EntityId); |
| 776 |
|
| 777 |
stk::ParallelMachine pm = MPI_COMM_WORLD; |
| 778 |
|
| 779 |
// Set up meta and bulk data |
| 780 |
const unsigned spatial_dim = 1; |
| 781 |
|
| 782 |
std::vector<std::string> entity_rank_names; |
| 783 |
entity_rank_names.push_back("NODE_RANK"); |
| 784 |
entity_rank_names.push_back("EDGE_RANK"); |
| 785 |
entity_rank_names.push_back("FACE_RANK"); |
| 786 |
entity_rank_names.push_back("ELEM_RANK"); |
| 787 |
entity_rank_names.push_back("FAMILY_TREE"); |
| 788 |
|
| 789 |
stk::mesh::MeshBuilder builder(pm); |
| 790 |
builder.set_spatial_dimension(spatial_dim); |
| 791 |
builder.set_entity_rank_names(entity_rank_names); |
| 792 |
std::shared_ptr<BulkData> bulkPtr = builder.create(); |
| 793 |
MetaData& meta_data = bulkPtr->mesh_meta_data(); |
| 794 |
Part & elem_part = meta_data.declare_part_with_topology("elem_part", stk::topology::LINE_2_1D); |
| 795 |
Part & node_part = meta_data.declare_part_with_topology("node_part", stk::topology::NODE); |
| 796 |
|
| 797 |
meta_data.commit(); |
| 798 |
BulkData& mesh = *bulkPtr; |
| 799 |
int p_rank = mesh.parallel_rank(); |
| 800 |
int p_size = mesh.parallel_size(); |
| 801 |
|
| 802 |
if (p_size != 3) return; |
| 803 |
|
| 804 |
// Build map for node sharing |
| 805 |
stk::mesh::fixtures::NodeToProcsMMap nodes_to_procs; |
| 806 |
{ |
| 807 |
for (unsigned ielem=0; ielem < nelems; ielem++) { |
| 808 |
int e_owner = static_cast<int>(elems_0[ielem][3]); |
| 809 |
stk::mesh::fixtures::AddToNodeProcsMMap(nodes_to_procs, elems_0[ielem][2], e_owner); |
| 810 |
stk::mesh::fixtures::AddToNodeProcsMMap(nodes_to_procs, elems_0[ielem][1], e_owner); |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
// |
| 815 |
// Begin modification cycle so we can create the entities and relations |
| 816 |
// |
| 817 |
{ |
| 818 |
// Create elements |
| 819 |
Entity elem = Entity(); |
| 820 |
|
| 821 |
mesh.modification_begin(); |
| 822 |
|
| 823 |
for (unsigned ielem=0; ielem < nelems; ielem++) { |
| 824 |
int owner = static_cast<int>(elems_0[ielem][3]); |
| 825 |
if (owner == p_rank) { |
| 826 |
elem = mesh.declare_element(elems_0[ielem][0], stk::mesh::ConstPartVector{&elem_part}); |
| 827 |
|
| 828 |
EntityVector nodes; |
| 829 |
// Create node on all procs |
| 830 |
nodes.push_back( mesh.declare_node(elems_0[ielem][2], stk::mesh::ConstPartVector{&node_part}) ); |
| 831 |
nodes.push_back( mesh.declare_node(elems_0[ielem][1], stk::mesh::ConstPartVector{&node_part}) ); |
| 832 |
|
| 833 |
// Add relations to nodes |
| 834 |
mesh.declare_relation( elem, nodes[0], 0 ); |
| 835 |
mesh.declare_relation( elem, nodes[1], 1 ); |
| 836 |
|
| 837 |
// Node sharing |
| 838 |
stk::mesh::fixtures::DoAddNodeSharings(mesh, nodes_to_procs, mesh.identifier(nodes[0]), nodes[0]); |
| 839 |
stk::mesh::fixtures::DoAddNodeSharings(mesh, nodes_to_procs, mesh.identifier(nodes[1]), nodes[1]); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
mesh.modification_end(); |
| 844 |
} |
| 845 |
|
| 846 |
// change node owners |
| 847 |
{ |
| 848 |
std::vector<EntityProc> change; |
| 849 |
|
| 850 |
for (unsigned inode=0; inode < nnodes; inode++) { |
| 851 |
Entity node = mesh.get_entity(stk::topology::NODE_RANK, nodes_0[inode][0]); |
| 852 |
if (mesh.is_valid(node) && mesh.parallel_owner_rank(node) == p_rank) { |
| 853 |
int dest = nodes_0[inode][1]; |
| 854 |
EntityProc eproc(node, dest); |
| 855 |
change.push_back(eproc); |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
mesh.change_entity_owner( change ); |
| 860 |
} |
| 861 |
|
| 862 |
// The real test is here |
| 863 |
{ |
| 864 |
Entity node_21_handle_before_elem_deletion = mesh.get_entity(stk::topology::NODE_RANK, 21); |
| 865 |
if (p_rank == 2) { |
| 866 |
ASSERT_TRUE(mesh.in_receive_ghost(mesh.entity_key(node_21_handle_before_elem_deletion))); |
| 867 |
} |
| 868 |
|
| 869 |
// attempt to delete a node and its elems but on a ghosted proc |
| 870 |
mesh.modification_begin(); |
| 871 |
|
| 872 |
Entity elem = mesh.get_entity(stk::topology::ELEMENT_RANK, 100); |
| 873 |
if (mesh.is_valid(elem)) mesh.destroy_entity(elem); |
| 874 |
|
| 875 |
mesh.modification_end(); |
| 876 |
|
| 877 |
// Key check is here |
| 878 |
if (p_rank == 2) { |
| 879 |
// mesh still thinks handle is valid and refers to the same entity with the same EntityKey! |
| 880 |
ASSERT_TRUE(mesh.is_valid(node_21_handle_before_elem_deletion)); |
| 881 |
ASSERT_EQ(mesh.entity_key(node_21_handle_before_elem_deletion), EntityKey(stk::topology::NODE_RANK, 21)); |
| 882 |
} |
| 883 |
} |
| 884 |
} |
| 885 |
|
| 886 |
TEST ( UnitTestBulkData_new , testCustomBucketCapacity ) |
| 887 |
{ |
| 888 |
const int spatial_dimension = 3; |
| 889 |
|
| 890 |
const unsigned non_standard_bucket_capacity = 42; |
| 891 |
stk::mesh::MeshBuilder builder(MPI_COMM_WORLD); |
| 892 |
builder.set_spatial_dimension(spatial_dimension); |
| 893 |
builder.set_aura_option(stk::mesh::BulkData::AUTO_AURA); |
| 894 |
builder.set_add_fmwk_data(true); |
| 895 |
builder.set_bucket_capacity(non_standard_bucket_capacity); |
| 896 |
std::shared_ptr<BulkData> bulk = builder.create(); |
| 897 |
MetaData& meta = bulk->mesh_meta_data(); |
| 898 |
|
| 899 |
|
| 900 |
Part & node_part = meta.declare_part_with_topology("node_part", stk::topology::NODE); |
| 901 |
|
| 902 |
meta.commit(); |
| 903 |
|
| 904 |
PartVector create_vector; |
| 905 |
create_vector.push_back ( &node_part ); |
| 906 |
|
| 907 |
bulk->modification_begin(); |
| 908 |
|
| 909 |
EntityId nodeID = bulk->parallel_rank()+1; |
| 910 |
Entity node = bulk->declare_node(nodeID, create_vector); |
| 911 |
bulk->modification_end(); |
| 912 |
|
| 913 |
EXPECT_EQ( bulk->bucket(node).capacity(), non_standard_bucket_capacity ); |
| 914 |
} |
| 915 |
|
| 916 |
TEST(BulkData, bucket_debug_ThrowsWithInvalidEntity) |
| 917 |
{ |
| 918 |
if (stk::parallel_machine_size(MPI_COMM_WORLD) != 1) { GTEST_SKIP(); } |
| 919 |
|
| 920 |
#ifndef NDEBUG |
| 921 |
std::unique_ptr<stk::mesh::BulkData> bulkPtr = stk::mesh::MeshBuilder(MPI_COMM_WORLD).create(); |
| 922 |
|
| 923 |
stk::mesh::Entity invalidEntity; |
| 924 |
EXPECT_TRUE(nullptr == bulkPtr->bucket_ptr(invalidEntity)); |
| 925 |
EXPECT_ANY_THROW(bulkPtr->bucket(invalidEntity)); |
| 926 |
#endif |
| 927 |
} |
| 928 |
|