From 44843f95269b051c45abd4015fcc5147b15306b5 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Mon, 9 Jul 2018 17:36:43 +0200 Subject: [PATCH] Add node->cell and node->node in cell matrices Still quite experimental --- src/mesh/Connectivity1D.hpp | 11 ++++++++--- src/mesh/Connectivity2D.hpp | 7 ++++++- src/mesh/Connectivity3D.hpp | 14 +++++++++----- src/mesh/ConnectivityUtils.hpp | 32 +++++++++++++++++++++++++++++++- src/scheme/AcousticSolver.hpp | 30 ++++++++++++++++++------------ 5 files changed, 72 insertions(+), 22 deletions(-) diff --git a/src/mesh/Connectivity1D.hpp b/src/mesh/Connectivity1D.hpp index d0422f7b2..ccaa7c065 100644 --- a/src/mesh/Connectivity1D.hpp +++ b/src/mesh/Connectivity1D.hpp @@ -14,7 +14,8 @@ class Connectivity1D { public: static constexpr size_t dimension = 1; - + ConnectivityMatrix m_node_to_cell_matrix; + ConnectivityMatrix m_node_to_cell_local_node_matrix; private: std::vector<RefNodeList> m_ref_node_list; @@ -177,7 +178,9 @@ public: m_number_of_nodes, m_node_nb_cells, m_node_cells, - m_node_cell_local_node); + m_node_cell_local_node, + m_node_to_cell_matrix, + m_node_to_cell_local_node_matrix); } Connectivity1D(const Kokkos::View<const unsigned short*> cell_nb_nodes, @@ -199,7 +202,9 @@ public: m_number_of_nodes, m_node_nb_cells, m_node_cells, - m_node_cell_local_node); + m_node_cell_local_node, + m_node_to_cell_matrix, + m_node_to_cell_local_node_matrix); } ~Connectivity1D() diff --git a/src/mesh/Connectivity2D.hpp b/src/mesh/Connectivity2D.hpp index bf87b5b9a..abf6d09f0 100644 --- a/src/mesh/Connectivity2D.hpp +++ b/src/mesh/Connectivity2D.hpp @@ -19,6 +19,9 @@ class Connectivity2D public: static constexpr size_t dimension = 2; + ConnectivityMatrix m_node_to_cell_matrix; + ConnectivityMatrix m_node_to_cell_local_node_matrix; + private: std::vector<RefFaceList> m_ref_face_list; std::vector<RefNodeList> m_ref_node_list; @@ -338,7 +341,9 @@ class Connectivity2D m_number_of_nodes, m_node_nb_cells, m_node_cells, - m_node_cell_local_node); + m_node_cell_local_node, + m_node_to_cell_matrix, + m_node_to_cell_local_node_matrix); this->_computeFaceCellConnectivities(); } diff --git a/src/mesh/Connectivity3D.hpp b/src/mesh/Connectivity3D.hpp index 7f613a539..0ad8bd98d 100644 --- a/src/mesh/Connectivity3D.hpp +++ b/src/mesh/Connectivity3D.hpp @@ -2,7 +2,6 @@ #define CONNECTIVITY_3D_HPP #include <Kokkos_Core.hpp> -#include <Kokkos_StaticCrsGraph.hpp> #include <PastisAssert.hpp> #include <TinyVector.hpp> @@ -23,6 +22,10 @@ class Connectivity3D public: static constexpr size_t dimension = 3; + ConnectivityMatrix m_node_to_cell_matrix; + ConnectivityMatrix m_node_to_cell_local_node_matrix; + ConnectivityMatrix m_face_to_cell_matrix; + private: std::vector<RefFaceList> m_ref_face_list; std::vector<RefNodeList> m_ref_node_list; @@ -313,9 +316,8 @@ private: } } - typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> StaticCrsGraphType; - StaticCrsGraphType face_to_cell_matrix - = Kokkos::create_staticcrsgraph<StaticCrsGraphType>("face_to_cell_matrix", face_to_cell_vector); + m_face_to_cell_matrix + = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("face_to_cell_matrix", face_to_cell_vector); #warning check that the number of cell per faces is <=2 Kokkos::View<unsigned int**> face_cells("face_cells", face_cells_map.size(), 2); @@ -571,7 +573,9 @@ private: m_number_of_nodes, m_node_nb_cells, m_node_cells, - m_node_cell_local_node); + m_node_cell_local_node, + m_node_to_cell_matrix, + m_node_to_cell_local_node_matrix); this->_computeFaceCellConnectivities(); } diff --git a/src/mesh/ConnectivityUtils.hpp b/src/mesh/ConnectivityUtils.hpp index 3fe9e6f6a..20acc1885 100644 --- a/src/mesh/ConnectivityUtils.hpp +++ b/src/mesh/ConnectivityUtils.hpp @@ -3,6 +3,9 @@ #include <map> #include <Kokkos_Core.hpp> +#include <Kokkos_StaticCrsGraph.hpp> + +typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrix; class ConnectivityUtils { @@ -14,7 +17,9 @@ class ConnectivityUtils size_t& number_of_nodes, Kokkos::View<const unsigned short*>& node_nb_cells, Kokkos::View<const unsigned int**>& node_cells, - Kokkos::View<const unsigned short**>& node_cell_local_node) + Kokkos::View<const unsigned short**>& node_cell_local_node, + ConnectivityMatrix& node_to_cell_matrix, + ConnectivityMatrix& node_to_cell_local_node_matrix) { std::map<unsigned int, std::vector<unsigned int>> node_cells_map; using namespace Kokkos::Experimental; @@ -64,6 +69,14 @@ class ConnectivityUtils } node_cells = built_node_cells; + std::vector<std::vector<unsigned int>> node_to_cell_vector(node_cells_map.size()); + for (const auto& i_cell_vector : node_cells_map) { + const auto& [r, cells_vector] = i_cell_vector; + node_to_cell_vector[r] = cells_vector; + } + node_to_cell_matrix + = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("node_to_cell_matrix", node_to_cell_vector); + Kokkos::View<unsigned short**> built_node_cell_local_node("node_cell_local_node", node_cells_map.size(), max_node_cells); Kokkos::parallel_for(number_of_nodes, KOKKOS_LAMBDA(const unsigned int& r){ @@ -78,6 +91,23 @@ class ConnectivityUtils } }); node_cell_local_node = built_node_cell_local_node; + + std::vector<std::vector<unsigned int>> node_to_cell_local_node_vector(node_cells_map.size()); + for (unsigned int r=0; r<node_cells_map.size(); ++r) { + node_to_cell_local_node_vector[r].resize(node_nb_cells[r]); + for (unsigned short J=0; J<node_nb_cells[r]; ++J) { + const unsigned int j = node_cells(r,J); + for (unsigned int R=0; R<cell_nb_nodes[j]; ++R) { + if (cell_nodes(j,R) == r) { + node_to_cell_local_node_vector[r][J] = R; + break; + } + } + } + } + node_to_cell_local_node_matrix + = Kokkos::create_staticcrsgraph<ConnectivityMatrix>("node_to_cell_local_node_matrix", node_to_cell_local_node_vector); + } }; diff --git a/src/scheme/AcousticSolver.hpp b/src/scheme/AcousticSolver.hpp index 3e2d108d7..b12da32ed 100644 --- a/src/scheme/AcousticSolver.hpp +++ b/src/scheme/AcousticSolver.hpp @@ -99,15 +99,15 @@ private: KOKKOS_INLINE_FUNCTION const Kokkos::View<const Rdd*> computeAr(const Kokkos::View<const Rdd**>& Ajr) { - const Kokkos::View<const unsigned int**> node_cells = m_connectivity.nodeCells(); - const Kokkos::View<const unsigned short**> node_cell_local_node = m_connectivity.nodeCellLocalNode(); const Kokkos::View<const unsigned short*> node_nb_cells = m_connectivity.nodeNbCells(); Kokkos::parallel_for(m_mesh.numberOfNodes(), KOKKOS_LAMBDA(const int& r) { Rdd sum = zero; + const auto& node_to_cell = m_connectivity.m_node_to_cell_matrix.rowConst(r); + const auto& node_to_cell_local_node = m_connectivity.m_node_to_cell_local_node_matrix.rowConst(r); for (int j=0; j<node_nb_cells(r); ++j) { - const int J = node_cells(r,j); - const int R = node_cell_local_node(r,j); + const unsigned int J = node_to_cell(j); + const unsigned int R = node_to_cell_local_node(j); sum += Ajr(J,R); } m_Ar(r) = sum; @@ -122,16 +122,16 @@ private: const Kokkos::View<const Rd**>& Cjr, const Kokkos::View<const Rd*>& uj, const Kokkos::View<const double*>& pj) { - const Kokkos::View<const unsigned int**>& node_cells = m_connectivity.nodeCells(); - const Kokkos::View<const unsigned short**>& node_cell_local_node = m_connectivity.nodeCellLocalNode(); const Kokkos::View<const unsigned short*>& node_nb_cells = m_connectivity.nodeNbCells(); Kokkos::parallel_for(m_mesh.numberOfNodes(), KOKKOS_LAMBDA(const int& r) { Rd& br = m_br(r); br = zero; + const auto& node_to_cell = m_connectivity.m_node_to_cell_matrix.rowConst(r); + const auto& node_to_cell_local_node = m_connectivity.m_node_to_cell_local_node_matrix.rowConst(r); for (int j=0; j<node_nb_cells(r); ++j) { - const int J = node_cells(r,j); - const int R = node_cell_local_node(r,j); + const unsigned int J = node_to_cell(j); + const unsigned int R = node_to_cell_local_node(j); br += Ajr(J,R)*uj(J) + pj(J)*Cjr(J,R); } }); @@ -167,10 +167,16 @@ private: // quite ugly: node/faces are melt in a bad way... at least works in 1d... const int l = pressure_bc.faceList()[l_number]; Assert(m_connectivity.faceNbCells()[l] == 1); - const unsigned int j = face_cells(l,0); - const unsigned int L = face_cell_local_face(l,0); - - m_br(l) -= pressure_bc.value()*Cjr(j,L); +#warning remove this specialization + if constexpr(dimension ==3) { + const unsigned int j = m_connectivity.m_face_to_cell_matrix.entries(l); //face_cells(l,0); + const unsigned int L = face_cell_local_face(l,0); + m_br(l) -= pressure_bc.value()*Cjr(j,L); + } else { + const unsigned int j = face_cells(l,0); + const unsigned int L = face_cell_local_face(l,0); + m_br(l) -= pressure_bc.value()*Cjr(j,L); + } }); break; } -- GitLab