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