| 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 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 35 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 36 |
#include <stk_mesh/base/Field.hpp> |
| 37 |
#include <stk_mesh/base/FieldBase.hpp> |
| 38 |
#include <stk_mesh/base/GetEntities.hpp> |
| 39 |
#include <stk_mesh/base/Selector.hpp> |
| 40 |
#include <stk_mesh/base/BulkData.hpp> |
| 41 |
#include <stk_mesh/base/EntityLess.hpp> |
| 42 |
#include <stk_mesh/base/MetaData.hpp> |
| 43 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 44 |
#include <stk_tools/mesh_clone/MeshClone.hpp> |
| 45 |
#include <stk_io/IossBridge.hpp> |
| 46 |
#include <stk_util/util/ReportHandler.hpp> |
| 47 |
#include <stk_mesh/base/Comm.hpp> |
| 48 |
#include <stk_io/WriteMesh.hpp> |
| 49 |
|
| 50 |
#include <algorithm> |
| 51 |
|
| 52 |
namespace |
| 53 |
{ |
| 54 |
using stk::unit_test_util::build_mesh; |
| 55 |
|
| 56 |
std::vector<size_t> get_entity_counts(const stk::mesh::BulkData &bulk, const stk::mesh::Selector &selector) |
| 57 |
{ |
| 58 |
std::vector<size_t> counts; |
| 59 |
stk::mesh::comm_mesh_counts(bulk, counts, &selector); |
| 60 |
return counts; |
| 61 |
} |
| 62 |
|
| 63 |
struct EntityConnectivity |
| 64 |
{ |
| 65 |
EntityConnectivity(const stk::mesh::BulkData &bulk, stk::mesh::Entity argEntity, stk::mesh::EntityRank relationRank_) |
| 66 |
: entity(argEntity), |
| 67 |
relationRank(relationRank_), |
| 68 |
numConnected(bulk.num_connectivity(entity, relationRank)), |
| 69 |
connected(bulk.begin(entity, relationRank), bulk.begin(entity, relationRank)+numConnected), |
| 70 |
ords(bulk.begin_ordinals(entity, relationRank), bulk.begin_ordinals(entity, relationRank)+numConnected), |
| 71 |
perms() |
| 72 |
{ |
| 73 |
if (nullptr != bulk.begin_permutations(entity, relationRank)) |
| 74 |
{ |
| 75 |
perms.assign(bulk.begin_permutations(entity, relationRank), bulk.begin_permutations(entity, relationRank)+numConnected); |
| 76 |
} |
| 77 |
const bool is_upward_connectivity = relationRank > bulk.entity_rank(entity); |
| 78 |
if (is_upward_connectivity) { |
| 79 |
sort_relations_by_identifier(entity, bulk); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
void sort_relations_by_identifier(stk::mesh::Entity entityArg, const stk::mesh::BulkData& bulk) |
| 84 |
{ |
| 85 |
std::sort(connected.begin(), connected.end(), stk::mesh::EntityLess(bulk)); |
| 86 |
|
| 87 |
const stk::mesh::Entity* unsortedEntities = bulk.begin(entityArg, relationRank); |
| 88 |
const stk::mesh::ConnectivityOrdinal* unsortedOrds = bulk.begin_ordinals(entityArg, relationRank); |
| 89 |
const stk::mesh::Permutation* unsortedPerms = bulk.begin_permutations(entityArg, relationRank); |
| 90 |
|
| 91 |
for(size_t i=0; i<connected.size(); ++i) |
| 92 |
{ |
| 93 |
stk::mesh::Entity ent = connected[i]; |
| 94 |
for(unsigned j=0; j<numConnected; ++j) |
| 95 |
{ |
| 96 |
if (i != j && ent == unsortedEntities[j]) |
| 97 |
{ |
| 98 |
ords[i] = unsortedOrds[j]; |
| 99 |
if (!perms.empty()) |
| 100 |
{ |
| 101 |
perms[i] = unsortedPerms[j]; |
| 102 |
} |
| 103 |
break; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
void remove_unselected(const stk::mesh::Selector& selector, const stk::mesh::BulkData& bulk) |
| 110 |
{ |
| 111 |
for(unsigned i=0; i<numConnected; ++i) |
| 112 |
{ |
| 113 |
unsigned backwardsIdx = numConnected - i - 1; |
| 114 |
if (!selector(bulk.bucket(connected[backwardsIdx]))) |
| 115 |
{ |
| 116 |
connected.erase(connected.begin()+backwardsIdx); |
| 117 |
ords.erase(ords.begin()+backwardsIdx); |
| 118 |
if (!perms.empty()) |
| 119 |
{ |
| 120 |
perms.erase(perms.begin()+backwardsIdx); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
numConnected = connected.size(); |
| 125 |
} |
| 126 |
|
| 127 |
stk::mesh::Entity entity; |
| 128 |
stk::mesh::EntityRank relationRank; |
| 129 |
unsigned numConnected; |
| 130 |
std::vector<stk::mesh::Entity> connected; |
| 131 |
std::vector<stk::mesh::ConnectivityOrdinal> ords; |
| 132 |
std::vector<stk::mesh::Permutation> perms; |
| 133 |
}; |
| 134 |
|
| 135 |
void expect_equal_entity_connectivity(const stk::mesh::BulkData &oldBulk, |
| 136 |
const stk::mesh::BulkData &newBulk, |
| 137 |
const EntityConnectivity &oldConnectivity, |
| 138 |
const EntityConnectivity &newConnectivity, |
| 139 |
stk::mesh::EntityRank rank) |
| 140 |
{ |
| 141 |
ASSERT_EQ(oldConnectivity.numConnected, newConnectivity.numConnected) << "rank: "<<rank << " oldEntity = " << oldBulk.entity_key(oldConnectivity.entity) << " newEntity = " << newBulk.entity_key(newConnectivity.entity); |
| 142 |
unsigned newConIndex = 0; |
| 143 |
for(unsigned oldConIndex = 0; oldConIndex < oldConnectivity.numConnected; oldConIndex++) |
| 144 |
{ |
| 145 |
EXPECT_EQ(oldBulk.identifier(oldConnectivity.connected[oldConIndex]), newBulk.identifier(newConnectivity.connected[newConIndex])) << "rank: "<<rank<<", relation_rank: "<<oldConnectivity.relationRank; |
| 146 |
EXPECT_EQ(oldConnectivity.ords[oldConIndex], newConnectivity.ords[newConIndex]) << "oldConIndex: "<<oldConIndex<<", newConIndex: "<<newConIndex |
| 147 |
<<", rank: " << rank << " relation_rank: " << oldConnectivity.relationRank; |
| 148 |
if(!oldConnectivity.perms.empty() && !newConnectivity.perms.empty()) |
| 149 |
EXPECT_EQ(oldConnectivity.perms[oldConIndex], newConnectivity.perms[newConIndex]) << "rank: " << rank << " relation_rank: " << oldConnectivity.relationRank; |
| 150 |
else |
| 151 |
EXPECT_TRUE(oldConnectivity.perms.empty() && newConnectivity.perms.empty()); |
| 152 |
|
| 153 |
++newConIndex; |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
void expect_equal_relations(const stk::mesh::Selector &oldSelector, |
| 158 |
const stk::mesh::BulkData &oldBulk, stk::mesh::Entity oldEntity, |
| 159 |
const stk::mesh::BulkData &newBulk, stk::mesh::Entity newEntity, |
| 160 |
stk::mesh::EntityRank endRank) |
| 161 |
{ |
| 162 |
stk::mesh::EntityRank rank = oldBulk.entity_rank(oldEntity); |
| 163 |
for(stk::mesh::EntityRank relationRank = stk::topology::NODE_RANK; relationRank < endRank; relationRank++) |
| 164 |
{ |
| 165 |
if(relationRank != rank) |
| 166 |
{ |
| 167 |
EntityConnectivity oldConnectivity(oldBulk, oldEntity, relationRank); |
| 168 |
oldConnectivity.remove_unselected(oldSelector, oldBulk); |
| 169 |
EntityConnectivity newConnectivity(newBulk, newEntity, relationRank); |
| 170 |
expect_equal_entity_connectivity(oldBulk, newBulk, oldConnectivity, newConnectivity, rank); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
void expect_equal_field_data(const stk::mesh::BulkData &oldBulk, stk::mesh::Entity oldEntity, |
| 176 |
const stk::mesh::BulkData &newBulk, stk::mesh::Entity newEntity, |
| 177 |
const stk::mesh::EntityRank rank) |
| 178 |
{ |
| 179 |
const stk::mesh::FieldVector &oldFields = oldBulk.mesh_meta_data().get_fields(rank); |
| 180 |
const stk::mesh::FieldVector &newFields = newBulk.mesh_meta_data().get_fields(rank); |
| 181 |
|
| 182 |
EXPECT_EQ(oldFields.size(), newFields.size()); |
| 183 |
|
| 184 |
for(unsigned i=0; i<oldFields.size(); ++i) |
| 185 |
{ |
| 186 |
unsigned oldBytesPerEntity = stk::mesh::field_bytes_per_entity(*oldFields[i], oldEntity); |
| 187 |
unsigned newBytesPerEntity = stk::mesh::field_bytes_per_entity(*newFields[i], newEntity); |
| 188 |
EXPECT_EQ(oldBytesPerEntity, newBytesPerEntity); |
| 189 |
unsigned char* oldData = static_cast<unsigned char*>(stk::mesh::field_data(*oldFields[i], oldEntity)); |
| 190 |
unsigned char* newData = static_cast<unsigned char*>(stk::mesh::field_data(*newFields[i], newEntity)); |
| 191 |
for(unsigned j=0; j<oldBytesPerEntity; ++j) |
| 192 |
EXPECT_EQ(oldData[j], newData[j]); |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
void expect_equal_entity_counts(const stk::mesh::BulkData &oldBulk, const stk::mesh::Selector &oldSelector, const stk::mesh::BulkData &newBulk) |
| 197 |
{ |
| 198 |
const stk::mesh::MetaData &oldMeta = oldBulk.mesh_meta_data(); |
| 199 |
const stk::mesh::MetaData &newMeta = newBulk.mesh_meta_data(); |
| 200 |
stk::mesh::Selector newSelector = newBulk.mesh_meta_data().universal_part(); |
| 201 |
|
| 202 |
ASSERT_EQ(oldBulk.is_automatic_aura_on(), newBulk.is_automatic_aura_on()) << "Aura needs to be the same for this test."; |
| 203 |
|
| 204 |
std::vector<size_t> oldCounts = get_entity_counts(oldBulk, (oldSelector & oldMeta.locally_owned_part())); |
| 205 |
std::vector<size_t> newCounts = get_entity_counts(newBulk, (newSelector & newMeta.locally_owned_part())); |
| 206 |
ASSERT_EQ(oldCounts.size(), newCounts.size()); |
| 207 |
stk::mesh::EntityRank endRank = static_cast<stk::mesh::EntityRank>(oldMeta.entity_rank_count()); |
| 208 |
for(stk::mesh::EntityRank rank = stk::topology::NODE_RANK; rank < endRank; rank++) |
| 209 |
EXPECT_EQ(oldCounts[rank], newCounts[rank]) << rank; |
| 210 |
} |
| 211 |
|
| 212 |
void expect_equal_sharing(const stk::mesh::BulkData& oldBulk, stk::mesh::Entity oldEntity, |
| 213 |
const stk::mesh::BulkData& newBulk, stk::mesh::Entity newEntity) |
| 214 |
{ |
| 215 |
std::vector<int> oldSharingProcs; |
| 216 |
std::vector<int> newSharingProcs; |
| 217 |
oldBulk.comm_shared_procs(oldBulk.entity_key(oldEntity), oldSharingProcs); |
| 218 |
newBulk.comm_shared_procs(newBulk.entity_key(newEntity), newSharingProcs); |
| 219 |
ASSERT_EQ(oldSharingProcs.size(), newSharingProcs.size()); |
| 220 |
for(size_t i=0; i<oldSharingProcs.size(); ++i) { |
| 221 |
EXPECT_EQ(oldSharingProcs[i], newSharingProcs[i]); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
void expect_superset_sharing(const stk::mesh::BulkData& oldBulk, stk::mesh::Entity oldEntity, |
| 226 |
const stk::mesh::BulkData& newBulk, stk::mesh::Entity newEntity) |
| 227 |
{ |
| 228 |
std::vector<int> oldSharingProcs; |
| 229 |
std::vector<int> newSharingProcs; |
| 230 |
oldBulk.comm_shared_procs(oldBulk.entity_key(oldEntity), oldSharingProcs); |
| 231 |
newBulk.comm_shared_procs(newBulk.entity_key(newEntity), newSharingProcs); |
| 232 |
ASSERT_GE(oldSharingProcs.size(), newSharingProcs.size()); |
| 233 |
|
| 234 |
std::set<int> oldSharingProcsSet(oldSharingProcs.begin(), oldSharingProcs.end()); |
| 235 |
std::set<int> newSharingProcsSet(newSharingProcs.begin(), newSharingProcs.end()); |
| 236 |
ASSERT_TRUE( |
| 237 |
std::includes(oldSharingProcsSet.begin(), oldSharingProcsSet.end(), |
| 238 |
newSharingProcsSet.begin(), newSharingProcsSet.end()) |
| 239 |
); |
| 240 |
} |
| 241 |
|
| 242 |
class CloningMesh : public stk::unit_test_util::MeshFixture |
| 243 |
{ |
| 244 |
protected: |
| 245 |
const char *get_mesh_spec_for_1x1x8_with_sideset() const {return "generated:1x1x8|sideset:x";} |
| 246 |
stk::mesh::BulkData::AutomaticAuraOption get_no_auto_aura_option() const {return stk::mesh::BulkData::NO_AUTO_AURA;} |
| 247 |
|
| 248 |
CloningMesh() |
| 249 |
: stk::unit_test_util::MeshFixture(3, {"node", "edge", "face", "element", "constraint"}) |
| 250 |
{ } |
| 251 |
|
| 252 |
void create_constraints() |
| 253 |
{ |
| 254 |
size_t numConstraintsPerProc = 10; |
| 255 |
size_t localConstraintId = 1; |
| 256 |
get_bulk().modification_begin(); |
| 257 |
stk::mesh::Part *submesh = get_meta().get_part("submesh"); |
| 258 |
STK_ThrowRequire(submesh != nullptr); |
| 259 |
stk::mesh::Entity constraint = get_bulk().declare_entity(stk::topology::CONSTRAINT_RANK, get_bulk().parallel_rank() * numConstraintsPerProc + localConstraintId, *submesh); |
| 260 |
declare_constraint_relations_to_block1_elements(constraint); |
| 261 |
get_bulk().modification_end(); |
| 262 |
} |
| 263 |
|
| 264 |
void declare_constraint_relations_to_block1_elements(stk::mesh::Entity constraint) |
| 265 |
{ |
| 266 |
stk::mesh::EntityVector block1Elements; |
| 267 |
stk::mesh::Part *block1Part = get_meta().get_part("block_1"); |
| 268 |
stk::mesh::get_selected_entities(get_meta().locally_owned_part() & *block1Part, get_bulk().buckets(stk::topology::ELEMENT_RANK), block1Elements); |
| 269 |
for(size_t i=0; i < block1Elements.size(); i++) |
| 270 |
get_bulk().declare_relation(constraint, block1Elements[i], i); |
| 271 |
} |
| 272 |
|
| 273 |
void declare_parts() |
| 274 |
{ |
| 275 |
get_meta().declare_part_with_topology("block_2", stk::topology::HEX_8); |
| 276 |
get_meta().declare_part("submesh", stk::topology::CONSTRAINT_RANK); |
| 277 |
} |
| 278 |
|
| 279 |
void move_half_of_mesh_to_block2() |
| 280 |
{ |
| 281 |
stk::mesh::Part *block1 = get_meta().get_part("block_1"); |
| 282 |
stk::mesh::Part *block2 = get_meta().get_part("block_2"); |
| 283 |
stk::mesh::PartVector remove{block1}; |
| 284 |
stk::mesh::PartVector add{block2}; |
| 285 |
|
| 286 |
stk::mesh::EntityVector localElements; |
| 287 |
stk::mesh::get_selected_entities(get_meta().locally_owned_part(), get_bulk().buckets(stk::topology::ELEMENT_RANK), localElements); |
| 288 |
|
| 289 |
get_bulk().modification_begin(); |
| 290 |
for(unsigned i = localElements.size() / 2; i < localElements.size(); i++) |
| 291 |
{ |
| 292 |
get_bulk().change_entity_parts(localElements[i], add, remove); |
| 293 |
} |
| 294 |
get_bulk().modification_end(); |
| 295 |
} |
| 296 |
|
| 297 |
void do_clone_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 298 |
{ |
| 299 |
stk::mesh::BulkData & oldBulk = get_bulk(); |
| 300 |
std::shared_ptr<stk::mesh::BulkData> newBulkPtr = build_mesh(oldBulk.parallel(), auraOption); |
| 301 |
stk::mesh::BulkData& newBulk = *newBulkPtr; |
| 302 |
stk::mesh::Selector copySelector = get_meta().universal_part(); |
| 303 |
stk::tools::copy_mesh(oldBulk, copySelector, newBulk); |
| 304 |
test_cloned_mesh(oldBulk, newBulk); |
| 305 |
expect_equal_entity_part_ordinals(oldBulk, copySelector, newBulk); |
| 306 |
} |
| 307 |
|
| 308 |
void do_clone_test_with_submesh_selector(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 309 |
{ |
| 310 |
stk::mesh::Part *submesh = get_meta().get_part("submesh"); |
| 311 |
stk::mesh::Part *block1 = get_meta().get_part("block_1"); |
| 312 |
stk::mesh::Selector copySelector = *submesh | *block1; |
| 313 |
stk::mesh::BulkData & oldBulk = get_bulk(); |
| 314 |
std::shared_ptr<stk::mesh::BulkData> newBulkPtr = build_mesh(oldBulk.parallel(), auraOption); |
| 315 |
stk::mesh::BulkData& newBulk = *newBulkPtr; |
| 316 |
stk::tools::copy_mesh(oldBulk, copySelector, newBulk); |
| 317 |
test_cloned_submesh(oldBulk, copySelector, newBulk); |
| 318 |
} |
| 319 |
|
| 320 |
void test_cloned_mesh(stk::mesh::BulkData &oldBulk, const stk::mesh::BulkData &newBulk) |
| 321 |
{ |
| 322 |
stk::mesh::Part& universalPart = oldBulk.mesh_meta_data().universal_part(); |
| 323 |
|
| 324 |
expect_equal_entity_counts(oldBulk, universalPart, newBulk); |
| 325 |
|
| 326 |
const stk::mesh::MetaData &oldMeta = oldBulk.mesh_meta_data(); |
| 327 |
ASSERT_EQ(5u, static_cast<unsigned>(oldMeta.entity_rank_count())); |
| 328 |
stk::mesh::Selector localOrSharedSelector = oldMeta.locally_owned_part() | oldMeta.globally_shared_part(); |
| 329 |
stk::mesh::EntityRank endRank = static_cast<stk::mesh::EntityRank>(oldMeta.entity_rank_count()); |
| 330 |
stk::mesh::EntityVector oldEntities; |
| 331 |
for(stk::mesh::EntityRank rank = stk::topology::NODE_RANK; rank < endRank; rank++) |
| 332 |
{ |
| 333 |
stk::mesh::get_selected_entities(localOrSharedSelector, oldBulk.buckets(rank), oldEntities); |
| 334 |
for(stk::mesh::Entity oldEntity : oldEntities) |
| 335 |
{ |
| 336 |
stk::mesh::Entity newEntity = newBulk.get_entity(rank, oldBulk.identifier(oldEntity)); |
| 337 |
EXPECT_TRUE(newBulk.is_valid(newEntity)); |
| 338 |
if (rank < stk::topology::ELEM_RANK) |
| 339 |
{ |
| 340 |
expect_equal_sharing(oldBulk, oldEntity, newBulk, newEntity); |
| 341 |
} |
| 342 |
expect_equal_relations(universalPart, oldBulk, oldEntity, newBulk, newEntity, endRank); |
| 343 |
expect_equal_field_data(oldBulk, oldEntity, newBulk, newEntity, rank); |
| 344 |
} |
| 345 |
} |
| 346 |
ASSERT_EQ(oldBulk.has_face_adjacent_element_graph(), newBulk.has_face_adjacent_element_graph()); |
| 347 |
} |
| 348 |
|
| 349 |
bool isEntityConnectedToOwnedSelectedElement(stk::mesh::Entity entity, const stk::mesh::Selector& selector, stk::mesh::BulkData& bulk) |
| 350 |
{ |
| 351 |
stk::mesh::Selector alsoOwnedSelector = selector & bulk.mesh_meta_data().locally_owned_part(); |
| 352 |
bool foundSelectedElement = false; |
| 353 |
const stk::mesh::Entity* elemIt = bulk.begin_elements(entity); |
| 354 |
const stk::mesh::Entity* elemEndIt = bulk.end_elements(entity); |
| 355 |
for (; (elemIt != elemEndIt) && !foundSelectedElement; ++elemIt) |
| 356 |
{ |
| 357 |
if (alsoOwnedSelector(bulk.bucket(*elemIt))) |
| 358 |
{ |
| 359 |
foundSelectedElement= true; |
| 360 |
} |
| 361 |
} |
| 362 |
return foundSelectedElement; |
| 363 |
} |
| 364 |
|
| 365 |
void test_cloned_submesh(stk::mesh::BulkData &oldBulk, const stk::mesh::Selector ©Selector, const stk::mesh::BulkData &newBulk) |
| 366 |
{ |
| 367 |
expect_equal_entity_counts(oldBulk, copySelector, newBulk); |
| 368 |
|
| 369 |
const stk::mesh::MetaData &oldMeta = oldBulk.mesh_meta_data(); |
| 370 |
ASSERT_EQ(5u, static_cast<unsigned>(oldMeta.entity_rank_count())); |
| 371 |
stk::mesh::Selector localOrSharedSelector = copySelector & (oldMeta.locally_owned_part() | oldMeta.globally_shared_part()); |
| 372 |
stk::mesh::EntityRank endRank = static_cast<stk::mesh::EntityRank>(oldMeta.entity_rank_count()); |
| 373 |
stk::mesh::EntityVector oldEntities; |
| 374 |
for(stk::mesh::EntityRank rank = stk::topology::NODE_RANK; rank < endRank; rank++) |
| 375 |
{ |
| 376 |
stk::mesh::get_selected_entities(localOrSharedSelector, oldBulk.buckets(rank), oldEntities); |
| 377 |
for(stk::mesh::Entity oldEntity : oldEntities) |
| 378 |
{ |
| 379 |
bool shouldBeValidInNewBulk = isEntityConnectedToOwnedSelectedElement(oldEntity, copySelector, oldBulk); |
| 380 |
if (shouldBeValidInNewBulk) |
| 381 |
{ |
| 382 |
stk::mesh::Entity newEntity = newBulk.get_entity(rank, oldBulk.identifier(oldEntity)); |
| 383 |
ASSERT_TRUE(newBulk.is_valid(newEntity)) << "Entity = " << oldBulk.entity_key(oldEntity); |
| 384 |
if (rank < stk::topology::ELEM_RANK) |
| 385 |
{ |
| 386 |
expect_superset_sharing(oldBulk, oldEntity, newBulk, newEntity); |
| 387 |
} |
| 388 |
//expect_equal_relations(copySelector, oldBulk, oldEntity, newBulk, newEntity, endRank); // Faces are different |
| 389 |
expect_equal_field_data(oldBulk, oldEntity, newBulk, newEntity, rank); |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
ASSERT_EQ(oldBulk.has_face_adjacent_element_graph(), newBulk.has_face_adjacent_element_graph()); |
| 394 |
} |
| 395 |
|
| 396 |
void expect_equal_entity_part_ordinals(stk::mesh::BulkData &oldBulk, const stk::mesh::Selector &oldSelector, stk::mesh::BulkData &newBulk) |
| 397 |
{ |
| 398 |
stk::mesh::Selector newSelector = newBulk.mesh_meta_data().universal_part(); |
| 399 |
stk::mesh::EntityRank endRank = static_cast<stk::mesh::EntityRank>(oldBulk.mesh_meta_data().entity_rank_count()); |
| 400 |
for(stk::mesh::EntityRank rank = stk::topology::NODE_RANK; rank < endRank; rank++) |
| 401 |
{ |
| 402 |
const stk::mesh::BucketVector &oldBuckets = oldBulk.get_buckets(rank, oldSelector); |
| 403 |
const stk::mesh::BucketVector &newBuckets = newBulk.get_buckets(rank, newSelector); |
| 404 |
ASSERT_EQ(oldBuckets.size(), newBuckets.size()); |
| 405 |
for(size_t b = 0; b < oldBuckets.size(); b++) |
| 406 |
{ |
| 407 |
const stk::mesh::Bucket &oldBucket = *oldBuckets[b]; |
| 408 |
const stk::mesh::Bucket &newBucket = *newBuckets[b]; |
| 409 |
ASSERT_EQ(oldBucket.size(), newBucket.size()); |
| 410 |
|
| 411 |
const stk::mesh::PartVector &oldParts = oldBucket.supersets(); |
| 412 |
const stk::mesh::PartVector &newParts = newBucket.supersets(); |
| 413 |
ASSERT_EQ(oldParts.size(), newParts.size()); |
| 414 |
for(size_t p = 0; p < oldParts.size(); p++) |
| 415 |
EXPECT_EQ(oldParts[p]->mesh_meta_data_ordinal(), newParts[p]->mesh_meta_data_ordinal()); |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
}; |
| 420 |
|
| 421 |
TEST_F(CloningMesh, cloningBulkDataNoAura_selector) |
| 422 |
{ |
| 423 |
setup_empty_mesh(get_no_auto_aura_option()); |
| 424 |
declare_parts(); |
| 425 |
stk::io::fill_mesh(get_mesh_spec_for_1x1x8_with_sideset(), get_bulk()); |
| 426 |
move_half_of_mesh_to_block2(); |
| 427 |
create_constraints(); |
| 428 |
do_clone_test_with_submesh_selector(get_no_auto_aura_option()); |
| 429 |
} |
| 430 |
|
| 431 |
TEST_F(CloningMesh, cloningBulkDataWithAura_selector) |
| 432 |
{ |
| 433 |
stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::AUTO_AURA; |
| 434 |
setup_empty_mesh(auraOption); |
| 435 |
declare_parts(); |
| 436 |
stk::io::fill_mesh(get_mesh_spec_for_1x1x8_with_sideset(), get_bulk()); |
| 437 |
move_half_of_mesh_to_block2(); |
| 438 |
create_constraints(); |
| 439 |
do_clone_test_with_submesh_selector(auraOption); |
| 440 |
} |
| 441 |
|
| 442 |
TEST_F(CloningMesh, cloningBulkDataWithFacesAndAura_selector) |
| 443 |
{ |
| 444 |
stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::AUTO_AURA; |
| 445 |
setup_empty_mesh(auraOption); |
| 446 |
declare_parts(); |
| 447 |
stk::io::fill_mesh(get_mesh_spec_for_1x1x8_with_sideset(), get_bulk()); |
| 448 |
stk::mesh::create_all_sides(get_bulk(), get_meta().universal_part(), stk::mesh::PartVector{}, true); |
| 449 |
move_half_of_mesh_to_block2(); |
| 450 |
create_constraints(); |
| 451 |
do_clone_test_with_submesh_selector(auraOption); |
| 452 |
} |
| 453 |
|
| 454 |
TEST_F(CloningMesh, cloningBulkDataNoAura_same) |
| 455 |
{ |
| 456 |
setup_mesh(get_mesh_spec_for_1x1x8_with_sideset(), get_no_auto_aura_option()); |
| 457 |
do_clone_test(get_no_auto_aura_option()); |
| 458 |
} |
| 459 |
|
| 460 |
TEST_F(CloningMesh, cloningBulkDataWithAura_same) |
| 461 |
{ |
| 462 |
stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::AUTO_AURA; |
| 463 |
setup_mesh(get_mesh_spec_for_1x1x8_with_sideset(), auraOption); |
| 464 |
do_clone_test(auraOption); |
| 465 |
} |
| 466 |
|
| 467 |
TEST_F(CloningMesh, cloningBulkDataWithFacesAndAura_same) |
| 468 |
{ |
| 469 |
stk::mesh::BulkData::AutomaticAuraOption auraOption = stk::mesh::BulkData::AUTO_AURA; |
| 470 |
setup_mesh(get_mesh_spec_for_1x1x8_with_sideset(), auraOption); |
| 471 |
stk::mesh::create_all_sides(get_bulk(), get_meta().universal_part(), stk::mesh::PartVector{}, true); |
| 472 |
do_clone_test(auraOption); |
| 473 |
} |
| 474 |
|
| 475 |
TEST_F(CloningMesh, cloningBulkData_modifiableStateThrows) |
| 476 |
{ |
| 477 |
setup_mesh(get_mesh_spec_for_1x1x8_with_sideset(), get_no_auto_aura_option()); |
| 478 |
|
| 479 |
stk::mesh::BulkData & oldBulk = get_bulk(); |
| 480 |
std::shared_ptr<stk::mesh::BulkData> newBulkPtr = build_mesh(oldBulk.parallel(), get_no_auto_aura_option()); |
| 481 |
stk::mesh::BulkData& newBulk = *newBulkPtr; |
| 482 |
oldBulk.modification_begin(); |
| 483 |
|
| 484 |
ASSERT_THROW(stk::tools::copy_mesh(oldBulk, get_meta().universal_part(), newBulk), std::logic_error); |
| 485 |
} |
| 486 |
|
| 487 |
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) |
| 488 |
//portability issue: bulk-data size seems to be different (48 bytes smaller) on intel 15.0 |
| 489 |
//running this test on gcc should be sufficient to detect addition/deletion of class members. |
| 490 |
|
| 491 |
TEST(BulkDataSize, sizeChanges_needToUpdateCopyMesh) |
| 492 |
{ |
| 493 |
// KHP: different compilers (and different version of a compiler) give different values for the sizeof bulk. |
| 494 |
// Only test on gcc 4.9.3 for now. |
| 495 |
#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) |
| 496 |
std::shared_ptr<stk::mesh::BulkData> bulk = build_mesh(3, MPI_COMM_WORLD); |
| 497 |
EXPECT_TRUE(1176u >= sizeof(*bulk)) << "Size of BulkData changed. Does mesh copying capability need to be updated?"; |
| 498 |
#endif |
| 499 |
} |
| 500 |
|
| 501 |
#endif |
| 502 |
|
| 503 |
} |