]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add move constructor to TrilinosWrappers::SparsityPattern
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 18 Dec 2017 00:12:18 +0000 (19:12 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 18 Dec 2017 01:22:34 +0000 (20:22 -0500)
include/deal.II/lac/trilinos_sparsity_pattern.h
source/lac/trilinos_sparsity_pattern.cc
tests/trilinos/sparsity_pattern_04.cc [new file with mode: 0644]
tests/trilinos/sparsity_pattern_04.output [new file with mode: 0644]

index 77557847415ca7091ce23dbac109a393226675eb..2ce1494d1059f69259c0f17086c5849cc2bfdfb9 100644 (file)
@@ -316,6 +316,12 @@ namespace TrilinosWrappers
                      const size_type               n,
                      const std::vector<size_type> &n_entries_per_row);
 
+    /**
+     * Move constructor. Create a new sparse matrix by stealing the internal
+     * data.
+     */
+    SparsityPattern (SparsityPattern &&other);
+
     /**
      * Copy constructor. Sets the calling sparsity pattern to be the same as
      * the input sparsity pattern.
index 98da5f3e1a46cf1faa4c4714001f87495f70d2ed..dbf1802db75b6d3ca318e92eaf15bf3ccd92f187 100644 (file)
@@ -145,6 +145,16 @@ namespace TrilinosWrappers
   }
 
 
+
+  SparsityPattern::SparsityPattern (SparsityPattern &&other)
+    :
+    Subscriptor(std::move(other)),
+    column_space_map(std::move(other.column_space_map)),
+    graph(std::move(other.graph)),
+    nonlocal_graph(std::move(other.nonlocal_graph))
+  {}
+
+
   // Copy function only works if the
   // sparsity pattern is empty.
   SparsityPattern::SparsityPattern (const SparsityPattern &input_sparsity)
diff --git a/tests/trilinos/sparsity_pattern_04.cc b/tests/trilinos/sparsity_pattern_04.cc
new file mode 100644 (file)
index 0000000..f45898e
--- /dev/null
@@ -0,0 +1,51 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <deal.II/lac/trilinos_sparsity_pattern.h>
+#include <deal.II/base/utilities.h>
+
+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 A(partitioning);
+  A.add(2,1);
+  A.compress();
+
+  TrilinosWrappers::SparsityPattern 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.exist(i,j) == true, ExcInternalError());
+          }
+        else
+          {
+            AssertThrow(B.exist(i,j) == false, ExcInternalError());
+          }
+      }
+
+  deallog << "OK" << std::endl;
+}
diff --git a/tests/trilinos/sparsity_pattern_04.output b/tests/trilinos/sparsity_pattern_04.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.