diff --git a/src/mesh/Connectivity1D.hpp b/src/mesh/Connectivity1D.hpp index d0422f7b25a7b1df91e444f9bea0b9e8ab04a602..ccaa7c065ab7baf4df52124cd737e9db8c6f8d1a 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 bf87b5b9ab2f69306ec4dbc68958927f7df6df6f..abf6d09f0107a787a9bd1feeb5f82e2001e0f8c3 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 7f613a539b8333240f05379e12432af3d1f8398d..0ad8bd98defe6a3ec122e202a512d21241ec5a3b 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 3fe9e6f6a11032e752ce5bdcd9d76e7a9c46e1b0..20acc1885d6e9d3b33515faa8b8577ea88e4bf5f 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 3e2d108d7eef1386aa4ec1c2679ecd26c80ec243..b12da32edc122e28b318bc414dc7d1386f80b8f6 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; }