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