]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add move constructor for TrilinosWrappers::SparseMatrix
authorBruno Turcksin <bruno.turcksin@gmail.com>
Sun, 17 Dec 2017 22:27:42 +0000 (17:27 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 18 Dec 2017 01:22:34 +0000 (20:22 -0500)
include/deal.II/lac/trilinos_sparse_matrix.h
source/lac/trilinos_sparse_matrix.cc
tests/trilinos/sparse_matrix_08.cc [new file with mode: 0644]
tests/trilinos/sparse_matrix_08.output [new file with mode: 0644]

index c3e3676526bf25f9a284ff19877032b6cd424cb4..0eac855c31c715ec7ab5ca41e52c3ff583433028 100644 (file)
@@ -567,6 +567,22 @@ namespace TrilinosWrappers
      */
     SparseMatrix (const SparsityPattern &InputSparsityPattern);
 
+    /**
+     * Move constructor. Create a new sparse matrix by stealing the internal
+     * data.
+     */
+    SparseMatrix (SparseMatrix  &&other);
+
+    /**
+     * Copy constructor is deleted.
+     */
+    SparseMatrix (const SparseMatrix &) = delete;
+
+    /**
+     * operator= is deleted.
+     */
+    SparseMatrix &operator = (const SparseMatrix &) = delete;
+
     /**
      * Destructor. Made virtual so that one can use pointers to this class.
      */
@@ -1990,15 +2006,6 @@ namespace TrilinosWrappers
 
 
   private:
-    /**
-     * Copy constructor is disabled.
-     */
-    SparseMatrix (const SparseMatrix &);
-    /**
-     * operator= is disabled.
-     */
-    SparseMatrix &operator = (const SparseMatrix &);
-
     /**
      * Pointer to the user-supplied Epetra Trilinos mapping of the matrix
      * columns that assigns parts of the matrix to the individual processes.
index 2daa3598b2ac31e94aded9469d7d44588251d741..8e502c99668ae117720f71f6cfa26db4cfad74d2 100644 (file)
@@ -356,6 +356,21 @@ namespace TrilinosWrappers
 
 
 
+  SparseMatrix::SparseMatrix (SparseMatrix &&other)
+    :
+    column_space_map(std::move(other.column_space_map)),
+    matrix(std::move(other.matrix)),
+    nonlocal_matrix(std::move(other.nonlocal_matrix)),
+    nonlocal_matrix_exporter(std::move(other.nonlocal_matrix_exporter)),
+    last_action(other.last_action),
+    compressed(other.compressed)
+  {
+    other.last_action = Zero;
+    other.compressed = false;
+  }
+
+
+
   void
   SparseMatrix::copy_from (const SparseMatrix &rhs)
   {
diff --git a/tests/trilinos/sparse_matrix_08.cc b/tests/trilinos/sparse_matrix_08.cc
new file mode 100644 (file)
index 0000000..ab1ee3b
--- /dev/null
@@ -0,0 +1,60 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// Test move constructor
+
+#include "../tests.h"
+#include <deal.II/base/utilities.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
+#include <deal.II/lac/trilinos_sparsity_pattern.h>
+#include <iostream>
+
+int main (int argc,char **argv)
+{
+  initlog();
+
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  IndexSet partitioning (3);
+
+  partitioning.add_range(0, 3);
+
+  // Add element (2,1) to the matrix
+  TrilinosWrappers::SparsityPattern sp (partitioning);
+  sp.add (2,1);
+  sp.compress();
+
+  TrilinosWrappers::SparseMatrix A (sp);
+  A.add (2, 1, 2.0);
+  A.compress(VectorOperation::add);
+
+  TrilinosWrappers::SparseMatrix B(std::move(A));
+
+  for (unsigned int i=0; i<3; ++i)
+    for (unsigned int j=0; j<3; ++j)
+      {
+        if ((i == 2) && (j == 1))
+          {
+            AssertThrow(B.el(i,j) == 2, ExcInternalError());
+          }
+        else
+          {
+            AssertThrow(B.el(i,j) == 0, ExcInternalError());
+          }
+      }
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/trilinos/sparse_matrix_08.output b/tests/trilinos/sparse_matrix_08.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.