OGS
ApplicationUtils::NodeWiseMeshPartitioner Class Reference

Detailed Description

Mesh partitioner.

Definition at line 58 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. More...
 
std::vector< PartitionpartitionOtherMesh (MeshLib::Mesh const &mesh) const
 
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
 
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 processPartition (std::size_t const part_id)
 

Private Attributes

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

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 68 of file NodeWiseMeshPartitioner.h.

70 : _partitions(num_partitions),
72 _mesh(std::move(mesh)),
73 _nodes_global_ids(_mesh->getNumberOfNodes()),
74 _nodes_partition_ids(_mesh->getNumberOfNodes())
75 {
76 }
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 110 of file NodeWiseMeshPartitioner.h.

110{ return *_mesh; }

References _mesh.

Referenced by MeshLib::addPropertyToMesh(), MeshLib::getOrCreateMeshProperty(), main(), and partitionOtherMesh().

◆ partitionByMETIS()

void ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS ( )

Partition by node.

Definition at line 537 of file NodeWiseMeshPartitioner.cpp.

538{
539 for (std::size_t part_id = 0; part_id < _partitions.size(); part_id++)
540 {
541 INFO("Processing partition: {:d}", part_id);
542 processPartition(part_id);
543 }
544
546
548
550 partitionProperties(_mesh->getProperties(), _partitions);
551}
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:34
void processPartition(std::size_t const part_id)
MeshLib::Properties partitionProperties(MeshLib::Properties const &properties, std::vector< Partition > const &partitions)
Partition existing properties and add vtkGhostType cell data array property.
void markDuplicateGhostCells(MeshLib::Mesh const &mesh, std::vector< Partition > &partitions)

References _mesh, _partitioned_properties, _partitions, INFO(), ApplicationUtils::markDuplicateGhostCells(), ApplicationUtils::partitionProperties(), processPartition(), and renumberNodeIndices().

Referenced by main().

◆ partitionOtherMesh()

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

Definition at line 653 of file NodeWiseMeshPartitioner.cpp.

