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

Remove ConnectivityUtils

since all connectivities are managed by the same template class, this common
code is displaced in the Connectivity class
parent ff1d6743
No related branches found
No related tags found
1 merge request!6Feature/crs
......@@ -5,7 +5,12 @@
#include <PastisAssert.hpp>
#include <TinyVector.hpp>
#include <ConnectivityUtils.hpp>
#include <Kokkos_StaticCrsGraph.hpp>
typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrix;
#warning use right type (unsigned short)
typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrixShort;
#include <vector>
#include <map>
#include <unordered_map>
......@@ -17,6 +22,7 @@
#include <RefFaceList.hpp>
#include <tuple>
#include <algorithm>
template <size_t Dimension>
class Connectivity;
......@@ -24,7 +30,6 @@ class Connectivity;
template <size_t Dimension>
class ConnectivityFace;
template<>
class ConnectivityFace<1>
{
......@@ -54,7 +59,6 @@ class ConnectivityFace<2>
unsigned int m_node0_id;
unsigned int m_node1_id;
friend std::ostream& operator<<(std::ostream& os, const ConnectivityFace& f)
{
os << f.m_node0_id << ' ' << f.m_node1_id << ' ';
......@@ -87,8 +91,9 @@ class ConnectivityFace<2>
{
Assert(given_node_id_list.size()==2);
#warning rework this dirty constructor
m_node0_id = std::min(given_node_id_list[0], given_node_id_list[1]);
m_node1_id = std::max(given_node_id_list[0], given_node_id_list[1]);
const auto& [min, max] = std::minmax(given_node_id_list[0], given_node_id_list[1]);
m_node0_id = min;
m_node1_id = max;
}
KOKKOS_INLINE_FUNCTION
......@@ -269,6 +274,9 @@ private:
std::unordered_map<Face, unsigned int, typename Face::Hash> m_face_number_map;
void _computeFaceCellConnectivities();
void _computeNodeCellConnectivity(const ConnectivityMatrix& cell_to_node_matrix,
ConnectivityMatrix& node_to_cell_matrix,
ConnectivityMatrixShort& node_to_cell_local_node_matrix);
public:
void addRefFaceList(const RefFaceList& ref_face_list)
......@@ -371,8 +379,7 @@ private:
node_id_per_cell_vector);
}
ConnectivityUtils utils;
utils.computeNodeCellConnectivity(m_cell_to_node_matrix,
this->_computeNodeCellConnectivity(m_cell_to_node_matrix,
m_node_to_cell_matrix,
m_node_to_cell_local_node_matrix);
......@@ -387,6 +394,63 @@ private:
}
};
template<size_t Dimension>
inline void Connectivity<Dimension>::
_computeNodeCellConnectivity(const ConnectivityMatrix& cell_to_node_matrix,
ConnectivityMatrix& node_to_cell_matrix,
ConnectivityMatrixShort& node_to_cell_local_node_matrix)
{
{
std::map<unsigned int, std::vector<unsigned int>> node_cells_map;
const size_t& number_of_cells = cell_to_node_matrix.numRows();
for (unsigned int j=0; j<number_of_cells; ++j) {
const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
for (unsigned int r=0; r<cell_nodes.length; ++r) {
node_cells_map[cell_nodes(r)].push_back(j);
}
}
{
size_t i=0;
for (const auto& [node_id, cell_vector] : node_cells_map) {
if (node_id != i) {
std::cerr << "sparse node numerotation NIY\n";
std::exit(0);
}
++i;
}
}
std::vector<std::vector<unsigned int>> node_to_cell_vector(node_cells_map.size());
for (const auto& [r, cells_vector] : node_cells_map) {
node_to_cell_vector[r] = cells_vector;
}
node_to_cell_matrix
= Kokkos::create_staticcrsgraph<ConnectivityMatrix>("node_to_cell_matrix", node_to_cell_vector);
}
{
std::vector<std::vector<unsigned int>> node_to_cell_local_node_vector(node_to_cell_matrix.numRows());
for (unsigned int r=0; r<node_to_cell_matrix.numRows(); ++r) {
const auto& node_to_cell = node_to_cell_matrix.rowConst(r);
node_to_cell_local_node_vector[r].resize(node_to_cell.length);
for (unsigned short J=0; J<node_to_cell.length; ++J) {
const unsigned int j = node_to_cell(J);
const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
for (unsigned int R=0; R<cell_nodes.length; ++R) {
if (cell_nodes(R) == r) {
node_to_cell_local_node_vector[r][J] = R;
break;
}
}
}
}
node_to_cell_local_node_matrix
= Kokkos::create_staticcrsgraph<ConnectivityMatrixShort>("node_to_cell_local_node_matrix", node_to_cell_local_node_vector);
}
}
using Connectivity3D = Connectivity<3>;
template <>
......
#ifndef CONNECTIVITY_UTILS_HPP
#define CONNECTIVITY_UTILS_HPP
#include <map>
#include <Kokkos_Core.hpp>
#include <Kokkos_StaticCrsGraph.hpp>
typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrix;
#warning use right type (unsigned short)
typedef Kokkos::StaticCrsGraph<unsigned int, Kokkos::HostSpace> ConnectivityMatrixShort;
class ConnectivityUtils
{
public:
void computeNodeCellConnectivity(const ConnectivityMatrix& cell_to_node_matrix,
ConnectivityMatrix& node_to_cell_matrix,
ConnectivityMatrixShort& node_to_cell_local_node_matrix)
{
std::map<unsigned int, std::vector<unsigned int>> node_cells_map;
const size_t& number_of_cells = cell_to_node_matrix.numRows();
for (unsigned int j=0; j<number_of_cells; ++j) {
const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
for (unsigned int r=0; r<cell_nodes.length; ++r) {
node_cells_map[cell_nodes(r)].push_back(j);
}
}
{
size_t i=0;
for (const auto& i_cell_vector : node_cells_map) {
const auto& [node_id, cell_vector] = i_cell_vector;
if (node_id != i) {
std::cerr << "sparse node numerotation NIY\n";
std::exit(0);
}
++i;
}
}
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);
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) {
const auto& node_to_cell = node_to_cell_matrix.rowConst(r);
node_to_cell_local_node_vector[r].resize(node_to_cell.length);
for (unsigned short J=0; J<node_to_cell.length; ++J) {
const unsigned int j = node_to_cell(J);
const auto& cell_nodes = cell_to_node_matrix.rowConst(j);
for (unsigned int R=0; R<cell_nodes.length; ++R) {
if (cell_nodes(R) == r) {
node_to_cell_local_node_vector[r][J] = R;
break;
}
}
}
}
node_to_cell_local_node_matrix
= Kokkos::create_staticcrsgraph<ConnectivityMatrixShort>("node_to_cell_local_node_matrix", node_to_cell_local_node_vector);
}
};
#endif // CONNECTIVITY_UTILS_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment