| 1 |
#include "gtest/gtest.h" |
| 2 |
#include <vector> |
| 3 |
#include "mpi.h" |
| 4 |
#include <stk_mesh/baseImpl/elementGraph/GraphEdgeData.hpp> |
| 5 |
#include <stk_mesh/baseImpl/elementGraph/ElemElemGraphImpl.hpp> |
| 6 |
#include <stk_mesh/baseImpl/elementGraph/ElemGraphShellConnections.hpp> |
| 7 |
|
| 8 |
namespace |
| 9 |
{ |
| 10 |
|
| 11 |
struct ProcAndId |
| 12 |
{ |
| 13 |
ProcAndId(int p, stk::mesh::impl::LocalId i) : proc(p), id(i) { } |
| 14 |
int proc; |
| 15 |
stk::mesh::impl::LocalId id; |
| 16 |
}; |
| 17 |
|
| 18 |
class GraphWithShells : public ::testing::Test |
| 19 |
{ |
| 20 |
protected: |
| 21 |
GraphWithShells() |
| 22 |
: procRank(stk::parallel_machine_rank(comm)), |
| 23 |
parGraphInfo(procRank), |
| 24 |
graphInfo(graph, parGraphInfo, elementTopologies) |
| 25 |
{ |
| 26 |
} |
| 27 |
|
| 28 |
void run_test_on_num_procs(int numProcs) |
| 29 |
{ |
| 30 |
if(stk::parallel_machine_size(comm) == numProcs) |
| 31 |
run_test(); |
| 32 |
} |
| 33 |
|
| 34 |
virtual void run_test() = 0; |
| 35 |
|
| 36 |
void set_element_topologies_per_proc(const std::vector<std::vector<stk::topology>> &tops) |
| 37 |
{ |
| 38 |
elementTopologies = tops[procRank]; |
| 39 |
} |
| 40 |
void create_graph_edges_for_hex0_shell1_hex2_on_procs(int hex0Proc, int shell1Proc, int hex2Proc) |
| 41 |
{ |
| 42 |
add_edges_on_proc(hex0Proc, graphEdgeHex0Shell1, graphEdgeHex0Hex2); |
| 43 |
add_edges_on_proc(shell1Proc, graphEdgeShell1Hex0, graphEdgeShell1Hex2); |
| 44 |
add_edges_on_proc(hex2Proc, graphEdgeHex2Hex0, graphEdgeHex2Shell1); |
| 45 |
} |
| 46 |
void expect_graph_edges_for_hex0_shell1_hex2_on_procs(ProcAndId hex0, ProcAndId shell1, ProcAndId hex2) |
| 47 |
{ |
| 48 |
expect_graph_has_edges_for_element(hex0, {graphEdgeHex0Shell1}); |
| 49 |
expect_graph_has_edges_for_element(shell1, {graphEdgeShell1Hex0, graphEdgeShell1Hex2}); |
| 50 |
expect_graph_has_edges_for_element(hex2, {graphEdgeHex2Shell1}); |
| 51 |
} |
| 52 |
|
| 53 |
private: |
| 54 |
void add_edges_on_proc(int creationProc, const stk::mesh::GraphEdge &graphEdge1, const stk::mesh::GraphEdge &graphEdge2) |
| 55 |
{ |
| 56 |
if(procRank == creationProc) |
| 57 |
add_two_edges(graphEdge1, graphEdge2); |
| 58 |
} |
| 59 |
void add_two_edges(const stk::mesh::GraphEdge& graphEdge1, const stk::mesh::GraphEdge& graphEdge2) |
| 60 |
{ |
| 61 |
graph.add_new_element(); |
| 62 |
std::vector<stk::mesh::GraphEdge> edges = {graphEdge1, graphEdge2}; |
| 63 |
graph.add_sorted_edges(edges); |
| 64 |
} |
| 65 |
void expect_graph_has_edges_for_element(ProcAndId procAndId, const std::vector<stk::mesh::GraphEdge> &expectedEdges) |
| 66 |
{ |
| 67 |
if(procRank == procAndId.proc) |
| 68 |
{ |
| 69 |
ASSERT_EQ(expectedEdges.size(), graph.get_num_edges_for_element(procAndId.id)); |
| 70 |
for(size_t i=0; i<expectedEdges.size(); i++) |
| 71 |
EXPECT_EQ(expectedEdges[i], graph.get_edge_for_element(procAndId.id, i)); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
protected: |
| 76 |
MPI_Comm comm = MPI_COMM_WORLD; |
| 77 |
int procRank; |
| 78 |
stk::mesh::Graph graph; |
| 79 |
stk::mesh::ParallelInfoForGraphEdges parGraphInfo; |
| 80 |
std::vector<stk::topology> elementTopologies; |
| 81 |
stk::mesh::GraphInfo graphInfo; |
| 82 |
stk::mesh::GraphEdge graphEdgeHex0Hex2; |
| 83 |
stk::mesh::GraphEdge graphEdgeHex0Shell1; |
| 84 |
stk::mesh::GraphEdge graphEdgeShell1Hex0; |
| 85 |
stk::mesh::GraphEdge graphEdgeShell1Hex2; |
| 86 |
stk::mesh::GraphEdge graphEdgeHex2Hex0; |
| 87 |
stk::mesh::GraphEdge graphEdgeHex2Shell1; |
| 88 |
}; |
| 89 |
|
| 90 |
class GraphWithShellsSerial : public GraphWithShells |
| 91 |
{ |
| 92 |
protected: |
| 93 |
GraphWithShellsSerial() |
| 94 |
{ |
| 95 |
graphEdgeHex0Hex2 = stk::mesh::GraphEdge(0, 0, 2, 4); |
| 96 |
graphEdgeHex0Shell1 = stk::mesh::GraphEdge(0, 0, 1, 0); |
| 97 |
graphEdgeShell1Hex0 = stk::mesh::GraphEdge(1, 0, 0, 0); |
| 98 |
graphEdgeShell1Hex2 = stk::mesh::GraphEdge(1, 1, 2, 4); |
| 99 |
graphEdgeHex2Hex0 = stk::mesh::GraphEdge(2, 4, 0, 0); |
| 100 |
graphEdgeHex2Shell1 = stk::mesh::GraphEdge(2, 4, 1, 1); |
| 101 |
} |
| 102 |
|
| 103 |
virtual void run_test() |
| 104 |
{ |
| 105 |
set_element_topologies_per_proc({{stk::topology::HEX_8, stk::topology::SHELL_QUAD_4, stk::topology::HEX_8}}); |
| 106 |
create_graph_edges_for_hex0_shell1_hex2_on_procs(0, 0, 0); |
| 107 |
remove_graph_edges_blocked_by_shell(graphInfo); |
| 108 |
expect_graph_edges_for_hex0_shell1_hex2_on_procs(ProcAndId(0, 0), ProcAndId(0, 1), ProcAndId(0, 2)); |
| 109 |
} |
| 110 |
}; |
| 111 |
TEST_F(GraphWithShellsSerial, HexShellHex) |
| 112 |
{ |
| 113 |
run_test_on_num_procs(1); |
| 114 |
} |
| 115 |
|
| 116 |
class GraphWithShells2Procs : public GraphWithShells |
| 117 |
{ |
| 118 |
protected: |
| 119 |
GraphWithShells2Procs() |
| 120 |
{ |
| 121 |
graphEdgeHex0Hex2 = stk::mesh::GraphEdge(0, 0, -3, 4); |
| 122 |
graphEdgeHex0Shell1 = stk::mesh::GraphEdge(0, 0, 1, 0); |
| 123 |
graphEdgeShell1Hex0 = stk::mesh::GraphEdge(1, 0, 0, 0); |
| 124 |
graphEdgeShell1Hex2 = stk::mesh::GraphEdge(1, 1, -3, 4); |
| 125 |
graphEdgeHex2Hex0 = stk::mesh::GraphEdge(0, 4, -1, 0); |
| 126 |
graphEdgeHex2Shell1 = stk::mesh::GraphEdge(0, 4, -2, 1); |
| 127 |
} |
| 128 |
|
| 129 |
virtual void run_test() |
| 130 |
{ |
| 131 |
setup_graph_for_two_procs(); |
| 132 |
remove_graph_edges_blocked_by_shell(graphInfo); |
| 133 |
expect_graph_edges_for_hex0_shell1_hex2_on_procs(ProcAndId(0, 0), ProcAndId(0, 1), ProcAndId(1, 0)); |
| 134 |
} |
| 135 |
|
| 136 |
void setup_graph_for_two_procs() |
| 137 |
{ |
| 138 |
set_element_topologies_per_proc( { {stk::topology::HEX_8, stk::topology::SHELL_QUAD_4}, {stk::topology::HEX_8}}); |
| 139 |
create_graph_edges_for_hex0_shell1_hex2_on_procs(0, 0, 1); |
| 140 |
setup_parallel_graph_info_for_two_procs(); |
| 141 |
} |
| 142 |
|
| 143 |
private: |
| 144 |
void setup_parallel_graph_info_for_two_procs() |
| 145 |
{ |
| 146 |
setup_parallel_graph_for_proc_0(); |
| 147 |
setup_parallel_graph_for_proc_1(); |
| 148 |
} |
| 149 |
void setup_parallel_graph_for_proc_0() |
| 150 |
{ |
| 151 |
if(procRank == 0) |
| 152 |
{ |
| 153 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex0Hex2, stk::mesh::impl::ParallelInfo(1, 0, stk::topology::HEX_8)); |
| 154 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeShell1Hex2, stk::mesh::impl::ParallelInfo(1, 0, stk::topology::HEX_8)); |
| 155 |
} |
| 156 |
} |
| 157 |
void setup_parallel_graph_for_proc_1() |
| 158 |
{ |
| 159 |
if(procRank == 1) |
| 160 |
{ |
| 161 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex2Hex0, stk::mesh::impl::ParallelInfo(0, 0, stk::topology::HEX_8)); |
| 162 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex2Shell1, stk::mesh::impl::ParallelInfo(0, 0, stk::topology::SHELL_QUAD_4)); |
| 163 |
} |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
TEST_F(GraphWithShells2Procs, HexShellHex) |
| 168 |
{ |
| 169 |
run_test_on_num_procs(2); |
| 170 |
} |
| 171 |
|
| 172 |
class GraphWithShells3Procs : public GraphWithShells |
| 173 |
{ |
| 174 |
protected: |
| 175 |
GraphWithShells3Procs() |
| 176 |
{ |
| 177 |
graphEdgeHex0Hex2 = stk::mesh::GraphEdge(0, 0, -3, 4); |
| 178 |
graphEdgeHex0Shell1 = stk::mesh::GraphEdge(0, 0, -2, 0); |
| 179 |
graphEdgeShell1Hex0 = stk::mesh::GraphEdge(0, 0, -1, 0); |
| 180 |
graphEdgeShell1Hex2 = stk::mesh::GraphEdge(0, 1, -3, 4); |
| 181 |
graphEdgeHex2Hex0 = stk::mesh::GraphEdge(0, 4, -1, 0); |
| 182 |
graphEdgeHex2Shell1 = stk::mesh::GraphEdge(0, 4, -2, 1); |
| 183 |
} |
| 184 |
|
| 185 |
virtual void run_test() |
| 186 |
{ |
| 187 |
setup_graph_for_three_procs(); |
| 188 |
remove_graph_edges_blocked_by_shell(graphInfo); |
| 189 |
expect_graph_edges_for_hex0_shell1_hex2_on_procs(ProcAndId(0, 0), ProcAndId(1, 0), ProcAndId(2, 0)); |
| 190 |
} |
| 191 |
|
| 192 |
private: |
| 193 |
void setup_graph_for_three_procs() |
| 194 |
{ |
| 195 |
set_element_topologies_per_proc( { {stk::topology::HEX_8}, {stk::topology::SHELL_QUAD_4}, {stk::topology::HEX_8}}); |
| 196 |
create_graph_edges_for_hex0_shell1_hex2_on_procs(0, 1, 2); |
| 197 |
setup_parallel_graph_info_for_three_procs(); |
| 198 |
} |
| 199 |
void setup_parallel_graph_info_for_three_procs() |
| 200 |
{ |
| 201 |
setup_parallel_graph_for_proc_0(); |
| 202 |
setup_parallel_graph_for_proc_1(); |
| 203 |
setup_parallel_graph_for_proc_2(); |
| 204 |
} |
| 205 |
void setup_parallel_graph_for_proc_0() |
| 206 |
{ |
| 207 |
if(procRank == 0) |
| 208 |
{ |
| 209 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex0Shell1, stk::mesh::impl::ParallelInfo(1, 0, stk::topology::SHELL_QUAD_4)); |
| 210 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex0Hex2, stk::mesh::impl::ParallelInfo(2, 0, stk::topology::HEX_8)); |
| 211 |
} |
| 212 |
} |
| 213 |
void setup_parallel_graph_for_proc_1() |
| 214 |
{ |
| 215 |
if(procRank == 1) |
| 216 |
{ |
| 217 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeShell1Hex0, stk::mesh::impl::ParallelInfo(0, 0, stk::topology::HEX_8)); |
| 218 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeShell1Hex2, stk::mesh::impl::ParallelInfo(2, 0, stk::topology::HEX_8)); |
| 219 |
} |
| 220 |
} |
| 221 |
void setup_parallel_graph_for_proc_2() |
| 222 |
{ |
| 223 |
if(procRank == 2) |
| 224 |
{ |
| 225 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex2Hex0, stk::mesh::impl::ParallelInfo(0, 0, stk::topology::HEX_8)); |
| 226 |
parGraphInfo.insert_parallel_info_for_graph_edge(graphEdgeHex2Shell1, stk::mesh::impl::ParallelInfo(1, 0, stk::topology::SHELL_QUAD_4)); |
| 227 |
} |
| 228 |
} |
| 229 |
}; |
| 230 |
|
| 231 |
TEST_F(GraphWithShells3Procs, HexShellHex) |
| 232 |
{ |
| 233 |
run_test_on_num_procs(3); |
| 234 |
} |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|