From 9da2ca5d37b0a44461d79b13ea0c91f898df7c78 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de> Date: Mon, 21 Nov 2016 07:40:44 +0100 Subject: [PATCH] [staggeredGrid][stencils] Improve pointer handling * Directly return a unique_ptr --- dumux/discretization/staggered/stencils.hh | 19 ++++++++++--------- dumux/freeflow/staggered/model.hh | 14 +++++++++----- dumux/implicit/staggered/assembler.hh | 8 ++------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/dumux/discretization/staggered/stencils.hh b/dumux/discretization/staggered/stencils.hh index a51d5bf075..a5a38759f1 100644 --- a/dumux/discretization/staggered/stencils.hh +++ b/dumux/discretization/staggered/stencils.hh @@ -194,23 +194,24 @@ public: return faceStencils_[scvFace.dofIndexSelf() - numElements]; } + /*! + * \brief Returns the size of a complete face dof stencil + */ size_t completeFaceDofStencilSize(const int idx) const { // const IndexType numElements = problemPtr_->gridView().size(0); + assert(fullFaceDofStencils_ && "fullFaceDofStencils_ has already been called and deleted!"); return fullFaceDofStencils_.get()[0][idx/*-numElements*/].size(); // TODO: why does this not work? } - void getFullFaceDofStencils(std::unique_ptr<std::vector<Stencil>>& ptr) + /*! + * \brief Returns a unique pointer to the complete face dof stencils which is used once for setting up the global matrix and deleted afterwards + */ + auto getFullFaceDofStencilsPtr() { - std::cout << "before move: "; - if(fullFaceDofStencils_) - std::cout << "object still there" << std::endl; - ptr = std::move(fullFaceDofStencils_); - - std::cout << "after move: "; - if(fullFaceDofStencils_) - std::cout << "object still there" << std::endl; + assert(fullFaceDofStencils_ && "fullFaceDofStencils_ has already been used and deleted!"); + return std::move(fullFaceDofStencils_); } diff --git a/dumux/freeflow/staggered/model.hh b/dumux/freeflow/staggered/model.hh index bb18ce217f..8ac0928724 100644 --- a/dumux/freeflow/staggered/model.hh +++ b/dumux/freeflow/staggered/model.hh @@ -144,16 +144,20 @@ public: return this->gridView_().size(0) + this->gridView_().size(1);; } - size_t completeFaceDofStencilSize(const int idx) + /*! + * \brief Returns the size of a complete face dof stencil + */ + size_t completeFaceDofStencilSize(const int idx) const { return this->stencilsVector_.completeFaceDofStencilSize(idx); } - template<class Stencil> - void getFullFaceDofStencils(std::unique_ptr<std::vector<Stencil>>& ptr) + /*! + * \brief Returns a unique pointer to the complete face dof stencils which is used once for setting up the global matrix and deleted afterwards + */ + auto getFullFaceDofStencilsPtr() { - this->stencilsVector_.getFullFaceDofStencils(ptr); - // TODO: find better way to do this + return this->stencilsVector_.getFullFaceDofStencilsPtr(); } }; diff --git a/dumux/implicit/staggered/assembler.hh b/dumux/implicit/staggered/assembler.hh index 4d36f5390e..af0a097e5f 100644 --- a/dumux/implicit/staggered/assembler.hh +++ b/dumux/implicit/staggered/assembler.hh @@ -77,16 +77,12 @@ class StaggeredAssembler : public ImplicitAssembler<TypeTag> this->matrix().addindex(globalI, globalJ); } - // TODO: this is a mess. find a better way for the pointer handling! - using Stencil = std::vector<IndexType>; - std::unique_ptr<std::vector<Stencil>> ptr; - - this->model_().getFullFaceDofStencils(ptr); + auto ptr = this->model_().getFullFaceDofStencilsPtr(); if(ptr) std::cout << "success!!!" << std::endl; - auto& fullFaceDofStencils = ptr.get()[0]; + const auto& fullFaceDofStencils = ptr.get()[0]; int globalI = this->gridView_().size(0); for(const auto& stencil : fullFaceDofStencils) -- GitLab