OGS
ApplicationUtils::NodeWiseMeshPartitioner Class Reference

Detailed Description

Mesh partitioner.

Definition at line 64 of file NodeWiseMeshPartitioner.h.

#include <NodeWiseMeshPartitioner.h>

Collaboration diagram for ApplicationUtils::NodeWiseMeshPartitioner:
[legend]

Public Types

using IntegerType = long
 

Public Member Functions

 NodeWiseMeshPartitioner (const IntegerType num_partitions, std::unique_ptr< MeshLib::Mesh > &&mesh)
 
void partitionByMETIS ()
 Partition by node.
 
std::vector< PartitionpartitionOtherMesh (MeshLib::Mesh const &mesh) const
 
void renumberBulkIdsProperty (std::vector< Partition > const &partitions, MeshLib::Properties &partitioned_properties)
 
void write (const std::string &file_name_base)
 
void writeOtherMesh (std::string const &output_filename_base, std::vector< Partition > const &partitions, MeshLib::Properties const &partitioned_properties) const
 
void resetPartitionIdsForNodes (std::vector< std::size_t > &&node_partition_ids)
 
MeshLib::Mesh const & mesh () const
 

Private Member Functions

void renumberNodeIndices ()
 
void renumberBulkNodeIdsProperty (MeshLib::PropertyVector< std::size_t > *const bulk_node_ids, std::vector< Partition > const &local_partitions) const
 
void renumberBulkElementIdsProperty (MeshLib::PropertyVector< std::size_t > *const bulk_element_ids_pv, std::vector< Partition > const &local_partitions) const
 

Private Attributes

std::vector< Partition_partitions
 Data for all partitions.
 
MeshLib::Properties _partitioned_properties
 Properties where values at ghost nodes and extra nodes are inserted.
 
std::unique_ptr< MeshLib::Mesh_mesh
 Pointer to a mesh object.
 
std::vector< std::size_t > _nodes_global_ids
 Global IDs of all nodes after partitioning.
 
std::vector< std::size_t > _nodes_partition_ids
 Partition IDs of each nodes.
 

Member Typedef Documentation

◆ IntegerType

Constructor & Destructor Documentation

◆ NodeWiseMeshPartitioner()

ApplicationUtils::NodeWiseMeshPartitioner::NodeWiseMeshPartitioner ( const IntegerType num_partitions,
std::unique_ptr< MeshLib::Mesh > && mesh )
inline
Parameters
num_partitionsNumber of partitions,
meshPointer to a mesh object.

Definition at line 74 of file NodeWiseMeshPartitioner.h.

76 : _partitions(num_partitions),
78 _mesh(std::move(mesh)),
79 _nodes_global_ids(_mesh->getNumberOfNodes()),
80 _nodes_partition_ids(_mesh->getNumberOfNodes())
81 {
82 }
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
MeshLib::Properties _partitioned_properties
Properties where values at ghost nodes and extra nodes are inserted.
std::vector< std::size_t > _nodes_global_ids
Global IDs of all nodes after partitioning.
std::vector< Partition > _partitions
Data for all partitions.
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.

Member Function Documentation

◆ mesh()

MeshLib::Mesh const & ApplicationUtils::NodeWiseMeshPartitioner::mesh ( ) const
inline

Definition at line 107 of file NodeWiseMeshPartitioner.h.

107{ return *_mesh; }

References _mesh.

Referenced by main(), and partitionOtherMesh().

◆ partitionByMETIS()

void ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS ( )

Partition by node.

Definition at line 738 of file NodeWiseMeshPartitioner.cpp.

739{
740 std::vector<std::size_t> bulk_node_ids(_mesh->getNumberOfNodes());
741 std::iota(bulk_node_ids.begin(), bulk_node_ids.end(), 0);
742
744
746
747 // In case the field data in the vtu file are manually added, e.g. by using
748 // some tools, the size of the field property vector has to be checked.
749 checkFieldPropertyVectorSize(_mesh->getElements(), _mesh->getProperties());
750
752
754}
void renumberBulkIdsProperty(std::vector< Partition > const &partitions, MeshLib::Properties &partitioned_properties)
void checkFieldPropertyVectorSize(std::vector< MeshLib::Element * > const &global_mesh_elements, MeshLib::Properties const &properties)
MeshLib::Properties partitionProperties(std::unique_ptr< MeshLib::Mesh > const &mesh, std::vector< Partition > &partitions)
Partition existing properties and add vtkGhostType cell data array property.
void partitionMesh(std::vector< Partition > &partitions, MeshLib::Mesh const &mesh, std::vector< std::size_t > const &nodes_partition_ids, std::vector< std::size_t > const &bulk_node_ids)

