OGS
geometryToGmshGeo.cpp File Reference

Detailed Description

A small tool to create a gmsh geometry out of gml geometry.

Definition in file geometryToGmshGeo.cpp.

Include dependency graph for geometryToGmshGeo.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 21 of file geometryToGmshGeo.cpp.

22{
23 TCLAP::CmdLine cmd(
24 "Tool to create gmsh geometry (geo-file) out of a gml geometry.\n\n"
25 "OpenGeoSys-6 software, version " +
27 ".\n"
28 "Copyright (c) 2012-2024, OpenGeoSys Community "
29 "(http://www.opengeosys.org)",
31 TCLAP::ValueArg<std::string> geo_output_arg(
32 "o", "output", "output gmsh geometry file (*.geo)", true, "",
33 "output file");
34 cmd.add(geo_output_arg);
35 TCLAP::MultiArg<std::string> geo_input_arg(
36 "i", "input", "input geometry file (*.gml)", true, "input file name");
37 cmd.add(geo_input_arg);
38 TCLAP::ValueArg<unsigned> max_number_of_points_in_quadtree_leaf_arg(
39 "", "max_points_in_quadtree_leaf", "positive number", false, 2,
40 "max points in a quadtree leaf before the leaf is split");
41 cmd.add(max_number_of_points_in_quadtree_leaf_arg);
42 TCLAP::ValueArg<double> mesh_density_scaling_points_arg(
43 "", "mesh_density_scaling_at_points", "positive floating point number",
44 false, 0.2, "desired mesh density at points");
45 cmd.add(mesh_density_scaling_points_arg);
46 TCLAP::ValueArg<double> mesh_density_scaling_stations_arg(
47 "", "mesh_density_scaling_at_stations",
48 "positive floating point number", false, 0.05,
49 "desired mesh density at stations");
50 cmd.add(mesh_density_scaling_stations_arg);
51 TCLAP::ValueArg<double> average_point_density_arg(
52 "a", "average_point_density",
53 "average point density / average edge length as a positive floating "
54 "point number",
55 false, 1,
56 "desired point density / edge length in homogeneous meshing approach");
57 cmd.add(average_point_density_arg);
58 TCLAP::SwitchArg homogeneous_flag(
59 "", "homogeneous", "Use Gmsh homogeneous meshing method.", false);
60 cmd.add(homogeneous_flag);
61 TCLAP::ValueArg<std::string> merged_geometries_output(
62 "", "write_merged_geometries",
63 "file name for the output of the internal created geometry (*.gml) "
64 "(useful for debugging the data)",
65 false, "", "output file name");
66 cmd.add(merged_geometries_output);
67
68 cmd.parse(argc, argv);
69
70 BaseLib::MPI::Setup mpi_setup(argc, argv);
71
72 GeoLib::GEOObjects geo_objects;
73 for (auto const& geometry_name : geo_input_arg.getValue())
74 {
75 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
76 try
77 {
78 if (!xml.readFile(geometry_name))
79 {
80 return EXIT_FAILURE;
81 }
82 }
83 catch (std::runtime_error const& err)
84 {
85 ERR("Failed to read file '{:s}'.", geometry_name);
86 ERR("{:s}", err.what());
87 return EXIT_FAILURE;
88 }
89 INFO("Successfully read file '{:s}'.", geometry_name);
90 }
91
92 auto const geo_names = geo_objects.getGeometryNames();
93
94 bool const rotate = false;
95 bool const keep_preprocessed_geometry = false;
96
97 try
98 {
99 if (homogeneous_flag.getValue())
100 { // homogeneous meshing
101 double const average_mesh_density =
102 average_point_density_arg.getValue();
104 geo_objects, true,
106 average_mesh_density, 0.0, 0, geo_names, rotate,
107 keep_preprocessed_geometry);
108 BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
109 geo_output_arg.getValue());
110 }
111 else
112 { // adaptive meshing
113 unsigned const max_number_of_points_in_quadtree_leaf =
114 max_number_of_points_in_quadtree_leaf_arg.getValue();
115 double const mesh_density_scaling_points =
116 mesh_density_scaling_points_arg.getValue();
117 double const mesh_density_scaling_stations =
118 mesh_density_scaling_stations_arg.getValue();
120 geo_objects, true,
122 mesh_density_scaling_points, mesh_density_scaling_stations,
123 max_number_of_points_in_quadtree_leaf, geo_names, rotate,
124 keep_preprocessed_geometry);
125 BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
126 geo_output_arg.getValue());
127 }
128 }
129 catch (std::runtime_error& error)
130 {
131 ERR("{}", error.what());
132 if (merged_geometries_output.isSet())
133 {
134 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
135 xml.export_name = geo_objects.getGeometryNames().back();
136 BaseLib::IO::writeStringToFile(xml.writeToString(),
137 merged_geometries_output.getValue());
138 }
139 else
140 {
141 INFO(
142 "Hint: Using the command line flag "
143 "'--write_merged_geometries buggy_geometry.gml' allows "
144 "for better analysis of the problem.");
145 }
146 ERR("An error has occurred - programme will be terminated.");
147 return EXIT_FAILURE;
148 }
149 return EXIT_SUCCESS;
150}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
std::string getValue(std::string const &line, std::string const &val_name, bool is_string)
Reads and writes GMSH-files to and from OGS data structures.
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
@ AdaptiveMeshDensity
computing the mesh density employing a QuadTree
@ FixedMeshDensity
set the parameter with a fixed value
GITINFOLIB_EXPORT const std::string ogs_version

References FileIO::GMSH::AdaptiveMeshDensity, ERR(), BaseLib::IO::XMLInterface::export_name, FileIO::GMSH::FixedMeshDensity, GeoLib::GEOObjects::getGeometryNames(), INFO(), GitInfoLib::GitInfo::ogs_version, GeoLib::IO::BoostXmlGmlInterface::readFile(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().