OGS
OGS2VTK.cpp
Go to the documentation of this file.
1
14#include <tclap/CmdLine.h>
15
16#ifdef USE_PETSC
17#include <mpi.h>
18#endif
19
20#include <memory>
21#include <string>
22
23#include "InfoLib/GitInfo.h"
26#include "MeshLib/Mesh.h"
27
28int main(int argc, char* argv[])
29{
30 TCLAP::CmdLine cmd(
31 "Converts OGS mesh into VTK mesh.\n\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2024, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38 TCLAP::ValueArg<std::string> mesh_in(
39 "i", "mesh-input-file",
40 "the name of the file containing the input mesh", true, "",
41 "file name of input mesh");
42 cmd.add(mesh_in);
43 TCLAP::ValueArg<std::string> mesh_out(
44 "o", "mesh-output-file",
45 "the name of the file the mesh will be written to", true, "",
46 "file name of output mesh");
47 cmd.add(mesh_out);
48 TCLAP::SwitchArg use_ascii_arg(
49 "", "ascii_output",
50 "Write VTU output in ASCII format. Due to possible rounding the ascii "
51 "output could result in lower accuracy.");
52 cmd.add(use_ascii_arg);
53 cmd.parse(argc, argv);
54
55#ifdef USE_PETSC
56 MPI_Init(&argc, &argv);
57#endif
58
59 std::unique_ptr<MeshLib::Mesh const> mesh(
60 MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
61 if (!mesh)
62 {
63#ifdef USE_PETSC
64 MPI_Finalize();
65#endif
66 return EXIT_FAILURE;
67 }
68 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
69 mesh->getNumberOfElements());
70
71 auto const data_mode =
72 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
73
74 MeshLib::IO::writeVtu(*mesh, mesh_out.getValue(), data_mode);
75
76#ifdef USE_PETSC
77 MPI_Finalize();
78#endif
79 return EXIT_SUCCESS;
80}
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the Mesh class.
int main(int argc, char *argv[])
Definition OGS2VTK.cpp:28
Implementation of the VtuInterface class.
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.