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