OGS
NodeWiseMeshPartitioner.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <memory>
7#include <string>
8#include <tuple>
9#include <vector>
10
13#include "MeshLib/Mesh.h"
14#include "MeshLib/Node.h"
15
16namespace ApplicationUtils
17{
20{
21 std::vector<MeshLib::Node const*> nodes;
28 std::vector<const MeshLib::Element*> regular_elements;
29 std::vector<const MeshLib::Element*> ghost_elements;
30 std::vector<bool> duplicate_ghost_cell;
31
33
34 // Note: for property vector OGS_VERSION or IntegrationPointMetaData, the
35 // number gotten from this function is not used for reading the property
36 // vector under MPI because the sizes of the partitions of such vectors are
37 // the same.
38 std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const;
39
40 std::ostream& writeNodes(
41 std::ostream& os,
42 std::vector<std::size_t> const& global_node_ids) const;
43
44 std::ostream& writeConfig(std::ostream& os) const;
45};
46
49 std::unique_ptr<MeshLib::Mesh> const& mesh,
50 std::vector<Partition>& partitions);
51
54{
55public:
56 using IntegerType = long;
57
58public:
64 std::unique_ptr<MeshLib::Mesh>&& mesh)
65 : _partitions(num_partitions),
67 _mesh(std::move(mesh)),
68 _nodes_global_ids(_mesh->getNumberOfNodes()),
69 _nodes_partition_ids(_mesh->getNumberOfNodes())
70 {
71 }
72
74 void partitionByMETIS();
75
76 std::vector<Partition> partitionOtherMesh(MeshLib::Mesh const& mesh) const;
77
78 void renumberBulkIdsProperty(std::vector<Partition> const& partitions,
79 MeshLib::Properties& partitioned_properties);
80
83 void write(const std::string& file_name_base);
84
85 void writeOtherMesh(
86 std::string const& output_filename_base,
87 std::vector<Partition> const& partitions,
88 MeshLib::Properties const& partitioned_properties) const;
89
91 std::vector<std::size_t>&& node_partition_ids)
92 {
93 _nodes_partition_ids = std::move(node_partition_ids);
94 }
95
96 MeshLib::Mesh const& mesh() const { return *_mesh; }
97
98private:
100 std::vector<Partition> _partitions;
101
104
106 std::unique_ptr<MeshLib::Mesh> _mesh;
107
109 std::vector<std::size_t> _nodes_global_ids;
110
112 std::vector<std::size_t> _nodes_partition_ids;
113
114 // Renumber the global indices of nodes,
115 void renumberNodeIndices();
116
120 MeshLib::PropertyVector<std::size_t>* const bulk_node_ids,
121 std::vector<Partition> const& local_partitions) const;
122
126 MeshLib::PropertyVector<std::size_t>* const bulk_element_ids_pv,
127 std::vector<Partition> const& local_partitions) const;
128};
129
130} // namespace ApplicationUtils
void renumberBulkElementIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_element_ids_pv, std::vector< Partition > const &local_partitions) const
std::vector< Partition > partitionOtherMesh(MeshLib::Mesh const &mesh) const
NodeWiseMeshPartitioner(const IntegerType num_partitions, std::unique_ptr< MeshLib::Mesh > &&mesh)
void write(const std::string &file_name_base)
void renumberBulkIdsProperty(std::vector< Partition > const &partitions, MeshLib::Properties &partitioned_properties)
void renumberBulkNodeIdsProperty(MeshLib::PropertyVector< std::size_t > *const bulk_node_ids, std::vector< Partition > const &local_partitions) const
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.
void resetPartitionIdsForNodes(std::vector< std::size_t > &&node_partition_ids)
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.
void writeOtherMesh(std::string const &output_filename_base, std::vector< Partition > const &partitions, MeshLib::Properties const &partitioned_properties) const
Property manager on mesh items. Class Properties manages scalar, vector or matrix 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.
std::ostream & writeConfig(std::ostream &os) const
std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const
std::vector< const MeshLib::Element * > regular_elements
Non ghost elements.
std::vector< const MeshLib::Element * > ghost_elements
std::ostream & writeNodes(std::ostream &os, std::vector< std::size_t > const &global_node_ids) const
std::vector< MeshLib::Node const * > nodes
nodes.