OGS
ExtractBoundary.cpp
Go to the documentation of this file.
1
12#include <tclap/CmdLine.h>
13
14#include <algorithm>
15#include <memory>
16#include <string>
17#include <vector>
18
19#include "BaseLib/FileTools.h"
20#include "BaseLib/Logging.h"
21#include "BaseLib/MPI.h"
22#include "BaseLib/StringTools.h"
24#include "InfoLib/GitInfo.h"
29#include "MeshLib/Mesh.h"
30#include "MeshLib/Node.h"
32
33int main(int argc, char* argv[])
34{
35 TCLAP::CmdLine cmd(
36 "Tool extracts the boundary of the given mesh. The documentation is "
37 "available at "
38 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
39 "extract-boundary.\n\n"
40 "OpenGeoSys-6 software, version " +
42 ".\n"
43 "Copyright (c) 2012-2025, OpenGeoSys Community "
44 "(http://www.opengeosys.org)",
46 TCLAP::ValueArg<std::string> mesh_in(
47 "i", "mesh-input-file",
48 "Input (.vtu). The name of the file containing the input mesh", true,
49 "", "INPUT_FILE");
50 cmd.add(mesh_in);
51 TCLAP::ValueArg<std::string> mesh_out(
52 "o", "mesh-output-file",
53 "Output (.vtu). The name of the file the surface mesh should be "
54 "written to",
55 false, "", "OUTPUT_FILE");
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 auto log_level_arg = BaseLib::makeLogLevelArg();
65 cmd.add(log_level_arg);
66 cmd.parse(argc, argv);
67
68 BaseLib::MPI::Setup mpi_setup(argc, argv);
69 BaseLib::initOGSLogger(log_level_arg.getValue());
70
71 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
72 mesh_in.getValue(), true /* compute_element_neighbors */));
73
74 if (!mesh)
75 {
76 return EXIT_FAILURE;
77 }
78
79 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
80 mesh->getNumberOfElements());
81
82 // extract surface
83 std::unique_ptr<MeshLib::Mesh> surface_mesh(
85 *mesh,
89
90 INFO("Created surface mesh: {:d} nodes, {:d} elements.",
91 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
92
93 std::string out_fname(mesh_out.getValue());
94 if (out_fname.empty())
95 {
96 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
97 }
98
99 auto const data_mode =
100 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
101 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
102
103 return EXIT_SUCCESS;
104}
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:36
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.
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
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)
Definition of readMeshFromFile function.