OGS
MoveMesh.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#include "BaseLib/FileTools.h"
15#include "BaseLib/MPI.h"
16#include "BaseLib/StringTools.h"
17#include "GeoLib/AABB.h"
18#include "InfoLib/GitInfo.h"
22#include "MeshLib/Mesh.h"
23#include "MeshLib/Node.h"
25
26int main(int argc, char* argv[])
27{
28 TCLAP::CmdLine cmd(
29 "Moves the mesh nodes using the given displacement vector or if no "
30 "displacement vector is given, moves the mesh nodes such that the "
31 "centroid of the given mesh is in the origin.\n\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2025, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38 // Define a value argument and add it to the command line.
39 // A value arg defines a flag and a type of value that it expects,
40 // such as "-m meshfile".
41 TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "Input (.vtu) mesh file",
42 true, "", "INPUT_FILE");
43
44 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
45 // uses this Arg to parse the command line.
46 cmd.add(mesh_arg);
47
48 TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction",
49 false, 0.0, "DISPLACEMENT_X");
50 cmd.add(x_arg);
51 TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction",
52 false, 0.0, "DISPLACEMENT_Y");
53 cmd.add(y_arg);
54 TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction",
55 false, 0.0, "DISPLACEMENT_Z");
56 cmd.add(z_arg);
57
58 TCLAP::ValueArg<std::string> mesh_out_arg("o", "output-mesh",
59 "Output (.vtu) mesh file", false,
60 "", "OUTPUT_FILE");
61 cmd.add(mesh_out_arg);
62
63 cmd.parse(argc, argv);
64
65 BaseLib::MPI::Setup mpi_setup(argc, argv);
66 std::string fname(mesh_arg.getValue());
67
68 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));
69
70 if (!mesh)
71 {
72 ERR("Could not read mesh from file '{:s}'.", fname);
73 return EXIT_FAILURE;
74 }
75
76 Eigen::Vector3d displacement{x_arg.getValue(), y_arg.getValue(),
77 z_arg.getValue()};
78 if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
79 fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
80 fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon())
81 {
82 GeoLib::AABB aabb(mesh->getNodes().begin(), mesh->getNodes().end());
83 auto const [min, max] = aabb.getMinMaxPoints();
84 displacement = -(max + min) / 2.0;
85 }
86
87 INFO("translate model ({:f}, {:f}, {:f}).",
88 displacement[0],
89 displacement[1],
90 displacement[2]);
91 MeshToolsLib::moveMeshNodes(mesh->getNodes().begin(),
92 mesh->getNodes().end(), displacement);
93
94 std::string out_fname(mesh_out_arg.getValue());
95 if (out_fname.empty())
96 {
97 out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
98 out_fname += "_displaced.vtu";
99 }
100
101 MeshLib::IO::writeMeshToFile(*mesh, out_fname);
102
103 return EXIT_SUCCESS;
104}
Definition of the AABB class.
Definition of the Element class.
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
Definition of the Mesh class.
int main(int argc, char *argv[])
Definition MoveMesh.cpp:26
Definition of the Node class.
Definition of string helper functions.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
MinMaxPoints getMinMaxPoints() const
Definition AABB.h:174
Functionality to move mesh nodes using a given displacement vec.
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
void moveMeshNodes(Iterator begin, Iterator end, Eigen::Vector3d const &displacement)
Definition of readMeshFromFile function.