From: Wolfgang Bangerth Date: Wed, 10 Aug 2005 23:26:59 +0000 (+0000) Subject: VectoBase::add X-Git-Tag: v8.0.0~13308 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b278eeebe5b4406dc5e6105fbfc8e1ab86156b5a;p=dealii.git VectoBase::add git-svn-id: https://svn.dealii.org/trunk@11279 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/petsc_vector_base.h b/deal.II/lac/include/lac/petsc_vector_base.h index 75db62118b..833e1407da 100644 --- a/deal.II/lac/include/lac/petsc_vector_base.h +++ b/deal.II/lac/include/lac/petsc_vector_base.h @@ -22,6 +22,7 @@ #include +#include #include @@ -350,6 +351,19 @@ namespace PETScWrappers */ PetscScalar operator () (const unsigned int index) const; + + /** + * A collective set operation: instead + * of setting individual elements of a + * vector, this function allows to set + * a whole set of elements at once. The + * indices of the elements to be set + * are stated in the first argument, + * the corresponding values in the + * second. + */ + void set (const std::vector &indices, + const std::vector &values); /** * Return the scalar product of two diff --git a/deal.II/lac/source/petsc_vector_base.cc b/deal.II/lac/source/petsc_vector_base.cc index 2c5aa4cb39..fca25cd832 100644 --- a/deal.II/lac/source/petsc_vector_base.cc +++ b/deal.II/lac/source/petsc_vector_base.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004 by the deal.II authors +// 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 @@ -209,6 +209,45 @@ namespace PETScWrappers + void + VectorBase::set (const std::vector &indices, + const std::vector &values) + { + Assert (indices.size() == values.size(), + ExcMessage ("Function called with arguments of different sizes")); + + if (last_action != VectorBase::LastAction::insert) + { + int ierr; + ierr = VecAssemblyBegin (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + ierr = VecAssemblyEnd (vector); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + } + +#if (PETSC_VERSION_MAJOR <= 2) && \ + ((PETSC_VERSION_MINOR < 2) || \ + ((PETSC_VERSION_MINOR == 2) && (PETSC_VERSION_SUBMINOR == 0))) + const std::vector petsc_indices (indices.begin(), + indices.end()); +#else + const std::vector petsc_indices (indices.begin(), + indices.end()); +#endif + + const int ierr + = VecSetValues (vector, indices.size(), + &petsc_indices[0], &values[0], + INSERT_VALUES); + AssertThrow (ierr == 0, ExcPETScError(ierr)); + + + last_action = LastAction::insert; + } + + + PetscScalar VectorBase::operator * (const VectorBase &vec) const {