OGS
MapGeometryToMeshSurface.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.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 20 of file MapGeometryToMeshSurface.cpp.

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