OGS
Utils/FileConverter/GocadSGridReader.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
5
6#include <spdlog/spdlog.h>
7#include <tclap/CmdLine.h>
8
9#include <fstream>
10#include <sstream>
11#include <string>
12
14#include "BaseLib/FileTools.h"
15#include "BaseLib/Logging.h"
16#include "BaseLib/MPI.h"
18#include "InfoLib/GitInfo.h"
21#include "MeshLib/Mesh.h"
22#include "MeshLib/Node.h"
24
25int main(int argc, char* argv[])
26{
27 TCLAP::CmdLine cmd(
28 "Reads a Gocad stratigraphic grid file (file ending sg) and writes the "
29 "data in the vtk unstructured grid file format. The documentation is "
30 "available at "
31 "https://www.opengeosys.org/docs/tools/meshing/gocadsgridreader/."
32 "\n"
33 "OpenGeoSys-6 "
34 "software, version " +
36 ".\n"
37 "Copyright (c) 2012-2026, OpenGeoSys Community "
38 "(http://www.opengeosys.org)",
40
41 TCLAP::SwitchArg face_set_arg("f", "generate-face-sets",
42 "Generate face sets.");
43 cmd.add(face_set_arg);
44
45 TCLAP::ValueArg<std::string> mesh_output_arg(
46 "o", "output-mesh", "Output (.vtu). Unstructured grid filename", true,
47 "", "OUTPUT_FILE");
48 cmd.add(mesh_output_arg);
49
50 TCLAP::ValueArg<std::string> sg_file_arg(
51 "s", "sg", "Input (.sg). Gocad stratigraphic grid filename", true, "",
52 "INPUT_FILE");
53 cmd.add(sg_file_arg);
54 auto log_level_arg = BaseLib::makeLogLevelArg();
55 cmd.add(log_level_arg);
56
57 cmd.parse(argc, argv);
58
59 BaseLib::MPI::Setup mpi_setup(argc, argv);
60 BaseLib::initOGSLogger(log_level_arg.getValue());
61
62 // read the Gocad SGrid
63 INFO("Start reading Gocad SGrid.");
64 FileIO::Gocad::GocadSGridReader reader(sg_file_arg.getValue());
65 INFO("End reading Gocad SGrid.");
66
67 if (face_set_arg.getValue())
68 {
69 INFO("Generating a mesh for every face set.");
71 reader, BaseLib::extractPath(sg_file_arg.getValue()));
72 }
73
74 std::unique_ptr<MeshLib::Mesh> mesh(reader.getMesh());
76
77 INFO("Writing mesh to '{:s}'.", mesh_output_arg.getValue());
78 MeshLib::IO::writeMeshToFile(*mesh, mesh_output_arg.getValue());
79 return EXIT_SUCCESS;
80}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
int main(int argc, char *argv[])
std::unique_ptr< MeshLib::Mesh > getMesh() const
static void writePropertyVectorInformation(const MeshLib::Mesh &mesh)
writes out property vector information
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
std::string extractPath(std::string const &pathname)
void generateFaceSets(GocadSGridReader const &reader, std::string const &path)
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)