53int main(
int argc,
char* argv[])
56 "Partition a mesh for parallel computing."
57 "The tasks of this tool are in twofold:\n"
58 "1. Convert mesh file to the input file of the partitioning tool,\n"
59 "2. Partition a mesh using the partitioning tool,\n"
60 "\tcreate the mesh data of each partition,\n"
61 "\trenumber the node indices of each partition,\n"
62 "\tand output the results for parallel computing.\n"
63 "Note: If this tool is installed as a system command,\n"
64 "\tthe command must be run with its full path.\n\n"
65 "OpenGeoSys-6 software, version " +
68 "Copyright (c) 2012-2026, OpenGeoSys Community "
69 "(http://www.opengeosys.org)",
71 TCLAP::ValueArg<std::string> mesh_input(
72 "i",
"mesh-input-file",
73 "Input (.vtu). The name of the file containing the input mesh",
true,
77 TCLAP::ValueArg<std::string> metis_mesh_input(
78 "x",
"metis-mesh-input-file",
79 "Input (.mesh). Base name (without .mesh extension) of the file "
80 "containing the metis input mesh",
81 false,
"",
"BASE_FILENAME_INPUT");
82 cmd.add(metis_mesh_input);
84 TCLAP::ValueArg<std::string> output_directory_arg(
85 "o",
"output",
"Output. Directory name for the output files",
false,
"",
87 cmd.add(output_directory_arg);
89 TCLAP::ValueArg<int> nparts(
"n",
"np",
90 "the number of partitions, "
95 TCLAP::SwitchArg ogs2metis_flag(
97 "Indicator to convert the ogs mesh file to METIS input file", cmd,
100 TCLAP::SwitchArg exe_metis_flag(
101 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
103 cmd.add(exe_metis_flag);
106 cmd.add(log_level_arg);
110 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
111 "other_meshes_filenames",
"mesh file names.",
false,
"file");
112 cmd.add(other_meshes_filenames_arg);
114 cmd.parse(argc, argv);
119 const auto output_directory = output_directory_arg.getValue();
127 const std::string input_file_name_wo_extension =
129 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
131 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
133 mesh_ptr->getNumberOfNodes(),
134 mesh_ptr->getNumberOfElements());
142 if (ogs2metis_flag.getValue())
144 INFO(
"Write the mesh into METIS input file.");
146 output_file_name_wo_extension +
".mesh");
147 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
148 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
154 nparts.getValue(), std::move(mesh_ptr));
156 const int num_partitions = nparts.getValue();
158 if (num_partitions < 1)
160 OGS_FATAL(
"Number of partitions must be positive.");
163 if (num_partitions == 1)
166 "Partitioning the mesh into one domain is unnecessary because OGS "
167 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
171 auto metis_mesh = output_file_name_wo_extension;
172 if (metis_mesh_input.getValue() !=
"")
174 metis_mesh = metis_mesh_input.getValue();
178 if (exe_metis_flag.getValue())
180 INFO(
"METIS is running ...");
181 const std::string exe_name = argv[0];
183 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
185 const std::string mpmetis_com =
187 metis_mesh +
".mesh" +
"\" " + std::to_string(nparts.getValue());
189 INFO(
"Running: {:s}", mpmetis_com);
190 const int status = system(mpmetis_com.c_str());
193 INFO(
"Failed in system calling.");
194 INFO(
"Return value of system call {:d} ", status);
203 if (exe_metis_flag.getValue())
208 INFO(
"Partitioning the mesh in the node wise way ...");
211 INFO(
"Partitioning other meshes according to the main mesh partitions.");
212 for (
auto const& filename : other_meshes_filenames_arg.getValue())
214 std::unique_ptr<MeshLib::Mesh> mesh(
216 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
217 mesh->getName(), filename, mesh->getNumberOfNodes(),
218 mesh->getNumberOfElements());
222 std::string
const other_mesh_output_file_name_wo_extension =
230 partitioned_properties);
233 other_mesh_output_file_name_wo_extension, partitions,
234 partitioned_properties);
238 io_run_timer.
start();
239 mesh_partitioner.
write(output_file_name_wo_extension);
240 INFO(
"Writing the partitions data into binary files took {:g} s",
243 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
244 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());