25{
26 TCLAP::CmdLine cmd(
27 "Tool to create gmsh geometry (geo-file) out of a gml geometry.\n\n"
28 "OpenGeoSys-6 software, version " +
30 ".\n"
31 "Copyright (c) 2012-2024, OpenGeoSys Community "
32 "(http://www.opengeosys.org)",
34 TCLAP::ValueArg<std::string> geo_output_arg(
35 "o", "output", "output gmsh geometry file (*.geo)", true, "",
36 "output file");
37 cmd.add(geo_output_arg);
38 TCLAP::MultiArg<std::string> geo_input_arg(
39 "i", "input", "input geometry file (*.gml)", true, "input file name");
40 cmd.add(geo_input_arg);
41 TCLAP::ValueArg<unsigned> max_number_of_points_in_quadtree_leaf_arg(
42 "", "max_points_in_quadtree_leaf", "positive number", false, 2,
43 "max points in a quadtree leaf before the leaf is split");
44 cmd.add(max_number_of_points_in_quadtree_leaf_arg);
45 TCLAP::ValueArg<double> mesh_density_scaling_points_arg(
46 "", "mesh_density_scaling_at_points", "positive floating point number",
47 false, 0.2, "desired mesh density at points");
48 cmd.add(mesh_density_scaling_points_arg);
49 TCLAP::ValueArg<double> mesh_density_scaling_stations_arg(
50 "", "mesh_density_scaling_at_stations",
51 "positive floating point number", false, 0.05,
52 "desired mesh density at stations");
53 cmd.add(mesh_density_scaling_stations_arg);
54 TCLAP::ValueArg<double> average_point_density_arg(
55 "a", "average_point_density",
56 "average point density / average edge length as a positive floating "
57 "point number",
58 false, 1,
59 "desired point density / edge length in homogeneous meshing approach");
60 cmd.add(average_point_density_arg);
61 TCLAP::SwitchArg homogeneous_flag(
62 "", "homogeneous", "Use Gmsh homogeneous meshing method.", false);
63 cmd.add(homogeneous_flag);
64 TCLAP::ValueArg<std::string> merged_geometries_output(
65 "", "write_merged_geometries",
66 "file name for the output of the internal created geometry (*.gml) "
67 "(useful for debugging the data)",
68 false, "", "output file name");
69 cmd.add(merged_geometries_output);
70
71 cmd.parse(argc, argv);
72
73#ifdef USE_PETSC
74 MPI_Init(&argc, &argv);
75#endif
76
78 for (auto const& geometry_name : geo_input_arg.getValue())
79 {
81 try
82 {
83 if (!xml.readFile(geometry_name))
84 {
85#ifdef USE_PETSC
86 MPI_Finalize();
87#endif
88 return EXIT_FAILURE;
89 }
90 }
91 catch (std::runtime_error const& err)
92 {
93 ERR(
"Failed to read file '{:s}'.", geometry_name);
94 ERR(
"{:s}", err.what());
95#ifdef USE_PETSC
96 MPI_Finalize();
97#endif
98 return EXIT_FAILURE;
99 }
100 INFO(
"Successfully read file '{:s}'.", geometry_name);
101 }
102
104
105 bool const rotate = false;
106 bool const keep_preprocessed_geometry = false;
107
108 try
109 {
110 if (homogeneous_flag.getValue())
111 {
112 double const average_mesh_density =
113 average_point_density_arg.getValue();
115 geo_objects, true,
117 average_mesh_density, 0.0, 0, geo_names, rotate,
118 keep_preprocessed_geometry);
120 geo_output_arg.getValue());
121 }
122 else
123 {
124 unsigned const max_number_of_points_in_quadtree_leaf =
125 max_number_of_points_in_quadtree_leaf_arg.getValue();
126 double const mesh_density_scaling_points =
127 mesh_density_scaling_points_arg.getValue();
128 double const mesh_density_scaling_stations =
129 mesh_density_scaling_stations_arg.getValue();
131 geo_objects, true,
133 mesh_density_scaling_points, mesh_density_scaling_stations,
134 max_number_of_points_in_quadtree_leaf, geo_names, rotate,
135 keep_preprocessed_geometry);
137 geo_output_arg.getValue());
138 }
139 }
140 catch (std::runtime_error& error)
141 {
142 ERR(
"{}", error.what());
143 if (merged_geometries_output.isSet())
144 {
148 merged_geometries_output.getValue());
149 }
150 else
151 {
153 "Hint: Using the command line flag "
154 "'--write_merged_geometries buggy_geometry.gml' allows "
155 "for better analysis of the problem.");
156 }
157 ERR(
"An error has occurred - programme will be terminated.");
158#ifdef USE_PETSC
159 MPI_Finalize();
160#endif
161 return EXIT_FAILURE;
162 }
163#ifdef USE_PETSC
164 MPI_Finalize();
165#endif
166 return EXIT_SUCCESS;
167}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Reads and writes GMSH-files to and from OGS data structures.
Container class for geometric objects.
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)
@ AdaptiveMeshDensity
computing the mesh density employing a QuadTree
@ FixedMeshDensity
set the parameter with a fixed value
GITINFOLIB_EXPORT const std::string ogs_version