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 22 of file geometryToGmshGeo.cpp.

23{
24 TCLAP::CmdLine cmd(
25 "Tool to create gmsh geometry (geo-file) out of a gml geometry.\n\n"
26 "OpenGeoSys-6 software, version " +
28 ".\n"
29 "Copyright (c) 2012-2025, OpenGeoSys Community "
30 "(http://www.opengeosys.org)",
32 TCLAP::ValueArg<std::string> geo_output_arg(
33 "o", "output", "Output (.geo) gmsh geometry file ", true, "",
34 "OUTPUT_FILE");
35 cmd.add(geo_output_arg);
36 TCLAP::MultiArg<std::string> geo_input_arg(
37 "i", "input", "Input (.gml) geometry file", true, "INPUT_FILE");
38 cmd.add(geo_input_arg);
39 TCLAP::ValueArg<unsigned> max_number_of_points_in_quadtree_leaf_arg(
40 "", "max_points_in_quadtree_leaf", "positive number/ (min = 0)", false,
41 2, "POINTS_QUADTREE");
42 cmd.add(max_number_of_points_in_quadtree_leaf_arg);
43 TCLAP::ValueArg<double> mesh_density_scaling_points_arg(
44 "", "mesh_density_scaling_at_points",
45 "positive floating point number, (min = 0)", false, 0.2,
46 "SCALING_POINTS");
47 cmd.add(mesh_density_scaling_points_arg);
48 TCLAP::ValueArg<double> mesh_density_scaling_stations_arg(
49 "", "mesh_density_scaling_at_stations",
50 "positive floating point number, (min = 0)", false, 0.05,
51 "SCALING_STATIONS");
52 cmd.add(mesh_density_scaling_stations_arg);
53 TCLAP::ValueArg<double> average_point_density_arg(
54 "a", "average_point_density",
55 "average point density / average edge length as a positive floating "
56 "point number, (min = 0)",
57 false, 1, "AVERAGE_POINT_DENSITY");
58 cmd.add(average_point_density_arg);
59 TCLAP::SwitchArg homogeneous_flag(
60 "", "homogeneous", "Use Gmsh homogeneous meshing method.", false);
61 cmd.add(homogeneous_flag);
62 TCLAP::ValueArg<std::string> merged_geometries_output(
63 "", "write_merged_geometries",
64 "Output (.gml). File name for the output of the internal created "
65 "geometry (useful for debugging the data)",
66 false, "", "OUTPUT_FILE");
67 cmd.add(merged_geometries_output);
68 auto log_level_arg = BaseLib::makeLogLevelArg();
69 cmd.add(log_level_arg);
70
71 cmd.parse(argc, argv);
72
73 BaseLib::MPI::Setup mpi_setup(argc, argv);
74 BaseLib::initOGSLogger(log_level_arg.getValue());
75
76 GeoLib::GEOObjects geo_objects;
77 for (auto const& geometry_name : geo_input_arg.getValue())
78 {
79 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
80 try
81 {
82 if (!xml.readFile(geometry_name))
83 {
84 return EXIT_FAILURE;
85 }
86 }
87 catch (std::runtime_error const& err)
88 {
89 ERR("Failed to read file '{:s}'.", geometry_name);
90 ERR("{:s}", err.what());
91 return EXIT_FAILURE;
92 }
93 INFO("Successfully read file '{:s}'.", geometry_name);
94 }
95
96 auto const geo_names = geo_objects.getGeometryNames();
97
98 bool const rotate = false;
99 bool const keep_preprocessed_geometry = false;
100
101 try
102 {
103 if (homogeneous_flag.getValue())
104 { // homogeneous meshing
105 double const average_mesh_density =
106 average_point_density_arg.getValue();
108 geo_objects, true,
110 average_mesh_density, 0.0, 0, geo_names, rotate,
111 keep_preprocessed_geometry);
112 BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
113 geo_output_arg.getValue());
114 }
115 else
116 { // adaptive meshing
117 unsigned const max_number_of_points_in_quadtree_leaf =
118 max_number_of_points_in_quadtree_leaf_arg.getValue();
119 double const mesh_density_scaling_points =
120 mesh_density_scaling_points_arg.getValue();
121 double const mesh_density_scaling_stations =
122 mesh_density_scaling_stations_arg.getValue();
124 geo_objects, true,
126 mesh_density_scaling_points, mesh_density_scaling_stations,
127 max_number_of_points_in_quadtree_leaf, geo_names, rotate,
128 keep_preprocessed_geometry);
129 BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
130 geo_output_arg.getValue());
131 }
132 }
133 catch (std::runtime_error& error)
134 {
135 ERR("{}", error.what());
136 if (merged_geometries_output.isSet())
137 {
138 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
139 xml.export_name = geo_objects.getGeometryNames().back();
140 BaseLib::IO::writeStringToFile(xml.writeToString(),
141 merged_geometries_output.getValue());
142 }
143 else
144 {
145 INFO(
146 "Hint: Using the command line flag "
147 "'--write_merged_geometries buggy_geometry.gml' allows "
148 "for better analysis of the problem.");
149 }
150 ERR("An error has occurred - programme will be terminated.");
151 return EXIT_FAILURE;
152 }
153 return EXIT_SUCCESS;
154}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
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
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
@ 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(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, GeoLib::IO::BoostXmlGmlInterface::readFile(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().