50{
51 TCLAP::CmdLine cmd(
52 "Converts a double or floating point cell data array of a vtk "
53 "unstructured grid into a int or double cell data array.\n\n"
54 "OpenGeoSys-6 software, version " +
56 ".\n"
57 "Copyright (c) 2012-2026, OpenGeoSys Community "
58 "(http://www.opengeosys.org)",
60
61 std::vector<std::string> allowed_types_vector{"int", "double"};
62 TCLAP::ValuesConstraint<std::string> allowed_types(allowed_types_vector);
63 TCLAP::ValueArg<std::string> new_property_data_type_arg(
64 "t",
65 "new-property-data-type",
66 "the name of the data type as string",
67 false,
68 "int",
69 &allowed_types);
70 cmd.add(new_property_data_type_arg);
71
72 TCLAP::ValueArg<std::string> new_property_arg(
73 "n",
74 "new-property-name",
75 "the name of the new cell data array (PropertyVector) the values are "
76 "stored",
77 false,
78 "MaterialIDs",
79 "NEW_PROP_NAME");
80 cmd.add(new_property_arg);
81
82 TCLAP::ValueArg<std::string> out_mesh_arg("o", "out-mesh",
83 "Output (.vtk) mesh file name",
84 true, "", "OUTPUT_FILE");
85 cmd.add(out_mesh_arg);
86
87 TCLAP::ValueArg<std::string> property_arg(
88 "e",
89 "existing-property-name",
90 "the name of the existing cell data array (PropertyVector)",
91 true,
92 "",
93 "EXISTING_PROP_NAME");
94 cmd.add(property_arg);
95
96 TCLAP::ValueArg<std::string> mesh_arg(
97 "i", "in-mesh", "Input (.vtk) mesh file name", true, "", "INPUT_FILE");
98 cmd.add(mesh_arg);
99
101 cmd.add(log_level_arg);
102 cmd.parse(argc, argv);
103
106
107 std::unique_ptr<MeshLib::Mesh> mesh(
109
110 if (!mesh)
111 {
112 return -1;
113 }
114
115 bool success = false;
116 std::string err_msg = "Could not find cell data array '" +
117 property_arg.getValue() + "' in the mesh '" +
118 mesh_arg.getValue() + "'";
119
120 if (new_property_data_type_arg.getValue() == "int")
121 {
122 if (mesh->getProperties().existsPropertyVector<double>(
124 {
125 std::tie(success, err_msg) =
127 mesh->getProperties(),
128 property_arg.getValue(),
129 new_property_arg.getValue());
130 }
131
132 if (mesh->getProperties().existsPropertyVector<float>(
134 {
135 std::tie(success, err_msg) =
137 mesh->getProperties(),
138 property_arg.getValue(),
139 new_property_arg.getValue());
140 }
141 }
142 if (new_property_data_type_arg.getValue() == "double")
143 {
144 if (mesh->getProperties().existsPropertyVector<float>(
146 {
147 std::tie(success, err_msg) =
149 mesh->getProperties(),
150 property_arg.getValue(),
151 new_property_arg.getValue());
152 }
153 }
154
155 if (!success)
156 {
157 ERR(
"{:s}", err_msg);
158 return -1;
159 }
160
162
163 return EXIT_SUCCESS;
164}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
std::pair< bool, std::string > castPropertyVectorToPropertyVector(MeshLib::Properties &properties, std::string const &property_vector_name_in, std::string const &property_vector_name_out)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
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)