From 01b18870d62f8f1b87e4aee4133c042c1078709c Mon Sep 17 00:00:00 2001 From: Christian Engwer <christi@dune-project.org> Date: Thu, 24 Jan 2019 16:00:48 +0100 Subject: [PATCH] [prec] change internal memory management of parallel preconditioners like all other preconditioners we now use shared_ptr to be able to go via the base class. --- dune/istl/novlpschwarz.hh | 37 ++++++++++++++++++++++++++++--------- dune/istl/schwarz.hh | 33 ++++++++++++++++++++++----------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/dune/istl/novlpschwarz.hh b/dune/istl/novlpschwarz.hh index 3f1167bb3..2b3e9634d 100644 --- a/dune/istl/novlpschwarz.hh +++ b/dune/istl/novlpschwarz.hh @@ -266,6 +266,7 @@ namespace Dune { : public Dune::Preconditioner<typename P::domain_type,typename P::range_type> { friend struct Amg::ConstructionTraits<NonoverlappingBlockPreconditioner<C,P> >; public: + typedef Preconditioner<typename P::domain_type,typename P::range_type> Prec; //! \brief The domain type of the preconditioner. typedef typename P::domain_type domain_type; //! \brief The range type of the preconditioner. @@ -280,9 +281,27 @@ namespace Dune { \param c The communication object for syncing owner and copy data points. (E.~g. OwnerOverlapCommunication ) */ - NonoverlappingBlockPreconditioner (P& prec, const communication_type& c) - : preconditioner(prec), communication(c) - {} + /*! \brief Constructor. + + constructor gets all parameters to operate the prec. + \param p The sequential preconditioner. + \param c The communication object for syncing overlap and copy + data points. (E.~g. OwnerOverlapCopyCommunication ) + */ + NonoverlappingBlockPreconditioner (Prec& p, const communication_type& c) + : _preconditioner(stackobject_to_shared_ptr(p)), _communication(c) + { } + + /*! \brief Constructor. + + constructor gets all parameters to operate the prec. + \param p The sequential preconditioner. + \param c The communication object for syncing overlap and copy + data points. (E.~g. OwnerOverlapCopyCommunication ) + */ + NonoverlappingBlockPreconditioner (const std::shared_ptr<Prec>& p, const communication_type& c) + : _preconditioner(p), _communication(c) + { } /*! \brief Prepare the preconditioner. @@ -291,7 +310,7 @@ namespace Dune { */ virtual void pre (domain_type& x, range_type& b) { - preconditioner.pre(x,b); + _preconditioner->pre(x,b); } /*! @@ -304,8 +323,8 @@ namespace Dune { // block preconditioner equivalent to WrappedPreconditioner from // pdelab/backend/ovlpistsolverbackend.hh, // but not to BlockPreconditioner from schwarz.hh - preconditioner.apply(v,d); - communication.addOwnerCopyToOwnerCopy(v,v); + _preconditioner->apply(v,d); + _communication.addOwnerCopyToOwnerCopy(v,v); } /*! @@ -315,7 +334,7 @@ namespace Dune { */ virtual void post (domain_type& x) { - preconditioner.post(x); + _preconditioner->post(x); } //! Category of the preconditioner (see SolverCategory::Category) @@ -326,10 +345,10 @@ namespace Dune { private: //! \brief a sequential preconditioner - P& preconditioner; + std::shared_ptr<Prec>& _preconditioner; //! \brief the communication object - const communication_type& communication; + const communication_type& _communication; }; /** @} end documentation */ diff --git a/dune/istl/schwarz.hh b/dune/istl/schwarz.hh index a81d02b5d..375525e03 100644 --- a/dune/istl/schwarz.hh +++ b/dune/istl/schwarz.hh @@ -294,8 +294,19 @@ namespace Dune { \param c The communication object for syncing overlap and copy data points. (E.~g. OwnerOverlapCopyCommunication ) */ - BlockPreconditioner (T& p, const communication_type& c) - : preconditioner(p), communication(c) + BlockPreconditioner (Preconditioner<X,Y>& p, const communication_type& c) + : _preconditioner(stackobject_to_shared_ptr(p)), _communication(c) + { } + + /*! \brief Constructor. + + constructor gets all parameters to operate the prec. + \param p The sequential preconditioner. + \param c The communication object for syncing overlap and copy + data points. (E.~g. OwnerOverlapCopyCommunication ) + */ + BlockPreconditioner (const std::shared_ptr<Preconditioner<X,Y>>& p, const communication_type& c) + : _preconditioner(p), _communication(c) { } /*! @@ -305,8 +316,8 @@ namespace Dune { */ virtual void pre (X& x, Y& b) { - communication.copyOwnerToAll(x,x); // make dirichlet values consistent - preconditioner.pre(x,b); + _communication.copyOwnerToAll(x,x); // make dirichlet values consistent + _preconditioner->pre(x,b); } /*! @@ -316,15 +327,15 @@ namespace Dune { */ virtual void apply (X& v, const Y& d) { - preconditioner.apply(v,d); - communication.copyOwnerToAll(v,v); + _preconditioner->apply(v,d); + _communication.copyOwnerToAll(v,v); } template<bool forward> void apply (X& v, const Y& d) { - preconditioner.template apply<forward>(v,d); - communication.copyOwnerToAll(v,v); + _preconditioner->template apply<forward>(v,d); + _communication.copyOwnerToAll(v,v); } /*! @@ -334,7 +345,7 @@ namespace Dune { */ virtual void post (X& x) { - preconditioner.post(x); + _preconditioner->post(x); } //! Category of the preconditioner (see SolverCategory::Category) @@ -345,10 +356,10 @@ namespace Dune { private: //! \brief a sequential preconditioner - T& preconditioner; + std::shared_ptr<Preconditioner<X,Y>> _preconditioner; //! \brief the communication object - const communication_type& communication; + const communication_type& _communication; }; /** @} end documentation */ -- GitLab