83 std::vector<std::size_t>
const& bulk_ids,
84 std::vector<std::string>
const& property_names,
87 for (
auto const& property_name : property_names)
90 reorderProperty<double>(original_properties, bulk_ids,
91 property_name, reordered_properties) ||
92 reorderProperty<float>(original_properties, bulk_ids, property_name,
93 reordered_properties) ||
94 reorderProperty<int>(original_properties, bulk_ids, property_name,
95 reordered_properties) ||
96 reorderProperty<long>(original_properties, bulk_ids, property_name,
97 reordered_properties) ||
98 reorderProperty<unsigned>(original_properties, bulk_ids,
99 property_name, reordered_properties) ||
100 reorderProperty<unsigned long>(original_properties, bulk_ids,
102 reordered_properties) ||
103 reorderProperty<std::size_t>(original_properties, bulk_ids,
104 property_name, reordered_properties) ||
105 reorderProperty<char>(original_properties, bulk_ids, property_name,
106 reordered_properties) ||
107 reorderProperty<unsigned char>(original_properties, bulk_ids,
108 property_name, reordered_properties);
111 OGS_FATAL(
"Could not reorder PropertyVector '{}'.", property_name);
116int main(
int argc,
char* argv[])
119 "Reorder mesh nodes and cells.\n\n"
120 "OpenGeoSys-6 software, version " +
123 "Copyright (c) 2012-2024, OpenGeoSys Community "
124 "(http://www.opengeosys.org)",
126 TCLAP::ValueArg<std::string> mesh_in_arg(
127 "i",
"input",
"name of the input mesh file",
true,
"",
"string");
128 cmd.add(mesh_in_arg);
129 TCLAP::ValueArg<std::string> mesh_out_arg(
130 "o",
"output",
"name of the output mesh file",
true,
"",
"string");
131 cmd.add(mesh_out_arg);
133 cmd.parse(argc, argv);
135 const std::string filename(mesh_in_arg.getValue());
148 OGS_FATAL(
"Property / data array '{}' has not been found in the mesh.",
152 auto const& nodes = mesh->getNodes();
153 auto const node_ids_reverse_mapping(
156 std::vector<MeshLib::Node*> reordered_nodes(nodes.size());
158 for (
auto const id : node_ids_reverse_mapping)
160 auto const& n = *(nodes[id]);
161 reordered_nodes[pos] =
new MeshLib::Node(n[0], n[1], n[2], pos);
165 auto const bulk_element_ids_string =
167 if (!mesh->getProperties().existsPropertyVector<std::size_t>(
168 bulk_element_ids_string))
170 OGS_FATAL(
"Property / data array '{}' has not been found in the mesh.",
171 bulk_element_ids_string);
173 auto const& bulk_element_ids =
174 *mesh->getProperties().getPropertyVector<std::size_t>(
175 bulk_element_ids_string);
177 std::vector<std::size_t> element_ids_reverse_mapping(
180 auto const& elements = mesh->getElements();
181 std::vector<MeshLib::Element*> reordered_elements(elements.size());
183 for (
auto const id : element_ids_reverse_mapping)
185 auto const& e = *elements[id];
186 auto* reordered_element =
189 auto const number_of_nodes = reordered_element->getNumberOfNodes();
190 for (std::size_t node_number = 0; node_number < number_of_nodes;
193 reordered_element->setNode(
196 *bulk_node_ids)[e.getNode(node_number)->getID()]]);
198 reordered_elements[pos] = reordered_element;
201 auto const& original_properties = mesh->getProperties();
203 std::vector<MeshLib::MeshItemType>
const exclude_property_vectors{
209 "reordered_mesh", reordered_nodes, reordered_elements,
211 original_properties.excludeCopyProperties(exclude_property_vectors)};
212 auto& properties = reordered_mesh.getProperties();
215 auto const node_property_names =
216 mesh->getProperties().getPropertyVectorNames(
222 auto const element_property_names =
223 mesh->getProperties().getPropertyVectorNames(
226 element_property_names, properties);
229 auto const number_of_properties =
230 mesh->getProperties().getPropertyVectorNames().size();
231 if (node_property_names.size() + element_property_names.size() <
232 number_of_properties)
235 "Properties that are not assigened to nodes or elements are not "
236 "transferred to the reordered mesh.");
void reorderProperties(MeshLib::Properties const &original_properties, std::vector< std::size_t > const &bulk_ids, std::vector< std::string > const &property_names, MeshLib::Properties &reordered_properties)