OGS
OGS2VTK.cpp
Go to the documentation of this file.
1
14#include <tclap/CmdLine.h>
15
16#include <memory>
17#include <string>
18
19#include "BaseLib/Logging.h"
20#include "BaseLib/MPI.h"
22#include "InfoLib/GitInfo.h"
25#include "MeshLib/Mesh.h"
26
27int main(int argc, char* argv[])
28{
29 TCLAP::CmdLine cmd(
30 "Converts OGS mesh into VTK mesh.\n\n"
31 "OpenGeoSys-6 software, version " +
33 ".\n"
34 "Copyright (c) 2012-2025, OpenGeoSys Community "
35 "(http://www.opengeosys.org)",
37 TCLAP::ValueArg<std::string> mesh_in(
38 "i", "mesh-input-file",
39 "Input (.msh). The name of the file containing the input mesh", true,
40 "", "INPUT_FILE");
41 cmd.add(mesh_in);
42 TCLAP::ValueArg<std::string> mesh_out(
43 "o", "mesh-output-file",
44 "Output (.vtk), The name of the file the mesh will be written to", true,
45 "", "OUTPUT_FILE");
46 cmd.add(mesh_out);
47 auto log_level_arg = BaseLib::makeLogLevelArg();
48 cmd.add(log_level_arg);
49 TCLAP::SwitchArg use_ascii_arg(
50 "", "ascii_output",
51 "Write VTU output in ASCII file. Due to possible rounding the ascii "
52 "output could result in lower accuracy");
53 cmd.add(use_ascii_arg);
54 cmd.parse(argc, argv);
55
56 BaseLib::MPI::Setup mpi_setup(argc, argv);
57 BaseLib::initOGSLogger(log_level_arg.getValue());
58
59 std::unique_ptr<MeshLib::Mesh const> mesh(
60 MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
61 if (!mesh)
62 {
63 return EXIT_FAILURE;
64 }
65 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
66 mesh->getNumberOfElements());
67
68 auto const data_mode =
69 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
70
71 MeshLib::IO::writeVtu(*mesh, mesh_out.getValue(), data_mode);
72
73 return EXIT_SUCCESS;
74}
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
Definition of the Mesh class.
int main(int argc, char *argv[])
Definition OGS2VTK.cpp:27
Implementation of the VtuInterface class.
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
GITINFOLIB_EXPORT const std::string ogs_version
int writeVtu(MeshLib::Mesh const &mesh, std::string const &file_name, int const data_mode)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
Definition of readMeshFromFile function.