diff --git a/dune/solvers/operators/sumoperator.hh b/dune/solvers/operators/sumoperator.hh index 7869d376537c6de50792e93e5c9fe567b57eed36..e6e978b7076131c905f1067d08e727722425bf20 100644 --- a/dune/solvers/operators/sumoperator.hh +++ b/dune/solvers/operators/sumoperator.hh @@ -16,46 +16,97 @@ class SumOperator //! export the summand type typedef LowRankMatrix LowRankMatrixType; + //! default constructor - allocates memory for summand operators internally + SumOperator(): + summands_allocated_internally_(true) + { + sparse_matrix_ = new SparseMatrixType; + lowrank_matrix_ = new LowRankMatrixType; + } + //! construct from summands SumOperator(SparseMatrixType& A, LowRankMatrixType& M): - sparse_matrix_(A), - lowrank_matrix_(M) + sparse_matrix_(&A), + lowrank_matrix_(&M), + summands_allocated_internally_(false) {} + ~SumOperator() + { + if (summands_allocated_internally_) + { + delete sparse_matrix_; + delete lowrank_matrix_; + } + } + //! b += (A+M)x 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_->umv(x,b); + lowrank_matrix_->umv(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); } //! b = (A+M)x template <class LVectorType, class RVectorType> void mv(const LVectorType& x, RVectorType& b) { - sparse_matrix_.mv(x,b); - lowrank_matrix_.umv(x,b); + sparse_matrix_->mv(x,b); + lowrank_matrix_->umv(x,b); + } + + //! return the number of rows + const size_t N() const + { + sparse_matrix_->N(); + } + + //! return the number of columns + const size_t M() const + { + sparse_matrix_->M(); + } + + //! return one summand + const SparseMatrixType& sparseMatrix() const + { + return *sparse_matrix_; } //! return one summand - SparseMatrixType& getSparseMatrix() + SparseMatrixType& sparseMatrix() + { + return *sparse_matrix_; + } + + //! return "the other" summand + const LowRankMatrixType& lowRankMatrix() const { - return sparse_matrix_; + return *lowrank_matrix_; } //! return "the other" summand - LowRankMatrixType& getLowRankMatrix() + LowRankMatrixType& lowRankMatrix() { - return lowrank_matrix_; + return *lowrank_matrix_; } private: //! one summand - SparseMatrixType& sparse_matrix_; + SparseMatrixType* sparse_matrix_; //! the other summand - LowRankMatrixType& lowrank_matrix_; - + LowRankMatrixType* lowrank_matrix_; + //! are the summands supplied or stored internally + const bool summands_allocated_internally_; }; #endif