diff --git a/dune/solvers/iterationsteps/mmgstep.cc b/dune/solvers/iterationsteps/mmgstep.cc index 982b6b8fdcd0484151ac4f219c382d2dba30c547..1fb98e6d66eba7e7a2d0e484fab46f22c91b1637 100644 --- a/dune/solvers/iterationsteps/mmgstep.cc +++ b/dune/solvers/iterationsteps/mmgstep.cc @@ -8,12 +8,12 @@ #include <dune/solvers/solvers/quadraticipopt.hh> #endif -template <class OperatorType, class DiscFuncType> -void MonotoneMGStep<OperatorType, DiscFuncType>:: +template <class MatrixType, class VectorType> +void MonotoneMGStep<MatrixType, VectorType>:: preprocess() { // Call preprocess of the base class - MultigridStep<OperatorType,DiscFuncType>::preprocess(); + MultigridStep<MatrixType,VectorType>::preprocess(); // Then specify the subset of entries to be reassembled at each iteration recompute_.resize(this->numLevels_); @@ -23,24 +23,24 @@ preprocess() for (size_t i=0; i<this->mgTransfer_.size(); i++) - dynamic_cast<TruncatedMGTransfer<DiscFuncType>*>(this->mgTransfer_[i])->recompute_ = &recompute_[i]; + dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[i])->recompute_ = &recompute_[i]; // ///////////////////////////////////////////// // Set up base solver // ///////////////////////////////////////////// - if (typeid(*this->basesolver_) == typeid(LoopSolver<DiscFuncType>)) { + if (typeid(*this->basesolver_) == typeid(LoopSolver<VectorType>)) { - LoopSolver<DiscFuncType>* loopBaseSolver = dynamic_cast<LoopSolver<DiscFuncType>* > (this->basesolver_); + LoopSolver<VectorType>* loopBaseSolver = dynamic_cast<LoopSolver<VectorType>* > (this->basesolver_); - typedef ProjectedBlockGSStep<OperatorType, DiscFuncType> SmootherType; + typedef ProjectedBlockGSStep<MatrixType, VectorType> SmootherType; dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->hasObstacle_ = &(*hasObstacle_)[0]; dynamic_cast<SmootherType*>(loopBaseSolver->iterationStep_)->obstacles_ = &(*obstacles_)[0]; #ifdef HAVE_IPOPT - } else if (typeid(*this->basesolver_) == typeid(QuadraticIPOptSolver<OperatorType,DiscFuncType>)) { + } else if (typeid(*this->basesolver_) == typeid(QuadraticIPOptSolver<MatrixType,VectorType>)) { - QuadraticIPOptSolver<OperatorType,DiscFuncType>* ipoptBaseSolver = dynamic_cast<QuadraticIPOptSolver<OperatorType,DiscFuncType>*> (this->basesolver_); + QuadraticIPOptSolver<MatrixType,VectorType>* ipoptBaseSolver = dynamic_cast<QuadraticIPOptSolver<MatrixType,VectorType>*> (this->basesolver_); ipoptBaseSolver->obstacles_ = &(*obstacles_)[0]; #endif @@ -50,8 +50,8 @@ preprocess() } } -template<class OperatorType, class DiscFuncType> -void MonotoneMGStep<OperatorType, DiscFuncType>::nestedIteration() +template<class MatrixType, class VectorType> +void MonotoneMGStep<MatrixType, VectorType>::nestedIteration() { for (int i=this->numLevels_-1; i>0; i--) { @@ -94,17 +94,17 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::nestedIteration() } -template <class OperatorType, class DiscFuncType> -void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() +template <class MatrixType, class VectorType> +void MonotoneMGStep<MatrixType, VectorType>::iterate() { this->preprocessCalled = false; int& level = this->level_; // Define references just for ease of notation - std::vector<Dune::shared_ptr<const OperatorType> >& mat = this->mat_; - std::vector<DiscFuncType>& x = this->x_; - std::vector<DiscFuncType>& rhs = this->rhs_; + std::vector<Dune::shared_ptr<const MatrixType> >& mat = this->mat_; + std::vector<VectorType>& x = this->x_; + std::vector<VectorType>& rhs = this->rhs_; std::vector<std::vector<BoxConstraint<field_type,dim> > >& obstacles = *this->obstacles_; Dune::BitSetVector<dim> critical(x[level].size(), false); @@ -131,7 +131,7 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() } else { // Presmoothing - ProjectedBlockGSStep<OperatorType,DiscFuncType>* presmoother = dynamic_cast<ProjectedBlockGSStep<OperatorType, DiscFuncType>*>(this->presmoother_[level].get()); + ProjectedBlockGSStep<MatrixType,VectorType>* presmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->presmoother_[level].get()); assert(presmoother); presmoother->setProblem(*(this->mat_[level]), x[level], rhs[level]); presmoother->obstacles_ = &(obstacles[level]); @@ -168,8 +168,8 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() // Restrict stiffness matrix - dynamic_cast<TruncatedMGTransfer<DiscFuncType>*>(this->mgTransfer_[level-1]) - ->galerkinRestrict(*(mat[level]), *(const_cast<OperatorType*>(mat[level-1].get())), critical); + dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[level-1]) + ->galerkinRestrict(*(mat[level]), *(const_cast<MatrixType*>(mat[level-1].get())), critical); // Restrict obstacles obstacleRestrictor_->restrict(obstacles[level], obstacles[level-1], @@ -180,11 +180,11 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() // ////////////////////////////////////////////////////////////////////// // Restriction: fineResiduum = rhs[level] - mat[level] * x[level]; // ////////////////////////////////////////////////////////////////////// - DiscFuncType fineResidual = rhs[level]; + VectorType fineResidual = rhs[level]; mat[level]->mmv(x[level], fineResidual); // restrict residual - dynamic_cast<TruncatedMGTransfer<DiscFuncType>*>(this->mgTransfer_[level-1])->restrict(fineResidual, rhs[level-1], critical); + dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[level-1])->restrict(fineResidual, rhs[level-1], critical); // Choose all zeros as the initial correction x[level-1] = 0; @@ -202,8 +202,8 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() // //////////////////////////////////////// // add correction to the presmoothed solution - DiscFuncType tmp; - dynamic_cast<TruncatedMGTransfer<DiscFuncType>*>(this->mgTransfer_[level-1])->prolong(x[level-1], tmp, critical); + VectorType tmp; + dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[level-1])->prolong(x[level-1], tmp, critical); x[level] += tmp; // restore the true (non-defect) obstacles @@ -212,7 +212,7 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() #ifndef NDEBUG // Debug: is the current iterate really admissible? for (size_t i=0; i<obstacles[level].size(); i++) - for (int j=0; j<DiscFuncType::block_type::dimension; j++) + for (int j=0; j<VectorType::block_type::dimension; j++) if (x[level][i][j] < obstacles[level][i].lower(j) || x[level][i][j] > obstacles[level][i].upper(j)) { @@ -224,7 +224,7 @@ void MonotoneMGStep<OperatorType, DiscFuncType>::iterate() #endif // Postsmoothing - ProjectedBlockGSStep<OperatorType,DiscFuncType>* postsmoother = dynamic_cast<ProjectedBlockGSStep<OperatorType, DiscFuncType>*>(this->postsmoother_[level].get()); + ProjectedBlockGSStep<MatrixType,VectorType>* postsmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->postsmoother_[level].get()); assert(postsmoother); postsmoother->setProblem(*(mat[level]), x[level], rhs[level]); postsmoother->obstacles_ = &obstacles[level]; diff --git a/dune/solvers/iterationsteps/mmgstep.hh b/dune/solvers/iterationsteps/mmgstep.hh index 25c5ddb2fa3e5049a51d64fc7b9a475fe59da0e6..a50f08fab40f5bdae574b4a067e7e3b222e2e37d 100644 --- a/dune/solvers/iterationsteps/mmgstep.hh +++ b/dune/solvers/iterationsteps/mmgstep.hh @@ -10,13 +10,13 @@ /** \brief The general monotone multigrid solver */ -template<class OperatorType, class DiscFuncType> -class MonotoneMGStep : public MultigridStep<OperatorType, DiscFuncType> +template<class MatrixType, class VectorType> +class MonotoneMGStep : public MultigridStep<MatrixType, VectorType> { - static const int dim = DiscFuncType::block_type::dimension; + static const int dim = VectorType::block_type::dimension; - typedef typename DiscFuncType::field_type field_type; + typedef typename VectorType::field_type field_type; public: @@ -27,22 +27,22 @@ public: } - MonotoneMGStep(const OperatorType& mat, - DiscFuncType& x, - DiscFuncType& rhs, int numLevels) - : MultigridStep<OperatorType, DiscFuncType>(mat, x, rhs, numLevels) + MonotoneMGStep(const MatrixType& mat, + VectorType& x, + VectorType& rhs, int numLevels) + : MultigridStep<MatrixType, VectorType>(mat, x, rhs, numLevels) { oldCritical.resize(x.size(), false); } virtual ~MonotoneMGStep() {} - virtual void setProblem(const OperatorType& mat, - DiscFuncType& x, - DiscFuncType& rhs, + virtual void setProblem(const MatrixType& mat, + VectorType& x, + VectorType& rhs, int numLevels) { - MultigridStep<OperatorType, DiscFuncType>::setProblem(mat,x,rhs, numLevels); + MultigridStep<MatrixType, VectorType>::setProblem(mat,x,rhs, numLevels); oldCritical.resize(x.size(), false); } @@ -52,7 +52,7 @@ public: virtual void nestedIteration(); - ObstacleRestrictor<DiscFuncType>* obstacleRestrictor_; + ObstacleRestrictor<VectorType>* obstacleRestrictor_; std::vector<Dune::BitSetVector<1> >* hasObstacle_;