diff --git a/MeshLib/NodePartitionedMesh.cpp b/MeshLib/NodePartitionedMesh.cpp new file mode 100644 index 0000000000000000000000000000000000000000..211a8e63e025f35b1b118e94aad8e4f2fd30f8ee --- /dev/null +++ b/MeshLib/NodePartitionedMesh.cpp @@ -0,0 +1,64 @@ +/** + * \file + * \copyright + * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * Created on October 1, 2021, 2:13 PM + */ + +#include "NodePartitionedMesh.h" + +namespace MeshLib +{ +std::vector<int> getEndNodeIDRanks( + std::vector<std::size_t> const& n_active_nodes_at_rank) +{ + std::vector<int> data; + int id_of_end_node_of_partition = 0; + std::transform( + n_active_nodes_at_rank.begin(), n_active_nodes_at_rank.end(), + std::back_inserter(data), + [&id_of_end_node_of_partition](std::size_t const n_active_node) + { + id_of_end_node_of_partition += n_active_node; + return id_of_end_node_of_partition; + }); + + return data; +} + +NodePartitionedMesh::NodePartitionedMesh( + const std::string& name, + const std::vector<Node*>& nodes, + const std::vector<std::size_t>& glb_node_ids, + const std::vector<Element*>& elements, + Properties properties, + const std::size_t n_global_base_nodes, + const std::size_t n_global_nodes, + const std::size_t n_active_base_nodes, + const std::size_t n_active_nodes, + std::vector<std::size_t>&& n_active_base_nodes_at_rank, + std::vector<std::size_t>&& n_active_nodes_at_rank) + : Mesh(name, nodes, elements, properties), + _global_node_ids(glb_node_ids), + _n_global_base_nodes(n_global_base_nodes), + _n_global_nodes(n_global_nodes), + _n_active_base_nodes(n_active_base_nodes), + _n_active_nodes(n_active_nodes), + _n_active_base_nodes_at_rank(std::move(n_active_base_nodes_at_rank)), + _n_active_nodes_at_rank(std::move(n_active_nodes_at_rank)), + _end_node_id_ranks(getEndNodeIDRanks(_n_active_nodes_at_rank)), + _is_single_thread(false) +{ +} + +int NodePartitionedMesh::getPartitionID(const int global_node_id) const +{ + return std::upper_bound(std::cbegin(_end_node_id_ranks), + std::cend(_end_node_id_ranks), global_node_id) - + _end_node_id_ranks.begin(); +} +} // namespace MeshLib \ No newline at end of file diff --git a/MeshLib/NodePartitionedMesh.h b/MeshLib/NodePartitionedMesh.h index 7e83b7f9fc0c7151143cdaa37e5d2d2d039bd0e2..68fff5cf9c9d6dcf0bfad7635773faf3561c637e 100644 --- a/MeshLib/NodePartitionedMesh.h +++ b/MeshLib/NodePartitionedMesh.h @@ -34,6 +34,7 @@ public: explicit NodePartitionedMesh(const Mesh& mesh) : Mesh(mesh), _global_node_ids(mesh.getNumberOfNodes()), + _n_global_base_nodes(mesh.getNumberOfBaseNodes()), _n_global_nodes(mesh.getNumberOfNodes()), _n_active_base_nodes(mesh.getNumberOfBaseNodes()), _n_active_nodes(mesh.getNumberOfNodes()), @@ -56,25 +57,31 @@ public: \param elements Vector for elements. Ghost elements are stored after regular (non-ghost) elements. \param properties Mesh property. + \param n_global_base_nodes Number of the base nodes of the global mesh. \param n_global_nodes Number of all nodes of the global mesh. \param n_active_base_nodes Number of the active base nodes. \param n_active_nodes Number of all active nodes. + \param n_active_base_nodes_at_rank Gathered \c n_active_base_nodes of + all partitions. + \param n_active_nodes_at_rank Gathered \c n_active_nodes + of all partitions. */ NodePartitionedMesh(const std::string& name, const std::vector<Node*>& nodes, const std::vector<std::size_t>& glb_node_ids, const std::vector<Element*>& elements, Properties properties, + const std::size_t n_global_base_nodes, const std::size_t n_global_nodes, const std::size_t n_active_base_nodes, - const std::size_t n_active_nodes) - : Mesh(name, nodes, elements, properties), - _global_node_ids(glb_node_ids), - _n_global_nodes(n_global_nodes), - _n_active_base_nodes(n_active_base_nodes), - _n_active_nodes(n_active_nodes), - _is_single_thread(false) + const std::size_t n_active_nodes, + std::vector<std::size_t>&& n_active_base_nodes_at_rank, + std::vector<std::size_t>&& n_active_nodes_at_rank); + + /// Get the number of nodes of the global mesh for linear elements. + std::size_t getNumberOfGlobalBaseNodes() const { + return _n_global_base_nodes; } /// Get the number of all nodes of the global mesh. @@ -131,12 +138,17 @@ public: return max_connections->size() + 1; } + int getPartitionID(const int global_node_id) const; + bool isForSingleThread() const { return _is_single_thread; } private: /// Global IDs of nodes of a partition std::vector<std::size_t> _global_node_ids; + /// Number of the nodes of the global mesh linear interpolations. + std::size_t _n_global_base_nodes; + /// Number of all nodes of the global mesh. std::size_t _n_global_nodes; @@ -146,6 +158,16 @@ private: /// Number of the all active nodes. std::size_t _n_active_nodes; + /// Gathered numbers of the active nodes for linear interpolations of all + /// partitions. + std::vector<std::size_t> _n_active_base_nodes_at_rank; + + /// Gathered numbers of the all active nodes of all partitions. + std::vector<std::size_t> _n_active_nodes_at_rank; + + /// Gathered end node id ranks of all partitions. + std::vector<int> _end_node_id_ranks; + const bool _is_single_thread; };