diff --git a/dune/solvers/transferoperators/compressedmultigridtransfer.hh b/dune/solvers/transferoperators/compressedmultigridtransfer.hh index cce655cb169c2ac384be4e85fc9bbdcbf8a0c770..bf99cb8138ed900f2f1c90d919f90cf3dc799047 100644 --- a/dune/solvers/transferoperators/compressedmultigridtransfer.hh +++ b/dune/solvers/transferoperators/compressedmultigridtransfer.hh @@ -4,6 +4,7 @@ #include <dune/istl/bcrsmatrix.hh> #include <dune/common/fmatrix.hh> #include <dune/common/bitsetvector.hh> +#include <dune/common/shared_ptr.hh> #include <dune/solvers/operators/sumoperator.hh> #include <dune/solvers/common/staticmatrixtools.hh> @@ -43,15 +44,15 @@ public: CompressedMultigridTransfer() { - matrix_ = new TransferOperatorType; - matrixInternallyAllocated = true; + matrix_ = Dune::make_shared<TransferOperatorType>(); } + CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) : + matrix_(matrix) + {} + virtual ~CompressedMultigridTransfer() - { - if (matrixInternallyAllocated) - delete matrix_; - } + {} /** \brief Sets up the operator between two P1 spaces @@ -134,22 +135,23 @@ public: return *matrix_; } + /** \brief Set matrix! */ + void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix) + { + matrix_ = matrix; + } + /** \brief Set matrix! */ void setMatrix(TransferOperatorType& matrix) { - if (matrixInternallyAllocated) - delete matrix_; - matrixInternallyAllocated = false; - matrix_ = &matrix; + matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix); } protected: - TransferOperatorType* matrix_; - bool matrixInternallyAllocated; - + typename Dune::shared_ptr<TransferOperatorType> matrix_; }; template< @@ -173,15 +175,15 @@ public: CompressedMultigridTransfer() { - matrix_ = new TransferOperatorType; - matrixInternallyAllocated = true; + matrix_ = Dune::make_shared<TransferOperatorType>(); } + CompressedMultigridTransfer(typename Dune::shared_ptr<TransferOperatorType>& matrix) : + matrix_(matrix) + {} + virtual ~CompressedMultigridTransfer() - { - if (matrixInternallyAllocated) - delete matrix_; - } + {} /** \brief Sets up the operator between two P1 spaces @@ -285,22 +287,23 @@ public: return *matrix_; } + /** \brief Set matrix! */ + void setMatrix(typename Dune::shared_ptr<TransferOperatorType>& matrix) + { + matrix_ = matrix; + } + /** \brief Set matrix! */ void setMatrix(TransferOperatorType& matrix) { - if (matrixInternallyAllocated) - delete matrix_; - matrixInternallyAllocated = false; - matrix_ = &matrix; + matrix_ = Dune::stackobject_to_shared_ptr<TransferOperatorType>(matrix); } protected: - TransferOperatorType* matrix_; - bool matrixInternallyAllocated; - + typename Dune::shared_ptr<TransferOperatorType> matrix_; }; #endif