Skip to content
Snippets Groups Projects
Commit 44843f95 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add node->cell and node->node in cell matrices

Still quite experimental
parent 03a5843c
No related branches found
No related tags found
1 merge request!6Feature/crs
......@@ -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()
......
......@@ -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();
}
......
......@@ -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();
}
......
......@@ -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);
}
};
......
......@@ -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);
#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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment