<h3>Specific improvements</h3>
<ol>
+<li> New: There is now a version of SparseMatrix::copy_from that can copy
+from TrilinosWrappers::SparseMatrix.
+<br>
+(Wolfgang Bangerth, Jörg Frohne, 2013/04/15)
+</li>
+
<li> Improved: The SolverCG implementation now uses only three auxiliary
vectors, down from previously four. Also, there are some shortcuts in case
PreconditionIdentity is used that improve the solver's performance.
template <typename Matrix> class BlockMatrixBase;
template <typename number> class SparseILU;
+
+#ifdef DEAL_II_WITH_TRILINOS
+namespace TrilinosWrappers
+{
+ class SparseMatrix;
+}
+#endif
+
/**
* @addtogroup Matrix1
* @{
void symmetrize ();
/**
- * Copy the given matrix to this one. The operation throws an error if the
+ * Copy the given matrix to this one. The operation triggers an assertion if the
* sparsity patterns of the two involved matrices do not point to the same
* object, since in this case the copy operation is cheaper. Since this
* operation is notheless not for free, we do not make it available through
template <typename somenumber>
void copy_from (const FullMatrix<somenumber> &matrix);
+#ifdef DEAL_II_WITH_TRILINOS
+ /**
+ * Copy the given Trilinos matrix to this one. The operation triggers an
+ * assertion if the sparsity patterns of the current object does not contain
+ * the location of a non-zero entry of the given argument.
+ *
+ * This function assumes that the two matrices have the same sizes.
+ *
+ * The function returns a reference to <tt>*this</tt>.
+ */
+ SparseMatrix<number> &
+ copy_from (const TrilinosWrappers::SparseMatrix &matrix);
+#endif
+
/**
* Add <tt>matrix</tt> scaled by <tt>factor</tt> to this matrix, i.e. the
* matrix <tt>factor*matrix</tt> is added to <tt>this</tt>. This function
//---------------------------------------------------------------------------
// $Id$
//
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by the deal.II authors
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
#include <deal.II/base/multithread_info.h>
#include <deal.II/base/utilities.h>
#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/trilinos_sparse_matrix.h>
#include <deal.II/lac/vector.h>
#include <deal.II/lac/full_matrix.h>
#include <deal.II/lac/compressed_simple_sparsity_pattern.h>
+#ifdef DEAL_II_WITH_TRILINOS
+
+template <typename number>
+SparseMatrix<number> &
+SparseMatrix<number>::copy_from (const TrilinosWrappers::SparseMatrix &matrix)
+{
+ Assert (m() == matrix.m(), ExcDimensionMismatch(m(), matrix.m()));
+ Assert (n() == matrix.n(), ExcDimensionMismatch(n(), matrix.n()));
+
+ // first delete previous content
+ *this = 0;
+
+ std::vector < TrilinosScalar > value_cache;
+ std::vector<unsigned int> colnum_cache;
+
+ for (unsigned int row = 0; row < matrix.m(); ++row)
+ {
+ value_cache.resize(matrix.n());
+ colnum_cache.resize(matrix.n());
+
+ // copy column indices and values and at the same time enquire about the
+ // length of the row
+ int ncols;
+ int ierr
+ = matrix.trilinos_matrix().ExtractGlobalRowCopy
+ (row, matrix.row_length(row), ncols,
+ &(value_cache[0]),
+ reinterpret_cast<int*>(&(colnum_cache[0])));
+ Assert (ierr==0, ExcTrilinosError(ierr));
+
+ // resize arrays to the size actually used
+ value_cache.resize(ncols);
+ colnum_cache.resize(ncols);
+
+ // then copy everything
+ for (int i = 0; i < ncols; ++i)
+ this->set(row, colnum_cache[i],
+ value_cache[i]);
+ }
+
+ return *this;
+}
+
+#endif
+
+
template <typename number>
template <typename somenumber>
void
--- /dev/null
+//----------------- sparse_matrix_copy_from_01.cc -------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2011, 2013 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//----------------- sparse_matrix_copy_from_01.cc -------------------------
+
+
+// test SparseMatrix::copy_from from a TrilinosWrappers::SparseMatrix
+
+#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 <deal.II/lac/sparse_matrix.h>
+#include <fstream>
+#include <iostream>
+
+
+int main (int argc,char **argv)
+{
+ Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv);
+
+ std::ofstream logfile("sparse_matrix_copy_from_01/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ SparsityPattern sparsity (5,5,5);
+ sparsity.add (1,2);
+ sparsity.add (2,3);
+ sparsity.add (3,4);
+ sparsity.add (4,3);
+ sparsity.compress();
+ SparseMatrix<double> matrix(sparsity);
+ {
+ double value = 1;
+ for (SparseMatrix<double>::iterator p=matrix.begin();
+ p != matrix.end(); ++p, ++value)
+ p->value() = value;
+ }
+ deallog << "Original:" << std::endl;
+ matrix.print_formatted (deallog.get_file_stream());
+
+ // now copy everything into a Trilinos matrix
+ Epetra_Map map(5,5,0,Utilities::Trilinos::comm_world());
+ TrilinosWrappers::SparseMatrix tmatrix;
+ tmatrix.reinit (map, map, matrix);
+
+ // now copy things back into a SparseMatrix
+ SparseMatrix<double> copy (sparsity);
+ copy.copy_from (tmatrix);
+
+ // print some output
+ deallog << "Copy with all values:" << std::endl;
+ matrix.print (deallog.get_file_stream());
+
+ // also compare for equality with the original
+ for (SparsityPattern::const_iterator
+ p = sparsity.begin(); p != sparsity.end(); ++p)
+ Assert (copy(p->row(), p->column()) == matrix(p->row(), p->column()),
+ ExcInternalError());
+}
--- /dev/null
+
+DEAL::Original:
+1.000e+00
+ 2.000e+00 3.000e+00
+ 4.000e+00 5.000e+00
+ 6.000e+00 7.000e+00
+ 9.000e+00 8.000e+00
+DEAL::Copy with all values:
+(0,0) 1.00000
+(1,1) 2.00000
+(1,2) 3.00000
+(2,2) 4.00000
+(2,3) 5.00000
+(3,3) 6.00000
+(3,4) 7.00000
+(4,4) 8.00000
+(4,3) 9.00000