| 1 |
#ifndef STK_STK_UNIT_TESTS_STK_MESH_UNITTESTTEXTMESHFIXTURE_HPP_ |
| 2 |
#define STK_STK_UNIT_TESTS_STK_MESH_UNITTESTTEXTMESHFIXTURE_HPP_ |
| 3 |
|
| 4 |
#include <stk_io/IossBridge.hpp> |
| 5 |
#include <stk_mesh/base/BulkData.hpp> |
| 6 |
#include <stk_mesh/base/Field.hpp> // for Field |
| 7 |
#include <stk_mesh/base/GetEntities.hpp> |
| 8 |
#include <stk_mesh/base/MetaData.hpp> // for MetaData, put_field, etc |
| 9 |
#include <stk_unit_test_utils/GetMeshSpec.hpp> |
| 10 |
#include <stk_unit_test_utils/MeshFixture.hpp> |
| 11 |
#include <stk_unit_test_utils/TextMesh.hpp> |
| 12 |
#include <stk_unit_test_utils/TextMeshFixture.hpp> |
| 13 |
#include <stk_unit_test_utils/TextMeshStkTopologyMapping.hpp> |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
#include "gtest/gtest.h" |
| 18 |
#include "mpi.h" |
| 19 |
|
| 20 |
namespace |
| 21 |
{ |
| 22 |
class TestTextMesh : public stk::unit_test_util::TextMeshFixture |
| 23 |
{ |
| 24 |
protected: |
| 25 |
TestTextMesh() : TextMeshFixture(3) |
| 26 |
{ |
| 27 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
class TestTextMeshAura : public stk::unit_test_util::TextMeshFixture |
| 32 |
{ |
| 33 |
protected: |
| 34 |
TestTextMeshAura() : TextMeshFixture(3) |
| 35 |
{ |
| 36 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 37 |
} |
| 38 |
}; |
| 39 |
|
| 40 |
class TestTextMesh2d : public stk::unit_test_util::TextMeshFixture |
| 41 |
{ |
| 42 |
protected: |
| 43 |
TestTextMesh2d() : TextMeshFixture(2) |
| 44 |
{ |
| 45 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 46 |
} |
| 47 |
}; |
| 48 |
|
| 49 |
class TestTextMeshAura2d : public stk::unit_test_util::TextMeshFixture |
| 50 |
{ |
| 51 |
protected: |
| 52 |
TestTextMeshAura2d() : TextMeshFixture(2) |
| 53 |
{ |
| 54 |
setup_empty_mesh(stk::mesh::BulkData::AUTO_AURA); |
| 55 |
} |
| 56 |
}; |
| 57 |
|
| 58 |
class TestTextMesh1d : public stk::unit_test_util::TextMeshFixture |
| 59 |
{ |
| 60 |
protected: |
| 61 |
TestTextMesh1d() : TextMeshFixture(1) |
| 62 |
{ |
| 63 |
setup_empty_mesh(stk::mesh::BulkData::NO_AUTO_AURA); |
| 64 |
} |
| 65 |
}; |
| 66 |
|
| 67 |
class TestTextMeshGraph : public stk::unit_test_util::TextMeshFixture |
| 68 |
{ |
| 69 |
protected: |
| 70 |
TestTextMeshGraph() : TextMeshFixture(3) {} |
| 71 |
|
| 72 |
class TextMeshGraph : public SideAdjacencyGraph |
| 73 |
{ |
| 74 |
public: |
| 75 |
TextMeshGraph(const TextMeshData& data) : m_data(data) {} |
| 76 |
|
| 77 |
size_t get_num_elements() const override |
| 78 |
{ |
| 79 |
return m_data.elementDataVec.size(); |
| 80 |
} |
| 81 |
|
| 82 |
int get_element_proc(const size_t elemIndex) const override |
| 83 |
{ |
| 84 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 85 |
return elemData.proc; |
| 86 |
} |
| 87 |
|
| 88 |
bool element_has_any_node_on_proc(const size_t elemIndex, int proc) const override |
| 89 |
{ |
| 90 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 91 |
|
| 92 |
for (const EntityId &nodeId : elemData.nodeIds) { |
| 93 |
const std::set<int> &procsForNode = m_data.procs_for_node(nodeId); |
| 94 |
if (procsForNode.count(proc) > 0) { |
| 95 |
return true; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
const std::string& get_element_block_name(const size_t elemIndex) const override |
| 103 |
{ |
| 104 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 105 |
return elemData.partName; |
| 106 |
} |
| 107 |
|
| 108 |
const std::vector<EntityId>& get_element_node_ids(const size_t elemIndex) const override |
| 109 |
{ |
| 110 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 111 |
return elemData.nodeIds; |
| 112 |
} |
| 113 |
|
| 114 |
const Topology& get_element_topology(const size_t elemIndex) const override |
| 115 |
{ |
| 116 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 117 |
return elemData.topology; |
| 118 |
} |
| 119 |
|
| 120 |
EntityId get_element_id(const size_t elemIndex) const override |
| 121 |
{ |
| 122 |
const ElementData &elemData = m_data.elementDataVec[elemIndex]; |
| 123 |
return elemData.identifier; |
| 124 |
} |
| 125 |
|
| 126 |
private: |
| 127 |
const TextMeshData& m_data; |
| 128 |
}; |
| 129 |
|
| 130 |
void dump_graph(std::ostream& out = std::cout) { m_graph->dump(m_data.elementDataVec, out); } |
| 131 |
|
| 132 |
void setup_text_mesh_graph(const std::string& meshDesc, |
| 133 |
const std::vector<std::string>& selectedBlocks = {}, |
| 134 |
int proc = SideAdjacencyGraph::ANY_PROC) |
| 135 |
{ |
| 136 |
TextMeshParser parser; |
| 137 |
m_data = parser.parse(meshDesc); |
| 138 |
m_graph = std::make_shared<TextMeshGraph>(m_data); |
| 139 |
m_graph->create_graph(selectedBlocks, proc); |
| 140 |
} |
| 141 |
|
| 142 |
void verify_side_adjacency(const std::vector<Adjacency>& goldNeighbors) |
| 143 |
{ |
| 144 |
EXPECT_EQ(m_graph->size(), goldNeighbors.size()); |
| 145 |
for (size_t i = 0; i < goldNeighbors.size(); ++i) { |
| 146 |
const auto& graphNeighborIndices = (*m_graph)[goldNeighbors[i].elemIndex]; |
| 147 |
const auto& goldNeighborIndices = goldNeighbors[i].neighborIndices; |
| 148 |
|
| 149 |
unsigned numActualGoldConnections = 0; |
| 150 |
for (const auto& entry : goldNeighborIndices) { |
| 151 |
if (entry.second >= 0) { |
| 152 |
numActualGoldConnections++; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
EXPECT_EQ(numActualGoldConnections, graphNeighborIndices.connections.size()); |
| 157 |
|
| 158 |
for (const auto& entry : goldNeighborIndices) { |
| 159 |
int side = entry.first + 1; |
| 160 |
SideAdjacencyGraph::IndexType neighborElemIndex = entry.second; |
| 161 |
|
| 162 |
if (neighborElemIndex >= 0) { |
| 163 |
EXPECT_LT(0, graphNeighborIndices.sideReference[side - 1]); |
| 164 |
EXPECT_TRUE(graphNeighborIndices.has_any_connection(side, neighborElemIndex)); |
| 165 |
} else { |
| 166 |
EXPECT_EQ(0, graphNeighborIndices.sideReference[side - 1]); |
| 167 |
EXPECT_FALSE(graphNeighborIndices.has_any_connection(side)); |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
TextMeshData m_data; |
| 174 |
std::shared_ptr<TextMeshGraph> m_graph; |
| 175 |
}; |
| 176 |
|
| 177 |
using TestTextMeshSkin = TestTextMesh; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
#endif /* STK_STK_UNIT_TESTS_STK_MESH_UNITTESTTEXTMESHFIXTURE_HPP_ */ |