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