| 1 |
#include <gtest/gtest.h> |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
#include <algorithm> |
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
#include <stk_topology/topology.hpp> |
| 8 |
#include <stk_mesh/base/BulkData.hpp> |
| 9 |
#include <stk_mesh/base/MetaData.hpp> |
| 10 |
#include <stk_mesh/base/Comm.hpp> |
| 11 |
#include <stk_mesh/base/GetEntities.hpp> |
| 12 |
#include <stk_mesh/base/FEMHelpers.hpp> |
| 13 |
#include <stk_mesh/baseImpl/MeshImplUtils.hpp> |
| 14 |
#include <stk_mesh/base/Field.hpp> |
| 15 |
|
| 16 |
#include <stk_mesh/base/SkinMesh.hpp> |
| 17 |
#include <stk_mesh/base/CreateFaces.hpp> |
| 18 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> |
| 19 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp> |
| 20 |
|
| 21 |
#include <stk_util/parallel/Parallel.hpp> |
| 22 |
#include <stk_util/parallel/ParallelVectorConcat.hpp> |
| 23 |
#include <stk_util/parallel/ParallelComm.hpp> |
| 24 |
#include <stk_util/environment/WallTime.hpp> |
| 25 |
#include <stk_util/environment/memory_util.hpp> |
| 26 |
#include <stk_util/parallel/CommSparse.hpp> |
| 27 |
#include <stk_util/util/ReportHandler.hpp> |
| 28 |
|
| 29 |
#include <stk_io/IossBridge.hpp> |
| 30 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 31 |
|
| 32 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 33 |
#include <stk_unit_test_utils/getOption.h> |
| 34 |
|
| 35 |
#include "stk_unit_test_utils/unittestMeshUtils.hpp" |
| 36 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 37 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 38 |
|
| 39 |
#include "SetupKeyholeMesh.hpp" |
| 40 |
#include "stk_unit_test_utils/stk_mesh_fixtures/QuadFixture.hpp" // for QuadFixture |
| 41 |
#include "stk_unit_test_utils/stk_mesh_fixtures/degenerate_mesh.hpp" |
| 42 |
#include "stk_unit_test_utils/stk_mesh_fixtures/heterogeneous_mesh.hpp" |
| 43 |
|
| 44 |
#include "UnitTestSkinMeshUseCaseUtils.hpp" |
| 45 |
|
| 46 |
namespace { |
| 47 |
|
| 48 |
using namespace stk::mesh::impl; |
| 49 |
using namespace stk::mesh; |
| 50 |
using stk::unit_test_util::build_mesh; |
| 51 |
|
| 52 |
TEST(ElementGraph, heterogeneous_mesh) |
| 53 |
{ |
| 54 |
stk::ParallelMachine comm = MPI_COMM_WORLD; |
| 55 |
|
| 56 |
if(stk::parallel_machine_size(comm) <= 17) |
| 57 |
{ |
| 58 |
std::string fileName("hetero.g"); |
| 59 |
{ |
| 60 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, MPI_COMM_SELF, stk::mesh::BulkData::NO_AUTO_AURA); |
| 61 |
stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data(); |
| 62 |
stk::mesh::BulkData& bulk_data = *bulkPtr; |
| 63 |
stk::mesh::fixtures::VectorFieldType & node_coord = |
| 64 |
meta_data.declare_field<double>(stk::topology::NODE_RANK, "coordinates"); |
| 65 |
stk::mesh::put_field_on_mesh( node_coord , meta_data.universal_part() , 3, nullptr); |
| 66 |
stk::io::set_field_output_type(node_coord, stk::io::FieldOutputType::VECTOR_3D); |
| 67 |
|
| 68 |
stk::mesh::fixtures::heterogeneous_mesh_meta_data( meta_data , node_coord ); |
| 69 |
meta_data.commit(); |
| 70 |
|
| 71 |
stk::mesh::fixtures::heterogeneous_mesh_bulk_data( bulk_data , node_coord ); |
| 72 |
if (stk::parallel_machine_rank(comm) == 0) |
| 73 |
{ |
| 74 |
stk::io::write_mesh(fileName, bulk_data); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
stk::parallel_machine_barrier(comm); |
| 79 |
|
| 80 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(3, comm, stk::mesh::BulkData::NO_AUTO_AURA); |
| 81 |
stk::mesh::MetaData& meta_data = bulkPtr->mesh_meta_data(); |
| 82 |
stk::mesh::BulkData& bulk_data = *bulkPtr; |
| 83 |
|
| 84 |
for(int i=1;i<=17;i++) |
| 85 |
{ |
| 86 |
std::ostringstream os; |
| 87 |
os << "skin_" << i; |
| 88 |
std::string part_name = os.str(); |
| 89 |
stk::mesh::Part &tmp = meta_data.declare_part(part_name, meta_data.side_rank()); |
| 90 |
stk::io::put_io_part_attribute(tmp); |
| 91 |
} |
| 92 |
|
| 93 |
stk::mesh::Part& skin = meta_data.declare_part("skin", meta_data.side_rank()); |
| 94 |
|
| 95 |
stk::unit_test_util::read_from_serial_file_and_decompose(fileName, bulk_data, "RIB"); |
| 96 |
unlink(fileName.c_str()); |
| 97 |
EXPECT_NO_FATAL_FAILURE(ElemGraphTestUtils::skin_boundary(bulk_data, meta_data.locally_owned_part(), {&skin})); |
| 98 |
std::vector<size_t> mesh_counts; |
| 99 |
stk::mesh::comm_mesh_counts(bulk_data, mesh_counts); |
| 100 |
EXPECT_EQ(23u, mesh_counts[meta_data.side_rank()]); |
| 101 |
|
| 102 |
std::vector<std::pair<stk::mesh::EntityId, int>> id_and_num_faces = { |
| 103 |
{7, 1}, |
| 104 |
{8, 1}, |
| 105 |
{9, 1}, |
| 106 |
{10, 2}, |
| 107 |
{11, 1}, |
| 108 |
{4, 2}, |
| 109 |
{5, 2}, |
| 110 |
{6, 2}, |
| 111 |
{1, 3}, |
| 112 |
{2, 2}, |
| 113 |
{3, 4}, |
| 114 |
{15, 0}, |
| 115 |
{16, 0}, |
| 116 |
{17, 1}, |
| 117 |
{12, 0}, |
| 118 |
{13, 0}, |
| 119 |
{14, 1} |
| 120 |
}; |
| 121 |
|
| 122 |
bulk_data.modification_begin(); |
| 123 |
|
| 124 |
for(size_t i=0;i<id_and_num_faces.size();++i) |
| 125 |
{ |
| 126 |
stk::mesh::EntityId id = id_and_num_faces[i].first; |
| 127 |
int gold_num_faces = id_and_num_faces[i].second; |
| 128 |
stk::mesh::Entity elem = bulk_data.get_entity(stk::topology::ELEM_RANK, id); |
| 129 |
if(bulk_data.is_valid(elem)) |
| 130 |
{ |
| 131 |
int num_faces = bulk_data.num_sides(elem); |
| 132 |
const stk::mesh::Entity *faces = bulk_data.begin_faces(elem); |
| 133 |
for(int j=0;j<num_faces;++j) |
| 134 |
{ |
| 135 |
std::ostringstream os; |
| 136 |
os << "skin_" << bulk_data.identifier(elem); |
| 137 |
stk::mesh::PartVector add_parts; |
| 138 |
add_parts.push_back(meta_data.get_part(os.str())); |
| 139 |
bulk_data.change_entity_parts(faces[j], add_parts, {}); |
| 140 |
|
| 141 |
} |
| 142 |
EXPECT_EQ(gold_num_faces, num_faces) << "element " << id << " has topology " << bulk_data.bucket(elem).topology() << " with num faces " << num_faces << " not same as gold value " << gold_num_faces << std::endl; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
bulk_data.modification_begin(); |
| 147 |
|
| 148 |
//stk::io::write_mesh("heter.g", bulk_data, comm); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
} |