20{
21 TCLAP::CmdLine cmd(
22 "Creates a new file for material properties and sets the material ids "
23 "in the msh-file to 0\n\n"
24 "OpenGeoSys-6 software, version " +
26 ".\n"
27 "Copyright (c) 2012-2026, OpenGeoSys Community "
28 "(http://www.opengeosys.org)",
30
31 TCLAP::ValueArg<std::string> mesh_arg(
32 "m",
33 "mesh",
34 "Input (.msh). The mesh to open from a file",
35 false,
36 "",
37 "INPUT_FILE");
38 cmd.add(mesh_arg);
40 cmd.add(log_level_arg);
41
42 cmd.parse(argc, argv);
43
46
47
48 std::unique_ptr<MeshLib::Mesh> mesh(
50
51 if (!mesh)
52 {
53 INFO(
"Could not read mesh from file '{:s}'.", mesh_arg.getValue());
54 return EXIT_FAILURE;
55 }
56
58 if (!materialIds)
59 {
60 OGS_FATAL(
"Mesh contains no int-property vector named 'MaterialIDs'.");
61 }
62
63 std::size_t const n_properties(materialIds->size());
64 assert(n_properties != mesh->getNumberOfElements());
65
66 std::string
const name =
68
69 std::string const new_matname(name + "_prop");
70 std::ofstream out_prop(new_matname.c_str(), std::ios::out);
71 if (out_prop.is_open())
72 {
73 for (std::size_t i = 0; i < n_properties; ++i)
74 {
75 out_prop << i << "\t" << (*materialIds)[i] << "\n";
76 }
77 out_prop.close();
78 }
79 else
80 {
81 ERR(
"Could not create property '{:s}' file.", new_matname);
82 return EXIT_FAILURE;
83 }
84
85 mesh->getProperties().removePropertyVector("MaterialIDs");
86
87 std::string const new_mshname(name + "_new.vtu");
88 INFO(
"Writing mesh to file '{:s}'.", new_mshname);
90
91 INFO(
"New files '{:s}' and '{:s}' written.", new_mshname, new_matname);
92
93 return EXIT_SUCCESS;
94}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
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)
PropertyVector< int > const * materialIDs(Mesh const &mesh)