From d55af07c33d728bd7dff3dc2550fd5e2bc6d5ff1 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 7 Dec 2018 02:25:43 +0100 Subject: [PATCH] Avoid a few reinterpret_casts --- include/deal.II/lac/trilinos_vector.h | 12 +++---- source/lac/trilinos_sparse_matrix.cc | 44 +++++++++++-------------- source/lac/trilinos_sparsity_pattern.cc | 17 ++++------ 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index 140f4b7318..45f6c796d2 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -1604,18 +1604,14 @@ namespace TrilinosWrappers for (size_type i = 0; i < n_elements; ++i) { - const size_type row = indices[i]; - const TrilinosWrappers::types::int_type local_row = vector->Map().LID( - static_cast(row)); + const TrilinosWrappers::types::int_type row = indices[i]; + const TrilinosWrappers::types::int_type local_row = + vector->Map().LID(row); if (local_row != -1) (*vector)[0][local_row] = values[i]; else { - const int ierr = vector->ReplaceGlobalValues( - 1, - reinterpret_cast( - &row), - &values[i]); + const int ierr = vector->ReplaceGlobalValues(1, &row, &values[i]); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); compressed = false; } diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index 3b5683449a..a523b2423c 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -1535,6 +1535,7 @@ namespace TrilinosWrappers TrilinosWrappers::types::int_type *col_index_ptr; TrilinosScalar * col_value_ptr; + TrilinosWrappers::types::int_type trilinos_row = row; TrilinosWrappers::types::int_type n_columns; boost::container::small_vector local_value_array( @@ -1619,26 +1620,22 @@ namespace TrilinosWrappers if (matrix->Filled() == false) { - ierr = matrix->InsertGlobalValues( - 1, - reinterpret_cast( - const_cast(&row)), - n_columns, - col_index_ptr, - &col_value_ptr, - Epetra_FECrsMatrix::ROW_MAJOR); + ierr = matrix->InsertGlobalValues(1, + &trilinos_row, + n_columns, + col_index_ptr, + &col_value_ptr, + Epetra_FECrsMatrix::ROW_MAJOR); if (ierr > 0) ierr = 0; } else - ierr = matrix->ReplaceGlobalValues( - 1, - reinterpret_cast( - const_cast(&row)), - n_columns, - col_index_ptr, - &col_value_ptr, - Epetra_FECrsMatrix::ROW_MAJOR); + ierr = matrix->ReplaceGlobalValues(1, + &trilinos_row, + n_columns, + col_index_ptr, + &col_value_ptr, + Epetra_FECrsMatrix::ROW_MAJOR); // use the FECrsMatrix facilities for set even in the case when we // have explicitly set the off-processor rows because that only works // properly when adding elements, not when setting them (since we want @@ -1734,6 +1731,7 @@ namespace TrilinosWrappers TrilinosWrappers::types::int_type *col_index_ptr; TrilinosScalar * col_value_ptr; + TrilinosWrappers::types::int_type trilinos_row = row; TrilinosWrappers::types::int_type n_columns; boost::container::small_vector local_value_array( @@ -1823,14 +1821,12 @@ namespace TrilinosWrappers // a time). compressed = false; - ierr = matrix->SumIntoGlobalValues( - 1, - reinterpret_cast( - const_cast(&row)), - n_columns, - col_index_ptr, - &col_value_ptr, - Epetra_FECrsMatrix::ROW_MAJOR); + ierr = matrix->SumIntoGlobalValues(1, + &trilinos_row, + n_columns, + col_index_ptr, + &col_value_ptr, + Epetra_FECrsMatrix::ROW_MAJOR); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); } diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 8da0186abf..c0eba0764a 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -453,11 +453,11 @@ namespace TrilinosWrappers ++p; } } - graph->InsertGlobalIndices( - 1, - reinterpret_cast(&row), - row_length, - row_indices.data()); + const TrilinosWrappers::types::int_type trilinos_row = row; + graph->InsertGlobalIndices(1, + &trilinos_row, + row_length, + row_indices.data()); } // TODO A dynamic_cast fails here, this is suspicious. @@ -802,15 +802,12 @@ namespace TrilinosWrappers nonlocal_graph->IndicesAreGlobal() == true, ExcInternalError()); - // TODO A dynamic_cast fails here, this is suspicious. - const auto &range_map = - static_cast(graph->RangeMap()); - nonlocal_graph->FillComplete(*column_space_map, range_map); + nonlocal_graph->FillComplete(*column_space_map, graph->RangeMap()); nonlocal_graph->OptimizeStorage(); Epetra_Export exporter(nonlocal_graph->RowMap(), graph->RowMap()); ierr = graph->Export(*nonlocal_graph, exporter, Add); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); - ierr = graph->FillComplete(*column_space_map, range_map); + ierr = graph->FillComplete(*column_space_map, graph->RangeMap()); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); } else -- 2.39.5