OGS
reviseMesh.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include <tclap/CmdLine.h>
5
6#include <array>
7#include <memory>
8#include <string>
9
10#include "BaseLib/FileTools.h"
11#include "BaseLib/Logging.h"
12#include "BaseLib/MPI.h"
13#include "BaseLib/StringTools.h"
15#include "InfoLib/GitInfo.h"
19#include "MeshLib/Mesh.h"
20#include "MeshLib/Node.h"
22
23int main(int argc, char* argv[])
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
MeshLib::Mesh * simplifyMesh(const std::string &new_mesh_name, double eps, unsigned min_elem_dim=1) const
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)
int main(int argc, char *argv[])