655{
656 auto const& bulk_node_ids =
657 mesh.getProperties().getPropertyVector<std::size_t>(
658 "bulk_node_ids", MeshLib::MeshItemType::Node, 1);
659
660 std::vector<Partition> partitions(_partitions.size());
661 for (std::size_t part_id = 0; part_id < _partitions.size(); part_id++)
662 {
663 auto& partition = partitions[part_id];
664 INFO("Processing partition: {:d}", part_id);
665 // Set the node numbers of base and all mesh nodes.
666 partition.number_of_mesh_base_nodes = mesh.getNumberOfBaseNodes();
667 partition.number_of_mesh_all_nodes = mesh.getNumberOfNodes();
668
669 std::vector<MeshLib::Node*> higher_order_regular_nodes;
670 std::tie(partition.nodes, higher_order_regular_nodes) =
673 bulk_node_ids);
674
675 partition.number_of_regular_base_nodes = partition.nodes.size();
676 std::copy(begin(higher_order_regular_nodes),
677 end(higher_order_regular_nodes),
678 std::back_inserter(partition.nodes));
679
680 partition.number_of_regular_nodes = partition.nodes.size();
681
682 std::tie(partition.regular_elements, partition.ghost_elements) =
684 _nodes_partition_ids, bulk_node_ids);
685
686 std::vector<MeshLib::Node*> base_ghost_nodes;
687 std::vector<MeshLib::Node*> higher_order_ghost_nodes;
688 std::tie(base_ghost_nodes, higher_order_ghost_nodes) =
690 part_id, mesh.getNodes(), partition.ghost_elements,
691 _nodes_partition_ids, mesh, bulk_node_ids);
692
693 std::copy(begin(base_ghost_nodes), end(base_ghost_nodes),
694 std::back_inserter(partition.nodes));
695
696 partition.number_of_base_nodes =
697 partition.number_of_regular_base_nodes + base_ghost_nodes.size();
698
699 std::copy(begin(higher_order_ghost_nodes),
700 end(higher_order_ghost_nodes),
701 std::back_inserter(partition.nodes));
702 }
703
704 markDuplicateGhostCells(mesh, partitions);
705 return partitions;
706}
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:95
std::size_t getNumberOfBaseNodes() const
Get the number of base nodes.
Definition: Mesh.cpp:214
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
Properties & getProperties()
Definition: Mesh.h:123
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:89
PropertyVector< T > const * getPropertyVector(std::string const &name) const
std::tuple< std::vector< MeshLib::Element const * >, std::vector< MeshLib::Element const * > > findElementsInPartition(std::size_t const part_id, std::vector< MeshLib::Element * > const &elements, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findRegularNodesInPartition(std::size_t const part_id, std::vector< MeshLib::Node * > const &nodes, std::vector< std::size_t > const &partition_ids, MeshLib::Mesh const &mesh, std::vector< std::size_t > const *node_id_mapping=nullptr)
std::tuple< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findGhostNodesInPartition(std::size_t const part_id, std::vector< MeshLib::Node * > const &nodes, std::vector< MeshLib::Element const * > const &ghost_elements, std::vector< std::size_t > const &partition_ids, MeshLib::Mesh const &mesh, std::vector< std::size_t > const *node_id_mapping=nullptr)
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37

References _nodes_partition_ids, _partitions, MathLib::LinAlg::copy(), ApplicationUtils::findElementsInPartition(), ApplicationUtils::findGhostNodesInPartition(), ApplicationUtils::findRegularNodesInPartition(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfBaseNodes(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), INFO(), ApplicationUtils::markDuplicateGhostCells(), mesh(), and MeshLib::Node.

Referenced by main().

◆ processPartition()

void ApplicationUtils::NodeWiseMeshPartitioner::processPartition ( std::size_t const  part_id)
private

Definition at line 268 of file NodeWiseMeshPartitioner.cpp.

269{
270 auto& partition = _partitions[part_id];
271 std::vector<MeshLib::Node*> higher_order_regular_nodes;
272 std::tie(partition.nodes, higher_order_regular_nodes) =
273 findRegularNodesInPartition(part_id, _mesh->getNodes(),
275
276 partition.number_of_regular_base_nodes = partition.nodes.size();
277 std::copy(begin(higher_order_regular_nodes),
278 end(higher_order_regular_nodes),
279 std::back_inserter(partition.nodes));
280
281 partition.number_of_regular_nodes = partition.nodes.size();
282
283 std::tie(partition.regular_elements, partition.ghost_elements) =
284 findElementsInPartition(part_id, _mesh->getElements(),
286 std::vector<MeshLib::Node*> base_ghost_nodes;
287 std::vector<MeshLib::Node*> higher_order_ghost_nodes;
288 std::tie(base_ghost_nodes, higher_order_ghost_nodes) =
289 findGhostNodesInPartition(part_id, _mesh->getNodes(),
290 partition.ghost_elements,
292
293 std::copy(begin(base_ghost_nodes), end(base_ghost_nodes),
294 std::back_inserter(partition.nodes));
295
296 partition.number_of_base_nodes =
297 partition.number_of_regular_base_nodes + base_ghost_nodes.size();
298
299 std::copy(begin(higher_order_ghost_nodes),
300 end(higher_order_ghost_nodes),
301 std::back_inserter(partition.nodes));
302
303 // Set the node numbers of base and all mesh nodes.
304 partition.number_of_mesh_base_nodes = _mesh->getNumberOfBaseNodes();
305 partition.number_of_mesh_all_nodes = _mesh->getNumberOfNodes();
306}

References _mesh, _nodes_partition_ids, _partitions, MathLib::LinAlg::copy(), ApplicationUtils::findElementsInPartition(), ApplicationUtils::findGhostNodesInPartition(), and ApplicationUtils::findRegularNodesInPartition().

Referenced by partitionByMETIS().

◆ renumberBulkElementIdsProperty()

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

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

Definition at line 595 of file NodeWiseMeshPartitioner.cpp.

598{
599 if (bulk_element_ids_pv == nullptr)
600 {
601 return;
602 }
603
604 auto& bulk_element_ids = *bulk_element_ids_pv;
605
606 std::size_t offset = 0; // offset in property vector for current partition
607
608 assert(_partitions.size() == local_partitions.size());
609 int const n_partitions = static_cast<int>(_partitions.size());
610 for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
611 {
612 auto const& bulk_partition = _partitions[partition_id];
613 auto const& local_partition = local_partitions[partition_id];
614
615 // Create global-to-local element id mapping for the bulk partition.
616 std::map<std::size_t, std::size_t> global_to_local;
617 auto map_elements =
618 [&global_to_local](
619 std::vector<MeshLib::Element const*> const& elements,
620 std::size_t const offset)
621 {
622 auto const n_elements = elements.size();
623 for (std::size_t e = 0; e < n_elements; ++e)
624 {
625 global_to_local[elements[e]->getID()] = offset + e;
626 }
627 };
628
629 map_elements(bulk_partition.regular_elements, 0);
630 map_elements(bulk_partition.ghost_elements,
631 bulk_partition.regular_elements.size());
632
633 // Renumber the local bulk_element_ids map.
634 auto renumber_elements =
635 [&bulk_element_ids, &global_to_local](
636 std::vector<MeshLib::Element const*> const& elements,
637 std::size_t const offset)
638 {
639 auto const n_elements = elements.size();
640 for (std::size_t e = 0; e < n_elements; ++e)
641 {
642 bulk_element_ids[offset + e] =
643 global_to_local[bulk_element_ids[offset + e]];
644 }
645 return n_elements;
646 };
647
648 offset += renumber_elements(local_partition.regular_elements, offset);
649 offset += renumber_elements(local_partition.ghost_elements, offset);
650 }
651}

References _partitions.

Referenced by main().

◆ renumberBulkNodeIdsProperty()

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

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

Definition at line 553 of file NodeWiseMeshPartitioner.cpp.

556{
557 if (bulk_node_ids_pv == nullptr)
558 {
559 return;
560 }
561
562 auto& bulk_node_ids = *bulk_node_ids_pv;
563
564 std::size_t offset = 0; // offset in property vector for current partition
565
566 assert(_partitions.size() == local_partitions.size());
567 int const n_partitions = static_cast<int>(_partitions.size());
568 for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
569 {
570 auto const& bulk_partition = _partitions[partition_id];
571 auto const& local_partition = local_partitions[partition_id];
572
573 // Create global-to-local node id mapping for the bulk partition.
574 auto const& bulk_nodes = bulk_partition.nodes;
575 auto const n_bulk_nodes = bulk_nodes.size();
576 std::map<std::size_t, std::size_t> global_to_local;
577 for (std::size_t local_node_id = 0; local_node_id < n_bulk_nodes;
578 ++local_node_id)
579 {
580 global_to_local[bulk_nodes[local_node_id]->getID()] = local_node_id;
581 }
582
583 auto const& local_nodes = local_partition.nodes;
584 auto const n_local_nodes = local_nodes.size();
585 for (std::size_t local_node_id = 0; local_node_id < n_local_nodes;
586 ++local_node_id)
587 {
588 bulk_node_ids[offset + local_node_id] =
589 global_to_local[bulk_node_ids[offset + local_node_id]];
590 }
591 offset += n_local_nodes;
592 }
593}

References _partitions.

Referenced by main().

◆ renumberNodeIndices()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberNodeIndices ( )
private

Definition at line 708 of file NodeWiseMeshPartitioner.cpp.

709{
710 std::size_t node_global_id_offset = 0;
711 // Renumber the global indices.
712 for (auto& partition : _partitions)
713 {
714 for (std::size_t i = 0; i < partition.number_of_regular_nodes; i++)
715 {
716 _nodes_global_ids[partition.nodes[i]->getID()] =
717 node_global_id_offset++;
718 }
719 }
720}

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 104 of file NodeWiseMeshPartitioner.h.

106 {
107 _nodes_partition_ids = std::move(node_partition_ids);
108 }

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 1040 of file NodeWiseMeshPartitioner.cpp.

1041{
1046
1047 const auto elements_offsets = writeConfigData(file_name_base, _partitions);
1048
1049 const std::vector<IntegerType>& regular_element_offsets =
1050 std::get<0>(elements_offsets);
1051 const std::vector<IntegerType>& ghost_element_offsets =
1052 std::get<1>(elements_offsets);
1053 writeElements(file_name_base, _partitions, regular_element_offsets,
1054 ghost_element_offsets);
1055
1056 writeNodes(file_name_base, _partitions, _nodes_global_ids);
1057}
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::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 1059 of file NodeWiseMeshPartitioner.cpp.

1063{
1064 writeNodes(output_filename_base, partitions, _nodes_global_ids);
1065
1066 const auto elem_integers =
1067 writeConfigData(output_filename_base, partitions);
1068
1069 const std::vector<IntegerType>& num_elem_integers =
1070 std::get<0>(elem_integers);
1071 const std::vector<IntegerType>& num_g_elem_integers =
1072 std::get<1>(elem_integers);
1073 writeElements(output_filename_base, partitions, num_elem_integers,
1074 num_g_elem_integers);
1075
1076 writeProperties(output_filename_base, partitioned_properties, partitions,
1078 writeProperties(output_filename_base, partitioned_properties, partitions,
1080}

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 120 of file NodeWiseMeshPartitioner.h.

Referenced by mesh(), partitionByMETIS(), and processPartition().

◆ _nodes_global_ids

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

Global IDs of all nodes after partitioning.

Definition at line 123 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 126 of file NodeWiseMeshPartitioner.h.

Referenced by partitionOtherMesh(), processPartition(), 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 117 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: