OGS
constructMeshesFromGeometry.cpp
Go to the documentation of this file.
1
11#include <tclap/CmdLine.h>
12
13#include "BaseLib/Logging.h"
14#include "BaseLib/MPI.h"
16#include "GeoLib/GEOObjects.h"
18#include "InfoLib/GitInfo.h"
23#include "MeshLib/Mesh.h"
24
25std::unique_ptr<GeoLib::GEOObjects> readGeometry(std::string const& filename)
26{
27 auto geo_objects = std::make_unique<GeoLib::GEOObjects>();
28 GeoLib::IO::BoostXmlGmlInterface gml_reader(*geo_objects);
29
30 DBUG("Reading geometry file '{:s}'.", filename);
31 gml_reader.readFile(filename);
32 return geo_objects;
33}
34
35int main(int argc, char* argv[])
36{
37 TCLAP::CmdLine cmd(
38 "Converts a geometry defined on a given mesh to distinct meshes. The "
39 "documentation is available at "
40 "https://www.opengeosys.org/docs/tools/meshing-submeshes/"
41 "constructmeshesfromgeometry/.\n\n"
42 "OpenGeoSys-6 software, version " +
44 ".\n"
45 "Copyright (c) 2012-2025, OpenGeoSys Community "
46 "(http://www.opengeosys.org)",
48
49 TCLAP::ValueArg<double> search_length_arg(
50 "s",
51 "searchlength",
52 "search length determining radius for the node search algorithm. "
53 "Non-negative floating point number, (min = 0)",
54 false,
55 1e-16,
56 "float");
57 cmd.add(search_length_arg);
58
59 TCLAP::ValueArg<std::string> geometry_arg(
60 "g",
61 "geometry",
62 "Input (.gml | .gli). The file name of the input geometry",
63 true,
64 "",
65 "INPUT_FILE");
66 cmd.add(geometry_arg);
67
68 TCLAP::ValueArg<std::string> mesh_arg(
69 "m",
70 "mesh",
71 "Input (.vtu). "
72 "The file name of the input mesh where the geometry is defined",
73 true,
74 "",
75 "INPUT_FILE");
76 cmd.add(mesh_arg);
77
78 TCLAP::SwitchArg multiple_nodes_allowed_arg(
79 "", "multiple-nodes-allowed",
80 "Allows multiple mesh nodes in eps environment.");
81 cmd.add(multiple_nodes_allowed_arg);
82
83 auto log_level_arg = BaseLib::makeLogLevelArg();
84 cmd.add(log_level_arg);
85 cmd.parse(argc, argv);
86
87 BaseLib::MPI::Setup mpi_setup(argc, argv);
88 BaseLib::initOGSLogger(log_level_arg.getValue());
89
90 std::unique_ptr<MeshLib::Mesh> mesh{
91 MeshLib::IO::readMeshFromFile(mesh_arg.getValue())};
92
93 auto const geo_objects = readGeometry(geometry_arg.getValue());
94
95 double const search_length = search_length_arg.getValue();
96
97 auto const extracted_meshes = constructAdditionalMeshesFromGeoObjects(
98 *geo_objects,
99 *mesh,
100 std::make_unique<MeshGeoToolsLib::SearchLength>(search_length),
101 multiple_nodes_allowed_arg.getValue());
102
103 for (auto const& m_ptr : extracted_meshes)
104 {
105 if (!m_ptr)
106 {
107 ERR("Could not create a mesh for each given geometry.");
108 return EXIT_FAILURE;
109 }
110 if (m_ptr->getNodes().empty())
111 {
112 WARN(
113 "The created mesh '{:s}' hasn't any nodes or elements and thus "
114 "it isn't written to file.",
115 m_ptr->getName());
116 continue;
117 }
118 MeshLib::IO::writeMeshToFile(*m_ptr, m_ptr->getName() + ".vtu");
119 }
120
121 return EXIT_SUCCESS;
122}
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
Git information.
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:42
Definition of the Mesh class.
Base class for different search length strategies.
bool readFile(const std::string &fname) override
Reads an xml-file containing OGS geometry.
int main(int argc, char *argv[])
std::unique_ptr< GeoLib::GEOObjects > readGeometry(std::string const &filename)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
GITINFOLIB_EXPORT const std::string ogs_version
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.