| 1 |
/*--------------------------------------------------------------------*/ |
| 2 |
/* Copyright 2002 - 2008, 2010, 2011 National Technology & */ |
| 3 |
/* Engineering Solutions of Sandia, LLC (NTESS). Under the terms */ |
| 4 |
/* of Contract DE-NA0003525 with NTESS, there is a */ |
| 5 |
/* non-exclusive license for use of this work by or on behalf */ |
| 6 |
/* of the U.S. Government. Export of this program may require */ |
| 7 |
/* a license from the United States Government. */ |
| 8 |
/*--------------------------------------------------------------------*/ |
| 9 |
|
| 10 |
#include <gtest/gtest.h> // for AssertHelper, EXPECT_EQ, etc |
| 11 |
#include <stddef.h> // for size_t, nullptr |
| 12 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraph.hpp> |
| 13 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 14 |
#include <stk_unit_test_utils/MeshFixture.hpp> // for MeshTestFixture |
| 15 |
#include <stk_unit_test_utils/FaceCreationTestUtils.hpp> |
| 16 |
#include <stk_unit_test_utils/BuildMesh.hpp> |
| 17 |
#include "mpi.h" |
| 18 |
#include <map> |
| 19 |
#include <string> |
| 20 |
#include <stk_mesh/baseImpl/EquivalentEntityBlocks.hpp> |
| 21 |
#include <stk_mesh/base/MeshDiagnostics.hpp> |
| 22 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
using stk::unit_test_util::build_mesh; |
| 26 |
|
| 27 |
struct SplitElementInfo |
| 28 |
{ |
| 29 |
stk::mesh::EntityId localElementId; |
| 30 |
stk::mesh::EntityId remoteElementId; |
| 31 |
int neighboringProc; |
| 32 |
}; |
| 33 |
|
| 34 |
struct TestCase |
| 35 |
{ |
| 36 |
std::string filename; |
| 37 |
int maxNumProcs; |
| 38 |
std::vector<std::vector<SplitElementInfo>> expectedSplitElementsPerProc; |
| 39 |
}; |
| 40 |
|
| 41 |
typedef std::vector<TestCase> TestCaseData; |
| 42 |
|
| 43 |
const TestCaseData badDecomps = |
| 44 |
{ |
| 45 |
/* filename, #procs, {local element id, remoted element id, remote proc} */ |
| 46 |
{"Aef.e", 2, { {{3u, 2u, 1}}, {{2u, 3u, 0}} }}, |
| 47 |
{"ef.e", 2, { {{1u, 2u, 1}}, {{2u, 1u, 0}} }}, |
| 48 |
{"AefB.e", 3, { {}, {{2u, 3u, 2}}, {{3u, 2u, 1}} }}, |
| 49 |
{"AP.e", 2, { {{1u, 2u, 1}}, {{2u, 1u, 0}} }} |
| 50 |
}; |
| 51 |
|
| 52 |
void expect_split_coincidents(const stk::mesh::BulkData &bulkData, |
| 53 |
const std::vector<std::vector<SplitElementInfo>> &expectedSplitElementsPerProc, |
| 54 |
const stk::mesh::SplitCoincidentInfo &splitCoincidentElements) |
| 55 |
{ |
| 56 |
const std::vector<SplitElementInfo> &expectedSplits = expectedSplitElementsPerProc[bulkData.parallel_rank()]; |
| 57 |
ASSERT_EQ(expectedSplits.size(), splitCoincidentElements.size()); |
| 58 |
auto foundSplitCoincident = splitCoincidentElements.begin(); |
| 59 |
for(size_t i = 0; i < expectedSplits.size(); i++) |
| 60 |
{ |
| 61 |
EXPECT_EQ(expectedSplits[i].localElementId, foundSplitCoincident->first); |
| 62 |
EXPECT_EQ(expectedSplits[i].remoteElementId, foundSplitCoincident->second[0].first); |
| 63 |
EXPECT_EQ(expectedSplits[i].neighboringProc, foundSplitCoincident->second[0].second); |
| 64 |
foundSplitCoincident++; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
class MeshChecker : public ::testing::Test |
| 69 |
{ |
| 70 |
public: |
| 71 |
MeshChecker() |
| 72 |
{ |
| 73 |
comm = MPI_COMM_WORLD; |
| 74 |
} |
| 75 |
|
| 76 |
void run_all_test_cases(const TestCaseData &testCases, stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 77 |
{ |
| 78 |
for(const TestCase& testCase : testCases) |
| 79 |
{ |
| 80 |
if(stk::parallel_machine_size(get_comm()) == testCase.maxNumProcs) |
| 81 |
{ |
| 82 |
EXPECT_THROW(test_one_case(testCase, auraOption), std::logic_error); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void test_one_case(const TestCase &testCase, stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 88 |
{ |
| 89 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(get_comm(), auraOption); |
| 90 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 91 |
SideTestUtil::read_and_decompose_mesh(testCase.filename, bulkData); |
| 92 |
|
| 93 |
stk::mesh::SplitCoincidentInfo splitCoincidentElements = stk::mesh::get_split_coincident_elements(bulkData); |
| 94 |
|
| 95 |
expect_split_coincidents(bulkData, testCase.expectedSplitElementsPerProc, splitCoincidentElements); |
| 96 |
stk::mesh::throw_if_any_proc_has_false(bulkData.parallel(), splitCoincidentElements.empty()); |
| 97 |
} |
| 98 |
|
| 99 |
MPI_Comm get_comm() const |
| 100 |
{ |
| 101 |
return comm; |
| 102 |
} |
| 103 |
|
| 104 |
private: |
| 105 |
MPI_Comm comm; |
| 106 |
}; |
| 107 |
|
| 108 |
|
| 109 |
TEST_F(MeshChecker, diagnose_bad_meshes) |
| 110 |
{ |
| 111 |
run_all_test_cases(badDecomps, stk::mesh::BulkData::NO_AUTO_AURA); |
| 112 |
} |
| 113 |
|
| 114 |
TEST(MeshCheckerIncremental, createSplitCoincident) |
| 115 |
{ |
| 116 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 117 |
if(stk::parallel_machine_size(comm) == 2) |
| 118 |
{ |
| 119 |
std::shared_ptr<stk::mesh::BulkData> bulkPtr = build_mesh(comm, stk::mesh::BulkData::NO_AUTO_AURA); |
| 120 |
stk::mesh::BulkData& bulkData = *bulkPtr; |
| 121 |
stk::mesh::MetaData& metaData = bulkData.mesh_meta_data(); |
| 122 |
SideTestUtil::read_and_decompose_mesh("Ae.e", bulkData); |
| 123 |
|
| 124 |
stk::mesh::SplitCoincidentInfo splitCoincidentElements = stk::mesh::get_split_coincident_elements(bulkData); |
| 125 |
ASSERT_EQ(0u, splitCoincidentElements.size()); |
| 126 |
|
| 127 |
bulkData.modification_begin(); |
| 128 |
if(bulkData.parallel_rank() == 0) |
| 129 |
{ |
| 130 |
stk::mesh::Part *block2 = metaData.get_part("block_2"); |
| 131 |
stk::mesh::declare_element(bulkData, *block2, 3, {5, 6, 7, 8}); |
| 132 |
} |
| 133 |
bulkData.modification_end(); |
| 134 |
|
| 135 |
splitCoincidentElements = stk::mesh::get_split_coincident_elements(bulkData); |
| 136 |
|
| 137 |
std::vector<std::vector<SplitElementInfo>> expectedSplitElementsPerProc = { {{3u, 2u, 1}}, {{2u, 3u, 0}} }; |
| 138 |
expect_split_coincidents(bulkData, expectedSplitElementsPerProc, splitCoincidentElements); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
} |