diff --git a/dumux/io/grid/gridmanager_sub.hh b/dumux/io/grid/gridmanager_sub.hh index 0d0f6ec5ff9e0e12a54c026ec1a738edb6f04f37..b2d71d8d3b576a367723d2b36a2fb7053ec163ba 100644 --- a/dumux/io/grid/gridmanager_sub.hh +++ b/dumux/io/grid/gridmanager_sub.hh @@ -73,7 +73,8 @@ public: const ES& selector, const std::string& paramGroup = "") { - this->gridPtr() = createGrid_(hostGrid, selector, paramGroup); + this->gridPtr() = std::make_unique<Grid>(hostGrid); + updateSubGrid_(selector); loadBalance(); } @@ -86,7 +87,8 @@ public: const std::string& paramGroup = "") { initHostGrid_(paramGroup); - this->gridPtr() = createGrid_(hostGridManager_->grid(), selector, paramGroup); + this->gridPtr() = std::make_unique<Grid>(hostGridManager_->grid()); + updateSubGrid_(selector); loadBalance(); } @@ -99,19 +101,27 @@ public: this->grid().loadBalance(); } + /*! + * \brief Update the existing subgrid. + */ + template<class ES, + typename std::enable_if_t<Dune::models<Concept::ElementSelector<HostElement>, ES>(), int> = 0> + void update(const ES& selector) + { + updateSubGrid_(selector); + loadBalance(); + } + protected: /*! - * \brief Make the subgrid. + * \brief Update the subgrid. */ template<class ES, typename std::enable_if_t<Dune::models<Concept::ElementSelector<HostElement>, ES>(), int> = 0> - static std::unique_ptr<Grid> createGrid_(HostGrid& hostGrid, - const ES& selector, - const std::string& paramGroup = "") + void updateSubGrid_(const ES& selector) { - // A unique pointer to the subgrid. - auto subgridPtr = std::make_unique<Grid>(hostGrid); + auto& subgridPtr = this->gridPtr(); // A container to store the host grid elements' ids. std::set<typename HostGrid::Traits::GlobalIdSet::IdType> elementsForSubgrid; @@ -132,9 +142,6 @@ protected: subgridPtr->insertSetPartial(elementsForSubgrid); subgridPtr->createEnd(); - - // Return a unique pointer to the subgrid. - return subgridPtr; } void initHostGrid_(const std::string& paramGroup) @@ -314,9 +321,15 @@ private: // create the grid if (repeated) - this->gridPtr() = this->createGrid_(this->hostGrid_(), repeatedElementSelector, paramGroup); + { + this->gridPtr() = std::make_unique<Grid>(this->hostGrid_()); + this->updateSubGrid_(repeatedElementSelector); + } else - this->gridPtr() = this->createGrid_(this->hostGrid_(), elementSelector, paramGroup); + { + this->gridPtr() = std::make_unique<Grid>(this->hostGrid_()); + this->updateSubGrid_(elementSelector); + } this->loadBalance(); }