27{
28 TCLAP::CmdLine cmd(
29 "Edit material IDs of mesh elements.\n\n"
30 "OpenGeoSys-6 software, version " +
32 ".\n"
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",
38 false);
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);
45 cmd.xorAdd(vec_xors);
46 TCLAP::ValueArg<std::string> mesh_in(
47 "i", "mesh-input-file",
48 "the name of the file containing the input mesh", true, "",
49 "file name");
50 cmd.add(mesh_in);
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, "",
54 "file name");
55 cmd.add(mesh_out);
56 TCLAP::MultiArg<unsigned> matIDArg("m", "current-material-id",
57 "current material id to be replaced",
58 false, "number");
59 cmd.add(matIDArg);
60 TCLAP::ValueArg<unsigned> newIDArg("n", "new-material-id",
61 "new material id", false, 0, "number");
62 cmd.add(newIDArg);
64 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
65 TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type", "element type",
66 false, "", &allowedVals);
67 cmd.add(eleTypeArg);
68
69 cmd.parse(argc, argv);
70
71#ifdef USE_PETSC
72 MPI_Init(&argc, &argv);
73#endif
74
75 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
76 {
77 INFO(
"Please select editing mode: -r or -c or -s");
78#ifdef USE_PETSC
79 MPI_Finalize();
80#endif
81 return 0;
82 }
83 if (replaceArg.isSet() && condenseArg.isSet())
84 {
85 INFO(
"Please select only one editing mode: -r or -c or -s");
86#ifdef USE_PETSC
87 MPI_Finalize();
88#endif
89 return 0;
90 }
91 if (replaceArg.isSet())
92 {
93 if (!matIDArg.isSet() || !newIDArg.isSet())
94 {
96 "current and new material IDs must be provided for "
97 "replacement");
98#ifdef USE_PETSC
99 MPI_Finalize();
100#endif
101 return 0;
102 }
103 }
104 else if (specifyArg.isSet())
105 {
106 if (!eleTypeArg.isSet() || !newIDArg.isSet())
107 {
109 "element type and new material IDs must be provided to specify "
110 "elements");
111#ifdef USE_PETSC
112 MPI_Finalize();
113#endif
114 return 0;
115 }
116 }
117
118 std::unique_ptr<MeshLib::Mesh> mesh(
120 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
121 mesh->getNumberOfElements());
122
123 if (condenseArg.isSet())
124 {
125 INFO(
"Condensing material ID...");
126 INFO(
"The MaterialIDs of the input file: [{}]",
128 ", "));
130 INFO(
"The MaterialIDs of the output file: [{}]",
132 ", "));
133 }
134 else if (replaceArg.isSet())
135 {
136 INFO(
"Replacing material ID...");
137 INFO(
"The MaterialIDs of the input file: [{}]",
139 ", "));
140
141 const auto vecOldID = matIDArg.getValue();
142 const unsigned newID = newIDArg.getValue();
143 for (auto oldID : vecOldID)
144 {
145 INFO(
"{:d} -> {:d}", oldID, newID);
147 true);
148 }
149 INFO(
"The MaterialIDs of the output file: [{}]",
151 ", "));
152 }
153 else if (specifyArg.isSet())
154 {
155 INFO(
"Specifying material ID...");
156 INFO(
"The MaterialIDs of the input file: [{}]",
158 ", "));
159
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: [{}]",
169 ", "));
170 }
172
173#ifdef USE_PETSC
174 MPI_Finalize();
175#endif
176 return EXIT_SUCCESS;
177}
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.