References _mesh, _nodes_partition_ids, _partitioned_properties, _partitions, ApplicationUtils::checkFieldPropertyVectorSize(), ApplicationUtils::partitionMesh(), ApplicationUtils::partitionProperties(), renumberBulkIdsProperty(), and renumberNodeIndices().

Referenced by main().

◆ partitionOtherMesh()

std::vector< Partition > ApplicationUtils::NodeWiseMeshPartitioner::partitionOtherMesh ( MeshLib::Mesh const & mesh) const

Definition at line 882 of file NodeWiseMeshPartitioner.cpp.

884{
885 auto const bulk_node_ids_string =
887 auto const& bulk_node_ids =
888 mesh.getProperties().getPropertyVector<std::size_t>(
889 bulk_node_ids_string, MeshLib::MeshItemType::Node, 1);
890
891 std::vector<Partition> partitions(_partitions.size());
892
893 partitionMesh(partitions, mesh, _nodes_partition_ids, *bulk_node_ids);
894
895 return partitions;
896}
Properties & getProperties()
Definition Mesh.h:134
PropertyVector< T > const * getPropertyVector(std::string_view name) const
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
Definition Properties.h:188

References _nodes_partition_ids, _partitions, MeshLib::getBulkIDString(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), mesh(), MeshLib::Node, and ApplicationUtils::partitionMesh().

Referenced by main().

◆ renumberBulkElementIdsProperty()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberBulkElementIdsProperty ( MeshLib::PropertyVector< std::size_t > *const bulk_element_ids_pv,
std::vector< Partition > const & local_partitions ) const
private

Renumber the bulk_element_ids property for each partition to match the partitioned bulk mesh elements.

Definition at line 824 of file NodeWiseMeshPartitioner.cpp.

827{
828 if (bulk_element_ids_pv == nullptr)
829 {
830 return;
831 }
832
833 auto& bulk_element_ids = *bulk_element_ids_pv;
834
835 std::size_t offset = 0; // offset in property vector for current partition
836
837 assert(_partitions.size() == local_partitions.size());
838 int const n_partitions = static_cast<int>(_partitions.size());
839 for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
840 {
841 auto const& bulk_partition = _partitions[partition_id];
842 auto const& local_partition = local_partitions[partition_id];
843
844 // Create global-to-local element id mapping for the bulk partition.
845 std::map<std::size_t, std::size_t> global_to_local;
846 auto map_elements =
847 [&global_to_local](
848 std::vector<MeshLib::Element const*> const& elements,
849 std::size_t const offset)
850 {
851 auto const n_elements = elements.size();
852 for (std::size_t e = 0; e < n_elements; ++e)
853 {
854 global_to_local[elements[e]->getID()] = offset + e;
855 }
856 };
857
858 map_elements(bulk_partition.regular_elements, 0);
859 map_elements(bulk_partition.ghost_elements,
860 bulk_partition.regular_elements.size());
861
862 // Renumber the local bulk_element_ids map.
863 auto renumber_elements =
864 [&bulk_element_ids, &global_to_local](
865 std::vector<MeshLib::Element const*> const& elements,
866 std::size_t const offset)
867 {
868 auto const n_elements = elements.size();
869 for (std::size_t e = 0; e < n_elements; ++e)
870 {
871 bulk_element_ids[offset + e] =
872 global_to_local[bulk_element_ids[offset + e]];
873 }
874 return n_elements;
875 };
876
877 offset += renumber_elements(local_partition.regular_elements, offset);
878 offset += renumber_elements(local_partition.ghost_elements, offset);
879 }
880}

References _partitions.

Referenced by renumberBulkIdsProperty().

◆ renumberBulkIdsProperty()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberBulkIdsProperty ( std::vector< Partition > const & partitions,
MeshLib::Properties & partitioned_properties )

Definition at line 756 of file NodeWiseMeshPartitioner.cpp.

