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

21 {
22  TCLAP::CmdLine cmd(
23  "Tool to create gmsh geometry (geo-file) out of a gml geometry.\n\n"
24  "OpenGeoSys-6 software, version " +
26  ".\n"
27  "Copyright (c) 2012-2021, OpenGeoSys Community "
28  "(http://www.opengeosys.org)",
30  TCLAP::ValueArg<std::string> geo_output_arg(
31  "o", "output", "output gmsh geometry file (*.geo)", true, "",
32  "output file");
33  cmd.add(geo_output_arg);
34  TCLAP::MultiArg<std::string> geo_input_arg(
35  "i", "input", "input geometry file (*.gml)", true, "input file name");
36  cmd.add(geo_input_arg);
37  TCLAP::ValueArg<unsigned> max_number_of_points_in_quadtree_leaf_arg(
38  "", "max_points_in_quadtree_leaf", "positive number", false, 2,
39  "max points in a quadtree leaf before the leaf is split");
40  cmd.add(max_number_of_points_in_quadtree_leaf_arg);
41  TCLAP::ValueArg<double> mesh_density_scaling_points_arg(
42  "", "mesh_density_scaling_at_points", "positive floating point number",
43  false, 0.2, "desired mesh density at points");
44  cmd.add(mesh_density_scaling_points_arg);
45  TCLAP::ValueArg<double> mesh_density_scaling_stations_arg(
46  "", "mesh_density_scaling_at_stations",
47  "positive floating point number", false, 0.05,
48  "desired mesh density at stations");
49  cmd.add(mesh_density_scaling_stations_arg);
50  TCLAP::ValueArg<double> average_point_density_arg(
51  "a", "average_point_density",
52  "average point density / average edge length as a positive floating "
53  "point number",
54  false, 1,
55  "desired point density / edge length in homogeneous meshing approach");
56  cmd.add(average_point_density_arg);
57  TCLAP::SwitchArg homogeneous_flag(
58  "", "homogeneous", "Use Gmsh homogeneous meshing method.", false);
59  cmd.add(homogeneous_flag);
60 
61  cmd.parse(argc, argv);
62 
63  GeoLib::GEOObjects geo_objects;
64  for (auto const& geometry_name : geo_input_arg.getValue())
65  {
66  GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
67  try
68  {
69  if (!xml.readFile(geometry_name))
70  {
71  return EXIT_FAILURE;
72  }
73  }
74  catch (std::runtime_error const& err)
75  {
76  ERR("Failed to read file '{:s}'.", geometry_name);
77  ERR("{:s}", err.what());
78  return EXIT_FAILURE;
79  }
80  INFO("Successfully read file '{:s}'.", geometry_name);
81  }
82 
83  auto const geo_names = geo_objects.getGeometryNames();
84 
85  bool const rotate = false;
86  bool const keep_preprocessed_geometry = false;
87 
88  if (homogeneous_flag.getValue())
89  { // homogeneous meshing
90  double const average_mesh_density =
91  average_point_density_arg.getValue();
93  geo_objects, true,
95  average_mesh_density, 0.0, 0, geo_names, rotate,
96  keep_preprocessed_geometry);
97  BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
98  geo_output_arg.getValue());
99  }
100  else
101  { // adaptive meshing
102  unsigned const max_number_of_points_in_quadtree_leaf =
103  max_number_of_points_in_quadtree_leaf_arg.getValue();
104  double const mesh_density_scaling_points =
105  mesh_density_scaling_points_arg.getValue();
106  double const mesh_density_scaling_stations =
107  mesh_density_scaling_stations_arg.getValue();
109  geo_objects, true,
111  mesh_density_scaling_points, mesh_density_scaling_stations,
112  max_number_of_points_in_quadtree_leaf, geo_names, rotate,
113  keep_preprocessed_geometry);
114  BaseLib::IO::writeStringToFile(gmsh_io.writeToString(),
115  geo_output_arg.getValue());
116  }
117 
118  return EXIT_SUCCESS;
119 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Reads and writes GMSH-files to and from OGS data structures.
Definition: GMSHInterface.h:46
Container class for geometric objects.
Definition: GEOObjects.h:61
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:401
int writeStringToFile(std::string 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(), FileIO::GMSH::FixedMeshDensity, GeoLib::GEOObjects::getGeometryNames(), INFO(), GitInfoLib::GitInfo::ogs_version, GeoLib::IO::BoostXmlGmlInterface::readFile(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().