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