OGS
reviseMesh.cpp File Reference

Detailed Description

Definition in file reviseMesh.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <array>
#include <memory>
#include <string>
#include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.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/MeshRevision.h"
Include dependency graph for reviseMesh.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 30 of file reviseMesh.cpp.

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}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
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)

References INFO(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), MeshToolsLib::MeshRevision::simplifyMesh(), and MeshLib::IO::writeMeshToFile().