84 std::vector<std::size_t>
const& bulk_ids,
85 std::vector<std::string>
const& property_names,
88 for (
auto const& property_name : property_names)
92 property_name, reordered_properties) ||
94 reordered_properties) ||
96 reordered_properties) ||
98 reordered_properties) ||
100 property_name, reordered_properties) ||
103 reordered_properties) ||
105 property_name, reordered_properties) ||
107 reordered_properties) ||
109 property_name, reordered_properties);
112 OGS_FATAL(
"Could not reorder PropertyVector '{}'.", property_name);
117int main(
int argc,
char* argv[])
120 "Reorder mesh nodes and cells.\n\n"
121 "OpenGeoSys-6 software, version " +
124 "Copyright (c) 2012-2024, OpenGeoSys Community "
125 "(http://www.opengeosys.org)",
127 TCLAP::ValueArg<std::string> mesh_in_arg(
128 "i",
"input",
"name of the input mesh file",
true,
"",
"string");
129 cmd.add(mesh_in_arg);
130 TCLAP::ValueArg<std::string> mesh_out_arg(
131 "o",
"output",
"name of the output mesh file",
true,
"",
"string");
132 cmd.add(mesh_out_arg);
134 cmd.parse(argc, argv);
138 const std::string filename(mesh_in_arg.getValue());
151 OGS_FATAL(
"Property / data array '{}' has not been found in the mesh.",
155 auto const& nodes = mesh->getNodes();
156 auto const node_ids_reverse_mapping(
159 std::vector<MeshLib::Node*> reordered_nodes(nodes.size());
161 for (
auto const id : node_ids_reverse_mapping)
163 auto const& n = *(nodes[id]);
164 reordered_nodes[pos] =
new MeshLib::Node(n[0], n[1], n[2], pos);
168 auto const bulk_element_ids_string =
170 if (!mesh->getProperties().existsPropertyVector<std::size_t>(
171 bulk_element_ids_string))
173 OGS_FATAL(
"Property / data array '{}' has not been found in the mesh.",
174 bulk_element_ids_string);
176 auto const& bulk_element_ids =
177 *mesh->getProperties().getPropertyVector<std::size_t>(
178 bulk_element_ids_string);
180 std::vector<std::size_t> element_ids_reverse_mapping(
183 auto const& elements = mesh->getElements();
184 std::vector<MeshLib::Element*> reordered_elements(elements.size());
186 for (
auto const id : element_ids_reverse_mapping)
188 auto const& e = *elements[id];
189 auto* reordered_element =
192 auto const number_of_nodes = reordered_element->getNumberOfNodes();
193 for (std::size_t node_number = 0; node_number < number_of_nodes;
196 reordered_element->setNode(
199 *bulk_node_ids)[e.getNode(node_number)->getID()]]);
201 reordered_elements[pos] = reordered_element;
204 auto const& original_properties = mesh->getProperties();
206 std::vector<MeshLib::MeshItemType>
const exclude_property_vectors{
212 "reordered_mesh", reordered_nodes, reordered_elements,
214 original_properties.excludeCopyProperties(exclude_property_vectors)};
215 auto& properties = reordered_mesh.getProperties();
218 auto const node_property_names =
219 mesh->getProperties().getPropertyVectorNames(
225 auto const element_property_names =
226 mesh->getProperties().getPropertyVectorNames(
229 element_property_names, properties);
232 auto const number_of_properties =
233 mesh->getProperties().getPropertyVectorNames().size();
234 if (node_property_names.size() + element_property_names.size() <
235 number_of_properties)
238 "Properties that are not assigened to nodes or elements are not "
239 "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)