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