64int main(
int argc,
char* argv[])
67 "Partition a mesh for parallel computing."
68 "The tasks of this tool are in twofold:\n"
69 "1. Convert mesh file to the input file of the partitioning tool,\n"
70 "2. Partition a mesh using the partitioning tool,\n"
71 "\tcreate the mesh data of each partition,\n"
72 "\trenumber the node indices of each partition,\n"
73 "\tand output the results for parallel computing.\n"
74 "Note: If this tool is installed as a system command,\n"
75 "\tthe command must be run with its full path.\n\n"
76 "OpenGeoSys-6 software, version " +
79 "Copyright (c) 2012-2025, OpenGeoSys Community "
80 "(http://www.opengeosys.org)",
82 TCLAP::ValueArg<std::string> mesh_input(
83 "i",
"mesh-input-file",
84 "Input (.vtu). The name of the file containing the input mesh",
true,
88 TCLAP::ValueArg<std::string> metis_mesh_input(
89 "x",
"metis-mesh-input-file",
90 "Input (.mesh). Base name (without .mesh extension) of the file "
91 "containing the metis input mesh",
92 false,
"",
"BASE_FILENAME_INPUT");
93 cmd.add(metis_mesh_input);
95 TCLAP::ValueArg<std::string> output_directory_arg(
96 "o",
"output",
"Output. Directory name for the output files",
false,
"",
98 cmd.add(output_directory_arg);
100 TCLAP::ValueArg<int> nparts(
"n",
"np",
101 "the number of partitions, "
103 false, 2,
"N_PARTS");
106 TCLAP::SwitchArg ogs2metis_flag(
108 "Indicator to convert the ogs mesh file to METIS input file", cmd,
111 TCLAP::SwitchArg exe_metis_flag(
112 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
114 cmd.add(exe_metis_flag);
117 cmd.add(log_level_arg);
121 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
122 "other_meshes_filenames",
"mesh file names.",
false,
"file");
123 cmd.add(other_meshes_filenames_arg);
125 cmd.parse(argc, argv);
130 const auto output_directory = output_directory_arg.getValue();
138 const std::string input_file_name_wo_extension =
140 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
142 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
144 mesh_ptr->getNumberOfNodes(),
145 mesh_ptr->getNumberOfElements());
153 if (ogs2metis_flag.getValue())
155 INFO(
"Write the mesh into METIS input file.");
157 output_file_name_wo_extension +
".mesh");
158 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
159 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
165 nparts.getValue(), std::move(mesh_ptr));
167 const int num_partitions = nparts.getValue();
169 if (num_partitions < 1)
171 OGS_FATAL(
"Number of partitions must be positive.");
174 if (num_partitions == 1)
177 "Partitioning the mesh into one domain is unnecessary because OGS "
178 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
182 auto metis_mesh = output_file_name_wo_extension;
183 if (metis_mesh_input.getValue() !=
"")
185 metis_mesh = metis_mesh_input.getValue();
189 if (exe_metis_flag.getValue())
191 INFO(
"METIS is running ...");
192 const std::string exe_name = argv[0];
194 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
196 const std::string mpmetis_com =
198 metis_mesh +
".mesh" +
"\" " + std::to_string(nparts.getValue());
200 INFO(
"Running: {:s}", mpmetis_com);
201 const int status = system(mpmetis_com.c_str());
204 INFO(
"Failed in system calling.");
205 INFO(
"Return value of system call {:d} ", status);
214 if (exe_metis_flag.getValue())
219 INFO(
"Partitioning the mesh in the node wise way ...");
222 INFO(
"Partitioning other meshes according to the main mesh partitions.");
223 for (
auto const& filename : other_meshes_filenames_arg.getValue())
225 std::unique_ptr<MeshLib::Mesh> mesh(
227 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
228 mesh->getName(), filename, mesh->getNumberOfNodes(),
229 mesh->getNumberOfElements());
233 std::string
const other_mesh_output_file_name_wo_extension =
241 partitioned_properties);
244 other_mesh_output_file_name_wo_extension, partitions,
245 partitioned_properties);
249 io_run_timer.
start();
250 mesh_partitioner.
write(output_file_name_wo_extension);
251 INFO(
"Writing the partitions data into binary files took {:g} s",
254 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
255 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());