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