From 56b4bc9b49a8f9fa44cc64476b315bf47f15ea5c Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 10 Aug 2005 23:26:59 +0000 Subject: [PATCH] VectoBase::add git-svn-id: https://svn.dealii.org/trunk@11279 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/petsc_vector_base.h | 14 +++++++ deal.II/lac/source/petsc_vector_base.cc | 41 ++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) 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 { -- 2.39.5