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)
91 property_name, reordered_properties) ||
93 reordered_properties) ||
95 reordered_properties) ||
97 reordered_properties) ||
99 property_name, reordered_properties) ||
102 reordered_properties) ||
104 property_name, reordered_properties) ||
106 reordered_properties) ||
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)};
215 auto const node_property_names =
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)