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 "Input (.vtu | .msh). The name of the file containing the input mesh",
47 true, "", "INPUT_FILE");
48 cmd.add(mesh_in);
49 TCLAP::ValueArg<std::string> mesh_out(
50 "o", "mesh-output-file",
51 "Output (.vtu | .msh). The name of the file the mesh will be written "
52 "to",
53 true, "", "OUTPUT_FILE");
54 cmd.add(mesh_out);
55 TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id",
56 "current material id to be replaced",
57 false, "CURRENT_MATERIAL_ID");
58 cmd.add(matIDArg);
59 TCLAP::ValueArg<unsigned> newIDArg(
60 "n", "new-material-id", "new material id", false, 0, "NEW_MATERIAL_ID");
61 cmd.add(newIDArg);
62
63
65 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
66 std::vector<std::string> allowed_elems_vector{
67 "point", "line", "quad", "hex", "tri", "tet", "pris", "pyra"};
68 TCLAP::ValuesConstraint<std::string> allowed_elems(allowed_elems_vector);
69 TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type",
70 false, "", &allowed_elems);
71 cmd.add(eleTypeArg);
72
73 cmd.parse(argc, argv);
74
76
77 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
78 {
79 INFO(
"Please select editing mode: -r or -c or -s");
80 return 0;
81 }
82 if (replaceArg.isSet() && condenseArg.isSet())
83 {
84 INFO(
"Please select only one editing mode: -r or -c or -s");
85 return 0;
86 }
87 if (replaceArg.isSet())
88 {
89 if (!matIDArg.isSet() || !newIDArg.isSet())
90 {
92 "current and new material IDs must be provided for "
93 "replacement");
94 return 0;
95 }
96 }
97 else if (specifyArg.isSet())
98 {
99 if (!eleTypeArg.isSet() || !newIDArg.isSet())
100 {
102 "element type and new material IDs must be provided to specify "
103 "elements");
104 return 0;
105 }
106 }
107
108 std::unique_ptr<MeshLib::Mesh> mesh(
110 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
111 mesh->getNumberOfElements());
112
113 if (condenseArg.isSet())
114 {
115 INFO(
"Condensing material ID...");
116 INFO(
"The MaterialIDs of the input file: [{}]",
118 ", "));
120 INFO(
"The MaterialIDs of the output file: [{}]",
122 ", "));
123 }
124 else if (replaceArg.isSet())
125 {
126 INFO(
"Replacing material ID...");
127 INFO(
"The MaterialIDs of the input file: [{}]",
129 ", "));
130
131 const auto vecOldID = matIDArg.getValue();
132 const unsigned newID = newIDArg.getValue();
133 for (auto oldID : vecOldID)
134 {
135 INFO(
"{:d} -> {:d}", oldID, newID);
137 true);
138 }
139 INFO(
"The MaterialIDs of the output file: [{}]",
141 ", "));
142 }
143 else if (specifyArg.isSet())
144 {
145 INFO(
"Specifying material ID...");
146 INFO(
"The MaterialIDs of the input file: [{}]",
148 ", "));
149
150 const std::string eleTypeName(eleTypeArg.getValue());
153 const unsigned newID = newIDArg.getValue();
155 *mesh, eleType, newID);
156 INFO(
"updated {:d} elements", cnt);
157 INFO(
"The MaterialIDs of the output file: [{}]",
159 ", "));
160 }
162
163 return EXIT_SUCCESS;
164}
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.