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;
23 std::size_t number_of_regular_nodes = 0;
24 std::size_t number_of_base_nodes = 0;
26 std::size_t number_of_mesh_all_nodes = 0;
27 std::vector<const MeshLib::Element*> elements;
28
30
31 // Note: for property vector OGS_VERSION or IntegrationPointMetaData, the
32 // number gotten from this function is not used for reading the property
33 // vector under MPI because the sizes of the partitions of such vectors are
34 // the same.
35 std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const;
36
37 std::ostream& writeNodes(
38 std::ostream& os,
39 std::vector<std::size_t> const& global_node_ids) const;
40
41 std::ostream& writeConfig(std::ostream& os) const;
42};
43
46 std::unique_ptr<MeshLib::Mesh> const& mesh,
47 std::vector<Partition>& partitions);
48
51{
52public:
53 using IntegerType = long;
54
55public:
61 std::unique_ptr<MeshLib::Mesh>&& mesh)
62 : _partitions(num_partitions),
64 _mesh(std::move(mesh)),
65 _nodes_global_ids(_mesh->getNumberOfNodes()),
66 _nodes_partition_ids(_mesh->getNumberOfNodes())
67 {
68 }
69
71 void partitionByMETIS();
72
73 std::vector<Partition> partitionOtherMesh(MeshLib::Mesh const& mesh) const;
74
75 void renumberBulkIdsProperty(std::vector<Partition> const& partitions,
76 MeshLib::Properties& partitioned_properties);
77
80 void write(const std::string& file_name_base);
81
82 void writeOtherMesh(
83 std::string const& output_filename_base,
84 std::vector<Partition> const& partitions,
85 MeshLib::Properties const& partitioned_properties) const;
86
88 std::vector<std::size_t>&& node_partition_ids)
89 {
90 _nodes_partition_ids = std::move(node_partition_ids);
91 }
92
93 MeshLib::Mesh const& mesh() const { return *_mesh; }
94
95private:
97 std::vector<Partition> _partitions;
98
101
103 std::unique_ptr<MeshLib::Mesh> _mesh;
104
106 std::vector<std::size_t> _nodes_global_ids;
107
109 std::vector<std::size_t> _nodes_partition_ids;
110
111 // Renumber the global indices of nodes,
112 void renumberNodeIndices();
113
117 MeshLib::PropertyVector<std::size_t>* const bulk_node_ids,
118 std::vector<Partition> const& local_partitions) const;
119
123 MeshLib::PropertyVector<std::size_t>* const bulk_element_ids_pv,
124 std::vector<Partition> const& local_partitions) const;
125};
126
127} // 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::vector< const MeshLib::Element * > elements
std::size_t numberOfMeshItems(MeshLib::MeshItemType const item_type) const
std::ostream & writeNodes(std::ostream &os, std::vector< std::size_t > const &global_node_ids) const
std::vector< MeshLib::Node const * > nodes
nodes.