diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp index 942465c2f06d662f19d32810194423eaadb75bd6..2a559ffec49c34252c26484fd41f770cd09b1365 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp @@ -687,6 +687,34 @@ void NodeWiseMeshPartitioner::partitionByMETIS() checkFieldPropertyVectorSize(_mesh->getElements(), _mesh->getProperties()); _partitioned_properties = partitionProperties(_mesh, _partitions); + + renumberBulkIdsProperty(_partitions, _partitioned_properties); +} + +void NodeWiseMeshPartitioner::renumberBulkIdsProperty( + std::vector<Partition> const& partitions, + MeshLib::Properties& partitioned_properties) +{ + auto const bulk_node_ids_string = + MeshLib::getBulkIDString(MeshLib::MeshItemType::Node); + if (partitioned_properties.hasPropertyVector(bulk_node_ids_string)) + { + renumberBulkNodeIdsProperty( + partitioned_properties.getPropertyVector<std::size_t>( + bulk_node_ids_string, MeshLib::MeshItemType::Node, 1), + partitions); + } + auto const bulk_element_ids_string = + MeshLib::getBulkIDString(MeshLib::MeshItemType::Cell); + if (partitioned_properties.hasPropertyVector<std::size_t>( + static_cast<std::string>(bulk_element_ids_string), + MeshLib::MeshItemType::Cell)) + { + renumberBulkElementIdsProperty( + partitioned_properties.getPropertyVector<std::size_t>( + bulk_element_ids_string, MeshLib::MeshItemType::Cell, 1), + partitions); + } } void NodeWiseMeshPartitioner::renumberBulkNodeIdsProperty( diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.h b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.h index d0048d8cecf554af4833dddadea3fb73012074bb..f0ded7b1e99b2e143fd380e852109e49b7b48ce1 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.h +++ b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.h @@ -86,17 +86,8 @@ public: std::vector<Partition> partitionOtherMesh(MeshLib::Mesh const& mesh) const; - /// Renumber the bulk_node_ids property for each partition to match the - /// partitioned bulk mesh nodes. - void renumberBulkNodeIdsProperty( - MeshLib::PropertyVector<std::size_t>* const bulk_node_ids, - std::vector<Partition> const& local_partitions) const; - - /// Renumber the bulk_element_ids property for each partition to match the - /// partitioned bulk mesh elements. - void renumberBulkElementIdsProperty( - MeshLib::PropertyVector<std::size_t>* const bulk_element_ids_pv, - std::vector<Partition> const& local_partitions) const; + void renumberBulkIdsProperty(std::vector<Partition> const& partitions, + MeshLib::Properties& partitioned_properties); /// Write the partitions into binary files /// \param file_name_base The prefix of the file name. @@ -135,6 +126,18 @@ private: void renumberNodeIndices(); void processPartition(std::size_t const part_id); + + /// Renumber the bulk_node_ids property for each partition to match the + /// partitioned bulk mesh nodes. + void renumberBulkNodeIdsProperty( + MeshLib::PropertyVector<std::size_t>* const bulk_node_ids, + std::vector<Partition> const& local_partitions) const; + + /// Renumber the bulk_element_ids property for each partition to match the + /// partitioned bulk mesh elements. + void renumberBulkElementIdsProperty( + MeshLib::PropertyVector<std::size_t>* const bulk_element_ids_pv, + std::vector<Partition> const& local_partitions) const; }; } // namespace ApplicationUtils diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp index f0e5e155e7f389b77479b68206cef6f29a95c740..07576d20d558cf695f9687c260e429f177db3f65 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/PartitionMesh.cpp @@ -224,21 +224,9 @@ int main(int argc, char* argv[]) auto partitions = mesh_partitioner.partitionOtherMesh(*mesh); auto partitioned_properties = partitionProperties(mesh, partitions); - auto const bulk_node_ids_string = - MeshLib::getBulkIDString(MeshLib::MeshItemType::Node); - mesh_partitioner.renumberBulkNodeIdsProperty( - partitioned_properties.getPropertyVector<std::size_t>( - bulk_node_ids_string, MeshLib::MeshItemType::Node, 1), - partitions); - auto const bulk_element_ids_string = - MeshLib::getBulkIDString(MeshLib::MeshItemType::Cell); - if (partitioned_properties.hasPropertyVector(bulk_element_ids_string)) - { - mesh_partitioner.renumberBulkElementIdsProperty( - partitioned_properties.getPropertyVector<std::size_t>( - bulk_element_ids_string, MeshLib::MeshItemType::Cell, 1), - partitions); - } + mesh_partitioner.renumberBulkIdsProperty(partitions, + partitioned_properties); + mesh_partitioner.writeOtherMesh( other_mesh_output_file_name_wo_extension, partitions, partitioned_properties); diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index ba0dcafd9bb81922f7aa58a8d7093172d1f578c5..fbde93ac70fb5105746257a4a1819310a3da919b 100644 --- a/MeshLib/Properties-impl.h +++ b/MeshLib/Properties-impl.h @@ -147,6 +147,23 @@ PropertyVector<T>* Properties::getPropertyVector(std::string_view name) return dynamic_cast<PropertyVector<T>*>(it->second); } +template <typename T> +bool Properties::hasPropertyVector(std::string const& name, + MeshItemType const item_type) const +{ + auto const it = _properties.find(name); + + if (it == _properties.end()) + { + return false; + } + + auto property = dynamic_cast<PropertyVector<T>*>(it->second); + + return (property == nullptr) ? false + : property->getMeshItemType() == item_type; +} + template <typename T> PropertyVector<T> const* Properties::getPropertyVector( std::string_view name, MeshItemType const item_type, diff --git a/MeshLib/Properties.h b/MeshLib/Properties.h index 94043d16e1589c1cf4415ff7eb0c3148de29261d..5412c2421b9ca1657624211191d37acdc03bda50 100644 --- a/MeshLib/Properties.h +++ b/MeshLib/Properties.h @@ -123,6 +123,14 @@ public: /// @param name the name of the property (for instance porosity) bool hasPropertyVector(std::string_view name) const; + /// Check if a PropertyVector accessible by the name and by the item type + /// is already stored within the Properties object. + /// @param name the name of the property, e.g. porosity. + /// @param item_type the type of mesh entity, e.g. CELL. + template <typename T> + bool hasPropertyVector(std::string const& name, + MeshItemType const item_type) const; + std::vector<std::string> getPropertyVectorNames() const; std::vector<std::string> getPropertyVectorNames( MeshLib::MeshItemType t) const; diff --git a/Tests/Data/NodePartitionedMesh/FieldDataWithoutIPData/A2_tunnel_surface_partitioned_node_properties_val2.bin b/Tests/Data/NodePartitionedMesh/FieldDataWithoutIPData/A2_tunnel_surface_partitioned_node_properties_val2.bin index 46ef093ef2594afc8f81af89d4eacdaa75bd0eec..c598844b2584e932ff21d743ab4b1b75485efbb6 100644 Binary files a/Tests/Data/NodePartitionedMesh/FieldDataWithoutIPData/A2_tunnel_surface_partitioned_node_properties_val2.bin and b/Tests/Data/NodePartitionedMesh/FieldDataWithoutIPData/A2_tunnel_surface_partitioned_node_properties_val2.bin differ