15 #include <spdlog/spdlog.h>
16 #include <tclap/CmdLine.h>
28 int main(
int argc,
char* argv[])
31 "Partition a mesh for parallel computing."
32 "The tasks of this tool are in twofold:\n"
33 "1. Convert mesh file to the input file of the partitioning tool,\n"
34 "2. Partition a mesh using the partitioning tool,\n"
35 "\tcreate the mesh data of each partition,\n"
36 "\trenumber the node indices of each partition,\n"
37 "\tand output the results for parallel computing.\n"
38 "Note: If this tool is installed as a system command,\n"
39 "\tthe command must be run with its full path.\n\n"
40 "OpenGeoSys-6 software, version " +
43 "Copyright (c) 2012-2021, OpenGeoSys Community "
44 "(http://www.opengeosys.org)",
46 TCLAP::ValueArg<std::string> mesh_input(
47 "i",
"mesh-input-file",
48 "the name of the file containing the input mesh",
true,
"",
49 "file name of input mesh");
52 TCLAP::ValueArg<std::string> metis_mesh_input(
53 "x",
"metis-mesh-input-file",
54 "base name (without .mesh extension) of the file containing the metis "
57 "base name (without .mesh extension) of the file containing the metis "
59 cmd.add(metis_mesh_input);
61 TCLAP::ValueArg<std::string> output_directory_arg(
62 "o",
"output",
"directory name for the output files",
false,
"",
64 cmd.add(output_directory_arg);
66 TCLAP::ValueArg<int> nparts(
"n",
"np",
"the number of partitions",
false, 2,
70 TCLAP::SwitchArg ogs2metis_flag(
72 "Indicator to convert the ogs mesh file to METIS input file", cmd,
75 TCLAP::SwitchArg exe_metis_flag(
76 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
78 cmd.add(exe_metis_flag);
80 TCLAP::SwitchArg lh_elems_flag(
81 "q",
"lh_elements",
"Mixed linear and high order elements.",
false);
82 cmd.add(lh_elems_flag);
84 TCLAP::ValueArg<std::string> log_level_arg(
86 "the verbosity of logging messages: none, error, warn, info, debug, "
95 cmd.add(log_level_arg);
99 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
100 "other_meshes_filenames",
"mesh file names.",
false,
"file");
101 cmd.add(other_meshes_filenames_arg);
103 cmd.parse(argc, argv);
106 spdlog::set_pattern(
"%^%l:%$ %v");
107 spdlog::set_error_handler(
108 [](
const std::string& msg)
110 std::cerr <<
"spdlog error: " << msg << std::endl;
111 OGS_FATAL(
"spdlog logger error occurred.");
119 const std::string input_file_name_wo_extension =
121 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
123 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
125 mesh_ptr->getNumberOfNodes(),
126 mesh_ptr->getNumberOfElements());
129 output_directory_arg.getValue(),
132 if (ogs2metis_flag.getValue())
134 INFO(
"Write the mesh into METIS input file.");
136 output_file_name_wo_extension +
".mesh");
137 INFO(
"Total runtime: {:g} s.", run_timer.elapsed());
138 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
144 nparts.getValue(), std::move(mesh_ptr));
146 const int num_partitions = nparts.getValue();
148 if (num_partitions < 1)
150 OGS_FATAL(
"Number of partitions must be positive.");
153 if (num_partitions == 1)
156 "Partitioning the mesh into one domain is unnecessary because OGS "
157 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
161 auto metis_mesh = output_file_name_wo_extension;
162 if (metis_mesh_input.getValue() !=
"")
164 metis_mesh = metis_mesh_input.getValue();
168 if (exe_metis_flag.getValue())
170 INFO(
"METIS is running ...");
171 const std::string exe_name = argv[0];
173 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
175 const std::string mpmetis_com =
177 metis_mesh +
".mesh" +
"' " + std::to_string(nparts.getValue());
179 INFO(
"Running: {:s}", mpmetis_com);
180 const int status = system(mpmetis_com.c_str());
183 INFO(
"Failed in system calling.");
184 INFO(
"Return value of system call {:d} ", status);
193 if (exe_metis_flag.getValue())
198 INFO(
"Partitioning the mesh in the node wise way ...");
199 bool const is_mixed_high_order_linear_elems = lh_elems_flag.getValue();
202 INFO(
"Partitioning other meshes according to the main mesh partitions.");
203 for (
auto const& filename : other_meshes_filenames_arg.getValue())
205 std::unique_ptr<MeshLib::Mesh> mesh(
207 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
208 mesh->getName(), filename, mesh->getNumberOfNodes(),
209 mesh->getNumberOfElements());
211 std::string
const other_mesh_output_file_name_wo_extension =
213 output_directory_arg.getValue(),
216 *mesh, is_mixed_high_order_linear_elems);
218 auto partitioned_properties =
221 partitioned_properties.getPropertyVector<std::size_t>(
225 partitioned_properties.getPropertyVector<std::size_t>(
229 other_mesh_output_file_name_wo_extension, partitions,
230 partitioned_properties);
233 INFO(
"Write the data of partitions into binary files ...");
234 mesh_partitioner.
write(output_file_name_wo_extension);
236 INFO(
"Total runtime: {:g} s.", run_timer.elapsed());
237 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
Definition of the CPUTime class.
void INFO(char const *fmt, Args const &... args)
Declare a class to perform node wise mesh partitioning.
int main(int argc, char *argv[])
Definition of the RunTime class.
void renumberBulkElementIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_element_ids_pv, std::vector< Partition > const &local_partitions) const
void partitionByMETIS(const bool is_mixed_high_order_linear_elems)
MeshLib::Mesh const & mesh() const
void write(const std::string &file_name_base)
void renumberBulkNodeIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_node_ids, std::vector< Partition > const &local_partitions) const
std::vector< Partition > partitionOtherMesh(MeshLib::Mesh const &mesh, bool const is_mixed_high_order_linear_elems) const
void resetPartitionIdsForNodes(std::vector< std::size_t > &&node_partition_ids)
void writeOtherMesh(std::string const &output_filename_base, std::vector< Partition > const &partitions, MeshLib::Properties const &partitioned_properties) const
void start()
Start the timer.
double elapsed() const
Get the elapsed time after started.
void start()
Start the timer.
std::size_t getNumberOfNodes() const
Get the number of nodes.
void writeMETIS(std::vector< MeshLib::Element * > const &elements, const std::string &file_name)
MeshLib::Properties partitionProperties(MeshLib::Properties const &properties, std::vector< Partition > const &partitions)
Partition existing properties and add vtkGhostType cell data array property.
void removeMetisPartitioningFiles(std::string const &file_name_base, long const number_of_partitions)
std::vector< std::size_t > readMetisData(const std::string &file_name_base, long const number_of_partitions, std::size_t const number_of_nodes)
void setConsoleLogLevel(std::string const &level_string)
std::string extractPath(std::string const &pathname)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
std::string dropFileExtension(std::string const &filename)
std::string joinPaths(std::string const &pathA, std::string const &pathB)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Definition of readMeshFromFile function.