OGS
VTK2OGS.cpp
Go to the documentation of this file.
1
14// STL
15#include <tclap/CmdLine.h>
16
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 VTK mesh into OGS 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 (.vtk). 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 (.msh). 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 cmd.parse(argc, argv);
50
51 BaseLib::MPI::Setup mpi_setup(argc, argv);
52 BaseLib::initOGSLogger(log_level_arg.getValue());
53
54 MeshLib::Mesh* mesh(
55 MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue()));
56 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
57 mesh->getNumberOfElements());
58
60 meshIO.setMesh(mesh);
61 BaseLib::IO::writeStringToFile(meshIO.writeToString(), mesh_out.getValue());
62
63 return EXIT_SUCCESS;
64}
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
Definition of the MeshIO class.
Definition of the Mesh class.
int main(int argc, char *argv[])
Definition VTK2OGS.cpp:27
Implementation of the VtuInterface class.
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
Interface for handling mesh files from OGS-5 and below. (*.msh files)
Definition MeshIO.h:37
void setMesh(const MeshLib::Mesh *mesh)
Set mesh for writing.
Definition MeshIO.cpp:437
static MeshLib::Mesh * readVTUFile(std::string const &file_name, bool const compute_element_neighbors=false)
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
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
GITINFOLIB_EXPORT const std::string ogs_version