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/MPI.h"
18#include "BaseLib/StringTools.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 "Revises meshes by collapsing duplicate nodes, (optionally) removing "
31 "elements of lower dimension than the mesh itself, and subdividing "
32 "geometrically broken mesh elements.\n\n"
33 "OpenGeoSys-6 software, version " +
35 ".\n"
36 "Copyright (c) 2012-2024, OpenGeoSys Community "
37 "(http://www.opengeosys.org)",
39 TCLAP::ValueArg<unsigned> minDim_arg(
40 "d", "min-ele-dim",
41 "Minimum dimension of elements to be inserted into new mesh", false, 1,
42 "unsigned");
43 cmd.add(minDim_arg);
44
45 TCLAP::ValueArg<double> eps_arg(
46 "e", "eps", "Minimum distance for nodes not to be collapsed", false,
47 std::numeric_limits<double>::epsilon(), "float");
48 cmd.add(eps_arg);
49
50 TCLAP::ValueArg<std::string> output_arg(
51 "o", "output-mesh-file", "output mesh file", true, "", "string");
52 cmd.add(output_arg);
53
54 TCLAP::ValueArg<std::string> input_arg(
55 "i", "input-mesh-file", "input mesh file", true, "", "string");
56 cmd.add(input_arg);
57 cmd.parse(argc, argv);
58
59 BaseLib::MPI::Setup mpi_setup(argc, argv);
60
61 // read a mesh file
62 std::unique_ptr<MeshLib::Mesh> org_mesh(
63 MeshLib::IO::readMeshFromFile(input_arg.getValue()));
64 if (!org_mesh)
65 {
66 return EXIT_FAILURE;
67 }
68 INFO("Mesh read: {:d} nodes, {:d} elements.", org_mesh->getNumberOfNodes(),
69 org_mesh->getNumberOfElements());
70
71 // revise the mesh
72 INFO("Simplifying the mesh...");
73 MeshToolsLib::MeshRevision const rev(const_cast<MeshLib::Mesh&>(*org_mesh));
74 unsigned int minDim =
75 (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension());
76 std::unique_ptr<MeshLib::Mesh> new_mesh(
77 rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim));
78
79 // write into a file
80 if (new_mesh)
81 {
82 INFO("Revised mesh: {:d} nodes, {:d} elements.",
83 new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
84 MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
85 }
86
87 return EXIT_SUCCESS;
88}
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[])