From: wolf Date: Mon, 23 Apr 2001 23:16:10 +0000 (+0000) Subject: Have another scale function that scales each element individually. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c841a86e261834e6088d9fb6a022c38901386204;p=dealii-svn.git Have another scale function that scales each element individually. git-svn-id: https://svn.dealii.org/trunk@4473 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/2001/c-3-1.html b/deal.II/doc/news/2001/c-3-1.html index 169aeb6aa5..89b4301971 100644 --- a/deal.II/doc/news/2001/c-3-1.html +++ b/deal.II/doc/news/2001/c-3-1.html @@ -234,8 +234,17 @@ documentation, etc.

lac

    +
  1. + New: There is now a function Vector::scale(Vector) + that scales each element of the vector by the corresponding + element of the argument. +
    + (WB 2001/04/23) +

    +
  2. Changed: Solver functions solve - are void now. If the solver has not converged within the + return void now. If the solver has not converged within the maximum number of iterations or encounters a breakdown, it throws an exception of type SolverControl::NoConvergence instead of diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index 723648035f..424702455b 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -364,11 +364,22 @@ class Vector const Number c, const Vector& X); /** - * Scale each element of the vector by the - * given factor. + * Scale each element of the + * vector by the given factor. */ //TODO:[?] Why not have an operator *= instead of/in addition to `scale'? void scale (const Number factor); + + /** + * Scale each element of this + * vector by the corresponding + * element in the argument. This + * function is mostly meant to + * simulate multiplication (and + * immediate re-assignment) by a + * diagonal scaling matrix. + */ + void scale (const Vector &scaling_factors); /** * U=a*V. Replacing. diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index bb45b600b0..d6442e10ae 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -452,17 +452,35 @@ void Vector::sadd (const Number x, const Number a, } + template void Vector::scale (const Number factor) { Assert (dim!=0, ExcEmptyVector()); - iterator ptr=begin(), eptr=end(); + iterator ptr = begin(); + const const_iterator eptr = end(); while (ptr!=eptr) *ptr++ *= factor; } + +template +void Vector::scale (const Vector &s) +{ + Assert (dim!=0, ExcEmptyVector()); + Assert (dim == s.dim, ExcDimensionMismatch(dim, s.dim)); + + iterator ptr = begin(); + const_iterator sptr = s.begin(); + const const_iterator eptr = end(); + while (ptr!=eptr) + *ptr++ *= *sptr++; +} + + + template void Vector::equ (const Number a, const Vector& u, const Number b, const Vector& v)