OGS
appendLinesAlongPolyline.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 <tclap/CmdLine.h>
7
9#include "BaseLib/FileTools.h"
10#include "BaseLib/Logging.h"
11#include "BaseLib/MPI.h"
13#include "GeoLib/GEOObjects.h"
14#include "GeoLib/PolylineVec.h"
15#include "InfoLib/GitInfo.h"
18#include "MeshLib/Mesh.h"
19
20int main(int argc, char* argv[])
21{
22 TCLAP::CmdLine cmd(
23 "Append line elements into a mesh.\n\n"
24 "OpenGeoSys-6 software, version " +
26 ".\n"
27 "Copyright (c) 2012-2026, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30 TCLAP::ValueArg<std::string> mesh_in(
31 "i", "mesh-input-file",
32 "Input (.vtu). The name of the file containing the input mesh", true,
33 "", "INPUT_FILE");
34 cmd.add(mesh_in);
35 TCLAP::ValueArg<std::string> mesh_out(
36 "o", "mesh-output-file",
37 "Output (.vtu | .msh). The name of the file the mesh will be written "
38 "to",
39 true, "", "OUTPUT_FILE");
40 cmd.add(mesh_out);
41 TCLAP::ValueArg<std::string> geoFileArg(
42 "g", "geo-file",
43 "Input (.gml). The name of the input geometry file which contains "
44 "polylines",
45 true, "", "INPUT_FILE");
46 cmd.add(geoFileArg);
47 auto log_level_arg = BaseLib::makeLogLevelArg();
48 cmd.add(log_level_arg);
49
50 TCLAP::ValueArg<std::string> gmsh_path_arg(
51 "", "gmsh-path", "Input (.msh). The path to the input gmsh binary file",
52 false, "", "INPUT_FILE");
53 cmd.add(gmsh_path_arg);
54
55 // parse arguments
56 cmd.parse(argc, argv);
57
58 BaseLib::MPI::Setup mpi_setup(argc, argv);
59 BaseLib::initOGSLogger(log_level_arg.getValue());
60
61 // read GEO objects
62 GeoLib::GEOObjects geo_objs;
63 FileIO::readGeometryFromFile(geoFileArg.getValue(), geo_objs,
64 gmsh_path_arg.getValue());
65
66 auto const geo_names = geo_objs.getGeometryNames();
67 if (geo_names.empty())
68 {
69 ERR("No geometries found.");
70 return EXIT_FAILURE;
71 }
72 const GeoLib::PolylineVec* ply_vec(
73 geo_objs.getPolylineVecObj(geo_names[0]));
74 if (!ply_vec)
75 {
76 ERR("Could not find polylines in geometry '{:s}'.", geo_names.front());
77 return EXIT_FAILURE;
78 }
79
80 // read a mesh
82 mesh_in.getValue(), true /* compute_element_neighbors */));
83 if (!mesh)
84 {
85 ERR("Mesh file '{:s}' not found", mesh_in.getValue());
86 return EXIT_FAILURE;
87 }
88 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
89 mesh->getNumberOfElements());
90
91 // add line elements
92 std::unique_ptr<MeshLib::Mesh> new_mesh =
94 INFO("Mesh created: {:d} nodes, {:d} elements.",
95 new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
96
97 MeshLib::IO::writeMeshToFile(*new_mesh, mesh_out.getValue());
98
99 return EXIT_SUCCESS;
100}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
int main(int argc, char *argv[])
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const PolylineVec * getPolylineVecObj(const std::string &name) const
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:91
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:88
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)
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
Definition PolylineVec.h:16
GITINFOLIB_EXPORT const std::string ogs_version
std::unique_ptr< MeshLib::Mesh > appendLinesAlongPolylines(const MeshLib::Mesh &mesh, const GeoLib::PolylineVec &ply_vec)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)