Skip to content
Snippets Groups Projects
Commit c55b5ac9 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge branch 'edit_source' into 'master'

[tools] New function to print material IDs

See merge request ogs/ogs!4492
parents ee6e3b44 d5ea58b0
No related branches found
No related tags found
No related merge requests found
......@@ -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())
......
......@@ -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
......
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment