30{
31 TCLAP::CmdLine cmd(
32 "Extracts a 2D surface from a 3D input mesh by specifying a normal "
33 "vector and an angle. (The surface normal (0, 0, 0) will extract the "
34 "complete outer boundary of the 3D mesh.)\n"
35 "An extensive documentation can be found at "
36 "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
37 "extract-surface\n"
38 "OpenGeoSys-6 software, version " +
40 ".\n"
41 "Copyright (c) 2012-2025, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
45 "If the switch is set use ascii instead of "
46 "binary format for data in the vtu output.",
47 false);
48 cmd.add(use_ascii_arg);
49 TCLAP::ValueArg<double> angle_arg(
50 "a", "angle",
51 "tolerated angle (in degrees) between given normal and "
52 "element normal, (min = 0), (max = 360)",
53 false, 90, "ANGLE");
54 cmd.add(angle_arg);
55 TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
56 false, -1.0, "Z-COMPONENT");
57 cmd.add(z);
58 TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
59 false, 0, "Y-COMPONENT");
60 cmd.add(y);
61 TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
62 false, 0, "X-COMPONENT");
63 cmd.add(x);
64 TCLAP::ValueArg<std::string> mesh_out(
65 "o", "mesh-output-file",
66 "Output (.vtu). The name of the file the surface mesh should be "
67 "written to",
68 false, "", "OUTPUT_FILE");
69 cmd.add(mesh_out);
70 TCLAP::ValueArg<std::string> mesh_in(
71 "i", "mesh-input-file",
72 "Input (.vtu). The name of the file containing the input mesh", true,
73 "", "INPUT_FILE");
74 cmd.add(mesh_in);
75 cmd.parse(argc, argv);
76
78
80 mesh_in.getValue(), true ));
81
82 if (!mesh)
83 {
84 ERR(
"Error reading mesh file.");
85 return EXIT_FAILURE;
86 }
87
88 if (mesh->getDimension() != 3)
89 {
90 ERR(
"Surfaces can currently only be extracted from 3D meshes.");
91 return EXIT_FAILURE;
92 }
93
94 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
95 mesh->getNumberOfElements());
96
97
98 Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
99 double const angle(angle_arg.getValue());
100 std::unique_ptr<MeshLib::Mesh> surface_mesh(
105
106 std::string out_fname(mesh_out.getValue());
107 if (out_fname.empty())
108 {
110 }
111
112 auto const data_mode =
113 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
115
116 return EXIT_SUCCESS;
117}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
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)