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