OGS
convertGEO.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <tclap/CmdLine.h>
5
6#include <string>
7#include <vector>
8
11#include "BaseLib/Logging.h"
12#include "BaseLib/MPI.h"
14#include "GeoLib/GEOObjects.h"
15#include "InfoLib/GitInfo.h"
16
17int main(int argc, char* argv[])
18{
19 TCLAP::CmdLine cmd(
20 "Converts OGS geometry file into another file format. "
21 "Currently *.gml (OGS6 XML-based format) and *.gli (OGS5 format) "
22 "formats are supported.\n\n"
23 "OpenGeoSys-6 software, version " +
25 ".\n"
26 "Copyright (c) 2012-2026, OpenGeoSys Community "
27 "(http://www.opengeosys.org)",
29 TCLAP::ValueArg<std::string> argInputFileName(
30 "i", "input-file",
31 "Input (.gml|.gli). The name of the geometry file to be converted",
32 true, "", "INPUT_FILE");
33 cmd.add(argInputFileName);
34 TCLAP::ValueArg<std::string> argOutputFileName(
35 "o", "output-file",
36 "Output. The name of the new geometry file whose file format is "
37 "guessed from "
38 "its file extension",
39 true, "", "OUTPUT_FILE");
40 cmd.add(argOutputFileName);
41
42 TCLAP::ValueArg<std::string> gmsh_path_arg(
43 "g", "gmsh-path", "Input (.msh). The path to the gmsh binary file",
44 false, "", "INPUT_FILE");
45 cmd.add(gmsh_path_arg);
46 auto log_level_arg = BaseLib::makeLogLevelArg();
47 cmd.add(log_level_arg);
48 cmd.parse(argc, argv);
49
50 BaseLib::MPI::Setup mpi_setup(argc, argv);
51 BaseLib::initOGSLogger(log_level_arg.getValue());
52
53 GeoLib::GEOObjects geoObjects;
54 FileIO::readGeometryFromFile(argInputFileName.getValue(), geoObjects,
55 gmsh_path_arg.getValue());
56 auto const geo_names = geoObjects.getGeometryNames();
57 assert(geo_names.size() == 1);
58
59 FileIO::writeGeometryToFile(geo_names[0], geoObjects,
60 argOutputFileName.getValue());
61
62 return EXIT_SUCCESS;
63}
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
int main(int argc, char *argv[])
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
void writeGeometryToFile(std::string const &geo_name, GeoLib::GEOObjects &geo_objs, std::string const &fname)
GITINFOLIB_EXPORT const std::string ogs_version