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

Remove some ItemIdT<T> usage

Get rid of dirty reinterpret_cast's
parent e86f9af0
No related branches found
No related tags found
1 merge request!7Feature/itemvalue
......@@ -98,7 +98,7 @@ void Connectivity<3>::_computeCellFaceAndFaceNodeConnectivities()
{
auto& cell_to_face_matrix
= m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::face)];
std::vector<std::vector<FaceId>> cell_to_face_vector(this->numberOfCells());
std::vector<std::vector<unsigned int>> cell_to_face_vector(this->numberOfCells());
for (CellId j=0; j<cell_to_face_vector.size(); ++j) {
cell_to_face_vector[j].resize(cell_nb_faces[j]);
}
......@@ -111,7 +111,7 @@ void Connectivity<3>::_computeCellFaceAndFaceNodeConnectivities()
}
++l;
}
cell_to_face_matrix = reinterpret_cast<std::vector<std::vector<unsigned int>>&>(cell_to_face_vector);
cell_to_face_matrix = cell_to_face_vector;
}
FaceValuePerCell<bool> cell_face_is_reversed(*this);
......@@ -131,15 +131,14 @@ void Connectivity<3>::_computeCellFaceAndFaceNodeConnectivities()
auto& face_to_node_matrix
= m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::node)];
std::vector<std::vector<NodeId>> face_to_node_vector(face_cells_map.size());
std::vector<std::vector<unsigned int>> face_to_node_vector(face_cells_map.size());
int l=0;
for (const auto& face_info : face_cells_map) {
const Face& face = face_info.first;
face_to_node_vector[l] = face.nodeIdList();
++l;
}
#warning remove all reinterpret_cast
face_to_node_matrix = reinterpret_cast<std::vector<std::vector<unsigned int>>&>(face_to_node_vector);
face_to_node_matrix = face_to_node_vector;
}
{
......@@ -185,7 +184,7 @@ void Connectivity<2>::_computeCellFaceAndFaceNodeConnectivities()
}
{
std::vector<std::vector<NodeId>> face_to_node_vector(face_cells_map.size());
std::vector<std::vector<unsigned int>> face_to_node_vector(face_cells_map.size());
int l=0;
for (const auto& face_info : face_cells_map) {
const Face& face = face_info.first;
......@@ -194,11 +193,11 @@ void Connectivity<2>::_computeCellFaceAndFaceNodeConnectivities()
}
auto& face_to_node_matrix
= m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::node)];
face_to_node_matrix = reinterpret_cast<std::vector<std::vector<unsigned int>>&>(face_to_node_vector);
face_to_node_matrix = face_to_node_vector;
}
{
std::vector<std::vector<CellId>> face_to_cell_vector(face_cells_map.size());
std::vector<std::vector<unsigned int>> face_to_cell_vector(face_cells_map.size());
int l=0;
for (const auto& face_cells_vector : face_cells_map) {
const auto& [face, cell_info_vector] = face_cells_vector;
......@@ -209,21 +208,21 @@ void Connectivity<2>::_computeCellFaceAndFaceNodeConnectivities()
}
auto& face_to_cell_matrix
= m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::cell)];
face_to_cell_matrix = reinterpret_cast<std::vector<std::vector<unsigned int>>&>(face_to_cell_vector);
face_to_cell_matrix = face_to_cell_vector;
}
}
template<size_t Dimension>
Connectivity<Dimension>::
Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector,
const std::vector<CellType>& cell_type_vector)
{
Assert(cell_by_node_vector.size() == cell_type_vector.size());
auto& cell_to_node_matrix
= m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)];
cell_to_node_matrix = reinterpret_cast<const std::vector<std::vector<unsigned int>>&>(cell_by_node_vector);
cell_to_node_matrix = cell_by_node_vector;
Assert(this->numberOfCells()>0);
......@@ -250,13 +249,13 @@ Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
template Connectivity1D::
Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector,
const std::vector<CellType>& cell_type_vector);
template Connectivity2D::
Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector,
const std::vector<CellType>& cell_type_vector);
template Connectivity3D::
Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector,
const std::vector<CellType>& cell_type_vector);
......@@ -53,14 +53,14 @@ class ConnectivityFace<2>
{
size_t operator()(const ConnectivityFace& f) const {
size_t hash = 0;
hash ^= std::hash<NodeId::base_type>()(f.m_node0_id);
hash ^= std::hash<NodeId::base_type>()(f.m_node1_id) >> 1;
hash ^= std::hash<unsigned int>()(f.m_node0_id);
hash ^= std::hash<unsigned int>()(f.m_node1_id) >> 1;
return hash;
}
};
NodeId m_node0_id;
NodeId m_node1_id;
unsigned int m_node0_id;
unsigned int m_node1_id;
friend std::ostream& operator<<(std::ostream& os, const ConnectivityFace& f)
{
......@@ -90,7 +90,7 @@ class ConnectivityFace<2>
ConnectivityFace& operator=(ConnectivityFace&&) = default;
KOKKOS_INLINE_FUNCTION
ConnectivityFace(const std::vector<NodeId>& given_node_id_list)
ConnectivityFace(const std::vector<unsigned int>& given_node_id_list)
{
Assert(given_node_id_list.size()==2);
#warning rework this dirty constructor
......@@ -120,14 +120,14 @@ class ConnectivityFace<3>
size_t operator()(const ConnectivityFace& f) const {
size_t hash = 0;
for (size_t i=0; i<f.m_node_id_list.size(); ++i) {
hash ^= std::hash<NodeId::base_type>()(f.m_node_id_list[i]) >> i;
hash ^= std::hash<unsigned int>()(f.m_node_id_list[i]) >> i;
}
return hash;
}
};
bool m_reversed;
std::vector<NodeId> m_node_id_list;
std::vector<NodeId::base_type> m_node_id_list;
friend std::ostream& operator<<(std::ostream& os, const ConnectivityFace& f)
{
......@@ -144,18 +144,18 @@ class ConnectivityFace<3>
}
KOKKOS_INLINE_FUNCTION
const std::vector<NodeId>& nodeIdList() const
const std::vector<unsigned int>& nodeIdList() const
{
return m_node_id_list;
}
KOKKOS_INLINE_FUNCTION
std::vector<NodeId> _sort(const std::vector<NodeId>& node_list)
std::vector<unsigned int> _sort(const std::vector<unsigned int>& node_list)
{
const auto min_id = std::min_element(node_list.begin(), node_list.end());
const int shift = std::distance(node_list.begin(), min_id);
std::vector<NodeId> rotated_node_list(node_list.size());
std::vector<unsigned int> rotated_node_list(node_list.size());
if (node_list[(shift+1)%node_list.size()] > node_list[(shift+node_list.size()-1)%node_list.size()]) {
for (size_t i=0; i<node_list.size(); ++i) {
rotated_node_list[i] = node_list[(shift+node_list.size()-i)%node_list.size()];
......@@ -171,7 +171,7 @@ class ConnectivityFace<3>
}
KOKKOS_INLINE_FUNCTION
ConnectivityFace(const std::vector<NodeId>& given_node_id_list)
ConnectivityFace(const std::vector<unsigned int>& given_node_id_list)
: m_reversed(false),
m_node_id_list(_sort(given_node_id_list))
{
......@@ -477,7 +477,7 @@ class Connectivity final
return m_inv_cell_nb_nodes;
}
FaceId getFaceNumber(const std::vector<NodeId>& face_nodes) const
unsigned int getFaceNumber(const std::vector<unsigned int>& face_nodes) const
{
const Face face(face_nodes);
auto i_face = m_face_number_map.find(face);
......@@ -491,7 +491,7 @@ class Connectivity final
Connectivity(const Connectivity&) = delete;
Connectivity(const std::vector<std::vector<CellId>>& cell_by_node_vector,
Connectivity(const std::vector<std::vector<unsigned int>>& cell_by_node_vector,
const std::vector<CellType>& cell_type_vector);
~Connectivity()
......
......@@ -791,7 +791,7 @@ GmshReader::__proceedData()
std::vector<CellType> cell_type_vector(nb_cells);
std::vector<std::vector<CellId>> cell_by_node_vector(nb_cells);
std::vector<std::vector<unsigned int>> cell_by_node_vector(nb_cells);
const size_t nb_tetrahedra = __tetrahedra.size();
for (size_t j=0; j<nb_tetrahedra; ++j) {
cell_by_node_vector[j].resize(4);
......@@ -853,7 +853,7 @@ GmshReader::__proceedData()
std::vector<CellType> cell_type_vector(nb_cells);
std::vector<std::vector<CellId>> cell_by_node_vector(nb_cells);
std::vector<std::vector<unsigned int>> cell_by_node_vector(nb_cells);
const size_t nb_triangles = __triangles.size();
for (size_t j=0; j<nb_triangles; ++j) {
cell_by_node_vector[j].resize(3);
......@@ -924,7 +924,7 @@ GmshReader::__proceedData()
std::vector<CellType> cell_type_vector(nb_cells);
std::vector<std::vector<CellId>> cell_by_node_vector(nb_cells);
std::vector<std::vector<unsigned int>> cell_by_node_vector(nb_cells);
for (size_t j=0; j<nb_cells; ++j) {
cell_by_node_vector[j].resize(2);
for (int r=0; r<2; ++r) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment