OGS
MoveGeometry.cpp File Reference
#include <tclap/CmdLine.h>
#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 dependency graph for MoveGeometry.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 13 of file MoveGeometry.cpp.

14{
15 TCLAP::CmdLine cmd(
16 "Moves the points of a geometry by a given displacement vector\n\n"
17 "OpenGeoSys-6 software, version " +
19 ".\n"
20 "Copyright (c) 2012-2026, OpenGeoSys Community "
21 "(http://www.opengeosys.org)",
23 TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction",
24 false, 0.0, "Z-DISPLACEMENT");
25 cmd.add(z_arg);
26 TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction",
27 false, 0.0, "Y-DISPLACEMENT");
28 cmd.add(y_arg);
29 TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction",
30 false, 0.0, "X-DISPLACEMENT");
31 cmd.add(x_arg);
32 TCLAP::ValueArg<std::string> geo_output_arg(
33 "o", "output", "Output (.gml) geometry file", true, "", "OUTPUT_FILE");
34 cmd.add(geo_output_arg);
35 TCLAP::ValueArg<std::string> geo_input_arg(
36 "i", "input", "Input (.gml) geometry file", true, "", "INPUT_FILE");
37 cmd.add(geo_input_arg);
38 auto log_level_arg = BaseLib::makeLogLevelArg();
39 cmd.add(log_level_arg);
40 cmd.parse(argc, argv);
41
42 BaseLib::MPI::Setup mpi_setup(argc, argv);
43 BaseLib::initOGSLogger(log_level_arg.getValue());
44
45 GeoLib::GEOObjects geo_objects;
46 GeoLib::IO::BoostXmlGmlInterface xml(geo_objects);
47 try
48 {
49 if (!xml.readFile(geo_input_arg.getValue()))
50 {
51 return EXIT_FAILURE;
52 }
53 }
54 catch (std::runtime_error const& err)
55 {
56 ERR("Failed to read file `{:s}'.", geo_input_arg.getValue());
57 ERR("{:s}", err.what());
58 return EXIT_FAILURE;
59 }
60
61 Eigen::Vector3d displacement = Eigen::Vector3d::Zero();
62 if (x_arg.isSet())
63 {
64 displacement[0] = x_arg.getValue();
65 }
66 if (y_arg.isSet())
67 {
68 displacement[1] = y_arg.getValue();
69 }
70 if (z_arg.isSet())
71 {
72 displacement[2] = z_arg.getValue();
73 }
74
75 auto const geo_name = geo_objects.getGeometryNames()[0];
76
77 std::vector<GeoLib::Point*> const* point_vec =
78 geo_objects.getPointVec(geo_name);
79 std::size_t const n_points = point_vec->size();
80 for (std::size_t i = 0; i < n_points; ++i)
81 {
82 for (std::size_t c = 0; c < 3; ++c)
83 {
84 (*(*point_vec)[i])[c] += displacement[c];
85 }
86 }
87
88 xml.export_name = geo_name;
89 BaseLib::IO::writeStringToFile(xml.writeToString(),
90 geo_output_arg.getValue());
91
92 return EXIT_SUCCESS;
93}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Container class for geometric objects.
Definition GEOObjects.h:46
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const std::vector< Point * > * getPointVec(const std::string &name) const
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

References ERR(), BaseLib::IO::XMLInterface::export_name, GeoLib::GEOObjects::getGeometryNames(), GeoLib::GEOObjects::getPointVec(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, GeoLib::IO::BoostXmlGmlInterface::readFile(), BaseLib::IO::writeStringToFile(), and BaseLib::IO::Writer::writeToString().