| 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 <Ionit_Initializer.h> // for Initializer |
| 12 |
#include <stddef.h> // for size_t, nullptr |
| 13 |
#include <string> // for string |
| 14 |
#include "mpi.h" // for MPI_COMM_WORLD |
| 15 |
#include <stk_io/StkMeshIoBroker.hpp> // for StkMeshIoBroker |
| 16 |
#include <stk_mesh/base/GetEntities.hpp> |
| 17 |
#include <stk_mesh/base/Comm.hpp> |
| 18 |
#include <stk_mesh/base/SkinBoundary.hpp> |
| 19 |
#include <stk_unit_test_utils/ioUtils.hpp> |
| 20 |
#include <stk_unit_test_utils/MeshFixture.hpp> // for MeshTestFixture |
| 21 |
#include <stk_mesh/baseImpl/EquivalentEntityBlocks.hpp> |
| 22 |
|
| 23 |
//#define VERBOSE_OUTPUT |
| 24 |
|
| 25 |
namespace |
| 26 |
{ |
| 27 |
|
| 28 |
///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 |
typedef std::map<std::string, unsigned> TestCaseData; |
| 30 |
typedef TestCaseData::value_type TestCaseDatum; |
| 31 |
|
| 32 |
class LoadMesh: public stk::unit_test_util::MeshTestFixture |
| 33 |
{ |
| 34 |
public: |
| 35 |
virtual ~LoadMesh() {} |
| 36 |
|
| 37 |
protected: |
| 38 |
void input_from_file(const std::string &meshSpec, stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 39 |
{ |
| 40 |
reset_mesh(); |
| 41 |
setup_empty_mesh(auraOption); |
| 42 |
|
| 43 |
#if defined(VERBOSE_OUTPUT) |
| 44 |
if(get_bulk().parallel_rank() == 0) std::cout << "Reading " << meshSpec << std::endl; |
| 45 |
#endif |
| 46 |
|
| 47 |
stk::unit_test_util::read_from_serial_file_and_decompose(meshSpec, get_bulk(), "cyclic"); |
| 48 |
} |
| 49 |
|
| 50 |
stk::mesh::EntityVector get_all_elements() |
| 51 |
{ |
| 52 |
stk::mesh::EntityVector elements; |
| 53 |
const bool sortById = true; |
| 54 |
stk::mesh::get_entities(get_bulk(), stk::topology::ELEM_RANK, get_meta().universal_part(), elements, sortById); |
| 55 |
return elements; |
| 56 |
} |
| 57 |
|
| 58 |
}; |
| 59 |
|
| 60 |
class TwoElementMesh: public LoadMesh |
| 61 |
{ |
| 62 |
public: |
| 63 |
TwoElementMesh(std::string inputFile) |
| 64 |
: m_inputFile(inputFile) |
| 65 |
{} |
| 66 |
|
| 67 |
protected: |
| 68 |
virtual void run_test(stk::mesh::BulkData::AutomaticAuraOption auraOption) |
| 69 |
{ |
| 70 |
EXPECT_NO_FATAL_FAILURE(input_from_file(m_inputFile, auraOption)); |
| 71 |
stk::mesh::EntityVector allElements = get_all_elements(); |
| 72 |
EXPECT_EQ(2u, allElements.size()); |
| 73 |
check_difference(allElements[0], allElements[1]); |
| 74 |
} |
| 75 |
|
| 76 |
virtual void check_difference(stk::mesh::Entity element1, stk::mesh::Entity element2) = 0; |
| 77 |
|
| 78 |
private: |
| 79 |
std::string m_inputFile; |
| 80 |
}; |
| 81 |
|
| 82 |
class TwoElementsInSameBlock: public TwoElementMesh |
| 83 |
{ |
| 84 |
public: |
| 85 |
TwoElementsInSameBlock() |
| 86 |
: TwoElementMesh("AA.e") |
| 87 |
{ } |
| 88 |
|
| 89 |
protected: |
| 90 |
virtual void check_difference(stk::mesh::Entity element1, stk::mesh::Entity element2) |
| 91 |
{ |
| 92 |
std::vector<stk::mesh::PartOrdinal> scratch1, scratch2; |
| 93 |
EXPECT_TRUE(stk::mesh::impl::are_entity_element_blocks_equivalent(get_bulk(), element1, element2, scratch1, scratch2)); |
| 94 |
} |
| 95 |
}; |
| 96 |
|
| 97 |
class TwoElementsInDifferentBlocks: public TwoElementMesh |
| 98 |
{ |
| 99 |
public: |
| 100 |
TwoElementsInDifferentBlocks() |
| 101 |
: TwoElementMesh("AB.e") |
| 102 |
{ } |
| 103 |
|
| 104 |
protected: |
| 105 |
virtual void check_difference(stk::mesh::Entity element1, stk::mesh::Entity element2) |
| 106 |
{ |
| 107 |
std::vector<stk::mesh::PartOrdinal> scratch1, scratch2; |
| 108 |
EXPECT_FALSE(stk::mesh::impl::are_entity_element_blocks_equivalent(get_bulk(), element1, element2, scratch1, scratch2)); |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
TEST_F(TwoElementsInSameBlock, test_difference_with_aura) |
| 114 |
{ |
| 115 |
run_test_on_num_procs_or_less(2, stk::mesh::BulkData::AUTO_AURA); |
| 116 |
} |
| 117 |
|
| 118 |
TEST_F(TwoElementsInDifferentBlocks, test_difference_with_aura) |
| 119 |
{ |
| 120 |
run_test_on_num_procs_or_less(2, stk::mesh::BulkData::AUTO_AURA); |
| 121 |
} |
| 122 |
|
| 123 |
} //namespace |