diff --git a/src/mesh/Connectivity.cpp b/src/mesh/Connectivity.cpp index 07701bbb950f6d1cf6ecccff9982b54a86146b67..9c9684c23b59e5296b22b6552399a06ed530cade 100644 --- a/src/mesh/Connectivity.cpp +++ b/src/mesh/Connectivity.cpp @@ -288,6 +288,87 @@ Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector, } +template<size_t Dimension> +Connectivity<Dimension>:: +Connectivity(const ConnectivityDescriptor& descriptor) +{ +#warning should be checked by + Assert(descriptor.cell_by_node_vector.size() == descriptor.cell_type_vector.size()); + Assert(descriptor.cell_number_vector.size() == descriptor.cell_type_vector.size()); + + auto& cell_to_node_matrix + = m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)]; + cell_to_node_matrix = descriptor.cell_by_node_vector; + + { + CellValue<CellType> cell_type(*this); + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ + cell_type[j] = descriptor.cell_type_vector[j]; + }); + m_cell_type = cell_type; + } + + { + CellValue<int> cell_number(*this); + cell_number = convert_to_array(descriptor.cell_number_vector); + m_cell_number = cell_number; + } + + { + NodeValue<int> node_number(*this); + node_number = convert_to_array(descriptor.node_number_vector); + m_node_number = node_number; + } + + { + CellValue<int> cell_global_index(*this); +#warning index must start accounting number of global indices of other procs +#warning must take care of ghost cells + int first_index = 0; + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + cell_global_index[j] = first_index+j; + }); + m_cell_global_index = cell_global_index; + } + + + { + CellValue<double> inv_cell_nb_nodes(*this); + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + const auto& cell_nodes = cell_to_node_matrix.rowConst(j); + inv_cell_nb_nodes[j] = 1./cell_nodes.length; + }); + m_inv_cell_nb_nodes = inv_cell_nb_nodes; + } + + { + CellValue<int> cell_owner(*this); + cell_owner = convert_to_array(descriptor.cell_owner_vector); + m_cell_owner = cell_owner; + } + + { + NodeValue<int> node_owner(*this); + node_owner = convert_to_array(descriptor.node_owner_vector); + m_node_owner = node_owner; + } + + if constexpr (Dimension>1) { + this->_computeCellFaceAndFaceNodeConnectivities(); + } +} + +template Connectivity1D:: +Connectivity(const ConnectivityDescriptor& descriptor); + +template Connectivity2D:: +Connectivity(const ConnectivityDescriptor& descriptor); + +template Connectivity3D:: +Connectivity(const ConnectivityDescriptor& descriptor); + + + template Connectivity1D:: Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector, const std::vector<CellType>& cell_type_vector, diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp index a04c0f7e00fb5fdafc293ad3817c72776ee6e563..71044616c22611e8a0d73d3edb406f528d15868d 100644 --- a/src/mesh/Connectivity.hpp +++ b/src/mesh/Connectivity.hpp @@ -36,6 +36,27 @@ #include <algorithm> #include <set> +class ConnectivityDescriptor +{ + private: + + public: + std::vector<std::vector<unsigned int>>& cell_by_node_vector; + std::vector<CellType>& cell_type_vector; + std::vector<int>& cell_number_vector; + std::vector<int>& node_number_vector; + std::vector<int>& cell_owner_vector; + std::vector<int>& node_owner_vector; + + ConnectivityDescriptor& operator=(const ConnectivityDescriptor&) = delete; + ConnectivityDescriptor& operator=(ConnectivityDescriptor&&) = delete; + + ConnectivityDescriptor() = default; + ConnectivityDescriptor(const ConnectivityDescriptor&) = default; + ConnectivityDescriptor(ConnectivityDescriptor&&) = delete; + ~ConnectivityDescriptor() = default; +}; + template <size_t Dimension> class Connectivity; @@ -688,6 +709,8 @@ class Connectivity final Connectivity(const Connectivity&) = delete; + Connectivity(const ConnectivityDescriptor& descriptor); + Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector, const std::vector<CellType>& cell_type_vector, const std::vector<int>& cell_number_vector,