26int main(
int argc,
char* argv[])
29 "Edit material IDs of mesh elements.\n\n"
30 "OpenGeoSys-6 software, version " +
33 "Copyright (c) 2012-2025, OpenGeoSys Community "
34 "(http://www.opengeosys.org)",
36 TCLAP::SwitchArg replaceArg(
"r",
"replace",
"replace material IDs",
false);
37 TCLAP::SwitchArg condenseArg(
"c",
"condense",
"condense material IDs",
39 TCLAP::SwitchArg specifyArg(
40 "s",
"specify",
"specify material IDs by element types (-e)",
false);
41 std::vector<TCLAP::Arg*> vec_xors;
42 vec_xors.push_back(&replaceArg);
43 vec_xors.push_back(&condenseArg);
44 vec_xors.push_back(&specifyArg);
46 TCLAP::ValueArg<std::string> mesh_in(
47 "i",
"mesh-input-file",
48 "Input (.vtu | .msh). The name of the file containing the input mesh",
49 true,
"",
"INPUT_FILE");
51 TCLAP::ValueArg<std::string> mesh_out(
52 "o",
"mesh-output-file",
53 "Output (.vtu | .msh). The name of the file the mesh will be written "
55 true,
"",
"OUTPUT_FILE");
57 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
58 "current material id to be replaced",
59 false,
"CURRENT_MATERIAL_ID");
61 TCLAP::ValueArg<unsigned> newIDArg(
62 "n",
"new-material-id",
"new material id",
false, 0,
"NEW_MATERIAL_ID");
67 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
68 std::vector<std::string> allowed_elems_vector{
69 "point",
"line",
"quad",
"hex",
"tri",
"tet",
"pris",
"pyra"};
70 TCLAP::ValuesConstraint<std::string> allowed_elems(allowed_elems_vector);
71 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
72 false,
"", &allowed_elems);
75 cmd.add(log_level_arg);
77 cmd.parse(argc, argv);
82 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
84 INFO(
"Please select editing mode: -r or -c or -s");
87 if (replaceArg.isSet() && condenseArg.isSet())
89 INFO(
"Please select only one editing mode: -r or -c or -s");
92 if (replaceArg.isSet())
94 if (!matIDArg.isSet() || !newIDArg.isSet())
97 "current and new material IDs must be provided for "
102 else if (specifyArg.isSet())
104 if (!eleTypeArg.isSet() || !newIDArg.isSet())
107 "element type and new material IDs must be provided to specify "
113 std::unique_ptr<MeshLib::Mesh> mesh(
115 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
116 mesh->getNumberOfElements());
118 if (condenseArg.isSet())
120 INFO(
"Condensing material ID...");
121 INFO(
"The MaterialIDs of the input file: [{}]",
125 INFO(
"The MaterialIDs of the output file: [{}]",
129 else if (replaceArg.isSet())
131 INFO(
"Replacing material ID...");
132 INFO(
"The MaterialIDs of the input file: [{}]",
136 const auto vecOldID = matIDArg.getValue();
137 const unsigned newID = newIDArg.getValue();
138 for (
auto oldID : vecOldID)
140 INFO(
"{:d} -> {:d}", oldID, newID);
144 INFO(
"The MaterialIDs of the output file: [{}]",
148 else if (specifyArg.isSet())
150 INFO(
"Specifying material ID...");
151 INFO(
"The MaterialIDs of the input file: [{}]",
155 const std::string eleTypeName(eleTypeArg.getValue());
158 const unsigned newID = newIDArg.getValue();
160 *mesh, eleType, newID);
161 INFO(
"updated {:d} elements", cnt);
162 INFO(
"The MaterialIDs of the output file: [{}]",