OGS
ExtractSurface.cpp File Reference

Detailed Description

Extracts the surface from the given mesh.

Definition in file ExtractSurface.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "BaseLib/FileTools.h"
#include "BaseLib/StringTools.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshToolsLib/MeshSurfaceExtraction.h"
Include dependency graph for ExtractSurface.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 32 of file ExtractSurface.cpp.

33{
34 TCLAP::CmdLine cmd(
35 "Extracts a 2D surface from a 3D input mesh by specifying a normal "
36 "vector and an angle. (The surface normal (0, 0, 0) will extract the "
37 "complete outer boundary of the 3D mesh.)\n"
38 "An extensive documentation can be found at "
39 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
40 "extract-surface\n"
41 "OpenGeoSys-6 software, version " +
43 ".\n"
44 "Copyright (c) 2012-2024, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
48 "If the switch is set use ascii instead of "
49 "binary format for data in the vtu output.",
50 false);
51 cmd.add(use_ascii_arg);
52 TCLAP::ValueArg<double> angle_arg(
53 "a", "angle",
54 "tolerated angle (in degrees) between given normal and element normal",
55 false, 90, "floating point value");
56 cmd.add(angle_arg);
57 TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
58 false, -1.0, "floating point value");
59 cmd.add(z);
60 TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
61 false, 0, "floating point value");
62 cmd.add(y);
63 TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
64 false, 0, "floating point value");
65 cmd.add(x);
66 TCLAP::ValueArg<std::string> mesh_out(
67 "o", "mesh-output-file",
68 "the name of the file the surface mesh should be written to", false, "",
69 "file name of output mesh");
70 cmd.add(mesh_out);
71 TCLAP::ValueArg<std::string> mesh_in(
72 "i", "mesh-input-file",
73 "the name of the file containing the input mesh", true, "",
74 "file name of input mesh");
75 cmd.add(mesh_in);
76 cmd.parse(argc, argv);
77
78#ifdef USE_PETSC
79 MPI_Init(&argc, &argv);
80#endif
81
82 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
83 mesh_in.getValue(), true /* compute_element_neighbors */));
84
85 if (!mesh)
86 {
87 ERR("Error reading mesh file.");
88#ifdef USE_PETSC
89 MPI_Finalize();
90#endif
91 return EXIT_FAILURE;
92 }
93
94 if (mesh->getDimension() != 3)
95 {
96 ERR("Surfaces can currently only be extracted from 3D meshes.");
97#ifdef USE_PETSC
98 MPI_Finalize();
99#endif
100 return EXIT_FAILURE;
101 }
102
103 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
104 mesh->getNumberOfElements());
105
106 // extract surface
107 Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
108 double const angle(angle_arg.getValue());
109 std::unique_ptr<MeshLib::Mesh> surface_mesh(
114
115 std::string out_fname(mesh_out.getValue());
116 if (out_fname.empty())
117 {
118 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
119 }
120
121 auto const data_mode =
122 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
123 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
124
125#ifdef USE_PETSC
126 MPI_Finalize();
127#endif
128 return EXIT_SUCCESS;
129}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
static MeshLib::Mesh * getMeshSurface(const MeshLib::Mesh &subsfc_mesh, Eigen::Vector3d const &dir, double angle, std::string_view subsfc_node_id_prop_name="", std::string_view subsfc_element_id_prop_name="", std::string_view face_id_prop_name="")
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version
int writeVtu(MeshLib::Mesh const &mesh, std::string const &file_name, int const data_mode)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:188

References MeshLib::Cell, BaseLib::dropFileExtension(), ERR(), MeshLib::Face, MeshToolsLib::MeshSurfaceExtraction::getMeshSurface(), INFO(), MeshLib::Node, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeVtu().