24int main(
int argc,
char* argv[])
27 "Edit material IDs of mesh elements.\n\n"
28 "OpenGeoSys-6 software, version " +
31 "Copyright (c) 2012-2025, OpenGeoSys Community "
32 "(http://www.opengeosys.org)",
34 TCLAP::SwitchArg replaceArg(
"r",
"replace",
"replace material IDs",
false);
35 TCLAP::SwitchArg condenseArg(
"c",
"condense",
"condense material IDs",
37 TCLAP::SwitchArg specifyArg(
38 "s",
"specify",
"specify material IDs by element types (-e)",
false);
39 std::vector<TCLAP::Arg*> vec_xors;
40 vec_xors.push_back(&replaceArg);
41 vec_xors.push_back(&condenseArg);
42 vec_xors.push_back(&specifyArg);
44 TCLAP::ValueArg<std::string> mesh_in(
45 "i",
"mesh-input-file",
46 "the name of the file containing the input mesh",
true,
"",
49 TCLAP::ValueArg<std::string> mesh_out(
50 "o",
"mesh-output-file",
51 "the name of the file the mesh will be written to",
true,
"",
54 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
55 "current material id to be replaced",
58 TCLAP::ValueArg<unsigned> newIDArg(
"n",
"new-material-id",
59 "new material id",
false, 0,
"number");
62 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
63 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
64 false,
"", &allowedVals);
67 cmd.parse(argc, argv);
71 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
73 INFO(
"Please select editing mode: -r or -c or -s");
76 if (replaceArg.isSet() && condenseArg.isSet())
78 INFO(
"Please select only one editing mode: -r or -c or -s");
81 if (replaceArg.isSet())
83 if (!matIDArg.isSet() || !newIDArg.isSet())
86 "current and new material IDs must be provided for "
91 else if (specifyArg.isSet())
93 if (!eleTypeArg.isSet() || !newIDArg.isSet())
96 "element type and new material IDs must be provided to specify "
102 std::unique_ptr<MeshLib::Mesh> mesh(
104 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
105 mesh->getNumberOfElements());
107 if (condenseArg.isSet())
109 INFO(
"Condensing material ID...");
110 INFO(
"The MaterialIDs of the input file: [{}]",
114 INFO(
"The MaterialIDs of the output file: [{}]",
118 else if (replaceArg.isSet())
120 INFO(
"Replacing material ID...");
121 INFO(
"The MaterialIDs of the input file: [{}]",
125 const auto vecOldID = matIDArg.getValue();
126 const unsigned newID = newIDArg.getValue();
127 for (
auto oldID : vecOldID)
129 INFO(
"{:d} -> {:d}", oldID, newID);
133 INFO(
"The MaterialIDs of the output file: [{}]",
137 else if (specifyArg.isSet())
139 INFO(
"Specifying material ID...");
140 INFO(
"The MaterialIDs of the input file: [{}]",
144 const std::string eleTypeName(eleTypeArg.getValue());
147 const unsigned newID = newIDArg.getValue();
149 *mesh, eleType, newID);
150 INFO(
"updated {:d} elements", cnt);
151 INFO(
"The MaterialIDs of the output file: [{}]",