OGS
BinaryToPVTU.cpp File Reference

Detailed Description

A tool for debugging the mesh partitioning.

Definition in file BinaryToPVTU.cpp.

#include <spdlog/spdlog.h>
#include <tclap/CmdLine.h>
#include <vtkMPIController.h>
#include <vtkSmartPointer.h>
#include "BaseLib/CPUTime.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/MPI.h"
#include "BaseLib/RunTime.h"
#include "BaseLib/TCLAPArguments.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/NodePartitionedMesh.h"
Include dependency graph for BinaryToPVTU.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 28 of file BinaryToPVTU.cpp.

29{
30 TCLAP::CmdLine cmd(
31 "Reads the binary mesh format and writes the data as vtus/pvtu.\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2025, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38 TCLAP::ValueArg<std::string> mesh_input(
39 "i", "mesh-input-file-base",
40 "Input (.bin). The base name of the files containing the input mesh, "
41 "i.e., the file "
42 "name without the string beginning with '_partitioned' and ending "
43 "with ",
44 true, "", "BASE_FILENAME_INPUT_MESH");
45 cmd.add(mesh_input);
46
47 TCLAP::ValueArg<std::string> output_directory_arg(
48 "o", "output",
49 "output directory name and output base file name without extensions",
50 true, "", "directory/base_file_name_without_extensions");
51 cmd.add(output_directory_arg);
52
53 auto log_level_arg = BaseLib::makeLogLevelArg();
54 cmd.add(*log_level_arg);
55
56 cmd.parse(argc, argv);
57
58 BaseLib::setConsoleLogLevel(log_level_arg->getValue());
59 spdlog::set_pattern("%^%l:%$ %v");
60 spdlog::set_error_handler(
61 [](const std::string& msg)
62 {
63 std::cerr << "spdlog error: " << msg << std::endl;
64 OGS_FATAL("spdlog logger error occurred.");
65 });
66
67 BaseLib::MPI::Setup mpi_setup(argc, argv);
68 // start the timer
69 BaseLib::RunTime run_timer;
70 run_timer.start();
71 BaseLib::CPUTime CPU_timer;
72 CPU_timer.start();
73
74 // add mpi_rank to logger output
75 int mpi_rank;
76 MPI_Comm_rank(BaseLib::MPI::OGS_COMM_WORLD, &mpi_rank);
77 spdlog::set_pattern(fmt::format("[{}] %^%l:%$ %v", mpi_rank));
78
79 // init vtkMPI
80 vtkSmartPointer<vtkMPIController> controller =
81 vtkSmartPointer<vtkMPIController>::New();
82 controller->Initialize(&argc, &argv, 1);
83 vtkMPIController::SetGlobalController(controller);
84
86 dynamic_cast<MeshLib::NodePartitionedMesh*>(
87 MeshLib::IO::readMeshFromFile(mesh_input.getValue()));
88 INFO("Mesh '{:s}' read: {:d} nodes, {:d} elements.",
89 mesh->getName(),
90 mesh->getNumberOfNodes(),
91 mesh->getNumberOfElements());
92 INFO("Mesh read runtime: {:g} s.", run_timer.elapsed());
93 INFO("Mesh read CPU time: {:g} s.", CPU_timer.elapsed());
94
95 // Write output file
96 auto const file_name = output_directory_arg.getValue() + ".vtu";
97 DBUG("Writing output to '{:s}'.", file_name);
98
99 MeshLib::IO::VtuInterface vtu_interface(mesh);
100 vtu_interface.writeToFile(file_name);
101
102 INFO("Total runtime: {:g} s.", run_timer.elapsed());
103 INFO("Total CPU time: {:g} s.", CPU_timer.elapsed());
104 return EXIT_SUCCESS;
105}
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Count CPU time.
Definition CPUTime.h:23
void start()
Start the timer.
Definition CPUTime.h:26
double elapsed() const
Get the elapsed time after started.
Definition CPUTime.h:29
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:105
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:102
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:99
MPI_Comm OGS_COMM_WORLD
Definition MPI.cpp:15
std::unique_ptr< TCLAP::ValueArg< std::string > > makeLogLevelArg()
void setConsoleLogLevel(std::string const &level_string)
Definition Logging.cpp:37
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)

References DBUG(), BaseLib::CPUTime::elapsed(), BaseLib::RunTime::elapsed(), MeshLib::Mesh::getName(), MeshLib::Mesh::getNumberOfElements(), MeshLib::Mesh::getNumberOfNodes(), INFO(), BaseLib::makeLogLevelArg(), BaseLib::MPI::OGS_COMM_WORLD, OGS_FATAL, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), BaseLib::setConsoleLogLevel(), BaseLib::CPUTime::start(), BaseLib::RunTime::start(), and MeshLib::IO::VtuInterface::writeToFile().