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/MPI.h"
21#include "BaseLib/StringTools.h"
22#include "InfoLib/GitInfo.h"
27#include "MeshLib/Mesh.h"
28#include "MeshLib/Node.h"
30
31int main(int argc, char* argv[])
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-2024, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::ValueArg<std::string> mesh_in(
45 "i", "mesh-input-file",
46 "the name of the file containing the input mesh", true, "",
47 "file name of input mesh");
48 cmd.add(mesh_in);
49 TCLAP::ValueArg<std::string> mesh_out(
50 "o", "mesh-output-file",
51 "the name of the file the surface mesh should be written to", false, "",
52 "file name of output mesh");
53 cmd.add(mesh_out);
54
55 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
56 "If the switch is set use ascii instead of "
57 "binary format for data in the vtu output.",
58 false);
59 cmd.add(use_ascii_arg);
60
61 cmd.parse(argc, argv);
62
63 BaseLib::MPI::Setup mpi_setup(argc, argv);
64
65 std::unique_ptr<MeshLib::Mesh const> mesh(MeshLib::IO::readMeshFromFile(
66 mesh_in.getValue(), true /* compute_element_neighbors */));
67
68 if (!mesh)
69 {
70 return EXIT_FAILURE;
71 }
72
73 INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
74 mesh->getNumberOfElements());
75
76 // extract surface
77 std::unique_ptr<MeshLib::Mesh> surface_mesh(
79 *mesh,
83
84 INFO("Created surface mesh: {:d} nodes, {:d} elements.",
85 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
86
87 std::string out_fname(mesh_out.getValue());
88 if (out_fname.empty())
89 {
90 out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
91 }
92
93 auto const data_mode =
94 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
95 MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
96
97 return EXIT_SUCCESS;
98}
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.