27{
28 TCLAP::CmdLine cmd(
29 "Adds a layer to an existing mesh."
30 "The documentation is available at "
31 "https://www.opengeosys.org/docs/tools/meshing/addlayer."
32 "\n"
33 "OpenGeoSys-6 software, version " +
35 ".\n"
36 "Copyright (c) 2012-2025, OpenGeoSys Community "
37 "(https://www.opengeosys.org)",
39 TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
40 "Input (.vtu). The name of the file "
41 "containing the mesh",
42 true, "", "INPUT_FILE");
43 cmd.add(mesh_arg);
44
45 TCLAP::ValueArg<std::string> mesh_out_arg(
46 "o", "output-mesh-file",
47 "Output (.vtu). The name of the file the mesh should be written to",
48 true, "", "OUTPUT_FILE");
49 cmd.add(mesh_out_arg);
50
51 TCLAP::ValueArg<double> layer_thickness_arg(
52 "t", "layer-tickness",
53 "the thickness of the new layer, "
54 "(min = 0)",
55 false, 10, "LAYER_THICKNESS");
56 cmd.add(layer_thickness_arg);
57
58 TCLAP::SwitchArg layer_position_arg(
59 "", "add-layer-on-bottom",
60 "Per default the layer is add on the top, if this argument is set the "
61 "layer is add on the bottom.",
62 true);
63 cmd.add(layer_position_arg);
64
65 TCLAP::SwitchArg copy_material_ids_arg(
66 "", "copy-material-ids",
67 "Copy the existing material distribution of the layer which is to be "
68 "extended. If the switch isn't given a new material id will be "
69 "created.",
70 false);
71 cmd.add(copy_material_ids_arg);
72
73 TCLAP::ValueArg<int> set_material_arg(
74 "", "set-material-id", "the material id of the new layer, (min = 0)",
75 false, 0, "MATERIAL_ID");
76 cmd.add(set_material_arg);
78 cmd.add(log_level_arg);
79 cmd.parse(argc, argv);
80
83
84 if (set_material_arg.isSet() && copy_material_ids_arg.isSet())
85 {
86 ERR(
"It is not possible to set both options '--copy-material-ids' and "
87 "'--set-material-id'.");
88 return EXIT_FAILURE;
89 }
90
91 INFO(
"Reading mesh '{:s}' ... ", mesh_arg.getValue());
92 auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>(
94 if (!subsfc_mesh)
95 {
96 ERR(
"Error reading mesh '{:s}'.", mesh_arg.getValue());
97 return EXIT_FAILURE;
98 }
100
101 std::optional<int> layer_id;
102 if (set_material_arg.isSet())
103 {
104 layer_id = set_material_arg.getValue();
105 }
106
108 *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
109 layer_position_arg.getValue(), copy_material_ids_arg.getValue(),
110 layer_id));
111 if (!result)
112 {
113 ERR(
"Failure while adding layer.");
114 return EXIT_FAILURE;
115 }
116
117 INFO(
"Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
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)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)