30int main(
int argc,
char* argv[])
33 "Partition a mesh for parallel computing."
34 "The tasks of this tool are in twofold:\n"
35 "1. Convert mesh file to the input file of the partitioning tool,\n"
36 "2. Partition a mesh using the partitioning tool,\n"
37 "\tcreate the mesh data of each partition,\n"
38 "\trenumber the node indices of each partition,\n"
39 "\tand output the results for parallel computing.\n"
40 "Note: If this tool is installed as a system command,\n"
41 "\tthe command must be run with its full path.\n\n"
42 "OpenGeoSys-6 software, version " +
45 "Copyright (c) 2012-2025, OpenGeoSys Community "
46 "(http://www.opengeosys.org)",
48 TCLAP::ValueArg<std::string> mesh_input(
49 "i",
"mesh-input-file",
50 "Input (.vtu). The name of the file containing the input mesh",
true,
54 TCLAP::ValueArg<std::string> metis_mesh_input(
55 "x",
"metis-mesh-input-file",
56 "Input (.mesh). Base name (without .mesh extension) of the file "
57 "containing the metis input mesh",
58 false,
"",
"BASE_FILENAME_INPUT");
59 cmd.add(metis_mesh_input);
61 TCLAP::ValueArg<std::string> output_directory_arg(
62 "o",
"output",
"Output. Directory name for the output files",
false,
"",
64 cmd.add(output_directory_arg);
66 TCLAP::ValueArg<int> nparts(
"n",
"np",
67 "the number of partitions, "
72 TCLAP::SwitchArg ogs2metis_flag(
74 "Indicator to convert the ogs mesh file to METIS input file", cmd,
77 TCLAP::SwitchArg exe_metis_flag(
78 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
80 cmd.add(exe_metis_flag);
83 cmd.add(log_level_arg);
87 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
88 "other_meshes_filenames",
"mesh file names.",
false,
"file");
89 cmd.add(other_meshes_filenames_arg);
91 cmd.parse(argc, argv);
96 const auto output_directory = output_directory_arg.getValue();
104 const std::string input_file_name_wo_extension =
106 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
108 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
110 mesh_ptr->getNumberOfNodes(),
111 mesh_ptr->getNumberOfElements());
117 if (ogs2metis_flag.getValue())
119 INFO(
"Write the mesh into METIS input file.");
121 output_file_name_wo_extension +
".mesh");
122 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
123 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
129 nparts.getValue(), std::move(mesh_ptr));
131 const int num_partitions = nparts.getValue();
133 if (num_partitions < 1)
135 OGS_FATAL(
"Number of partitions must be positive.");
138 if (num_partitions == 1)
141 "Partitioning the mesh into one domain is unnecessary because OGS "
142 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
146 auto metis_mesh = output_file_name_wo_extension;
147 if (metis_mesh_input.getValue() !=
"")
149 metis_mesh = metis_mesh_input.getValue();
153 if (exe_metis_flag.getValue())
155 INFO(
"METIS is running ...");
156 const std::string exe_name = argv[0];
158 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
160 const std::string mpmetis_com =
162 metis_mesh +
".mesh" +
"\" " + std::to_string(nparts.getValue());
164 INFO(
"Running: {:s}", mpmetis_com);
165 const int status = system(mpmetis_com.c_str());
168 INFO(
"Failed in system calling.");
169 INFO(
"Return value of system call {:d} ", status);
178 if (exe_metis_flag.getValue())
183 INFO(
"Partitioning the mesh in the node wise way ...");
186 INFO(
"Partitioning other meshes according to the main mesh partitions.");
187 for (
auto const& filename : other_meshes_filenames_arg.getValue())
189 std::unique_ptr<MeshLib::Mesh> mesh(
191 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
192 mesh->getName(), filename, mesh->getNumberOfNodes(),
193 mesh->getNumberOfElements());
195 std::string
const other_mesh_output_file_name_wo_extension =
203 partitioned_properties);
206 other_mesh_output_file_name_wo_extension, partitions,
207 partitioned_properties);
211 io_run_timer.
start();
212 mesh_partitioner.
write(output_file_name_wo_extension);
213 INFO(
"Writing the partitions data into binary files took {:g} s",
216 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
217 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());