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-2024, 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 element normal",
52 false, 90, "floating point value");
53 cmd.add(angle_arg);
54 TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
55 false, -1.0, "floating point value");
56 cmd.add(z);
57 TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
58 false, 0, "floating point value");
59 cmd.add(y);
60 TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
61 false, 0, "floating point value");
62 cmd.add(x);
63 TCLAP::ValueArg<std::string> mesh_out(
64 "o", "mesh-output-file",
65 "the name of the file the surface mesh should be written to", false, "",
66 "file name of output mesh");
67 cmd.add(mesh_out);
68 TCLAP::ValueArg<std::string> mesh_in(
69 "i", "mesh-input-file",
70 "the name of the file containing the input mesh", true, "",
71 "file name of input mesh");
72 cmd.add(mesh_in);
73 cmd.parse(argc, argv);
74
76
78 mesh_in.getValue(), true ));
79
80 if (!mesh)
81 {
82 ERR(
"Error reading mesh file.");
83 return EXIT_FAILURE;
84 }
85
86 if (mesh->getDimension() != 3)
87 {
88 ERR(
"Surfaces can currently only be extracted from 3D meshes.");
89 return EXIT_FAILURE;
90 }
91
92 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
93 mesh->getNumberOfElements());
94
95
96 Eigen::Vector3d const dir({x.getValue(), y.getValue(), z.getValue()});
97 double const angle(angle_arg.getValue());
98 std::unique_ptr<MeshLib::Mesh> surface_mesh(
103
104 std::string out_fname(mesh_out.getValue());
105 if (out_fname.empty())
106 {
108 }
109
110 auto const data_mode =
111 use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
113
114 return EXIT_SUCCESS;
115}
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)