26int main(
int argc,
char* argv[])
29 "Edit material IDs of mesh elements.\n\n"
30 "OpenGeoSys-6 software, version " +
33 "Copyright (c) 2012-2024, 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 "the name of the file containing the input mesh",
true,
"",
51 TCLAP::ValueArg<std::string> mesh_out(
52 "o",
"mesh-output-file",
53 "the name of the file the mesh will be written to",
true,
"",
56 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
57 "current material id to be replaced",
60 TCLAP::ValueArg<unsigned> newIDArg(
"n",
"new-material-id",
61 "new material id",
false, 0,
"number");
64 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
65 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
66 false,
"", &allowedVals);
69 cmd.parse(argc, argv);
72 MPI_Init(&argc, &argv);
75 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
77 INFO(
"Please select editing mode: -r or -c or -s");
83 if (replaceArg.isSet() && condenseArg.isSet())
85 INFO(
"Please select only one editing mode: -r or -c or -s");
91 if (replaceArg.isSet())
93 if (!matIDArg.isSet() || !newIDArg.isSet())
96 "current and new material IDs must be provided for "
104 else if (specifyArg.isSet())
106 if (!eleTypeArg.isSet() || !newIDArg.isSet())
109 "element type and new material IDs must be provided to specify "
118 std::unique_ptr<MeshLib::Mesh> mesh(
120 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
121 mesh->getNumberOfElements());
123 if (condenseArg.isSet())
125 INFO(
"Condensing material ID...");
126 INFO(
"The MaterialIDs of the input file: [{}]",
130 INFO(
"The MaterialIDs of the output file: [{}]",
134 else if (replaceArg.isSet())
136 INFO(
"Replacing material ID...");
137 INFO(
"The MaterialIDs of the input file: [{}]",
141 const auto vecOldID = matIDArg.getValue();
142 const unsigned newID = newIDArg.getValue();
143 for (
auto oldID : vecOldID)
145 INFO(
"{:d} -> {:d}", oldID, newID);
149 INFO(
"The MaterialIDs of the output file: [{}]",
153 else if (specifyArg.isSet())
155 INFO(
"Specifying material ID...");
156 INFO(
"The MaterialIDs of the input file: [{}]",
160 const std::string eleTypeName(eleTypeArg.getValue());
163 const unsigned newID = newIDArg.getValue();
165 *mesh, eleType, newID);
166 INFO(
"updated {:d} elements", cnt);
167 INFO(
"The MaterialIDs of the output file: [{}]",