OGS
reviseMesh.cpp File Reference
#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 23 of file reviseMesh.cpp.

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