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