59{
60 TCLAP::CmdLine cmd(
61 "Converts a double or floating point cell data array of a vtk "
62 "unstructured grid into a int or double cell data array.\n\n"
63 "OpenGeoSys-6 software, version " +
65 ".\n"
66 "Copyright (c) 2012-2024, OpenGeoSys Community "
67 "(http://www.opengeosys.org)",
69
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 (int or double)",
74 false,
75 "int",
76 "data type as string");
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 "name of the new cell data array (PropertyVector) as string");
87 cmd.add(new_property_arg);
88
89 TCLAP::ValueArg<std::string> out_mesh_arg(
90 "o", "out-mesh", "output mesh file name", true, "", "file name");
91 cmd.add(out_mesh_arg);
92
93 TCLAP::ValueArg<std::string> property_arg(
94 "e",
95 "existing-property-name",
96 "the name of the existing cell data array (PropertyVector)",
97 true,
98 "",
99 "property name as string");
100 cmd.add(property_arg);
101
102 TCLAP::ValueArg<std::string> mesh_arg(
103 "i", "in-mesh", "input mesh file name", true, "", "file name");
104 cmd.add(mesh_arg);
105
106 cmd.parse(argc, argv);
107
108#ifdef USE_PETSC
109 MPI_Init(&argc, &argv);
110#endif
111
112 std::unique_ptr<MeshLib::Mesh> mesh(
114
115 if (!mesh)
116 {
117#ifdef USE_PETSC
118 MPI_Finalize();
119#endif
120 return -1;
121 }
122
123 bool success = false;
124 std::string err_msg = "Could not find cell data array '" +
125 property_arg.getValue() + "' in the mesh '" +
126 mesh_arg.getValue() + "'";
127
128 if (new_property_data_type_arg.getValue() == "int")
129 {
130 if (mesh->getProperties().existsPropertyVector<double>(
132 {
133 std::tie(success, err_msg) =
134 castPropertyVectorToPropertyVector<double, int>(
135 mesh->getProperties(),
136 property_arg.getValue(),
137 new_property_arg.getValue());
138 }
139
140 if (mesh->getProperties().existsPropertyVector<float>(
142 {
143 std::tie(success, err_msg) =
144 castPropertyVectorToPropertyVector<float, int>(
145 mesh->getProperties(),
146 property_arg.getValue(),
147 new_property_arg.getValue());
148 }
149 }
150 if (new_property_data_type_arg.getValue() == "double")
151 {
152 if (mesh->getProperties().existsPropertyVector<float>(
154 {
155 std::tie(success, err_msg) =
156 castPropertyVectorToPropertyVector<float, double>(
157 mesh->getProperties(),
158 property_arg.getValue(),
159 new_property_arg.getValue());
160 }
161 }
162
163 if (!success)
164 {
165 ERR(
"{:s}", err_msg);
166#ifdef USE_PETSC
167 MPI_Finalize();
168#endif
169 return -1;
170 }
171
173
174#ifdef USE_PETSC
175 MPI_Finalize();
176#endif
177 return EXIT_SUCCESS;
178}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
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)