OGS
ExtractBoundary.cpp File Reference

Detailed Description

Extracts the entire boundary from the given mesh.

Definition in file ExtractBoundary.cpp.

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

32{
33 TCLAP::CmdLine cmd(
34 "Tool extracts the boundary of the given mesh. The documentation is "
35 "available at "
36 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
37 "extract-boundary.\n\n"
38 "OpenGeoSys-6 software, version " +
40 ".\n"
41 "Copyright (c) 2012-2025, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::ValueArg<std::string> mesh_in(
45 "i", "mesh-input-file",
46 "Input (.vtu). The name of the file containing the input mesh", true,
47 "", "INPUT_FILE");
48 cmd.add(mesh_in);
49 TCLAP::ValueArg<std::string> mesh_out(
50 "o", "mesh-output-file",
51 "Output (.vtu). The name of the file the surface mesh should be "
52 "written to",
53 false, "", "OUTPUT_FILE");
54 cmd.add(mesh_out);
55
56 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
57 "If the switch is set use ascii instead of "
58 "binary format for data in the vtu output.",
59 false);
60 cmd.add(use_ascii_arg);
61
62 cmd.parse(argc, argv);
63
64 BaseLib::MPI::Setup mpi_setup(argc, argv);
65
66 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
67 mesh_in.getValue(), true /* compute_element_neighbors */));
68
69 if (!mesh)
70 {
71 return EXIT_FAILURE;
72 }
73
74 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
75 mesh->getNumberOfElements());
76
77 // extract surface
78 std::unique_ptr<MeshLib::Mesh> surface_mesh(
80 *mesh,
84
85 INFO("Created surface mesh: {:d} nodes, {:d} elements.",
86 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
87
88 std::string out_fname(mesh_out.getValue());
89 if (out_fname.empty())
90 {
91 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
92 }
93
94 auto const data_mode =
95 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
96 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
97
98 return EXIT_SUCCESS;
99}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
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:191
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)

References MeshLib::Cell, BaseLib::dropFileExtension(), MeshLib::Face, MeshToolsLib::BoundaryExtraction::getBoundaryElementsAsMesh(), MeshLib::getBulkIDString(), INFO(), MeshLib::Node, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeVtu().