OGS
appendLinesAlongPolyline.cpp
Go to the documentation of this file.
1
11
12#include <tclap/CmdLine.h>
13
15#include "BaseLib/FileTools.h"
16#include "BaseLib/Logging.h"
17#include "BaseLib/MPI.h"
19#include "GeoLib/GEOObjects.h"
20#include "GeoLib/PolylineVec.h"
21#include "InfoLib/GitInfo.h"
24#include "MeshLib/Mesh.h"
25
26int main(int argc, char* argv[])
27{
28 TCLAP::CmdLine cmd(
29 "Append line elements into a mesh.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
33 "Copyright (c) 2012-2025, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36 TCLAP::ValueArg<std::string> mesh_in(
37 "i", "mesh-input-file",
38 "Input (.vtu). The name of the file containing the input mesh", true,
39 "", "INPUT_FILE");
40 cmd.add(mesh_in);
41 TCLAP::ValueArg<std::string> mesh_out(
42 "o", "mesh-output-file",
43 "Output (.vtu | .msh). The name of the file the mesh will be written "
44 "to",
45 true, "", "OUTPUT_FILE");
46 cmd.add(mesh_out);
47 TCLAP::ValueArg<std::string> geoFileArg(
48 "g", "geo-file",
49 "Input (.gml). The name of the input geometry file which contains "
50 "polylines",
51 true, "", "INPUT_FILE");
52 cmd.add(geoFileArg);
53 auto log_level_arg = BaseLib::makeLogLevelArg();
54 cmd.add(log_level_arg);
55
56 TCLAP::ValueArg<std::string> gmsh_path_arg(
57 "", "gmsh-path", "Input (.msh). The path to the input gmsh binary file",
58 false, "", "INPUT_FILE");
59 cmd.add(gmsh_path_arg);
60
61 // parse arguments
62 cmd.parse(argc, argv);
63
64 BaseLib::MPI::Setup mpi_setup(argc, argv);
65 BaseLib::initOGSLogger(log_level_arg.getValue());
66
67 // read GEO objects
68 GeoLib::GEOObjects geo_objs;
69 FileIO::readGeometryFromFile(geoFileArg.getValue(), geo_objs,
70 gmsh_path_arg.getValue());
71
72 auto const geo_names = geo_objs.getGeometryNames();
73 if (geo_names.empty())
74 {
75 ERR("No geometries found.");
76 return EXIT_FAILURE;
77 }
78 const GeoLib::PolylineVec* ply_vec(
79 geo_objs.getPolylineVecObj(geo_names[0]));
80 if (!ply_vec)
81 {
82 ERR("Could not find polylines in geometry '{:s}'.", geo_names.front());
83 return EXIT_FAILURE;
84 }
85
86 // read a mesh
88 mesh_in.getValue(), true /* compute_element_neighbors */));
89 if (!mesh)
90 {
91 ERR("Mesh file '{:s}' not found", mesh_in.getValue());
92 return EXIT_FAILURE;
93 }
94 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
95 mesh->getNumberOfElements());
96
97 // add line elements
98 std::unique_ptr<MeshLib::Mesh> new_mesh =
100 INFO("Mesh created: {:d} nodes, {:d} elements.",
101 new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
102
103 MeshLib::IO::writeMeshToFile(*new_mesh, mesh_out.getValue());
104
105 return EXIT_SUCCESS;
106}
Filename manipulation routines.
Definition of the GEOObjects class.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
Definition of the Mesh class.
Definition of the PolylineVec class.
int main(int argc, char *argv[])
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const PolylineVec * getPolylineVecObj(const std::string &name) const
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
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
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
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)
Definition of readMeshFromFile function.