139 std::cout <<
"\nMETIS_TEST\n";
140 std::cout <<
"\n Test the METIS library for graph partitioning for realistic mesh with nonlocal interaction.\n" ;
141 std::cout << fmt::format(
"\n Arguments: nPart = {}, nGrid = {}, mHorizon = {}\n", nPart, nGrid, mHorizon);
144 auto t1 = steady_clock::now();
149 mesh.d_spatialDiscretization =
"finite_difference";
152 std::string outMeshFilename =
"";
153 if (testOption == 1) {
155 std::pair<std::vector<double>, std::vector<double>> box;
156 std::vector<size_t> nGridVec;
157 for (
size_t i=0; i<dim; i++) {
158 box.first.push_back(0.);
159 box.second.push_back(1.);
160 nGridVec.push_back(nGrid);
167 outMeshFilename = fmt::format(
"uniform_mesh_Lx_{}_Ly_{}_Nx_{}_Ny_{}",
168 box.second[0], box.second[1],
169 nGridVec[0], nGridVec[1]);
171 else if (testOption == 2) {
172 if (meshFilename.empty()) {
173 std::cerr <<
"testGraphPartitioning(): mesh filename is empty.\n";
178 mesh.createData(meshFilename);
185 std::cerr <<
"testGraphPartitioning() accepts either 0 or 1 for testOption. The value "
186 << testOption <<
" is invalid.\n";
191 double horizon = mHorizon*mesh.d_h;
194 std::ostringstream msg;
195 msg << mesh.printStr();
196 std::cout << msg.str();
198 auto t2 = steady_clock::now();
200 std::cout << fmt::format(
"Setup time (ms) = {}. \n", setup_time);
203 std::vector<std::vector<size_t>> nodeNeighs(mesh.d_numNodes);
205 auto t3 = steady_clock::now();
207 std::cout << fmt::format(
"Neighborhood calculation time (ms) = {}.\n", neigh_time);
211 std::vector<size_t> nodePartitionRecursive(mesh.d_numNodes, 0);
212 std::vector<size_t> nodePartitionKWay(mesh.d_numNodes, 0);
215 auto t4 = steady_clock::now();
217 auto t5 = steady_clock::now();
221 auto t6 = steady_clock::now();
225 std::cout << fmt::format(
"Partition (Recursive) calculation time (ms) = {}.\n", partition_recursive_time);
226 std::cout << fmt::format(
"Partition (KWay) calculation time (ms) = {}.\n", partition_kway_time);
229 outMeshFilename = outMeshFilename + fmt::format(
"_mHorizon_{}_nPart_{}", mHorizon, nPart);
230 std::cout <<
"out mesh filename = " << outMeshFilename << std::endl;
232 writer.appendMesh(&mesh.d_nodes, mesh.d_eType, &mesh.d_enc);
233 writer.appendPointData(
"Nodal_Volume", &mesh.d_vol);
234 writer.appendPointData(
"Nodal_Partition_Metis_Recursive_Index", &nodePartitionRecursive);
235 writer.appendPointData(
"Nodal_Partition_Metis_KWay_Index", &nodePartitionKWay);
void createUniformMesh(fe::Mesh *mesh_p, size_t dim, std::pair< std::vector< double >, std::vector< double > > box, std::vector< size_t > nGrid)
Creates uniform mesh for rectangle/cuboid domain.
void metisGraphPartition(std::string partitionMethod, const std::vector< std::vector< size_t > > &nodeNeighs, std::vector< size_t > &nodePartition, size_t nPartitions)
Partitions the nodes based on node neighborlist supplied. Function first creates a graph with nodes a...
void testGraphPartitioning(size_t nPart=4, size_t nGrid=10, size_t mHorizon=3, size_t testOption=0, std::string meshFilename="")
Tests metis partitioning of graph from a 2-D mesh with nonlocal interaction.