diff --git a/dune/solvers/operators/sumoperator.hh b/dune/solvers/operators/sumoperator.hh index ddead966c87efcdae3d9ae0696a265a3a6c00c75..6e3d185cc8b82045e77cc1aee962475b1046ad2a 100644 --- a/dune/solvers/operators/sumoperator.hh +++ b/dune/solvers/operators/sumoperator.hh @@ -22,15 +22,28 @@ class SumOperator //! default constructor - allocates memory for summand operators internally SumOperator(): + alpha_(1.0), + beta_(1.0), summands_allocated_internally_(true) { sparse_matrix_ = new SparseMatrixType; lowrank_matrix_ = new LowRankMatrixType; } + //! construct from summands + SumOperator(double a, SparseMatrixType& A, double b, LowRankMatrixType& M): + alpha_(a), + sparse_matrix_(&A), + beta_(b), + lowrank_matrix_(&M), + summands_allocated_internally_(false) + {} + //! construct from summands SumOperator(SparseMatrixType& A, LowRankMatrixType& M): + alpha_(1.0), sparse_matrix_(&A), + beta_(1.0), lowrank_matrix_(&M), summands_allocated_internally_(false) {} @@ -48,32 +61,33 @@ class SumOperator template <class LVectorType, class RVectorType> void umv(const LVectorType& x, RVectorType& b) const { - sparse_matrix_->umv(x,b); - lowrank_matrix_->umv(x,b); + sparse_matrix_->usmv(alpha_,x,b); + lowrank_matrix_->usmv(beta_,x,b); } //! b -= (A+M)x template <class LVectorType, class RVectorType> void mmv(const LVectorType& x, RVectorType& b) const { - sparse_matrix_->mmv(x,b); - lowrank_matrix_->mmv(x,b); + sparse_matrix_->usmv(-alpha_,x,b); + lowrank_matrix_->usmv(-beta_,x,b); } //! b = (A+M)x template <class LVectorType, class RVectorType> void mv(const LVectorType& x, RVectorType& b) const { - sparse_matrix_->mv(x,b); - lowrank_matrix_->umv(x,b); + b = 0.0; + sparse_matrix_->usmv(alpha_,x,b); + lowrank_matrix_->usmv(beta_,x,b); } //! b += a*(A+M)x template <class LVectorType, class RVectorType> void usmv(const field_type a, const LVectorType& x, RVectorType& b) const { - sparse_matrix_->usmv(a,x,b); - lowrank_matrix_->usmv(a,x,b); + sparse_matrix_->usmv(a*alpha_,x,b); + lowrank_matrix_->usmv(a*beta_,x,b); } //! return the number of rows @@ -112,6 +126,8 @@ class SumOperator return *lowrank_matrix_; } + double alpha_, + beta_; private: //! one summand SparseMatrixType* sparse_matrix_;