OGS 6.3.0-179-g962fdcd4e.dirty.20200403132553
ApplicationUtils::NodeWiseMeshPartitioner Class Reference

Detailed Description

Mesh partitioner.

Definition at line 57 of file NodeWiseMeshPartitioner.h.

#include <NodeWiseMeshPartitioner.h>

Collaboration diagram for ApplicationUtils::NodeWiseMeshPartitioner:

Public Types

using IntegerType = long
 

Public Member Functions

 NodeWiseMeshPartitioner (const IntegerType num_partitions, std::unique_ptr< MeshLib::Mesh > &&mesh)
 
void partitionByMETIS (const bool is_mixed_high_order_linear_elems)
 
std::vector< PartitionpartitionOtherMesh (MeshLib::Mesh const &mesh, bool const is_mixed_high_order_linear_elems) 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 writeASCII (const std::string &file_name_base)
 
void writeBinary (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 (const bool is_mixed_high_order_linear_elems)
 
void processPartition (std::size_t const part_id, const bool is_mixed_high_order_linear_elems)
 
void writeConfigDataASCII (const std::string &file_name_base)
 
void writeElementsASCII (const std::string &file_name_base)
 
void writeNodesASCII (const std::string &file_name_base)
 
void writeLocalElementNodeIndices (std::ostream &os, const MeshLib::Element &elem, const std::vector< IntegerType > &local_node_ids)
 Write local indices of element nodes to a ASCII file. More...
 

Private Attributes

IntegerType _npartitions
 Number of partitions. More...
 
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 67 of file NodeWiseMeshPartitioner.h.

69  : _npartitions(num_partitions),
70  _partitions(num_partitions),
72  _mesh(std::move(mesh)),
73  _nodes_global_ids(_mesh->getNumberOfNodes()),
74  _nodes_partition_ids(_mesh->getNumberOfNodes())
75  {
76  }
IntegerType _npartitions
Number of partitions.
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::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.
std::vector< Partition > _partitions
Data for all partitions.

Member Function Documentation

◆ mesh()

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

Definition at line 119 of file NodeWiseMeshPartitioner.h.

Referenced by MeshLib::getOrCreateMeshProperty().

119 { return *_mesh; }
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.

◆ partitionByMETIS()

void ApplicationUtils::NodeWiseMeshPartitioner::partitionByMETIS ( const bool  is_mixed_high_order_linear_elems)

Partition by node.

Parameters
is_mixed_high_order_linear_elemsFlag to indicate whether the elements of a mesh can be used for both linear and high order interpolation

Definition at line 486 of file NodeWiseMeshPartitioner.cpp.

References ApplicationUtils::partitionProperties().

488 {
489  for (std::size_t part_id = 0; part_id < _partitions.size(); part_id++)
490  {
491  INFO("Processing partition: %d", part_id);
492  processPartition(part_id, is_mixed_high_order_linear_elems);
493  }
494 
495  renumberNodeIndices(is_mixed_high_order_linear_elems);
496 
498  partitionProperties(_mesh->getProperties(), _partitions);
499 }
MeshLib::Properties _partitioned_properties
Properties where values at ghost nodes and extra nodes are inserted.
void processPartition(std::size_t const part_id, const bool is_mixed_high_order_linear_elems)
MeshLib::Properties partitionProperties(MeshLib::Properties const &properties, std::vector< Partition > const &partitions)
Creates partitioned mesh properties for nodes and cells.
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
void renumberNodeIndices(const bool is_mixed_high_order_linear_elems)
std::vector< Partition > _partitions
Data for all partitions.

◆ partitionOtherMesh()

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

Definition at line 599 of file NodeWiseMeshPartitioner.cpp.

References MathLib::LinAlg::copy(), ApplicationUtils::findElementsInPartition(), ApplicationUtils::findGhostNodesInPartition(), ApplicationUtils::findNonGhostNodesInPartition(), MeshLib::Mesh::getElements(), MeshLib::Mesh::getNodes(), MeshLib::Mesh::getNumberOfBaseNodes(), MeshLib::Mesh::getNumberOfNodes(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), and MeshLib::Node.

602 {
603  auto const& bulk_node_ids =
604  mesh.getProperties().getPropertyVector<std::size_t>(
605  "bulk_node_ids", MeshLib::MeshItemType::Node, 1);
606 
607  std::vector<Partition> partitions(_partitions.size());
608  for (std::size_t part_id = 0; part_id < _partitions.size(); part_id++)
609  {
610  auto& partition = partitions[part_id];
611  INFO("Processing partition: %d", part_id);
612  // Set the node numbers of base and all mesh nodes.
613  partition.number_of_mesh_base_nodes = mesh.getNumberOfBaseNodes();
614  partition.number_of_mesh_all_nodes = mesh.getNumberOfNodes();
615 
616  std::vector<MeshLib::Node*> higher_order_regular_nodes;
617  std::tie(partition.nodes, higher_order_regular_nodes) =
619  part_id, is_mixed_high_order_linear_elems,
621  _nodes_partition_ids, bulk_node_ids);
622 
623  partition.number_of_non_ghost_base_nodes = partition.nodes.size();
624  partition.number_of_non_ghost_nodes =
625  partition.number_of_non_ghost_base_nodes +
626  higher_order_regular_nodes.size();
627 
628  std::tie(partition.regular_elements, partition.ghost_elements) =
630  _nodes_partition_ids, bulk_node_ids);
631 
632  std::vector<MeshLib::Node*> base_ghost_nodes;
633  std::vector<MeshLib::Node*> higher_order_ghost_nodes;
634  std::tie(base_ghost_nodes, higher_order_ghost_nodes) =
635  findGhostNodesInPartition(part_id, is_mixed_high_order_linear_elems,
637  mesh.getNodes(), partition.ghost_elements,
638  _nodes_partition_ids, bulk_node_ids);
639 
640  std::copy(begin(base_ghost_nodes), end(base_ghost_nodes),
641  std::back_inserter(partition.nodes));
642 
643  partition.number_of_base_nodes = partition.nodes.size();
644 
645  if (is_mixed_high_order_linear_elems)
646  {
647  std::copy(begin(higher_order_regular_nodes),
648  end(higher_order_regular_nodes),
649  std::back_inserter(partition.nodes));
650  std::copy(begin(higher_order_ghost_nodes),
651  end(higher_order_ghost_nodes),
652  std::back_inserter(partition.nodes));
653  }
654  }
655 
656  return partitions;
657 }
std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findNonGhostNodesInPartition(std::size_t const part_id, const bool is_mixed_high_order_linear_elems, std::size_t const n_base_nodes, std::vector< MeshLib::Node *> const &nodes, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
std::size_t getNumberOfBaseNodes() const
Get the number of base nodes.
Definition: Mesh.h:123
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:102
MeshLib::Properties & getProperties()
Definition: Mesh.h:131
std::tuple< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findGhostNodesInPartition(std::size_t const part_id, const bool is_mixed_high_order_linear_elems, std::size_t const number_of_base_nodes, std::vector< MeshLib::Node *> const &nodes, std::vector< MeshLib::Element const *> const &ghost_elements, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
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)
PropertyVector< T > const * getPropertyVector(std::string const &name) const
Definition: Properties.h:119
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37
std::vector< Partition > _partitions
Data for all partitions.

◆ processPartition()

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

Definition at line 284 of file NodeWiseMeshPartitioner.cpp.

References MathLib::LinAlg::copy(), ApplicationUtils::findElementsInPartition(), ApplicationUtils::findGhostNodesInPartition(), and ApplicationUtils::findNonGhostNodesInPartition().

286 {
287  auto& partition = _partitions[part_id];
288  std::vector<MeshLib::Node*> higher_order_regular_nodes;
289  std::tie(partition.nodes, higher_order_regular_nodes) =
290  findNonGhostNodesInPartition(part_id, is_mixed_high_order_linear_elems,
291  _mesh->getNumberOfBaseNodes(),
292  _mesh->getNodes(), _nodes_partition_ids);
293 
294  partition.number_of_non_ghost_base_nodes = partition.nodes.size();
295  partition.number_of_non_ghost_nodes =
296  partition.number_of_non_ghost_base_nodes +
297  higher_order_regular_nodes.size();
298 
299  std::tie(partition.regular_elements, partition.ghost_elements) =
300  findElementsInPartition(part_id, _mesh->getElements(),
302  std::vector<MeshLib::Node*> base_ghost_nodes;
303  std::vector<MeshLib::Node*> higher_order_ghost_nodes;
304  std::tie(base_ghost_nodes, higher_order_ghost_nodes) =
305  findGhostNodesInPartition(part_id, is_mixed_high_order_linear_elems,
306  _mesh->getNumberOfBaseNodes(),
307  _mesh->getNodes(), partition.ghost_elements,
309 
310  std::copy(begin(base_ghost_nodes), end(base_ghost_nodes),
311  std::back_inserter(partition.nodes));
312 
313  partition.number_of_base_nodes = partition.nodes.size();
314 
315  if (is_mixed_high_order_linear_elems)
316  {
317  std::copy(begin(higher_order_regular_nodes),
318  end(higher_order_regular_nodes),
319  std::back_inserter(partition.nodes));
320  std::copy(begin(higher_order_ghost_nodes),
321  end(higher_order_ghost_nodes),
322  std::back_inserter(partition.nodes));
323  }
324 
325  // Set the node numbers of base and all mesh nodes.
326  partition.number_of_mesh_base_nodes = _mesh->getNumberOfBaseNodes();
327  partition.number_of_mesh_all_nodes = _mesh->getNumberOfNodes();
328 }
std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > findNonGhostNodesInPartition(std::size_t const part_id, const bool is_mixed_high_order_linear_elems, std::size_t const n_base_nodes, std::vector< MeshLib::Node *> const &nodes, std::vector< std::size_t > const &partition_ids, 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, const bool is_mixed_high_order_linear_elems, std::size_t const number_of_base_nodes, std::vector< MeshLib::Node *> const &nodes, std::vector< MeshLib::Element const *> const &ghost_elements, std::vector< std::size_t > const &partition_ids, std::vector< std::size_t > const *node_id_mapping=nullptr)
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::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.
void copy(MatrixOrVector const &x, MatrixOrVector &y)
Copies x to y.
Definition: LinAlg.h:37
std::vector< Partition > _partitions
Data for all partitions.

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

References MeshLib::PropertyVector< PROP_VAL_TYPE >::size().

546 {
547  if (bulk_element_ids_pv == nullptr)
548  {
549  return;
550  }
551 
552  auto& bulk_element_ids = *bulk_element_ids_pv;
553 
554  std::size_t offset = 0; // offset in property vector for current partition
555 
556  assert(_partitions.size() == local_partitions.size());
557  int const n_partitions = static_cast<int>(_partitions.size());
558  for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
559  {
560  auto const& bulk_partition = _partitions[partition_id];
561  auto const& local_partition = local_partitions[partition_id];
562 
563  // Create global-to-local element id mapping for the bulk partition.
564  std::map<std::size_t, std::size_t> global_to_local;
565  auto map_elements =
566  [&global_to_local](
567  std::vector<MeshLib::Element const*> const& elements,
568  std::size_t const offset) {
569  auto const n_elements = elements.size();
570  for (std::size_t e = 0; e < n_elements; ++e)
571  {
572  global_to_local[elements[e]->getID()] = offset + e;
573  }
574  };
575 
576  map_elements(bulk_partition.regular_elements, 0);
577  map_elements(bulk_partition.ghost_elements,
578  bulk_partition.regular_elements.size());
579 
580  // Renumber the local bulk_element_ids map.
581  auto renumber_elements =
582  [&bulk_element_ids, &global_to_local](
583  std::vector<MeshLib::Element const*> const& elements,
584  std::size_t const offset) {
585  auto const n_elements = elements.size();
586  for (std::size_t e = 0; e < n_elements; ++e)
587  {
588  bulk_element_ids[offset + e] =
589  global_to_local[bulk_element_ids[offset + e]];
590  }
591  return n_elements;
592  };
593 
594  offset += renumber_elements(local_partition.regular_elements, offset);
595  offset += renumber_elements(local_partition.ghost_elements, offset);
596  }
597 }
std::vector< Partition > _partitions
Data for all partitions.

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

References MeshLib::PropertyVector< PROP_VAL_TYPE >::size().

504 {
505  if (bulk_node_ids_pv == nullptr)
506  {
507  return;
508  }
509 
510  auto& bulk_node_ids = *bulk_node_ids_pv;
511 
512  std::size_t offset = 0; // offset in property vector for current partition
513 
514  assert(_partitions.size() == local_partitions.size());
515  int const n_partitions = static_cast<int>(_partitions.size());
516  for (int partition_id = 0; partition_id < n_partitions; ++partition_id)
517  {
518  auto const& bulk_partition = _partitions[partition_id];
519  auto const& local_partition = local_partitions[partition_id];
520 
521  // Create global-to-local node id mapping for the bulk partition.
522  auto const& bulk_nodes = bulk_partition.nodes;
523  auto const n_bulk_nodes = bulk_nodes.size();
524  std::map<std::size_t, std::size_t> global_to_local;
525  for (std::size_t local_node_id = 0; local_node_id < n_bulk_nodes;
526  ++local_node_id)
527  {
528  global_to_local[bulk_nodes[local_node_id]->getID()] = local_node_id;
529  }
530 
531  auto const& local_nodes = local_partition.nodes;
532  auto const n_local_nodes = local_nodes.size();
533  for (std::size_t local_node_id = 0; local_node_id < n_local_nodes;
534  ++local_node_id)
535  {
536  bulk_node_ids[offset + local_node_id] =
537  global_to_local[bulk_node_ids[offset + local_node_id]];
538  }
539  offset += n_local_nodes;
540  }
541 }
std::vector< Partition > _partitions
Data for all partitions.

◆ renumberNodeIndices()

void ApplicationUtils::NodeWiseMeshPartitioner::renumberNodeIndices ( const bool  is_mixed_high_order_linear_elems)
private
Parameters
is_mixed_high_order_linear_elemsFlag to indicate whether the elements of a mesh can be used for both linear and high order interpolation

Definition at line 659 of file NodeWiseMeshPartitioner.cpp.

661 {
662  std::size_t node_global_id_offset = 0;
663  // Renumber the global indices.
664  // -- Base nodes
665  for (auto& partition : _partitions)
666  {
667  for (std::size_t i = 0; i < partition.number_of_non_ghost_base_nodes;
668  i++)
669  {
670  _nodes_global_ids[partition.nodes[i]->getID()] =
671  node_global_id_offset;
672  node_global_id_offset++;
673  }
674  }
675 
676  if (!is_mixed_high_order_linear_elems)
677  {
678  return;
679  }
680 
681  // -- Nodes for high order elements.
682  for (auto& partition : _partitions)
683  {
684  const std::size_t end_id = partition.number_of_base_nodes +
685  partition.number_of_non_ghost_nodes -
686  partition.number_of_non_ghost_base_nodes;
687  for (std::size_t i = partition.number_of_base_nodes; i < end_id; i++)
688  {
689  _nodes_global_ids[partition.nodes[i]->getID()] =
690  node_global_id_offset;
691  node_global_id_offset++;
692  }
693  }
694 }
std::vector< std::size_t > _nodes_global_ids
Global IDs of all nodes after partitioning.
std::vector< Partition > _partitions
Data for all partitions.

◆ resetPartitionIdsForNodes()

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

Definition at line 113 of file NodeWiseMeshPartitioner.h.

115  {
116  _nodes_partition_ids = std::move(node_partition_ids);
117  }
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.

◆ writeASCII()

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

Write the partitions into ASCII files

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1139 of file NodeWiseMeshPartitioner.cpp.

1140 {
1141  writeConfigDataASCII(file_name_base);
1142  writeElementsASCII(file_name_base);
1143  writeNodesASCII(file_name_base);
1144 }
void writeNodesASCII(const std::string &file_name_base)
void writeElementsASCII(const std::string &file_name_base)
void writeConfigDataASCII(const std::string &file_name_base)

◆ writeBinary()

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

Write the partitions into binary files

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1009 of file NodeWiseMeshPartitioner.cpp.

References MeshLib::Cell, MeshLib::Node, ApplicationUtils::writeConfigDataBinary(), ApplicationUtils::writeElementsBinary(), ApplicationUtils::writeNodesBinary(), and ApplicationUtils::writePropertiesBinary().

1010 {
1015 
1016  const auto elem_integers =
1017  writeConfigDataBinary(file_name_base, _partitions);
1018 
1019  const std::vector<IntegerType>& num_elem_integers =
1020  std::get<0>(elem_integers);
1021  const std::vector<IntegerType>& num_g_elem_integers =
1022  std::get<1>(elem_integers);
1023  writeElementsBinary(file_name_base, _partitions, num_elem_integers,
1024  num_g_elem_integers);
1025 
1027 }
void writePropertiesBinary(const std::string &file_name_base, MeshLib::Properties const &partitioned_properties, std::vector< Partition > const &partitions, MeshLib::MeshItemType const mesh_item_type)
void writeElementsBinary(std::string const &file_name_base, std::vector< Partition > const &partitions, std::vector< long > const &num_elem_integers, std::vector< long > const &num_g_elem_integers)
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::tuple< std::vector< long >, std::vector< long > > writeConfigDataBinary(const std::string &file_name_base, std::vector< Partition > const &partitions)
void writeNodesBinary(const std::string &file_name_base, std::vector< Partition > const &partitions, std::vector< std::size_t > const &global_node_ids)
std::vector< Partition > _partitions
Data for all partitions.

◆ writeConfigDataASCII()

void ApplicationUtils::NodeWiseMeshPartitioner::writeConfigDataASCII ( const std::string &  file_name_base)
private

Write the configuration data of the partition data in ASCII files.

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1052 of file NodeWiseMeshPartitioner.cpp.

References ApplicationUtils::getNumberOfIntegerVariablesOfElements().

1054 {
1055  const std::string fname = file_name_base + "_partitioned_cfg" +
1056  std::to_string(_npartitions) + ".msh";
1057  std::fstream os_subd_head(fname, std::ios::out | std::ios::trunc);
1058  const std::string mesh_info =
1059  "Subdomain mesh ("
1060  "Number of nodes; Number of base nodes;"
1061  " Number of regular elements; Number of ghost elements;"
1062  " Number of non-ghost base nodes; Number of non-ghost nodes"
1063  " Number of base nodes of the global mesh;"
1064  " Number of nodes of the global mesh;"
1065  " Number of integer variables to define non-ghost elements;"
1066  " Number of integer variables to define ghost elements.)";
1067  os_subd_head << mesh_info << "\n";
1068  os_subd_head << _npartitions << "\n";
1069 
1070  for (const auto& partition : _partitions)
1071  {
1072  os_subd_head << partition.nodes.size();
1073  os_subd_head << " " << partition.number_of_base_nodes;
1074  os_subd_head << " " << partition.regular_elements.size();
1075  os_subd_head << " " << partition.ghost_elements.size();
1076  os_subd_head << " " << partition.number_of_non_ghost_base_nodes;
1077  os_subd_head << " " << partition.number_of_non_ghost_nodes;
1078  os_subd_head << " " << _mesh->getNumberOfBaseNodes();
1079  os_subd_head << " " << _mesh->getNumberOfNodes();
1080  os_subd_head << " "
1082  partition.regular_elements);
1083  os_subd_head << " "
1085  partition.ghost_elements)
1086  << " 0\n";
1087  }
1088 }
IntegerType _npartitions
Number of partitions.
NodeWiseMeshPartitioner::IntegerType getNumberOfIntegerVariablesOfElements(std::vector< const MeshLib::Element *> const &elements)
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
std::vector< Partition > _partitions
Data for all partitions.

◆ writeElementsASCII()

void ApplicationUtils::NodeWiseMeshPartitioner::writeElementsASCII ( const std::string &  file_name_base)
private

Write the element integer variables of all partitions into ASCII files.

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1090 of file NodeWiseMeshPartitioner.cpp.

1092 {
1093  const std::string fname = file_name_base + "_partitioned_elems_" +
1094  std::to_string(_npartitions) + ".msh";
1095  std::fstream os_subd(fname, std::ios::out | std::ios::trunc);
1096  for (const auto& partition : _partitions)
1097  {
1098  // Set the local node indices of the current partition.
1099  IntegerType node_local_id_offset = 0;
1100  std::vector<IntegerType> nodes_local_ids(_mesh->getNumberOfNodes(), -1);
1101  for (const auto* node : partition.nodes)
1102  {
1103  nodes_local_ids[node->getID()] = node_local_id_offset;
1104  ++node_local_id_offset;
1105  }
1106 
1107  for (const auto* elem : partition.regular_elements)
1108  {
1109  writeLocalElementNodeIndices(os_subd, *elem, nodes_local_ids);
1110  }
1111  for (const auto* elem : partition.ghost_elements)
1112  {
1113  writeLocalElementNodeIndices(os_subd, *elem, nodes_local_ids);
1114  }
1115  os_subd << std::endl;
1116  }
1117 }
IntegerType _npartitions
Number of partitions.
void writeLocalElementNodeIndices(std::ostream &os, const MeshLib::Element &elem, const std::vector< IntegerType > &local_node_ids)
Write local indices of element nodes to a ASCII file.
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
std::vector< Partition > _partitions
Data for all partitions.

◆ writeLocalElementNodeIndices()

void ApplicationUtils::NodeWiseMeshPartitioner::writeLocalElementNodeIndices ( std::ostream &  os,
const MeshLib::Element elem,
const std::vector< IntegerType > &  local_node_ids 
)
private

Write local indices of element nodes to a ASCII file.

Parameters
osOutput stream
elemElement
local_node_idsLocal node indices of a partition

Definition at line 1146 of file NodeWiseMeshPartitioner.cpp.

References MeshLib::Element::getCellType(), MeshLib::Element::getNodeIndex(), and MeshLib::Element::getNumberOfNodes().

1150 {
1151  unsigned mat_id = 0; // TODO: Material ID to be set from the mesh data
1152  os << mat_id << " " << static_cast<unsigned>(elem.getCellType()) << " "
1153  << elem.getNumberOfNodes() << " ";
1154  for (unsigned i = 0; i < elem.getNumberOfNodes(); i++)
1155  {
1156  os << " " << local_node_ids[elem.getNodeIndex(i)];
1157  }
1158  os << "\n";
1159 }
std::size_t getNodeIndex(unsigned i) const
Definition: Element.cpp:182
virtual CellType getCellType() const =0
virtual unsigned getNumberOfNodes() const =0
Returns the number of all nodes including both linear and nonlinear nodes.

◆ writeNodesASCII()

void ApplicationUtils::NodeWiseMeshPartitioner::writeNodesASCII ( const std::string &  file_name_base)
private

Write the nodes of all partitions into a ASCII file.

Parameters
file_name_baseThe prefix of the file name.

Definition at line 1119 of file NodeWiseMeshPartitioner.cpp.

1120 {
1121  const std::string fname = file_name_base + "_partitioned_nodes_" +
1122  std::to_string(_npartitions) + ".msh";
1123  std::fstream os_subd_node(fname, std::ios::out | std::ios::trunc);
1124  os_subd_node.precision(std::numeric_limits<double>::digits10);
1125  os_subd_node.setf(std::ios::scientific);
1126 
1127  for (const auto& partition : _partitions)
1128  {
1129  for (const auto* node : partition.nodes)
1130  {
1131  double const* coords = node->getCoords();
1132  os_subd_node << _nodes_global_ids[node->getID()] << " " << coords[0]
1133  << " " << coords[1] << " " << coords[2] << "\n";
1134  }
1135  os_subd_node << std::endl;
1136  }
1137 }
IntegerType _npartitions
Number of partitions.
std::vector< std::size_t > _nodes_global_ids
Global IDs of all nodes after partitioning.
std::vector< Partition > _partitions
Data for all partitions.

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

References MeshLib::Cell, MeshLib::Node, ApplicationUtils::writeConfigDataBinary(), ApplicationUtils::writeElementsBinary(), ApplicationUtils::writeNodesBinary(), and ApplicationUtils::writePropertiesBinary().

1033 {
1034  writeNodesBinary(output_filename_base, partitions, _nodes_global_ids);
1035 
1036  const auto elem_integers =
1037  writeConfigDataBinary(output_filename_base, partitions);
1038 
1039  const std::vector<IntegerType>& num_elem_integers =
1040  std::get<0>(elem_integers);
1041  const std::vector<IntegerType>& num_g_elem_integers =
1042  std::get<1>(elem_integers);
1043  writeElementsBinary(output_filename_base, partitions, num_elem_integers,
1044  num_g_elem_integers);
1045 
1046  writePropertiesBinary(output_filename_base, partitioned_properties,
1047  partitions, MeshLib::MeshItemType::Node);
1048  writePropertiesBinary(output_filename_base, partitioned_properties,
1049  partitions, MeshLib::MeshItemType::Cell);
1050 }
void writePropertiesBinary(const std::string &file_name_base, MeshLib::Properties const &partitioned_properties, std::vector< Partition > const &partitions, MeshLib::MeshItemType const mesh_item_type)
void writeElementsBinary(std::string const &file_name_base, std::vector< Partition > const &partitions, std::vector< long > const &num_elem_integers, std::vector< long > const &num_g_elem_integers)
std::vector< std::size_t > _nodes_global_ids
Global IDs of all nodes after partitioning.
std::tuple< std::vector< long >, std::vector< long > > writeConfigDataBinary(const std::string &file_name_base, std::vector< Partition > const &partitions)
void writeNodesBinary(const std::string &file_name_base, std::vector< Partition > const &partitions, std::vector< std::size_t > const &global_node_ids)

Member Data Documentation

◆ _mesh

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

Pointer to a mesh object.

Definition at line 132 of file NodeWiseMeshPartitioner.h.

◆ _nodes_global_ids

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

Global IDs of all nodes after partitioning.

Definition at line 135 of file NodeWiseMeshPartitioner.h.

◆ _nodes_partition_ids

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

Partition IDs of each nodes.

Definition at line 138 of file NodeWiseMeshPartitioner.h.

◆ _npartitions

IntegerType ApplicationUtils::NodeWiseMeshPartitioner::_npartitions
private

Number of partitions.

Definition at line 123 of file NodeWiseMeshPartitioner.h.

◆ _partitioned_properties

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

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

Definition at line 129 of file NodeWiseMeshPartitioner.h.

◆ _partitions

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

Data for all partitions.

Definition at line 126 of file NodeWiseMeshPartitioner.h.


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