OGS
reviseMesh.cpp
Go to the documentation of this file.
1 
10 #include <tclap/CmdLine.h>
11 
12 #include <array>
13 #include <memory>
14 #include <string>
15 
16 #include "BaseLib/FileTools.h"
17 #include "BaseLib/StringTools.h"
18 #include "InfoLib/GitInfo.h"
22 #include "MeshLib/Mesh.h"
24 #include "MeshLib/Node.h"
25 
26 int main(int argc, char* argv[])
27 {
28  TCLAP::CmdLine cmd(
29  "Revises meshes by collapsing duplicate nodes, (optionally) removing "
30  "elements of lower dimension than the mesh itself, and subdividing "
31  "geometrically broken mesh elements.\n\n"
32  "OpenGeoSys-6 software, version " +
34  ".\n"
35  "Copyright (c) 2012-2021, OpenGeoSys Community "
36  "(http://www.opengeosys.org)",
38  TCLAP::ValueArg<unsigned> minDim_arg(
39  "d", "min-ele-dim",
40  "Minimum dimension of elements to be inserted into new mesh", false, 1,
41  "unsigned");
42  cmd.add(minDim_arg);
43 
44  TCLAP::ValueArg<double> eps_arg(
45  "e", "eps", "Minimum distance for nodes not to be collapsed", false,
46  std::numeric_limits<double>::epsilon(), "float");
47  cmd.add(eps_arg);
48 
49  TCLAP::ValueArg<std::string> output_arg(
50  "o", "output-mesh-file", "output mesh file", true, "", "string");
51  cmd.add(output_arg);
52 
53  TCLAP::ValueArg<std::string> input_arg(
54  "i", "input-mesh-file", "input mesh file", true, "", "string");
55  cmd.add(input_arg);
56  cmd.parse(argc, argv);
57 
58  // read a mesh file
59  std::unique_ptr<MeshLib::Mesh> org_mesh(
60  MeshLib::IO::readMeshFromFile(input_arg.getValue()));
61  if (!org_mesh)
62  {
63  return EXIT_FAILURE;
64  }
65  INFO("Mesh read: {:d} nodes, {:d} elements.", org_mesh->getNumberOfNodes(),
66  org_mesh->getNumberOfElements());
67 
68  // revise the mesh
69  INFO("Simplifying the mesh...");
70  MeshLib::MeshRevision const rev(const_cast<MeshLib::Mesh&>(*org_mesh));
71  unsigned int minDim =
72  (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension());
73  std::unique_ptr<MeshLib::Mesh> new_mesh(
74  rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim));
75 
76  // write into a file
77  if (new_mesh)
78  {
79  INFO("Revised mesh: {:d} nodes, {:d} elements.",
80  new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
81  MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
82  }
83 
84  return EXIT_SUCCESS;
85 }
Definition of the Element class.
Filename manipulation routines.
Git information.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
Definition of the MeshRevision class.
Definition of the Mesh class.
Definition of the Node class.
Definition of string helper functions.
MeshLib::Mesh * simplifyMesh(const std::string &new_mesh_name, double eps, unsigned min_elem_dim=1) const
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
Definition of readMeshFromFile function.
int main(int argc, char *argv[])
Definition: reviseMesh.cpp:26