| 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_EQ, etc |
| 36 |
#include <stddef.h> // for size_t, NULL |
| 37 |
#include <string.h> // for memcpy |
| 38 |
#include <unistd.h> // for unlink |
| 39 |
#include <iostream> // for operator<<, etc |
| 40 |
#include <map> // for map, etc |
| 41 |
#include <set> // for set, operator==, etc |
| 42 |
#include <stk_mesh/base/GetEntities.hpp> // for count_entities |
| 43 |
#include <string> // for string, basic_string, etc |
| 44 |
#include <utility> // for make_pair, pair |
| 45 |
#include <vector> // for vector |
| 46 |
#include <stk_unit_test_utils/BulkDataTester.hpp> |
| 47 |
#include "mpi.h" // for MPI_Comm_size, etc |
| 48 |
#include "stk_io/DatabasePurpose.hpp" // for DatabasePurpose::READ_MESH, etc |
| 49 |
#include "stk_io/IossBridge.hpp" // for is_part_io_part, etc |
| 50 |
#include "stk_io/StkMeshIoBroker.hpp" // for StkMeshIoBroker |
| 51 |
#include "stk_mesh/base/Bucket.hpp" // for Bucket |
| 52 |
#include "stk_mesh/base/Entity.hpp" // for Entity |
| 53 |
#include "stk_mesh/base/Field.hpp" // for Field |
| 54 |
#include "stk_mesh/base/FieldBase.hpp" // for FieldBase, field_data, etc |
| 55 |
#include "stk_mesh/base/MetaData.hpp" // for MetaData, put_field |
| 56 |
#include "stk_mesh/base/Part.hpp" // for Part |
| 57 |
#include "stk_mesh/base/Selector.hpp" // for Selector, operator|, etc |
| 58 |
#include "stk_mesh/base/Types.hpp" // for PartVector, EntityProc, etc |
| 59 |
#include "stk_mesh/base/FEMHelpers.hpp" |
| 60 |
#include "stk_topology/topology.hpp" // for topology, etc |
| 61 |
#include "stk_mesh/baseImpl/MeshImplUtils.hpp" |
| 62 |
#include <stk_tools/mesh_clone/MeshClone.hpp> |
| 63 |
|
| 64 |
namespace stk { namespace mesh { class BulkData; } } |
| 65 |
namespace stk { namespace mesh { namespace fixtures { class BoxFixture; } } } |
| 66 |
namespace stk { namespace mesh { namespace fixtures { class RingFixture; } } } |
| 67 |
namespace stk { namespace mesh { struct EntityKey; } } |
| 68 |
namespace stk { namespace mesh { class FieldBase; } } |
| 69 |
|
| 70 |
namespace |
| 71 |
{ |
| 72 |
|
| 73 |
void testSubMesh(stk::unit_test_util::BulkDataTester &oldBulkData, stk::mesh::Selector select, int elementToTestId, size_t goldNumberNodes, size_t goldNumberElements) |
| 74 |
{ |
| 75 |
const stk::mesh::MetaData &oldMetaData = oldBulkData.mesh_meta_data(); |
| 76 |
stk::mesh::MetaData newMetaData; |
| 77 |
stk::unit_test_util::BulkDataTester newBulkData(newMetaData, MPI_COMM_SELF); |
| 78 |
|
| 79 |
stk::tools::copy_mesh(oldBulkData, select, newBulkData); |
| 80 |
|
| 81 |
const stk::mesh::PartVector &oldParts = oldMetaData.get_parts(); |
| 82 |
const stk::mesh::PartVector &newParts = newMetaData.get_parts(); |
| 83 |
ASSERT_EQ(oldParts.size(), newParts.size()); |
| 84 |
for(size_t i=0; i<oldParts.size(); i++) |
| 85 |
{ |
| 86 |
EXPECT_EQ(oldParts[i]->name(), newParts[i]->name()); |
| 87 |
EXPECT_EQ(stk::io::is_part_io_part(*oldParts[i]), stk::io::is_part_io_part(*newParts[i])); |
| 88 |
} |
| 89 |
|
| 90 |
std::vector<size_t> entityCounts; |
| 91 |
stk::mesh::count_entities(newMetaData.universal_part(), newBulkData, entityCounts); |
| 92 |
EXPECT_EQ(goldNumberElements, entityCounts[stk::topology::ELEMENT_RANK]); |
| 93 |
EXPECT_EQ(goldNumberNodes, entityCounts[stk::topology::NODE_RANK]); |
| 94 |
|
| 95 |
stk::mesh::Entity elementParallel = oldBulkData.get_entity(stk::topology::ELEMENT_RANK, elementToTestId); |
| 96 |
stk::mesh::Entity elementSerial = newBulkData.get_entity(stk::topology::ELEMENT_RANK, elementToTestId); |
| 97 |
EXPECT_EQ(oldBulkData.identifier(elementParallel), newBulkData.identifier(elementSerial)); |
| 98 |
unsigned numNodesParallel = oldBulkData.num_nodes(elementParallel); |
| 99 |
unsigned numNodesSerial = newBulkData.num_nodes(elementSerial); |
| 100 |
ASSERT_EQ(numNodesParallel, numNodesSerial); |
| 101 |
|
| 102 |
const stk::mesh::Entity *nodesParallel = oldBulkData.begin_nodes(elementParallel); |
| 103 |
const stk::mesh::Entity *nodesSerial = newBulkData.begin_nodes(elementSerial); |
| 104 |
std::set<stk::mesh::EntityId> parallelNodeIds; |
| 105 |
std::set<stk::mesh::EntityId> serialNodeIds; |
| 106 |
for(unsigned i = 0; i < numNodesParallel; i++) |
| 107 |
{ |
| 108 |
parallelNodeIds.insert(oldBulkData.identifier(nodesParallel[i])); |
| 109 |
serialNodeIds.insert(newBulkData.identifier(nodesSerial[i])); |
| 110 |
} |
| 111 |
EXPECT_TRUE(parallelNodeIds == serialNodeIds); |
| 112 |
|
| 113 |
|
| 114 |
const stk::mesh::FieldVector &oldFields = oldMetaData.get_fields(); |
| 115 |
const stk::mesh::FieldVector &newFields = newMetaData.get_fields(); |
| 116 |
ASSERT_EQ(oldFields.size(), newFields.size()); |
| 117 |
for(size_t i=0; i<oldFields.size(); i++) |
| 118 |
{ |
| 119 |
EXPECT_EQ(oldFields[i]->name(), newFields[i]->name()); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
TEST(CloningParallelMesh, destinationHasMpiCommSelf_destinationHasAuraEntities) |
| 124 |
{ |
| 125 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 126 |
int numProcs = -1; |
| 127 |
MPI_Comm_size(comm, &numProcs); |
| 128 |
if(numProcs == 2) |
| 129 |
{ |
| 130 |
std::string exodusFileName = "generated:1x1x4|sideset:xXyYzZ|nodeset:xXyYzZ"; |
| 131 |
const int spatialDim = 3; |
| 132 |
stk::mesh::MetaData stkMeshMetaData(spatialDim); |
| 133 |
stk::unit_test_util::BulkDataTester stkMeshBulkData(stkMeshMetaData, comm); |
| 134 |
|
| 135 |
stk::io::StkMeshIoBroker exodusFileReader(comm); |
| 136 |
|
| 137 |
exodusFileReader.set_bulk_data(stkMeshBulkData); |
| 138 |
exodusFileReader.add_mesh_database(exodusFileName, stk::io::READ_MESH); |
| 139 |
exodusFileReader.create_input_mesh(); |
| 140 |
exodusFileReader.populate_bulk_data(); |
| 141 |
|
| 142 |
{ |
| 143 |
stk::mesh::Selector sel = stkMeshMetaData.universal_part(); |
| 144 |
int elementToTestId = 3; |
| 145 |
size_t goldNumberNodes = 16; |
| 146 |
size_t goldNumberElements = 3; |
| 147 |
|
| 148 |
testSubMesh(stkMeshBulkData, sel, elementToTestId, goldNumberNodes, goldNumberElements); |
| 149 |
} |
| 150 |
|
| 151 |
{ |
| 152 |
stk::mesh::Selector sel = stkMeshMetaData.locally_owned_part() | stkMeshMetaData.globally_shared_part(); |
| 153 |
int elementToTestId = 2 + stkMeshBulkData.parallel_rank(); |
| 154 |
size_t goldNumberNodes = 12; |
| 155 |
size_t goldNumberElements = 2; |
| 156 |
|
| 157 |
testSubMesh(stkMeshBulkData, sel, elementToTestId, goldNumberNodes, goldNumberElements); |
| 158 |
} |
| 159 |
|
| 160 |
{ |
| 161 |
stk::mesh::Part *part = stkMeshMetaData.get_part("block_1"); |
| 162 |
stk::mesh::Selector sel = *part; |
| 163 |
int elementToTestId = 2 + stkMeshBulkData.parallel_rank(); |
| 164 |
size_t goldNumberNodes = 16; |
| 165 |
size_t goldNumberElements = 3; |
| 166 |
|
| 167 |
testSubMesh(stkMeshBulkData, sel, elementToTestId, goldNumberNodes, goldNumberElements); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
} |