diff --git a/Applications/Utils/MeshEdit/checkMesh.cpp b/Applications/Utils/MeshEdit/checkMesh.cpp index c243fbece8085d0f323179bb7d2452c184f63fdf..ae8bb0f220a4f9b4ac1fd0d4f9aa55b4f6845354 100644 --- a/Applications/Utils/MeshEdit/checkMesh.cpp +++ b/Applications/Utils/MeshEdit/checkMesh.cpp @@ -13,6 +13,8 @@ #include <mpi.h> #endif +#include <fmt/ranges.h> + #include <array> #include <string> @@ -92,6 +94,8 @@ int main(int argc, char* argv[]) if (print_properties_arg.isSet()) { MeshLib::MeshInformation::writePropertyVectorInformation(*mesh); + INFO("MaterialID-list: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); } if (valid_arg.isSet()) diff --git a/Applications/Utils/MeshEdit/editMaterialID.cpp b/Applications/Utils/MeshEdit/editMaterialID.cpp index 0edf62b7e321a3b75bb403c45227e1ce7ac44907..cb46ed992cd26541c8447726611d594b0af43341 100644 --- a/Applications/Utils/MeshEdit/editMaterialID.cpp +++ b/Applications/Utils/MeshEdit/editMaterialID.cpp @@ -21,6 +21,7 @@ #include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/MeshEditing/ElementValueModification.h" +#include "MeshLib/MeshInformation.h" int main(int argc, char* argv[]) { @@ -122,11 +123,18 @@ int main(int argc, char* argv[]) if (condenseArg.isSet()) { INFO("Condensing material ID..."); + INFO("The MaterialIDs of the input file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); MeshLib::ElementValueModification::condense(*mesh); + INFO("The MaterialIDs of the output file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); } else if (replaceArg.isSet()) { INFO("Replacing material ID..."); + INFO("The MaterialIDs of the input file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); + const auto vecOldID = matIDArg.getValue(); const unsigned newID = newIDArg.getValue(); for (auto oldID : vecOldID) @@ -135,10 +143,15 @@ int main(int argc, char* argv[]) MeshLib::ElementValueModification::replace(*mesh, oldID, newID, true); } + INFO("The MaterialIDs of the output file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); } else if (specifyArg.isSet()) { INFO("Specifying material ID..."); + INFO("The MaterialIDs of the input file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); + const std::string eleTypeName(eleTypeArg.getValue()); const MeshLib::MeshElemType eleType = MeshLib::String2MeshElemType(eleTypeName); @@ -146,8 +159,9 @@ int main(int argc, char* argv[]) unsigned cnt = MeshLib::ElementValueModification::setByElementType( *mesh, eleType, newID); INFO("updated {:d} elements", cnt); + INFO("The MaterialIDs of the output file: [{}]", + fmt::join(MeshLib::MeshInformation::getMaterialIDs(*mesh), ", ")); } - MeshLib::IO::writeMeshToFile(*mesh, mesh_out.getValue()); #ifdef USE_PETSC diff --git a/MeshLib/MeshInformation.cpp b/MeshLib/MeshInformation.cpp index 4c244d2df50dfc6915bdf496b117a4e78512e873..d0aca02cb19605c7b5f81362e78602d1373da212 100644 --- a/MeshLib/MeshInformation.cpp +++ b/MeshLib/MeshInformation.cpp @@ -147,4 +147,27 @@ void MeshInformation::writeMeshValidationResults(MeshLib::Mesh& mesh) } } +std::vector<int> MeshInformation::getMaterialIDs(const MeshLib::Mesh& mesh) +{ + auto const* matids = MeshLib::materialIDs(mesh); + if (!matids) + { + INFO("No MaterialIDs were found."); + return {}; + } + std::vector<int> unique_matids = {}; + + for (auto matid : *matids) + { + if (std::find(unique_matids.begin(), unique_matids.end(), matid) == + unique_matids.end()) + { + unique_matids.push_back(matid); + } + } + std::sort(unique_matids.begin(), unique_matids.end()); + + return unique_matids; +} + } // namespace MeshLib diff --git a/MeshLib/MeshInformation.h b/MeshLib/MeshInformation.h index d8febac72615dcf0171e7af4446bedd3b8c9b125..f1a3b345d642c893fe565c53a240a96cea5b80f0 100644 --- a/MeshLib/MeshInformation.h +++ b/MeshLib/MeshInformation.h @@ -75,6 +75,9 @@ public: /// writes out mesh validation results /// Remark: MeshValidation can modify the original mesh static void writeMeshValidationResults(MeshLib::Mesh& mesh); + + /// writes out a list of all material IDs that occur in the mesh. + static std::vector<int> getMaterialIDs(const MeshLib::Mesh& mesh); }; } // namespace MeshLib