OGS
reviseMesh.cpp File Reference

Detailed Description

Definition in file reviseMesh.cpp.

#include <tclap/CmdLine.h>
#include <array>
#include <memory>
#include <string>
#include "BaseLib/FileTools.h"
#include "BaseLib/MPI.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 27 of file reviseMesh.cpp.

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}
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().