20int main(
int argc,
char* argv[])
23 "Edit material IDs of mesh elements.\n\n"
24 "OpenGeoSys-6 software, version " +
27 "Copyright (c) 2012-2026, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30 TCLAP::SwitchArg replaceArg(
"r",
"replace",
"replace material IDs",
false);
31 TCLAP::SwitchArg condenseArg(
"c",
"condense",
"condense material IDs",
33 TCLAP::SwitchArg specifyArg(
34 "s",
"specify",
"specify material IDs by element types (-e)",
false);
35 std::vector<TCLAP::Arg*> vec_xors;
36 vec_xors.push_back(&replaceArg);
37 vec_xors.push_back(&condenseArg);
38 vec_xors.push_back(&specifyArg);
40 TCLAP::ValueArg<std::string> mesh_in(
41 "i",
"mesh-input-file",
42 "Input (.vtu | .msh). The name of the file containing the input mesh",
43 true,
"",
"INPUT_FILE");
45 TCLAP::ValueArg<std::string> mesh_out(
46 "o",
"mesh-output-file",
47 "Output (.vtu | .msh). The name of the file the mesh will be written "
49 true,
"",
"OUTPUT_FILE");
51 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
52 "current material id to be replaced",
53 false,
"CURRENT_MATERIAL_ID");
55 TCLAP::ValueArg<unsigned> newIDArg(
56 "n",
"new-material-id",
"new material id",
false, 0,
"NEW_MATERIAL_ID");
61 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
62 std::vector<std::string> allowed_elems_vector{
63 "point",
"line",
"quad",
"hex",
"tri",
"tet",
"pris",
"pyra"};
64 TCLAP::ValuesConstraint<std::string> allowed_elems(allowed_elems_vector);
65 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
66 false,
"", &allowed_elems);
69 cmd.add(log_level_arg);
71 cmd.parse(argc, argv);
76 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
78 INFO(
"Please select editing mode: -r or -c or -s");
81 if (replaceArg.isSet() && condenseArg.isSet())
83 INFO(
"Please select only one editing mode: -r or -c or -s");
86 if (replaceArg.isSet())
88 if (!matIDArg.isSet() || !newIDArg.isSet())
91 "current and new material IDs must be provided for "
96 else if (specifyArg.isSet())
98 if (!eleTypeArg.isSet() || !newIDArg.isSet())
101 "element type and new material IDs must be provided to specify "
107 std::unique_ptr<MeshLib::Mesh> mesh(
109 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
110 mesh->getNumberOfElements());
112 if (condenseArg.isSet())
114 INFO(
"Condensing material ID...");
115 INFO(
"The MaterialIDs of the input file: [{}]",
119 INFO(
"The MaterialIDs of the output file: [{}]",
123 else if (replaceArg.isSet())
125 INFO(
"Replacing material ID...");
126 INFO(
"The MaterialIDs of the input file: [{}]",
130 const auto vecOldID = matIDArg.getValue();
131 const unsigned newID = newIDArg.getValue();
132 for (
auto oldID : vecOldID)
134 INFO(
"{:d} -> {:d}", oldID, newID);
138 INFO(
"The MaterialIDs of the output file: [{}]",
142 else if (specifyArg.isSet())
144 INFO(
"Specifying material ID...");
145 INFO(
"The MaterialIDs of the input file: [{}]",
149 const std::string eleTypeName(eleTypeArg.getValue());
152 const unsigned newID = newIDArg.getValue();
154 *mesh, eleType, newID);
155 INFO(
"updated {:d} elements", cnt);
156 INFO(
"The MaterialIDs of the output file: [{}]",