OGS
MoveMesh.cpp File Reference
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 20 of file MoveMesh.cpp.

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