OGS
MoveMesh.cpp File Reference

Detailed Description

Date
Jan 17, 2014

Definition in file MoveMesh.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.h"
#include "GeoLib/AABB.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
#include "MeshToolsLib/MeshEditing/moveMeshNodes.h"
Include dependency graph for MoveMesh.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 29 of file MoveMesh.cpp.

30{
31 TCLAP::CmdLine cmd(
32 "Moves the mesh nodes using the given displacement vector or if no "
33 "displacement vector is given, moves the mesh nodes such that the "
34 "centroid of the given mesh is in the origin.\n\n"
35 "OpenGeoSys-6 software, version " +
37 ".\n"
38 "Copyright (c) 2012-2024, OpenGeoSys Community "
39 "(http://www.opengeosys.org)",
41 // Define a value argument and add it to the command line.
42 // A value arg defines a flag and a type of value that it expects,
43 // such as "-m meshfile".
44 TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "input mesh file", true,
45 "", "string");
46
47 // Add the argument mesh_arg to the CmdLine object. The CmdLine object
48 // uses this Arg to parse the command line.
49 cmd.add(mesh_arg);
50
51 TCLAP::ValueArg<double> x_arg("x", "x", "displacement in x direction",
52 false, 0.0, "floating point number");
53 cmd.add(x_arg);
54 TCLAP::ValueArg<double> y_arg("y", "y", "displacement in y direction",
55 false, 0.0, "floating point number");
56 cmd.add(y_arg);
57 TCLAP::ValueArg<double> z_arg("z", "z", "displacement in z direction",
58 false, 0.0, "floating point number");
59 cmd.add(z_arg);
60
61 TCLAP::ValueArg<std::string> mesh_out_arg(
62 "o", "output-mesh", "output mesh file", false, "", "string");
63 cmd.add(mesh_out_arg);
64
65 cmd.parse(argc, argv);
66
67#ifdef USE_PETSC
68 MPI_Init(&argc, &argv);
69#endif
70 std::string fname(mesh_arg.getValue());
71
72 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));
73
74 if (!mesh)
75 {
76 ERR("Could not read mesh from file '{:s}'.", fname);
77#ifdef USE_PETSC
78 MPI_Finalize();
79#endif
80 return EXIT_FAILURE;
81 }
82
83 Eigen::Vector3d displacement{x_arg.getValue(), y_arg.getValue(),
84 z_arg.getValue()};
85 if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
86 fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon() &&
87 fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon())
88 {
89 GeoLib::AABB aabb(mesh->getNodes().begin(), mesh->getNodes().end());
90 auto const [min, max] = aabb.getMinMaxPoints();
91 displacement = -(max + min) / 2.0;
92 }
93
94 INFO("translate model ({:f}, {:f}, {:f}).",
95 displacement[0],
96 displacement[1],
97 displacement[2]);
98 MeshToolsLib::moveMeshNodes(mesh->getNodes().begin(),
99 mesh->getNodes().end(), displacement);
100
101 std::string out_fname(mesh_out_arg.getValue());
102 if (out_fname.empty())
103 {
104 out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
105 out_fname += "_displaced.vtu";
106 }
107
108 MeshLib::IO::writeMeshToFile(*mesh, out_fname);
109
110#ifdef USE_PETSC
111 MPI_Finalize();
112#endif
113 return EXIT_SUCCESS;
114}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition AABB.h:56
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)

References BaseLib::dropFileExtension(), ERR(), GeoLib::AABB::getMinMaxPoints(), INFO(), MeshToolsLib::moveMeshNodes(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().