OGS
MapGeometryToMeshSurface.cpp
Go to the documentation of this file.
1/*
2 * \file
3 * \date 2015-04-20
4 * \brief Map geometric objects to the surface of the given mesh.
5 *
6 * \copyright
7 * Copyright (c) 2012-2025, OpenGeoSys Community (http://www.opengeosys.org)
8 * Distributed under a Modified BSD License.
9 * See accompanying file LICENSE.txt or
10 */
11
12#include <tclap/CmdLine.h>
13
14#include <algorithm>
15#include <cstdlib>
16#include <vector>
17
18#include "BaseLib/Logging.h"
19#include "BaseLib/MPI.h"
21#include "GeoLib/GEOObjects.h"
23#include "InfoLib/GitInfo.h"
26#include "MeshLib/Mesh.h"
27
28int main(int argc, char* argv[])
29{
30 TCLAP::CmdLine cmd(
31 "Maps geometric objects to the surface of a given mesh. "
32 "The documentation is available at "
33 "https://docs.opengeosys.org/docs/tools/model-preparation/"
34 "map-geometric-object-to-the-surface-of-a-mesh.\n\n"
35 "OpenGeoSys-6 software, version " +
37 ".\n"
38 "Copyright (c) 2012-2025, OpenGeoSys Community "
39 "(http://www.opengeosys.org)",
41 TCLAP::ValueArg<std::string> mesh_in(
42 "m", "mesh-file",
43 "Input (.vtu). The name of the input file containing the mesh", true,
44 "", "INPUT_FILE");
45 cmd.add(mesh_in);
46 TCLAP::ValueArg<std::string> input_geometry_fname(
47 "i", "input-geometry",
48 "Input (.gml). The name of the file containing the input geometry",
49 true, "", "INPUT_FILE");
50 cmd.add(input_geometry_fname);
51 TCLAP::SwitchArg additional_insert_mapping(
52 "a", "additional-insert-mapping",
53 "Advanced mapping algorithm will be applied, i.e. a new geometry will "
54 "be created and possibly new points will be inserted.");
55 cmd.add(additional_insert_mapping);
56 TCLAP::ValueArg<std::string> output_geometry_fname(
57 "o", "output-geometry",
58 "Output (.gml). The name of the file containing the output geometry",
59 true, "", "OUTPUT_FILE");
60 cmd.add(output_geometry_fname);
61 auto log_level_arg = BaseLib::makeLogLevelArg();
62 cmd.add(log_level_arg);
63 cmd.parse(argc, argv);
64
65 BaseLib::MPI::Setup mpi_setup(argc, argv);
66 BaseLib::initOGSLogger(log_level_arg.getValue());
67
68 // *** read geometry
69 GeoLib::GEOObjects geometries;
70 {
71 GeoLib::IO::BoostXmlGmlInterface xml_io(geometries);
72 if (xml_io.readFile(input_geometry_fname.getValue()))
73 {
74 INFO("Read geometry from file '{:s}'.",
75 input_geometry_fname.getValue());
76 }
77 else
78 {
79 return EXIT_FAILURE;
80 }
81 }
82
83 auto const geo_name = geometries.getGeometryNames()[0];
84
85 MeshGeoToolsLib::GeoMapper geo_mapper(geometries, geo_name);
86
87 // *** read mesh
88 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
89 mesh_in.getValue(), true /* compute_element_neighbors */));
90
91 if (additional_insert_mapping.getValue())
92 {
93 geo_mapper.advancedMapOnMesh(*mesh);
94 }
95 else
96 {
97 geo_mapper.mapOnMesh(mesh.get());
98 }
99
100 {
101 GeoLib::IO::BoostXmlGmlInterface xml_io(geometries);
102 xml_io.export_name = geo_name;
104 output_geometry_fname.getValue());
105 }
106 return EXIT_SUCCESS;
107}
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
Definition of the GeoMapper class.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
int main(int argc, char *argv[])
Definition of the Mesh class.
std::string writeToString()
Writes the object to a string.
Definition Writer.cpp:31
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
bool readFile(const std::string &fname) override
Reads an xml-file containing OGS geometry.
A set of tools for mapping the elevation of geometric objects.
Definition GeoMapper.h:40
void mapOnMesh(MeshLib::Mesh const *const mesh)
Definition GeoMapper.cpp:73
void advancedMapOnMesh(MeshLib::Mesh const &mesh)
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
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
Definition of readMeshFromFile function.