759{
760 auto const bulk_node_ids_string =
762 if (partitioned_properties.hasPropertyVector(bulk_node_ids_string))
763 {
765 partitioned_properties.getPropertyVector<std::size_t>(
766 bulk_node_ids_string, MeshLib::MeshItemType::Node, 1),
767 partitions);
768 }
769 auto const bulk_element_ids_string =
771 if (partitioned_properties.hasPropertyVector<std::size_t>(
772 static_cast<std::string>(bulk_element_ids_string),
774 {
776 partitioned_properties.getPropertyVector<std::size_t>(
777 bulk_element_ids_string, MeshLib::MeshItemType::Cell, 1),
778 partitions);
779 }
780}
void renumberBulkElementIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_element_ids_pv, std::vector< Partition > const &local_partitions) const
void renumberBulkNodeIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_node_ids, std::vector< Partition > const &local_partitions) const
bool hasPropertyVector(std::string_view name) const

References MeshLib::Cell, MeshLib::getBulkIDString(), MeshLib::Properties::getPropertyVector(), MeshLib::Properties::hasPropertyVector(), MeshLib::Node, renumberBulkElementIdsProperty(), and renumberBulkNodeIdsProperty().

Referenced by main(), and partitionByMETIS().

◆ renumberBulkNodeIdsProperty()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberBulkNodeIdsProperty ( MeshLib::PropertyVector< std::size_t > *const bulk_node_ids,
std::vector< Partition > const & local_partitions ) const
private

Renumber the bulk_node_ids property for each partition to match the partitioned bulk mesh nodes.

Definition at line 782 of file NodeWiseMeshPartitioner.cpp.

785{
786 if (bulk_node_ids_pv == nullptr)
787 {
788 return;
789 }
790
791 auto& bulk_node_ids = *bulk_node_ids_pv;
792
793 std::size_t offset = 0; // offset in property vector for current partition
794
795 assert(_partitions.size() == local_partitions.size());
796 int const n_partitions = static_cast<int>(_partitions.size());
797 for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
798 {
799 auto const& bulk_partition = _partitions[partition_id];
800 auto const& local_partition = local_partitions[partition_id];
801
802 // Create global-to-local node id mapping for the bulk partition.
803 auto const& bulk_nodes = bulk_partition.nodes;
804 auto const n_bulk_nodes = bulk_nodes.size();
805 std::map<std::size_t, std::size_t> global_to_local;
806 for (std::size_t local_node_id = 0; local_node_id < n_bulk_nodes;
807 ++local_node_id)
808 {
809 global_to_local[bulk_nodes[local_node_id]->getID()] = local_node_id;
810 }
811
812 auto const& local_nodes = local_partition.nodes;
813 auto const n_local_nodes = local_nodes.size();
814 for (std::size_t local_node_id = 0; local_node_id < n_local_nodes;
815 ++local_node_id)
816 {
817 bulk_node_ids[offset + local_node_id] =
818 global_to_local[bulk_node_ids[offset + local_node_id]];
819 }
820 offset += n_local_nodes;
821 }
822}

References _partitions.

Referenced by renumberBulkIdsProperty().

◆ renumberNodeIndices()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberNodeIndices ( )
private

Definition at line 898 of file NodeWiseMeshPartitioner.cpp.

899{
900 std::size_t node_global_id_offset = 0;
901 // Renumber the global indices.
902 for (auto& partition : _partitions)
903 {
904 for (std::size_t i = 0; i < partition.number_of_regular_nodes; i++)
905 {
906 _nodes_global_ids[partition.nodes[i]->getID()] =
907 node_global_id_offset++;
908 }
909 }
910}

References _nodes_global_ids, and _partitions.

Referenced by partitionByMETIS().

◆ resetPartitionIdsForNodes()

void ApplicationUtils::NodeWiseMeshPartitioner::resetPartitionIdsForNodes ( std::vector< std::size_t > && node_partition_ids)
inline

Definition at line 101 of file NodeWiseMeshPartitioner.h.

103 {
104 _nodes_partition_ids = std::move(node_partition_ids);
105 }

References _nodes_partition_ids.

Referenced by main().

◆ write()

void ApplicationUtils::NodeWiseMeshPartitioner::write ( const std::string & file_name_base)

Write the partitions into binary files

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1230 of file NodeWiseMeshPartitioner.cpp.

