From c2400532eab3bb8fc44121f486c94ba3f99be2df Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Wed, 13 Jul 2016 01:08:26 +0200 Subject: [PATCH] Clean up ignoreNodes usage. - Use all()/any()/none() from BitSetVector - Use the ignore() getter --- dune/solvers/iterationsteps/blockgsstep.cc | 10 +++++----- dune/solvers/iterationsteps/blockgssteps.hh | 2 +- dune/solvers/iterationsteps/cgstep.cc | 4 ++-- dune/solvers/iterationsteps/iterationstep.hh | 4 ---- dune/solvers/iterationsteps/linegsstep.cc | 4 ++-- dune/solvers/iterationsteps/obstacletnnmgstep.hh | 4 ++-- dune/solvers/iterationsteps/projectedblockgsstep.cc | 5 ++--- dune/solvers/iterationsteps/projectedgradientstep.cc | 2 +- dune/solvers/iterationsteps/projectedlinegsstep.cc | 6 +++--- .../iterationsteps/semidefiniteblockgsstep.hh | 2 +- dune/solvers/iterationsteps/truncatedblockgsstep.hh | 4 ++-- .../iterationsteps/truncatedsaddlepointgsstep.hh | 1 - dune/solvers/iterationsteps/trustregiongsstep.cc | 6 +++--- dune/solvers/solvers/trustregionsolver.cc | 2 +- dune/solvers/solvers/umfpacksolver.hh | 12 ++++++------ dune/solvers/test/mmgtest.cc | 2 +- 16 files changed, 32 insertions(+), 38 deletions(-) diff --git a/dune/solvers/iterationsteps/blockgsstep.cc b/dune/solvers/iterationsteps/blockgsstep.cc index 9511522..926445c 100644 --- a/dune/solvers/iterationsteps/blockgsstep.cc +++ b/dune/solvers/iterationsteps/blockgsstep.cc @@ -30,7 +30,7 @@ template<class MatrixType, class DiscFuncType, class BitVectorType> inline void BlockGSStep<MatrixType, DiscFuncType, BitVectorType>::iterate() { - assert(this->ignoreNodes_ != NULL); + assert(this->ignoreNodes_ != nullptr); if (gs_type_ != Direction::BACKWARD) for (std::size_t i=0; i<this->x_->size(); i++) @@ -47,8 +47,8 @@ void BlockGSStep<MatrixType, DiscFuncType, BitVectorType>::iterate_step(int i) { const MatrixType& mat = *this->mat_; - size_t const count = (*this->ignoreNodes_)[i].count(); - if (count == BlockSize) + auto const &ignore_i = this->ignore()[i]; + if (ignore_i.all()) return; VectorBlock r; @@ -58,7 +58,7 @@ void BlockGSStep<MatrixType, DiscFuncType, BitVectorType>::iterate_step(int i) // Compute correction v = A_{i,i}^{-1} r[i] VectorBlock v; - if (count == 0) { + if (ignore_i.none()) { // No degree of freedom shall be ignored --> solve linear problem mat_ii.solve(v, r); } else { @@ -66,7 +66,7 @@ void BlockGSStep<MatrixType, DiscFuncType, BitVectorType>::iterate_step(int i) // are not touched typename MatrixType::block_type matRes; for (int j = 0; j < BlockSize; ++j) { - if ((*this->ignoreNodes_)[i][j]) { + if (ignore_i[j]) { r[j] = 0; for (int k = 0; k < BlockSize; ++k) diff --git a/dune/solvers/iterationsteps/blockgssteps.hh b/dune/solvers/iterationsteps/blockgssteps.hh index d05a37b..aa995c0 100644 --- a/dune/solvers/iterationsteps/blockgssteps.hh +++ b/dune/solvers/iterationsteps/blockgssteps.hh @@ -60,7 +60,7 @@ template <class M, class V, class BitVector, class LocalSolver> void linearStep(LinearIterationStep<M, V, BitVector>& lis, LocalSolver&& localSolver, Direction direction = Direction::FORWARD) { - return linearStep(*lis.mat_, *lis.x_, *lis.rhs_, *lis.ignoreNodes_, + return linearStep(*lis.mat_, *lis.x_, *lis.rhs_, lis.ignore(), std::forward<LocalSolver>(localSolver), direction); } diff --git a/dune/solvers/iterationsteps/cgstep.cc b/dune/solvers/iterationsteps/cgstep.cc index a34354a..4e00a3b 100644 --- a/dune/solvers/iterationsteps/cgstep.cc +++ b/dune/solvers/iterationsteps/cgstep.cc @@ -14,7 +14,7 @@ void CGStep<MatrixType, VectorType>::preprocess() // Compute the residual (r starts out as the rhs) matrix_->mmv(*x_,r_); for (size_t i=0; i < r_.size(); ++i) - if ((*this->ignoreNodes_)[i].any()) + if (this->ignore()[i].any()) r_[i] = 0; if (preconditioner_) { @@ -37,7 +37,7 @@ void CGStep<MatrixType, VectorType>::iterate() r_.axpy(-alpha, q); // r_1 = r_0 - alpha_0 Ap_0 for (size_t i=0; i < r_.size(); ++i) - if ((*this->ignoreNodes_)[i].any()) + if (this->ignore()[i].any()) r_[i] = 0; if (preconditioner_) diff --git a/dune/solvers/iterationsteps/iterationstep.hh b/dune/solvers/iterationsteps/iterationstep.hh index d2ce942..94bf596 100644 --- a/dune/solvers/iterationsteps/iterationstep.hh +++ b/dune/solvers/iterationsteps/iterationstep.hh @@ -78,10 +78,6 @@ class IterationStep : virtual public NumProc, public CanIgnore<BitVectorType> //! The solution container VectorType* x_; - - - using CanIgnore<BitVectorType>::ignoreNodes_; - }; #endif diff --git a/dune/solvers/iterationsteps/linegsstep.cc b/dune/solvers/iterationsteps/linegsstep.cc index a3d0d6b..aada568 100755 --- a/dune/solvers/iterationsteps/linegsstep.cc +++ b/dune/solvers/iterationsteps/linegsstep.cc @@ -29,7 +29,7 @@ void LineGSStep<MatrixType, DiscFuncType, BitVectorType >::iterate() DiscFuncType permuted_r_i(current_block_size); for (int k=0; k<current_block_size; k++) { - if ( (*this->ignoreNodes_)[blockStructure_[b_num][k]][0]) + if ( this->ignore()[blockStructure_[b_num][k]][0]) permuted_r_i[k] = 0.0; else this->residual( blockStructure_[b_num][k], permuted_r_i[k]); // get r[p(i+k)] @@ -49,7 +49,7 @@ void LineGSStep<MatrixType, DiscFuncType, BitVectorType >::iterate() for (int j=0; j<current_block_size; j++) { - if ( (*this->ignoreNodes_)[blockStructure_[b_num][j]][0] ) { + if ( this->ignore()[blockStructure_[b_num][j]][0] ) { // left off-diagonal: if (j>0) diff --git a/dune/solvers/iterationsteps/obstacletnnmgstep.hh b/dune/solvers/iterationsteps/obstacletnnmgstep.hh index 04d232e..8f369cf 100644 --- a/dune/solvers/iterationsteps/obstacletnnmgstep.hh +++ b/dune/solvers/iterationsteps/obstacletnnmgstep.hh @@ -120,7 +120,7 @@ class ObstacleTNNMGStep linearPreSmoothingSteps_(3), linearPostSmoothingSteps_(3) { - ignoreNodes_ = &ignore; + this->setIgnore(ignore); } /** @@ -377,7 +377,7 @@ class ObstacleTNNMGStep transfer_[maxLevel-1]->galerkinRestrictSetOccupation(mat_, coarseMatrix[maxLevel-1]); transfer_[maxLevel-1]->galerkinRestrict(mat_, coarseMatrix[maxLevel-1]); transfer_[maxLevel-1]->restrict(rhs_, coarseRhs[maxLevel-1]); - transfer_[maxLevel-1]->restrictToFathers(*ignoreNodes_, coarseIgnore[maxLevel-1]); + transfer_[maxLevel-1]->restrictToFathers(this->ignore(), coarseIgnore[maxLevel-1]); obstacleRestrictor.restrict(obstacles_, coarseObstacle[maxLevel-1], hasObstacle_, hasObstacle_, *(transfer_[maxLevel-1]), critical); coarseSolution[maxLevel-1].resize(coarseMatrix[maxLevel-1].N()); for (int i = maxLevel-2; i>=0; --i) diff --git a/dune/solvers/iterationsteps/projectedblockgsstep.cc b/dune/solvers/iterationsteps/projectedblockgsstep.cc index 981c6b7..83e28e0 100644 --- a/dune/solvers/iterationsteps/projectedblockgsstep.cc +++ b/dune/solvers/iterationsteps/projectedblockgsstep.cc @@ -12,10 +12,9 @@ void ProjectedBlockGSStep<MatrixType, VectorType>::iterate() const MatrixType& mat = *this->mat_; for (size_t i=0; i<this->x_->size(); i++) { - auto ignoreCount = (*this->ignoreNodes_)[i].count(); - if (ignoreCount == BlockSize) + if (this->ignore()[i].all()) continue; - if (ignoreCount > 0) + if (this->ignore()[i].any()) DUNE_THROW(Dune::NotImplemented, "Individual blocks must be either ignored completely, or not at all"); diff --git a/dune/solvers/iterationsteps/projectedgradientstep.cc b/dune/solvers/iterationsteps/projectedgradientstep.cc index debdd8a..1cff07b 100644 --- a/dune/solvers/iterationsteps/projectedgradientstep.cc +++ b/dune/solvers/iterationsteps/projectedgradientstep.cc @@ -25,7 +25,7 @@ inline void ProjectedGradientStep<MatrixType, VectorType>::computeGeneralizedCP( for (size_t i=0; i<obstacles_->size(); i++) for (int j=0; j<blocksize; j++) { - if ((*this->ignoreNodes_)[i][j]) { + if (this->ignore()[i][j]) { projGrad[i][j]=0; continue; } diff --git a/dune/solvers/iterationsteps/projectedlinegsstep.cc b/dune/solvers/iterationsteps/projectedlinegsstep.cc index 6b806b2..dab1236 100755 --- a/dune/solvers/iterationsteps/projectedlinegsstep.cc +++ b/dune/solvers/iterationsteps/projectedlinegsstep.cc @@ -43,7 +43,7 @@ solveLocalSystem(const Dune::BTDMatrix<typename MatrixType::block_type>& matrix, ProjectedBlockGSStep<LocalMatrixType, VectorType> nonlinearSmootherStep(matrix, x, rhsCopy); - nonlinearSmootherStep.ignoreNodes_ = &ignoreNodes; + nonlinearSmootherStep.setIgnore(ignoreNodes); nonlinearSmootherStep.hasObstacle_ = &hasObstacle; nonlinearSmootherStep.obstacles_ = &localObstacles; @@ -184,7 +184,7 @@ void ProjectedLineGSStep<MatrixType, VectorType, BitVectorType>::iterate() VectorType permuted_r_i(current_block_size); for (int k=0; k<current_block_size; k++) { - if ( (*this->ignoreNodes_)[this->blockStructure_[b_num][k]][0]) + if ( this->ignore()[this->blockStructure_[b_num][k]][0]) permuted_r_i[k] = 0.0; else this->residual( this->blockStructure_[b_num][k], permuted_r_i[k]); // get r[p(i+k)] @@ -204,7 +204,7 @@ void ProjectedLineGSStep<MatrixType, VectorType, BitVectorType>::iterate() for (int j=0; j<current_block_size; j++) { - if ( (*this->ignoreNodes_)[this->blockStructure_[b_num][j]][0] ) { + if ( this->ignore()[this->blockStructure_[b_num][j]][0] ) { // left off-diagonal: if (j>0) diff --git a/dune/solvers/iterationsteps/semidefiniteblockgsstep.hh b/dune/solvers/iterationsteps/semidefiniteblockgsstep.hh index fe6dbe4..2b9cbd1 100644 --- a/dune/solvers/iterationsteps/semidefiniteblockgsstep.hh +++ b/dune/solvers/iterationsteps/semidefiniteblockgsstep.hh @@ -119,7 +119,7 @@ public: virtual void iterate() { const MatrixType& mat = *(this->mat_); const VectorType& rhs = *(this->rhs_); - const BitVectorType& ignore = *(this->ignoreNodes_); + const BitVectorType& ignore = this->ignore(); VectorType& x = *(this->x_); for (size_t i=0; i<mat.N(); ++i) { diff --git a/dune/solvers/iterationsteps/truncatedblockgsstep.hh b/dune/solvers/iterationsteps/truncatedblockgsstep.hh index 42511d8..bd9b143 100644 --- a/dune/solvers/iterationsteps/truncatedblockgsstep.hh +++ b/dune/solvers/iterationsteps/truncatedblockgsstep.hh @@ -42,7 +42,7 @@ public: //! Perform one iteration virtual void iterate() { - TruncatedBlockGSStepNS::RecursiveGSStep<MatrixType::blocklevel>::apply(*this->mat_, *this->rhs_, *this->ignoreNodes_, *this->x_, innerLoops_); + TruncatedBlockGSStepNS::RecursiveGSStep<MatrixType::blocklevel>::apply(*this->mat_, *this->rhs_, this->ignore(), *this->x_, innerLoops_); } protected: @@ -166,7 +166,7 @@ public: const LowRankMatrixType& lowrank_mat = mat.lowRankMatrix(); const VectorType& rhs = *this->rhs_; VectorType& x = *this->x_; - const BitVectorType& ignore = *this->ignoreNodes_; + const BitVectorType& ignore = this->ignore(); // compute m*x once and only add/subtract single summands in the iterations later VectorType mx(lowrank_mat.lowRankFactor().N()); diff --git a/dune/solvers/iterationsteps/truncatedsaddlepointgsstep.hh b/dune/solvers/iterationsteps/truncatedsaddlepointgsstep.hh index b47d592..2a29933 100644 --- a/dune/solvers/iterationsteps/truncatedsaddlepointgsstep.hh +++ b/dune/solvers/iterationsteps/truncatedsaddlepointgsstep.hh @@ -31,7 +31,6 @@ public: { const MatrixType& mat = *this->mat_; const VectorType& rhs = *this->rhs_; - const BitVectorType& ignore = *this->ignoreNodes_; VectorType& x = *this->x_; typedef typename VectorType::block_type VectorBlock; diff --git a/dune/solvers/iterationsteps/trustregiongsstep.cc b/dune/solvers/iterationsteps/trustregiongsstep.cc index ef95d3c..5bd9c19 100644 --- a/dune/solvers/iterationsteps/trustregiongsstep.cc +++ b/dune/solvers/iterationsteps/trustregiongsstep.cc @@ -13,10 +13,10 @@ void TrustRegionGSStep<MatrixType, VectorType>::iterate() // Dirichlet nodes in this block std::bitset<BlockSize> ignoreNodes(0); - if (this->ignoreNodes_) - ignoreNodes = (*this->ignoreNodes_)[i]; + if (this->ignoreNodes_ != nullptr) + ignoreNodes = this->ignore()[i]; - if (ignoreNodes.count() == BlockSize) + if (ignoreNodes.all()) continue; VectorBlock blockResidual; diff --git a/dune/solvers/solvers/trustregionsolver.cc b/dune/solvers/solvers/trustregionsolver.cc index 3f65815..6ed0930 100644 --- a/dune/solvers/solvers/trustregionsolver.cc +++ b/dune/solvers/solvers/trustregionsolver.cc @@ -53,7 +53,7 @@ void TrustRegionSolver<ProblemType,VectorType,MatrixType>::solve() VectorType gradient = problem_->f_; for (size_t j=0; j<gradient.size(); j++) for (int k=0; k<gradient[j].size(); k++) - if ((*mgStep->ignoreNodes_)[j][k]) + if (mgStep.ignore()[j][k]) gradient[j][k] = 0; if (this->verbosity_ == Solver::FULL) diff --git a/dune/solvers/solvers/umfpacksolver.hh b/dune/solvers/solvers/umfpacksolver.hh index 1c1becd..f2a36ac 100644 --- a/dune/solvers/solvers/umfpacksolver.hh +++ b/dune/solvers/solvers/umfpacksolver.hh @@ -70,7 +70,7 @@ public: // We may use the original rhs, but ISTL modifies it, so we need a non-const type here VectorType mutableRhs = *rhs_; - if (not this->ignoreNodes_) + if (this->ignoreNodes_ == nullptr) { ///////////////////////////////////////////////////////////////// // Solve the system @@ -93,10 +93,10 @@ public: std::set<std::size_t> nonIgnoreRows; for (size_t i=0; i<matrix_->N(); i++) { - auto ignoreCount = (*this->ignoreNodes_)[i].count(); - if (ignoreCount==0) + auto const &ignore = this->ignore()[i]; + if (ignore.none()) nonIgnoreRows.insert(i); - else if (ignoreCount!=blocksize) + else if (not ignore.all()) DUNE_THROW(Dune::NotImplemented, "Individual blocks must be either ignored completely, or not at all"); } @@ -117,14 +117,14 @@ public: shortRowCount = 0; for (size_t i=0; i<matrix_->N(); i++) { - if ((*this->ignoreNodes_)[i][0]) + if (this->ignore()[i].all()) continue; auto cIt = (*matrix_)[i].begin(); auto cEndIt = (*matrix_)[i].end(); for (; cIt!=cEndIt; ++cIt) - if ((*this->ignoreNodes_)[cIt.index()][0]) + if (this->ignore()[cIt.index()].all()) cIt->mmv((*x_)[cIt.index()], shortRhs[shortRowCount]); shortRowCount++; diff --git a/dune/solvers/test/mmgtest.cc b/dune/solvers/test/mmgtest.cc index 3b53492..56aec59 100644 --- a/dune/solvers/test/mmgtest.cc +++ b/dune/solvers/test/mmgtest.cc @@ -55,7 +55,7 @@ void solveObstacleProblemByMMGSolver(const GridType& grid, const MatrixType& mat mmgStep.setProblem(mat,x,rhs); mmgStep.setMGType(1, 3, 3); - mmgStep.ignoreNodes_ = &ignore; + mmgStep.setIgnore(ignore); mmgStep.basesolver_ = &baseSolver; mmgStep.setSmoother(&smoother); MandelObstacleRestrictor<VectorType> obsRestrictor; -- GitLab