OGS
constructMeshesFromGeometry.cpp
Go to the documentation of this file.
1
11#include <tclap/CmdLine.h>
12
13#include "GeoLib/GEOObjects.h"
15#include "InfoLib/GitInfo.h"
20#include "MeshLib/Mesh.h"
21
22#ifdef USE_PETSC
23#include <mpi.h>
24#endif
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-2024, 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 (default 1e-16) ",
54 false,
55 1e-16,
56 "float");
57 cmd.add(search_length_arg);
58
59 TCLAP::ValueArg<std::string> geometry_arg("g",
60 "geometry",
61 "the file name the geometry",
62 true,
63 "",
64 "geometry file name");
65 cmd.add(geometry_arg);
66
67 TCLAP::ValueArg<std::string> mesh_arg(
68 "m",
69 "mesh",
70 "the file name of the mesh where the geometry is defined",
71 true,
72 "",
73 "mesh file name");
74 cmd.add(mesh_arg);
75
76 TCLAP::SwitchArg multiple_nodes_allowed_arg(
77 "", "multiple-nodes-allowed",
78 "Allows multiple mesh nodes in eps environment.");
79 cmd.add(multiple_nodes_allowed_arg);
80
81 cmd.parse(argc, argv);
82
83#ifdef USE_PETSC
84 MPI_Init(&argc, &argv);
85#endif
86 std::unique_ptr<MeshLib::Mesh> mesh{
87 MeshLib::IO::readMeshFromFile(mesh_arg.getValue())};
88
89 auto const geo_objects = readGeometry(geometry_arg.getValue());
90
91 double const search_length = search_length_arg.getValue();
92
93 auto const extracted_meshes = constructAdditionalMeshesFromGeoObjects(
94 *geo_objects,
95 *mesh,
96 std::make_unique<MeshGeoToolsLib::SearchLength>(search_length),
97 multiple_nodes_allowed_arg.getValue());
98
99 for (auto const& m_ptr : extracted_meshes)
100 {
101 if (!m_ptr)
102 {
103 ERR("Could not create a mesh for each given geometry.");
104#ifdef USE_PETSC
105 MPI_Finalize();
106#endif
107 return EXIT_FAILURE;
108 }
109 if (m_ptr->getNodes().empty())
110 {
111 WARN(
112 "The created mesh '{:s}' hasn't any nodes or elements and thus "
113 "it isn't written to file.",
114 m_ptr->getName());
115 continue;
116 }
117 MeshLib::IO::writeMeshToFile(*m_ptr, m_ptr->getName() + ".vtu");
118 }
119
120#ifdef USE_PETSC
121 MPI_Finalize();
122#endif
123 return EXIT_SUCCESS;
124}
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:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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)
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.