From 102f91ac19f9d488c7425392165793a013bcf843 Mon Sep 17 00:00:00 2001 From: heister Date: Tue, 19 Feb 2013 19:17:13 +0000 Subject: [PATCH] add PETScWrappers::*Matrix::add(other, factor) with test. Patch by Jose Javier Munoz Criollo git-svn-id: https://svn.dealii.org/trunk@28478 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 5 ++ .../include/deal.II/lac/petsc_matrix_base.h | 9 ++- deal.II/source/lac/petsc_matrix_base.cc | 13 +++ tests/petsc/sparse_matrix_01.cc | 79 +++++++++++++++++++ tests/petsc/sparse_matrix_01/cmp/generic | 8 ++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/petsc/sparse_matrix_01.cc create mode 100644 tests/petsc/sparse_matrix_01/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index a5dd2d7f2f..4f791bf6af 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -208,6 +208,11 @@ DoFHandler, in particular removal of specializations.

Specific improvements

    +
  1. New: PETScWrappers::*Matrix::add(other, factor) to +add a scaled other matrix to the current matrix. +
    +(Jose Javier Munoz Criollo, 2013/02/19) +
  2. New: GridGenerator::extrude_triangulation() allows you to extrude a 2d mesh to turn it into a 3d mesh.
    diff --git a/deal.II/include/deal.II/lac/petsc_matrix_base.h b/deal.II/include/deal.II/lac/petsc_matrix_base.h index a8f137b846..bc81805f3f 100644 --- a/deal.II/include/deal.II/lac/petsc_matrix_base.h +++ b/deal.II/include/deal.II/lac/petsc_matrix_base.h @@ -926,6 +926,13 @@ namespace PETScWrappers */ MatrixBase &operator /= (const PetscScalar factor); + /** + * Add the matrix @p other scaled by the factor @p factor to the current + * matrix. + */ + MatrixBase & add (const MatrixBase &other, + const PetscScalar factor); + /** * Matrix-vector multiplication: * let dst = M*src with @@ -1700,7 +1707,7 @@ namespace PETScWrappers #ifndef PETSC_USE_64BIT_INDICES if (elide_zero_values == false) { - col_index_ptr = (int *)col_indices; + col_index_ptr = (int*)col_indices; col_value_ptr = values; n_columns = n_cols; } diff --git a/deal.II/source/lac/petsc_matrix_base.cc b/deal.II/source/lac/petsc_matrix_base.cc index c8a3d456c1..f41fbd9f21 100644 --- a/deal.II/source/lac/petsc_matrix_base.cc +++ b/deal.II/source/lac/petsc_matrix_base.cc @@ -478,6 +478,19 @@ namespace PETScWrappers } + MatrixBase & + MatrixBase::add (const MatrixBase &other, + const PetscScalar factor) + { + const int ierr = MatAXPY (matrix, factor, + other, DIFFERENT_NONZERO_PATTERN); + + Assert (ierr == 0, ExcPETScError(ierr)); + + return *this; + } + + void MatrixBase::vmult (VectorBase &dst, const VectorBase &src) const diff --git a/tests/petsc/sparse_matrix_01.cc b/tests/petsc/sparse_matrix_01.cc new file mode 100644 index 0000000000..d91d62ef80 --- /dev/null +++ b/tests/petsc/sparse_matrix_01.cc @@ -0,0 +1,79 @@ +//---------------------------- petsc_sparse_matrix_vector_07.cc --------------------------- +// $Id: sparse_matrix_vector_07.cc 24924 2012-01-25 12:35:17Z kormann $ +// Version: $Name$ +// +// Copyright (C) 2004, 2005 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. +// +//---------------------------- petsc_sparse_matrix_vector_07.cc --------------------------- + + +// check SparseMatrix::add(other, factor) + +#include "../tests.h" +#include +#include +#include +#include +#include + + +void test () +{ + const unsigned int s = 10; + PETScWrappers::SparseMatrix m(s,s,s); + for (unsigned int i=0; i