OGS
BinaryToPVTU.cpp
Go to the documentation of this file.
1
13#include <tclap/CmdLine.h>
14#include <vtkMPIController.h>
15#include <vtkSmartPointer.h>
16
17#include "BaseLib/CPUTime.h"
18#include "BaseLib/FileTools.h"
19#include "BaseLib/Logging.h"
20#include "BaseLib/MPI.h"
21#include "BaseLib/RunTime.h"
23#include "InfoLib/GitInfo.h"
27
28int main(int argc, char* argv[])
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::MPI::Setup mpi_setup(argc, argv);
59 BaseLib::initOGSLogger(log_level_arg.getValue());
60
61 // start the timer
62 BaseLib::RunTime run_timer;
63 run_timer.start();
64 BaseLib::CPUTime CPU_timer;
65 CPU_timer.start();
66
67 // init vtkMPI
68 vtkSmartPointer<vtkMPIController> controller =
69 vtkSmartPointer<vtkMPIController>::New();
70 controller->Initialize(&argc, &argv, 1);
71 vtkMPIController::SetGlobalController(controller);
72
74 dynamic_cast<MeshLib::NodePartitionedMesh*>(
75 MeshLib::IO::readMeshFromFile(mesh_input.getValue()));
76 INFO("Mesh '{:s}' read: {:d} nodes, {:d} elements.",
77 mesh->getName(),
78 mesh->getNumberOfNodes(),
79 mesh->getNumberOfElements());
80 INFO("Mesh read runtime: {:g} s.", run_timer.elapsed());
81 INFO("Mesh read CPU time: {:g} s.", CPU_timer.elapsed());
82
83 // Write output file
84 auto const file_name = output_directory_arg.getValue() + ".vtu";
85 DBUG("Writing output to '{:s}'.", file_name);
86
87 MeshLib::IO::VtuInterface vtu_interface(mesh);
88 vtu_interface.writeToFile(file_name);
89
90 INFO("Total runtime: {:g} s.", run_timer.elapsed());
91 INFO("Total CPU time: {:g} s.", CPU_timer.elapsed());
92 return EXIT_SUCCESS;
93}
int main(int argc, char *argv[])
Definition of the CPUTime class.
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
Definition of mesh class for partitioned mesh (by node) for parallel computing within the framework o...
Definition of the RunTime class.
Implementation of the VtuInterface class.
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....
bool writeToFile(std::filesystem::path const &file_path)
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
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
Definition of readMeshFromFile function.