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