25{
26 TCLAP::CmdLine cmd(
27 "Edit material IDs of mesh elements.\n\n"
28 "OpenGeoSys-6 software, version " +
30 ".\n"
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",
36 false);
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);
43 cmd.xorAdd(vec_xors);
44 TCLAP::ValueArg<std::string> mesh_in(
45 "i", "mesh-input-file",
46 "the name of the file containing the input mesh", true, "",
47 "file name");
48 cmd.add(mesh_in);
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, "",
52 "file name");
53 cmd.add(mesh_out);
54 TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id",
55 "current material id to be replaced",
56 false, "number");
57 cmd.add(matIDArg);
58 TCLAP::ValueArg<unsigned> newIDArg("n", "new-material-id",
59 "new material id", false, 0, "number");
60 cmd.add(newIDArg);
62 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
63 TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type",
64 false, "", &allowedVals);
65 cmd.add(eleTypeArg);
66
67 cmd.parse(argc, argv);
68
70
71 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
72 {
73 INFO(
"Please select editing mode: -r or -c or -s");
74 return 0;
75 }
76 if (replaceArg.isSet() && condenseArg.isSet())
77 {
78 INFO(
"Please select only one editing mode: -r or -c or -s");
79 return 0;
80 }
81 if (replaceArg.isSet())
82 {
83 if (!matIDArg.isSet() || !newIDArg.isSet())
84 {
86 "current and new material IDs must be provided for "
87 "replacement");
88 return 0;
89 }
90 }
91 else if (specifyArg.isSet())
92 {
93 if (!eleTypeArg.isSet() || !newIDArg.isSet())
94 {
96 "element type and new material IDs must be provided to specify "
97 "elements");
98 return 0;
99 }
100 }
101
102 std::unique_ptr<MeshLib::Mesh> mesh(
104 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
105 mesh->getNumberOfElements());
106
107 if (condenseArg.isSet())
108 {
109 INFO(
"Condensing material ID...");
110 INFO(
"The MaterialIDs of the input file: [{}]",
112 ", "));
114 INFO(
"The MaterialIDs of the output file: [{}]",
116 ", "));
117 }
118 else if (replaceArg.isSet())
119 {
120 INFO(
"Replacing material ID...");
121 INFO(
"The MaterialIDs of the input file: [{}]",
123 ", "));
124
125 const auto vecOldID = matIDArg.getValue();
126 const unsigned newID = newIDArg.getValue();
127 for (auto oldID : vecOldID)
128 {
129 INFO(
"{:d} -> {:d}", oldID, newID);
131 true);
132 }
133 INFO(
"The MaterialIDs of the output file: [{}]",
135 ", "));
136 }
137 else if (specifyArg.isSet())
138 {
139 INFO(
"Specifying material ID...");
140 INFO(
"The MaterialIDs of the input file: [{}]",
142 ", "));
143
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: [{}]",
153 ", "));
154 }
156
157 return EXIT_SUCCESS;
158}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
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)
MeshElemType String2MeshElemType(const std::string &s)
Given a string of the shortened name of the element type, this returns the corresponding MeshElemType...
std::vector< std::string > getMeshElemTypeStringsShort()
Returns a vector of strings of mesh element types.
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.