10 #include <tclap/CmdLine.h>
21 int main(
int argc,
char* argv[])
24 "Edit material IDs of mesh elements.\n\n"
25 "OpenGeoSys-6 software, version " +
28 "Copyright (c) 2012-2021, OpenGeoSys Community "
29 "(http://www.opengeosys.org)",
31 TCLAP::SwitchArg replaceArg(
"r",
"replace",
"replace material IDs",
false);
32 TCLAP::SwitchArg condenseArg(
"c",
"condense",
"condense material IDs",
34 TCLAP::SwitchArg specifyArg(
35 "s",
"specify",
"specify material IDs by element types (-e)",
false);
36 std::vector<TCLAP::Arg*> vec_xors;
37 vec_xors.push_back(&replaceArg);
38 vec_xors.push_back(&condenseArg);
39 vec_xors.push_back(&specifyArg);
41 TCLAP::ValueArg<std::string> mesh_in(
42 "i",
"mesh-input-file",
43 "the name of the file containing the input mesh",
true,
"",
46 TCLAP::ValueArg<std::string> mesh_out(
47 "o",
"mesh-output-file",
48 "the name of the file the mesh will be written to",
true,
"",
51 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
52 "current material id to be replaced",
55 TCLAP::ValueArg<unsigned> newIDArg(
"n",
"new-material-id",
56 "new material id",
false, 0,
"number");
59 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
60 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
61 false,
"", &allowedVals);
64 cmd.parse(argc, argv);
66 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
68 INFO(
"Please select editing mode: -r or -c or -s");
71 if (replaceArg.isSet() && condenseArg.isSet())
73 INFO(
"Please select only one editing mode: -r or -c or -s");
76 if (replaceArg.isSet())
78 if (!matIDArg.isSet() || !newIDArg.isSet())
81 "current and new material IDs must be provided for "
86 else if (specifyArg.isSet())
88 if (!eleTypeArg.isSet() || !newIDArg.isSet())
91 "element type and new material IDs must be provided to specify "
97 std::unique_ptr<MeshLib::Mesh> mesh(
99 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
100 mesh->getNumberOfElements());
102 if (condenseArg.isSet())
104 INFO(
"Condensing material ID...");
107 else if (replaceArg.isSet())
109 INFO(
"Replacing material ID...");
110 const auto vecOldID = matIDArg.getValue();
111 const unsigned newID = newIDArg.getValue();
112 for (
auto oldID : vecOldID)
114 INFO(
"{:d} -> {:d}", oldID, newID);
119 else if (specifyArg.isSet())
121 INFO(
"Specifying material ID...");
122 const std::string eleTypeName(eleTypeArg.getValue());
125 const unsigned newID = newIDArg.getValue();
127 *mesh, eleType, newID);
128 INFO(
"updated {:d} elements", cnt);
Definition of the ElementValueModification class.
Definition of the Element class.
void INFO(char const *fmt, Args const &... args)
Definition of the Mesh class.
static bool replace(MeshLib::Mesh &mesh, int const old_value, int const new_value, bool replace_if_exists=false)
static std::size_t condense(MeshLib::Mesh &mesh)
static std::size_t setByElementType(MeshLib::Mesh &mesh, MeshElemType ele_type, int const new_value)
int main(int argc, char *argv[])
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] 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.
Definition of readMeshFromFile function.