| 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 |
|
| 36 |
|
| 37 |
#include "../stk_unit_tests/stk_mesh/Setup8Quad4ProcMesh.hpp" |
| 38 |
#include "stk_io/StkMeshIoBroker.hpp" |
| 39 |
#include "stk_io/FillMesh.hpp" |
| 40 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket, has_superset |
| 41 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 42 |
#include "stk_mesh/base/EntityKey.hpp" // for EntityKey |
| 43 |
#include "stk_mesh/base/Field.hpp" // for Field |
| 44 |
#include "stk_mesh/base/FieldBase.hpp" // for field_data, etc |
| 45 |
#include "stk_mesh/base/Ghosting.hpp" // for Ghosting |
| 46 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData, entity_rank_names, etc |
| 47 |
#include "stk_mesh/base/Part.hpp" // for Part |
| 48 |
#include "stk_mesh/base/Relation.hpp" |
| 49 |
#include "stk_mesh/base/Selector.hpp" // for Selector, operator| |
| 50 |
#include "stk_mesh/base/Types.hpp" // for EntityProc, EntityVector, etc |
| 51 |
#include "stk_mesh/baseImpl/MeshImplUtils.hpp" |
| 52 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 53 |
#include "stk_util/util/PairIter.hpp" // for PairIter |
| 54 |
#include <algorithm> // for sort |
| 55 |
#include <exception> // for exception |
| 56 |
#include <gtest/gtest.h> |
| 57 |
#include <iostream> // for ostringstream, etc |
| 58 |
#include <iterator> // for distance |
| 59 |
#include <map> // for _Rb_tree_const_iterator, etc |
| 60 |
#include <stddef.h> // for size_t |
| 61 |
#include <stdexcept> // for logic_error, runtime_error |
| 62 |
#include <stdlib.h> // for exit |
| 63 |
#include <stk_mesh/base/BulkData.hpp> // for BulkData, etc |
| 64 |
#include <stk_mesh/base/Comm.hpp> |
| 65 |
#include <stk_mesh/base/FEMHelpers.hpp> // for declare_element |
| 66 |
#include <stk_mesh/base/FieldBLAS.hpp> // for stk::mesh::field_fill |
| 67 |
#include <stk_mesh/base/FieldParallel.hpp> // for communicate_field_data, etc |
| 68 |
#include <stk_mesh/base/GetEntities.hpp> // for count_entities, etc |
| 69 |
#include <stk_unit_test_utils/BulkDataTester.hpp> |
| 70 |
#include <stk_unit_test_utils/getOption.h> |
| 71 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 72 |
#include <stk_util/parallel/Parallel.hpp> // for ParallelMachine, etc |
| 73 |
#include <string> // for string, basic_string, etc |
| 74 |
#include <utility> // for pair |
| 75 |
#include <vector> // for vector, etc |
| 76 |
|
| 77 |
namespace |
| 78 |
{ |
| 79 |
using stk::unit_test_util::build_mesh; |
| 80 |
|
| 81 |
//BEGIN_DOC1 |
| 82 |
TEST(BulkData_test, use_entity_ids_for_resolving_sharing) |
| 83 |
{ |
| 84 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 85 |
|
| 86 |
const int spatialDim = 3; |
| 87 |
stk::mesh::MetaData stkMeshMetaData(spatialDim); |
| 88 |
stk::unit_test_util::BulkDataTester stkMeshBulkData(stkMeshMetaData, communicator); |
| 89 |
|
| 90 |
if(stkMeshBulkData.parallel_size() == 2) |
| 91 |
{ |
| 92 |
std::string exodusFileName = stk::unit_test_util::get_option("-i", "mesh.exo"); |
| 93 |
|
| 94 |
stk::io::fill_mesh(exodusFileName, stkMeshBulkData); |
| 95 |
} |
| 96 |
|
| 97 |
stkMeshBulkData.set_use_entity_ids_for_resolving_sharing(false); |
| 98 |
EXPECT_FALSE(stkMeshBulkData.use_entity_ids_for_resolving_sharing()); |
| 99 |
|
| 100 |
stkMeshBulkData.set_use_entity_ids_for_resolving_sharing(true); |
| 101 |
EXPECT_TRUE(stkMeshBulkData.use_entity_ids_for_resolving_sharing()); |
| 102 |
} |
| 103 |
|
| 104 |
TEST(BulkData_test, testTwoDimProblemForSharingOfDifferentEdgesWithSameNodesFourProc) |
| 105 |
{ |
| 106 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 107 |
const int spatialDim = 2; |
| 108 |
stk::mesh::MetaData stkMeshMetaData(spatialDim); |
| 109 |
stk::unit_test_util::BulkDataTester stkMeshBulkData(stkMeshMetaData, communicator); |
| 110 |
|
| 111 |
if ( stkMeshBulkData.parallel_size() == 4 ) |
| 112 |
{ |
| 113 |
std::string exodusFileName = stk::unit_test_util::get_option("-i", "mesh.exo"); |
| 114 |
|
| 115 |
stk::io::fill_mesh(exodusFileName, stkMeshBulkData); |
| 116 |
|
| 117 |
std::vector<size_t> globalCounts; |
| 118 |
stk::mesh::comm_mesh_counts(stkMeshBulkData, globalCounts); |
| 119 |
EXPECT_EQ(15u, globalCounts[stk::topology::EDGE_RANK]); |
| 120 |
} |
| 121 |
} |
| 122 |
//END_DOC1 |
| 123 |
|
| 124 |
TEST(BulkData_test, test3DProblemSharingOfDifferentFacesWithSameNodesTwoProc) |
| 125 |
{ |
| 126 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 127 |
|
| 128 |
const int spatialDim = 3; |
| 129 |
stk::mesh::MetaData stkMeshMetaData(spatialDim); |
| 130 |
stk::unit_test_util::BulkDataTester stkMeshBulkData(stkMeshMetaData, communicator); |
| 131 |
|
| 132 |
if ( stkMeshBulkData.parallel_size() == 2 ) |
| 133 |
{ |
| 134 |
std::string exodusFileName = stk::unit_test_util::get_option("-i", "mesh.exo"); |
| 135 |
|
| 136 |
{ |
| 137 |
stk::io::StkMeshIoBroker exodusFileReader(communicator); |
| 138 |
exodusFileReader.set_sideset_face_creation_behavior(stk::io::StkMeshIoBroker::STK_IO_SIDESET_FACE_CREATION_CURRENT); |
| 139 |
stk::io::fill_mesh_preexisting(exodusFileReader, exodusFileName, stkMeshBulkData); |
| 140 |
} |
| 141 |
|
| 142 |
std::vector<size_t> globalCounts; |
| 143 |
stk::mesh::comm_mesh_counts(stkMeshBulkData, globalCounts); |
| 144 |
EXPECT_EQ(2u, globalCounts[stk::topology::FACE_RANK]); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
TEST(BulkData_test, test3DProblemSharingOfDifferentFacesWithSameNodesOneProc) |
| 149 |
{ |
| 150 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 151 |
|
| 152 |
const int spatialDim = 3; |
| 153 |
stk::mesh::MetaData stkMeshMetaData(spatialDim); |
| 154 |
stk::unit_test_util::BulkDataTester stkMeshBulkData(stkMeshMetaData, communicator); |
| 155 |
if ( stkMeshBulkData.parallel_size() == 1 ) |
| 156 |
{ |
| 157 |
std::string exodusFileName = stk::unit_test_util::get_option("-i", "mesh.exo"); |
| 158 |
|
| 159 |
{ |
| 160 |
stk::io::StkMeshIoBroker exodusFileReader(communicator); |
| 161 |
exodusFileReader.set_sideset_face_creation_behavior(stk::io::StkMeshIoBroker::STK_IO_SIDESET_FACE_CREATION_CURRENT); |
| 162 |
stk::io::fill_mesh_preexisting(exodusFileReader, exodusFileName, stkMeshBulkData); |
| 163 |
} |
| 164 |
|
| 165 |
std::vector<size_t> globalCounts; |
| 166 |
stk::mesh::comm_mesh_counts(stkMeshBulkData, globalCounts); |
| 167 |
EXPECT_EQ(1u, globalCounts[stk::topology::FACE_RANK]); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
TEST(IntegrationTest, PartChangeGenerated) |
| 172 |
{ |
| 173 |
//demonstrates expected behavior, no shells so part changes work fine. see ticket 13216 |
| 174 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 175 |
|
| 176 |
const int spatialDim = 3; |
| 177 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 178 |
stk::mesh::BulkData& stkMeshBulkData = *bulkPtr; |
| 179 |
stk::mesh::MetaData& stkMeshMetaData = stkMeshBulkData.mesh_meta_data(); |
| 180 |
if (stkMeshBulkData.parallel_size() != 4) return; |
| 181 |
stk::mesh::Part& partToAdd = stkMeshMetaData.declare_part("urp_part", stk::topology::ELEM_RANK); |
| 182 |
stk::mesh::PartVector add_parts; |
| 183 |
add_parts.push_back(&partToAdd); |
| 184 |
|
| 185 |
{ |
| 186 |
stk::io::StkMeshIoBroker exodusFileReader(communicator); |
| 187 |
exodusFileReader.property_add(Ioss::Property("DECOMPOSITION_METHOD", "RIB")); |
| 188 |
stk::io::fill_mesh_preexisting(exodusFileReader, "generated:1x1x4", stkMeshBulkData); |
| 189 |
stkMeshBulkData.modification_begin(); |
| 190 |
stk::mesh::EntityVector entities; |
| 191 |
stk::mesh::Selector select_owned(stkMeshMetaData.locally_owned_part()); |
| 192 |
{ |
| 193 |
const stk::mesh::BucketVector &buckets = stkMeshBulkData.get_buckets(stk::topology::ELEM_RANK, select_owned); |
| 194 |
for(size_t i = 0; i < buckets.size(); ++i) |
| 195 |
{ |
| 196 |
for (unsigned j = 0; j < buckets[i]->size(); j++) { |
| 197 |
stk::mesh::Entity entity = (*buckets[i])[j]; |
| 198 |
entities.push_back(entity); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
for (size_t i = 0; i < entities.size(); ++i) { |
| 203 |
stkMeshBulkData.change_entity_parts(entities[i], add_parts); |
| 204 |
} |
| 205 |
EXPECT_NO_THROW(stkMeshBulkData.modification_end()); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
TEST(IntegrationTest, ShellPartChangeCylinder) |
| 210 |
{ |
| 211 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 212 |
if (stk::parallel_machine_size(communicator) != 4) { GTEST_SKIP(); } |
| 213 |
|
| 214 |
const std::string exodusFileName = "cyl_3block.g"; |
| 215 |
|
| 216 |
const int spatialDim = 3; |
| 217 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 218 |
stk::mesh::BulkData& stkMeshBulkData = *bulkPtr; |
| 219 |
stk::mesh::MetaData& stkMeshMetaData = stkMeshBulkData.mesh_meta_data(); |
| 220 |
stk::mesh::PartVector add_parts {&stkMeshMetaData.declare_part("urp_part", stk::topology::ELEM_RANK)}; |
| 221 |
|
| 222 |
stk::io::StkMeshIoBroker exodusFileReader(communicator); |
| 223 |
exodusFileReader.property_add(Ioss::Property("DECOMPOSITION_METHOD", "RIB")); |
| 224 |
stk::io::fill_mesh_preexisting(exodusFileReader, exodusFileName, stkMeshBulkData); |
| 225 |
stk::mesh::EntityVector entities; |
| 226 |
stk::mesh::get_entities(stkMeshBulkData, stk::topology::ELEM_RANK, stkMeshMetaData.locally_owned_part(), entities); |
| 227 |
stkMeshBulkData.modification_begin(); |
| 228 |
stkMeshBulkData.change_entity_parts(entities, add_parts); |
| 229 |
EXPECT_NO_THROW(stkMeshBulkData.modification_end()); |
| 230 |
} |
| 231 |
|
| 232 |
// now using graph to create faces during mesh read, split coincident test cases fail |
| 233 |
TEST(IntegrationTest, ShellPartChange2Hexes2Shells) |
| 234 |
{ |
| 235 |
//demonstrates failing when reading a mesh with shells and changing parts, see ticket 13216 |
| 236 |
MPI_Comm communicator = MPI_COMM_WORLD; |
| 237 |
const std::string exodusFileName = "ALefLRA.e"; |
| 238 |
|
| 239 |
const int spatialDim = 3; |
| 240 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(spatialDim, communicator); |
| 241 |
stk::mesh::BulkData& stkMeshBulkData = *bulkPtr; |
| 242 |
stk::mesh::MetaData& stkMeshMetaData = stkMeshBulkData.mesh_meta_data(); |
| 243 |
if (stkMeshBulkData.parallel_size() != 4) return; |
| 244 |
stk::mesh::Part& partToAdd = stkMeshMetaData.declare_part("urp_part", stk::topology::ELEM_RANK); |
| 245 |
stk::mesh::PartVector add_parts; |
| 246 |
add_parts.push_back(&partToAdd); |
| 247 |
|
| 248 |
|
| 249 |
stk::io::StkMeshIoBroker exodusFileReader(communicator); |
| 250 |
exodusFileReader.property_add(Ioss::Property("DECOMPOSITION_METHOD", "RIB")); |
| 251 |
stk::io::fill_mesh_preexisting(exodusFileReader, exodusFileName, stkMeshBulkData); |
| 252 |
stk::mesh::EntityVector entities; |
| 253 |
stk::mesh::Selector select_owned(stkMeshMetaData.locally_owned_part()); |
| 254 |
|
| 255 |
{ |
| 256 |
const stk::mesh::BucketVector &buckets = stkMeshBulkData.get_buckets(stk::topology::ELEM_RANK, select_owned); |
| 257 |
for(size_t i = 0; i < buckets.size(); ++i) |
| 258 |
{ |
| 259 |
for (unsigned j = 0; j < buckets[i]->size(); j++) { |
| 260 |
stk::mesh::Entity entity = (*buckets[i])[j]; |
| 261 |
entities.push_back(entity); |
| 262 |
} |
| 263 |
} |
| 264 |
} |
| 265 |
stkMeshBulkData.modification_begin(); |
| 266 |
for (size_t i = 0; i < entities.size(); ++i) { |
| 267 |
stkMeshBulkData.change_entity_parts(entities[i], add_parts); |
| 268 |
} |
| 269 |
EXPECT_NO_THROW(stkMeshBulkData.modification_end()); |
| 270 |
} |
| 271 |
|
| 272 |
} |
| 273 |
// empty namespace |