OGS
MapGeometryToMeshSurface.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include "BaseLib/MPI.h"
#include "GeoLib/GEOObjects.h"
#include "GeoLib/IO/XmlIO/Boost/BoostXmlGmlInterface.h"
#include "InfoLib/GitInfo.h"
#include "MeshGeoToolsLib/GeoMapper.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/Mesh.h"
Include dependency graph for MapGeometryToMeshSurface.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 26 of file MapGeometryToMeshSurface.cpp.

27{
28 TCLAP::CmdLine cmd(
29 "Maps geometric objects to the surface of a given mesh. "
30 "The documentation is available at "
31 "https://docs.opengeosys.org/docs/tools/model-preparation/"
32 "map-geometric-object-to-the-surface-of-a-mesh.\n\n"
33 "OpenGeoSys-6 software, version " +
35 ".\n"
36 "Copyright (c) 2012-2025, OpenGeoSys Community "
37 "(http://www.opengeosys.org)",
39 TCLAP::ValueArg<std::string> mesh_in(
40 "m", "mesh-file",
41 "Input (.vtu). The name of the input file containing the mesh", true,
42 "", "INPUT_FILE");
43 cmd.add(mesh_in);
44 TCLAP::ValueArg<std::string> input_geometry_fname(
45 "i", "input-geometry",
46 "Input (.gml). The name of the file containing the input geometry",
47 true, "", "INPUT_FILE");
48 cmd.add(input_geometry_fname);
49 TCLAP::SwitchArg additional_insert_mapping(
50 "a", "additional-insert-mapping",
51 "Advanced mapping algorithm will be applied, i.e. a new geometry will "
52 "be created and possibly new points will be inserted.");
53 cmd.add(additional_insert_mapping);
54 TCLAP::ValueArg<std::string> output_geometry_fname(
55 "o", "output-geometry",
56 "Output (.gml). The name of the file containing the output geometry",
57 true, "", "OUTPUT_FILE");
58 cmd.add(output_geometry_fname);
59 cmd.parse(argc, argv);
60
61 BaseLib::MPI::Setup mpi_setup(argc, argv);
62
63 // *** read geometry
64 GeoLib::GEOObjects geometries;
65 {
66 GeoLib::IO::BoostXmlGmlInterface xml_io(geometries);
67 if (xml_io.readFile(input_geometry_fname.getValue()))
68 {
69 INFO("Read geometry from file '{:s}'.",
70 input_geometry_fname.getValue());
71 }
72 else
73 {
74 return EXIT_FAILURE;
75 }
76 }
77
78 auto const geo_name = geometries.getGeometryNames()[0];
79
80 MeshGeoToolsLib::GeoMapper geo_mapper(geometries, geo_name);
81
82 // *** read mesh
83 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
84 mesh_in.getValue(), true /* compute_element_neighbors */));
85
86 if (additional_insert_mapping.getValue())
87 {
88 geo_mapper.advancedMapOnMesh(*mesh);
89 }
90 else
91 {
92 geo_mapper.mapOnMesh(mesh.get());
93 }
94
95 {
96 GeoLib::IO::BoostXmlGmlInterface xml_io(geometries);
97 xml_io.export_name = geo_name;
98 BaseLib::IO::writeStringToFile(xml_io.writeToString(),
99 output_geometry_fname.getValue());
100 }
101 return EXIT_SUCCESS;
102}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
A set of tools for mapping the elevation of geometric objects.
Definition GeoMapper.h:40
int writeStringToFile(std::string_view content, std::filesystem::path const &file_path)
Definition Writer.cpp:45
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)

References MeshGeoToolsLib::GeoMapper::advancedMapOnMesh(), BaseLib::IO::XMLInterface::export_name, GeoLib::GEOObjects::getGeometryNames(), INFO(), MeshGeoToolsLib::GeoMapper::mapOnMesh(), GitInfoLib::GitInfo::ogs_version, GeoLib::IO::BoostXmlGmlInterface::readFile(), MeshLib::IO::readMeshFromFile(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().