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/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/StringTools.h"
#include "BaseLib/TCLAPArguments.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 29 of file reviseMesh.cpp.

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

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