1231{
1238
1239 const auto elements_offsets = writeConfigData(file_name_base, _partitions);
1240
1241 const std::vector<IntegerType>& regular_element_offsets =
1242 std::get<0>(elements_offsets);
1243 const std::vector<IntegerType>& ghost_element_offsets =
1244 std::get<1>(elements_offsets);
1245 writeElements(file_name_base, _partitions, regular_element_offsets,
1246 ghost_element_offsets);
1247
1248 writeNodes(file_name_base, _partitions, _nodes_global_ids);
1249}
void writeNodes(const std::string &file_name_base, std::vector< Partition > const &partitions, std::vector< std::size_t > const &global_node_ids)
std::tuple< std::vector< long >, std::vector< long > > writeConfigData(const std::string &file_name_base, std::vector< Partition > const &partitions)
void writeProperties(const std::string &file_name_base, MeshLib::Properties const &partitioned_properties, std::vector< Partition > const &partitions, MeshLib::MeshItemType const mesh_item_type)
void writeElements(std::string const &file_name_base, std::vector< Partition > const &partitions, std::vector< long > const &regular_element_offsets, std::vector< long > const &ghost_element_offsets)

References _nodes_global_ids, _partitioned_properties, _partitions, MeshLib::Cell, MeshLib::IntegrationPoint, MeshLib::Node, ApplicationUtils::writeConfigData(), ApplicationUtils::writeElements(), ApplicationUtils::writeNodes(), and ApplicationUtils::writeProperties().

Referenced by main().

◆ writeOtherMesh()

void ApplicationUtils::NodeWiseMeshPartitioner::writeOtherMesh ( std::string const & output_filename_base,
std::vector< Partition > const & partitions,
MeshLib::Properties const & partitioned_properties ) const

Definition at line 1251 of file NodeWiseMeshPartitioner.cpp.

1255{
1256 writeNodes(output_filename_base, partitions, _nodes_global_ids);
1257
1258 const auto elem_integers =
1259 writeConfigData(output_filename_base, partitions);
1260
1261 const std::vector<IntegerType>& num_elem_integers =
1262 std::get<0>(elem_integers);
1263 const std::vector<IntegerType>& num_g_elem_integers =
1264 std::get<1>(elem_integers);
1265 writeElements(output_filename_base, partitions, num_elem_integers,
1266 num_g_elem_integers);
1267
1268 writeProperties(output_filename_base, partitioned_properties, partitions,
1270 writeProperties(output_filename_base, partitioned_properties, partitions,
1272}

References _nodes_global_ids, MeshLib::Cell, MeshLib::Node, ApplicationUtils::writeConfigData(), ApplicationUtils::writeElements(), ApplicationUtils::writeNodes(), and ApplicationUtils::writeProperties().

Referenced by main().

Member Data Documentation

◆ _mesh

std::unique_ptr<MeshLib::Mesh> ApplicationUtils::NodeWiseMeshPartitioner::_mesh
private

Pointer to a mesh object.

Definition at line 117 of file NodeWiseMeshPartitioner.h.

Referenced by mesh(), and partitionByMETIS().

◆ _nodes_global_ids

std::vector<std::size_t> ApplicationUtils::NodeWiseMeshPartitioner::_nodes_global_ids
private

Global IDs of all nodes after partitioning.

Definition at line 120 of file NodeWiseMeshPartitioner.h.

Referenced by renumberNodeIndices(), write(), and writeOtherMesh().

◆ _nodes_partition_ids

std::vector<std::size_t> ApplicationUtils::NodeWiseMeshPartitioner::_nodes_partition_ids
private

Partition IDs of each nodes.

Definition at line 123 of file NodeWiseMeshPartitioner.h.

Referenced by partitionByMETIS(), partitionOtherMesh(), and resetPartitionIdsForNodes().

◆ _partitioned_properties

MeshLib::Properties ApplicationUtils::NodeWiseMeshPartitioner::_partitioned_properties
private

Properties where values at ghost nodes and extra nodes are inserted.

Definition at line 114 of file NodeWiseMeshPartitioner.h.

Referenced by partitionByMETIS(), and write().

◆ _partitions

std::vector<Partition> ApplicationUtils::NodeWiseMeshPartitioner::_partitions
private

The documentation for this class was generated from the following files: