]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid a few reinterpret_casts 7496/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 7 Dec 2018 01:25:43 +0000 (02:25 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 7 Dec 2018 10:39:44 +0000 (11:39 +0100)
include/deal.II/lac/trilinos_vector.h
source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_sparsity_pattern.cc

index 140f4b7318297cd0f970b0411d7c1554247f4f8f..45f6c796d20e7581ea00fd554eb0ed6a1d681e10 100644 (file)
@@ -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<TrilinosWrappers::types::int_type>(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<const TrilinosWrappers::types::int_type *>(
-                  &row),
-                &values[i]);
+              const int ierr = vector->ReplaceGlobalValues(1, &row, &values[i]);
               AssertThrow(ierr == 0, ExcTrilinosError(ierr));
               compressed = false;
             }
index 3b5683449a93867b2de1ed3c0c3d1e05a29a7e1c..a523b2423c72d1a5771fbf25223d776b1e6c6b16 100644 (file)
@@ -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<TrilinosScalar, 200> local_value_array(
@@ -1619,26 +1620,22 @@ namespace TrilinosWrappers
 
         if (matrix->Filled() == false)
           {
-            ierr = matrix->InsertGlobalValues(
-              1,
-              reinterpret_cast<TrilinosWrappers::types::int_type *>(
-                const_cast<size_type *>(&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<TrilinosWrappers::types::int_type *>(
-              const_cast<size_type *>(&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<TrilinosScalar, 100> local_value_array(
@@ -1823,14 +1821,12 @@ namespace TrilinosWrappers
         // a time).
         compressed = false;
 
-        ierr = matrix->SumIntoGlobalValues(
-          1,
-          reinterpret_cast<TrilinosWrappers::types::int_type *>(
-            const_cast<size_type *>(&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));
       }
 
index 8da0186abf68def65a68ee25a3d9fff61c3a655d..c0eba0764ac5eba3c2944601a27d7ebf66e7fc12 100644 (file)
@@ -453,11 +453,11 @@ namespace TrilinosWrappers
                     ++p;
                 }
             }
-            graph->InsertGlobalIndices(
-              1,
-              reinterpret_cast<TrilinosWrappers::types::int_type *>(&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<const Epetra_Map &>(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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.