From 958aac082dfb53ff48645fac6c6ef76e2116ba22 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 9 May 2011 22:45:32 +0000 Subject: [PATCH] Fix a problem where we look up elements in a matrix using the row map instead of the proper column map. This manifests only if the matrix is rectangular. git-svn-id: https://svn.dealii.org/trunk@23684 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 6 ++ deal.II/source/lac/trilinos_sparse_matrix.cc | 4 +- tests/trilinos/sparse_matrix_01.cc | 62 ++++++++++++++++++++ tests/trilinos/sparse_matrix_01/cmp/generic | 2 + 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/trilinos/sparse_matrix_01.cc create mode 100644 tests/trilinos/sparse_matrix_01/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 315aa47ef0..5e7fa9daac 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -100,6 +100,12 @@ should be fixed now.

Specific improvements

    +
  1. Fixed: The TrilinosWrappers::SparseMatrix::operator() and +TrilinosWrappers::SparseMatrix::el() functions sometimes produced +wrong results for rectangular matrices. This is now fixed. +
    +(Habib Talavatifard, Wolfgang Bangerth 2011/05/09) +
  2. Changed: DoFTools is now a namespace. It has long been a class that had only public, static member functions, making the end result semantically exactly equivalent to a namespace, which is also how it was used. This is diff --git a/deal.II/source/lac/trilinos_sparse_matrix.cc b/deal.II/source/lac/trilinos_sparse_matrix.cc index c4457d22a2..7449c8accf 100644 --- a/deal.II/source/lac/trilinos_sparse_matrix.cc +++ b/deal.II/source/lac/trilinos_sparse_matrix.cc @@ -770,7 +770,7 @@ namespace TrilinosWrappers { // Extract local indices in // the matrix. - int trilinos_i = matrix->LRID(i), trilinos_j = matrix->LRID(j); + int trilinos_i = matrix->LRID(i), trilinos_j = matrix->LCID(j); TrilinosScalar value = 0.; // If the data is not on the @@ -844,7 +844,7 @@ namespace TrilinosWrappers { // Extract local indices in // the matrix. - int trilinos_i = matrix->LRID(i), trilinos_j = matrix->LRID(j); + int trilinos_i = matrix->LRID(i), trilinos_j = matrix->LCID(j); TrilinosScalar value = 0.; // If the data is not on the diff --git a/tests/trilinos/sparse_matrix_01.cc b/tests/trilinos/sparse_matrix_01.cc new file mode 100644 index 0000000000..971ba5f454 --- /dev/null +++ b/tests/trilinos/sparse_matrix_01.cc @@ -0,0 +1,62 @@ +//----------------- trilinos_sparse_matrix_01.cc ------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2011 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. +// +//----------------- trilinos_sparse_matrix_01.cc ------------------------- + + +// TrilinosWrappers::SparseMatrix::el() and operator() had problems +// looking up indices in rectangular matrices because they +// accidentally used the row instead of the column map. verify that +// this is now fixed +// +// this testcase is reduced from one contributed by Habib Talavatifard + +#include "../tests.h" +#include +#include +#include +#include +#include + + +int main (int argc,char **argv) +{ + std::ofstream logfile("sparse_matrix_01/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + Utilities::System::MPI_InitFinalize mpi_initialization (argc, argv); + + IndexSet row_partitioning (3); + IndexSet col_partitioning (4); + + row_partitioning.add_range(0, 3); + col_partitioning.add_range(0, 4); + + // Add element (2,3) to the matrix + TrilinosWrappers::SparsityPattern sp (row_partitioning, col_partitioning); + sp.add (2,3); + sp.compress(); + + TrilinosWrappers::SparseMatrix A (sp); + A.add (2, 3, 2.0); + A.compress(); + + // verify that entry (2,3) is + // indeed what we expect. verify + // that both methods of accessing + // the entry work + Assert (A.el(2, 3) == 2, ExcInternalError()); + Assert (A(2, 3) == 2, ExcInternalError()); + + deallog << "OK" << std::endl; +} diff --git a/tests/trilinos/sparse_matrix_01/cmp/generic b/tests/trilinos/sparse_matrix_01/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/trilinos/sparse_matrix_01/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5