OGS
ExtractBoundary.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#ifdef USE_PETSC
15#include <mpi.h>
16#endif
17
18#include <algorithm>
19#include <memory>
20#include <string>
21#include <vector>
22
23#include "BaseLib/FileTools.h"
24#include "BaseLib/StringTools.h"
25#include "InfoLib/GitInfo.h"
30#include "MeshLib/Mesh.h"
31#include "MeshLib/Node.h"
33
34int main(int argc, char* argv[])
35{
36 TCLAP::CmdLine cmd(
37 "Tool extracts the boundary of the given mesh. The documentation is "
38 "available at "
39 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
40 "extract-boundary.\n\n"
41 "OpenGeoSys-6 software, version " +
43 ".\n"
44 "Copyright (c) 2012-2024, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47 TCLAP::ValueArg<std::string> mesh_in(
48 "i", "mesh-input-file",
49 "the name of the file containing the input mesh", true, "",
50 "file name of input mesh");
51 cmd.add(mesh_in);
52 TCLAP::ValueArg<std::string> mesh_out(
53 "o", "mesh-output-file",
54 "the name of the file the surface mesh should be written to", false, "",
55 "file name of output mesh");
56 cmd.add(mesh_out);
57
58 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
59 "If the switch is set use ascii instead of "
60 "binary format for data in the vtu output.",
61 false);
62 cmd.add(use_ascii_arg);
63
64 cmd.parse(argc, argv);
65
66#ifdef USE_PETSC
67 MPI_Init(&argc, &argv);
68#endif
69
70 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
71 mesh_in.getValue(), true /* compute_element_neighbors */));
72
73 if (!mesh)
74 {
75#ifdef USE_PETSC
76 MPI_Finalize();
77#endif
78 return EXIT_FAILURE;
79 }
80
81 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
82 mesh->getNumberOfElements());
83
84 // extract surface
85 std::unique_ptr<MeshLib::Mesh> surface_mesh(
87 *mesh,
91
92 INFO("Created surface mesh: {:d} nodes, {:d} elements.",
93 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
94
95 std::string out_fname(mesh_out.getValue());
96 if (out_fname.empty())
97 {
98 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
99 }
100
101 auto const data_mode =
102 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
103 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
104
105#ifdef USE_PETSC
106 MPI_Finalize();
107#endif
108 return EXIT_SUCCESS;
109}
Definition of the Element class.
int main(int argc, char *argv[])
Filename manipulation routines.
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Definition of the MeshSurfaceExtraction class.
Definition of the Mesh class.
Definition of the Node class.
Definition of string helper functions.
Implementation of the VtuInterface class.
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
std::unique_ptr< MeshLib::Mesh > getBoundaryElementsAsMesh(MeshLib::Mesh const &bulk_mesh, std::string_view subsfc_node_id_prop_name, std::string_view subsfc_element_id_prop_name, std::string_view face_id_prop_name)
Definition of readMeshFromFile function.