OGS
reviseMesh.cpp
Go to the documentation of this file.
1
10#include <tclap/CmdLine.h>
11
12#include <array>
13#include <memory>
14#include <string>
15
16#include "BaseLib/FileTools.h"
17#include "BaseLib/Logging.h"
18#include "BaseLib/MPI.h"
19#include "BaseLib/StringTools.h"
21#include "InfoLib/GitInfo.h"
25#include "MeshLib/Mesh.h"
26#include "MeshLib/Node.h"
28
29int main(int argc, char* argv[])
30{
31 TCLAP::CmdLine cmd(
32 "Revises meshes by collapsing duplicate nodes, (optionally) removing "
33 "elements of lower dimension than the mesh itself, and subdividing "
34 "geometrically broken mesh elements.\n\n"
35 "OpenGeoSys-6 software, version " +
37 ".\n"
38 "Copyright (c) 2012-2025, OpenGeoSys Community "
39 "(http://www.opengeosys.org)",
41 TCLAP::ValueArg<unsigned> minDim_arg(
42 "d", "min-ele-dim",
43 "Minimum dimension of elements to be inserted into new mesh", false, 1,
44 "MIN_DIMENSION");
45 cmd.add(minDim_arg);
46
47 TCLAP::ValueArg<double> eps_arg(
48 "e", "eps", "Minimum distance for nodes not to be collapsed", false,
49 std::numeric_limits<double>::epsilon(), "MIN_DISTANCE");
50 cmd.add(eps_arg);
51
52 TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file",
53 "Output (.vtu) mesh file", true, "",
54 "OUTPUT_FILE");
55 cmd.add(output_arg);
56
57 TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file",
58 "Input (.vtu) mesh file", true, "",
59 "INPUT_FILE");
60 cmd.add(input_arg);
61 auto log_level_arg = BaseLib::makeLogLevelArg();
62 cmd.add(log_level_arg);
63 cmd.parse(argc, argv);
64
65 BaseLib::MPI::Setup mpi_setup(argc, argv);
66 BaseLib::initOGSLogger(log_level_arg.getValue());
67
68 // read a mesh file
69 std::unique_ptr<MeshLib::Mesh> org_mesh(
70 MeshLib::IO::readMeshFromFile(input_arg.getValue()));
71 if (!org_mesh)
72 {
73 return EXIT_FAILURE;
74 }
75 INFO("Mesh read: {:d} nodes, {:d} elements.", org_mesh->getNumberOfNodes(),
76 org_mesh->getNumberOfElements());
77
78 // revise the mesh
79 INFO("Simplifying the mesh...");
80 MeshToolsLib::MeshRevision const rev(const_cast<MeshLib::Mesh&>(*org_mesh));
81 unsigned int minDim =
82 (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension());
83 std::unique_ptr<MeshLib::Mesh> new_mesh(
84 rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim));
85
86 // write into a file
87 if (new_mesh)
88 {
89 INFO("Revised mesh: {:d} nodes, {:d} elements.",
90 new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
91 MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
92 }
93
94 return EXIT_SUCCESS;
95}
Definition of the Element class.
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
Definition of the MeshRevision class.
Definition of the Mesh class.
Definition of the Node class.
Definition of string helper functions.
MeshLib::Mesh * simplifyMesh(const std::string &new_mesh_name, double eps, unsigned min_elem_dim=1) const
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
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)
Definition of readMeshFromFile function.
int main(int argc, char *argv[])