OGS 6.3.0-179-g962fdcd4e.dirty.20200403132553
NodeWiseMeshPartitioner.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <memory>
18 #include <string>
19 #include <tuple>
20 #include <vector>
21 
24 #include "MeshLib/Mesh.h"
25 #include "MeshLib/Node.h"
26 
27 namespace ApplicationUtils
28 {
30 struct Partition
31 {
32  std::vector<MeshLib::Node*> nodes;
35  std::size_t number_of_base_nodes;
39  std::vector<const MeshLib::Element*> regular_elements;
40  std::vector<const MeshLib::Element*> ghost_elements;
41 
42  std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const;
43 
44  std::ostream& writeNodesBinary(
45  std::ostream& os,
46  std::vector<std::size_t> const& global_node_ids) const;
47 
48  std::ostream& writeConfigBinary(std::ostream& os) const;
49 };
50 
53  MeshLib::Properties const& properties,
54  std::vector<Partition> const& partitions);
55 
58 {
59 public:
60  using IntegerType = long;
61 
62 public:
67  NodeWiseMeshPartitioner(const IntegerType num_partitions,
68  std::unique_ptr<MeshLib::Mesh>&& mesh)
69  : _npartitions(num_partitions),
70  _partitions(num_partitions),
71  _partitioned_properties(),
72  _mesh(std::move(mesh)),
73  _nodes_global_ids(_mesh->getNumberOfNodes()),
74  _nodes_partition_ids(_mesh->getNumberOfNodes())
75  {
76  }
77 
82  void partitionByMETIS(const bool is_mixed_high_order_linear_elems);
83 
84  std::vector<Partition> partitionOtherMesh(
85  MeshLib::Mesh const& mesh,
86  bool const is_mixed_high_order_linear_elems) const;
87 
90  void renumberBulkNodeIdsProperty(
91  MeshLib::PropertyVector<std::size_t>* const bulk_node_ids,
92  std::vector<Partition> const& local_partitions) const;
93 
96  void renumberBulkElementIdsProperty(
97  MeshLib::PropertyVector<std::size_t>* const bulk_element_ids_pv,
98  std::vector<Partition> const& local_partitions) const;
99 
102  void writeASCII(const std::string& file_name_base);
103 
106  void writeBinary(const std::string& file_name_base);
107 
108  void writeOtherMesh(
109  std::string const& output_filename_base,
110  std::vector<Partition> const& partitions,
111  MeshLib::Properties const& partitioned_properties) const;
112 
114  std::vector<std::size_t>&& node_partition_ids)
115  {
116  _nodes_partition_ids = std::move(node_partition_ids);
117  }
118 
119  MeshLib::Mesh const& mesh() const { return *_mesh; }
120 
121 private:
124 
126  std::vector<Partition> _partitions;
127 
130 
132  std::unique_ptr<MeshLib::Mesh> _mesh;
133 
135  std::vector<std::size_t> _nodes_global_ids;
136 
138  std::vector<std::size_t> _nodes_partition_ids;
139 
140  // Renumber the global indices of nodes,
144  void renumberNodeIndices(const bool is_mixed_high_order_linear_elems);
145 
146  void processPartition(std::size_t const part_id,
147  const bool is_mixed_high_order_linear_elems);
148 
151  void writeConfigDataASCII(const std::string& file_name_base);
152 
156  void writeElementsASCII(const std::string& file_name_base);
157 
160  void writeNodesASCII(const std::string& file_name_base);
161 
168  void writeLocalElementNodeIndices(
169  std::ostream& os,
170  const MeshLib::Element& elem,
171  const std::vector<IntegerType>& local_node_ids);
172 };
173 
174 } // namespace ApplicationUtils
IntegerType _npartitions
Number of partitions.
std::ostream & writeNodesBinary(std::ostream &os, std::vector< std::size_t > const &global_node_ids) const
NodeWiseMeshPartitioner(const IntegerType num_partitions, std::unique_ptr< MeshLib::Mesh > &&mesh)
Definition of the Node class.
MeshLib::Properties _partitioned_properties
Properties where values at ghost nodes and extra nodes are inserted.
Definition of the Mesh class.
std::vector< const MeshLib::Element * > ghost_elements
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties...
Definition: Properties.h:36
MeshLib::Properties partitionProperties(MeshLib::Properties const &properties, std::vector< Partition > const &partitions)
Creates partitioned mesh properties for nodes and cells.
MeshItemType
Definition: Location.h:21
std::vector< std::size_t > _nodes_global_ids
Global IDs of all nodes after partitioning.
std::ostream & writeConfigBinary(std::ostream &os) const
void resetPartitionIdsForNodes(std::vector< std::size_t > &&node_partition_ids)
std::unique_ptr< MeshLib::Mesh > _mesh
Pointer to a mesh object.
std::vector< MeshLib::Node * > nodes
nodes.
std::vector< std::size_t > _nodes_partition_ids
Partition IDs of each nodes.
std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const
std::vector< Partition > _partitions
Data for all partitions.
Definition of the Element class.
std::vector< const MeshLib::Element * > regular_elements
Non ghost elements.