From: Bruno Turcksin Date: Mon, 18 Dec 2017 00:12:18 +0000 (-0500) Subject: Add move constructor to TrilinosWrappers::SparsityPattern X-Git-Tag: v9.0.0-rc1~646^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39be46a39e50178c118d766a1a6a7493b37b7600;p=dealii.git Add move constructor to TrilinosWrappers::SparsityPattern --- diff --git a/include/deal.II/lac/trilinos_sparsity_pattern.h b/include/deal.II/lac/trilinos_sparsity_pattern.h index 7755784741..2ce1494d10 100644 --- a/include/deal.II/lac/trilinos_sparsity_pattern.h +++ b/include/deal.II/lac/trilinos_sparsity_pattern.h @@ -316,6 +316,12 @@ namespace TrilinosWrappers const size_type n, const std::vector &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. diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 98da5f3e1a..dbf1802db7 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -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 index 0000000000..f45898ec1f --- /dev/null +++ b/tests/trilinos/sparsity_pattern_04.cc @@ -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 +#include + +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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos/sparsity_pattern_04.output @@ -0,0 +1,2 @@ + +DEAL::OK