21{
22 TCLAP::CmdLine cmd(
23 "Edit material IDs of mesh elements.\n\n"
24 "OpenGeoSys-6 software, version " +
26 ".\n"
27 "Copyright (c) 2012-2026, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30 TCLAP::SwitchArg replaceArg("r", "replace", "replace material IDs", false);
31 TCLAP::SwitchArg condenseArg("c", "condense", "condense material IDs",
32 false);
33 TCLAP::SwitchArg specifyArg(
34 "s", "specify", "specify material IDs by element types (-e)", false);
35 std::vector<TCLAP::Arg*> vec_xors;
36 vec_xors.push_back(&replaceArg);
37 vec_xors.push_back(&condenseArg);
38 vec_xors.push_back(&specifyArg);
39 cmd.xorAdd(vec_xors);
40 TCLAP::ValueArg<std::string> mesh_in(
41 "i", "mesh-input-file",
42 "Input (.vtu | .msh). The name of the file containing the input mesh",
43 true, "", "INPUT_FILE");
44 cmd.add(mesh_in);
45 TCLAP::ValueArg<std::string> mesh_out(
46 "o", "mesh-output-file",
47 "Output (.vtu | .msh). The name of the file the mesh will be written "
48 "to",
49 true, "", "OUTPUT_FILE");
50 cmd.add(mesh_out);
51 TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id",
52 "current material id to be replaced",
53 false, "CURRENT_MATERIAL_ID");
54 cmd.add(matIDArg);
55 TCLAP::ValueArg<unsigned> newIDArg(
56 "n", "new-material-id", "new material id", false, 0, "NEW_MATERIAL_ID");
57 cmd.add(newIDArg);
58
59
61 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
62 std::vector<std::string> allowed_elems_vector{
63 "point", "line", "quad", "hex", "tri", "tet", "pris", "pyra"};
64 TCLAP::ValuesConstraint<std::string> allowed_elems(allowed_elems_vector);
65 TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type",
66 false, "", &allowed_elems);
67 cmd.add(eleTypeArg);
69 cmd.add(log_level_arg);
70
71 cmd.parse(argc, argv);
72
75
76 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
77 {
78 INFO(
"Please select editing mode: -r or -c or -s");
79 return 0;
80 }
81 if (replaceArg.isSet() && condenseArg.isSet())
82 {
83 INFO(
"Please select only one editing mode: -r or -c or -s");
84 return 0;
85 }
86 if (replaceArg.isSet())
87 {
88 if (!matIDArg.isSet() || !newIDArg.isSet())
89 {
91 "current and new material IDs must be provided for "
92 "replacement");
93 return 0;
94 }
95 }
96 else if (specifyArg.isSet())
97 {
98 if (!eleTypeArg.isSet() || !newIDArg.isSet())
99 {
101 "element type and new material IDs must be provided to specify "
102 "elements");
103 return 0;
104 }
105 }
106
107 std::unique_ptr<MeshLib::Mesh> mesh(
109 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
110 mesh->getNumberOfElements());
111
112 if (condenseArg.isSet())
113 {
114 INFO(
"Condensing material ID...");
115 INFO(
"The MaterialIDs of the input file: [{}]",
117 ", "));
119 INFO(
"The MaterialIDs of the output file: [{}]",
121 ", "));
122 }
123 else if (replaceArg.isSet())
124 {
125 INFO(
"Replacing material ID...");
126 INFO(
"The MaterialIDs of the input file: [{}]",
128 ", "));
129
130 const auto vecOldID = matIDArg.getValue();
131 const unsigned newID = newIDArg.getValue();
132 for (auto oldID : vecOldID)
133 {
134 INFO(
"{:d} -> {:d}", oldID, newID);
136 true);
137 }
138 INFO(
"The MaterialIDs of the output file: [{}]",
140 ", "));
141 }
142 else if (specifyArg.isSet())
143 {
144 INFO(
"Specifying material ID...");
145 INFO(
"The MaterialIDs of the input file: [{}]",
147 ", "));
148
149 const std::string eleTypeName(eleTypeArg.getValue());
152 const unsigned newID = newIDArg.getValue();
154 *mesh, eleType, newID);
155 INFO(
"updated {:d} elements", cnt);
156 INFO(
"The MaterialIDs of the output file: [{}]",
158 ", "));
159 }
161
162 return EXIT_SUCCESS;
163}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
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.