Skip to content
Snippets Groups Projects
Commit fc8d2394 authored by Uli Sack's avatar Uli Sack Committed by usack
Browse files

adapted to recent changes in baseclass MultigridStep

[[Imported from SVN: r7378]]
parent 05d3854e
Branches
Tags
No related merge requests found
...@@ -55,7 +55,7 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration() ...@@ -55,7 +55,7 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration()
{ {
for (int i=this->numLevels_-1; i>0; i--) { for (int i=this->numLevels_-1; i>0; i--) {
Dune::BitSetVector<dim> dummy(this->rhs_[i].size(), false); Dune::BitSetVector<dim> dummy(this->rhsHierarchy_[i].size(), false);
// ///////////////////////////// // /////////////////////////////
// Restrict obstacles // Restrict obstacles
...@@ -68,7 +68,7 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration() ...@@ -68,7 +68,7 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration()
dummy); dummy);
// Restrict right hand side // Restrict right hand side
this->mgTransfer_[i-1]->restrict(this->rhs_[i], this->rhs_[i-1]); this->mgTransfer_[i-1]->restrict(this->rhsHierarchy_[i], this->rhsHierarchy_[i-1]);
} }
for (this->level_ = 0; this->level_<this->numLevels_-1; this->level_++) { for (this->level_ = 0; this->level_<this->numLevels_-1; this->level_++) {
...@@ -86,8 +86,8 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration() ...@@ -86,8 +86,8 @@ void MonotoneMGStep<MatrixType, VectorType>::nestedIteration()
std::cout << "Nested iteration on level " << this->level_ << std::endl; std::cout << "Nested iteration on level " << this->level_ << std::endl;
iterate(); iterate();
iterate(); iterate();
//std::cout << this->x_[this->level_] << std::endl; //std::cout << this->xHierarchy_[this->level_] << std::endl;
this->mgTransfer_[this->level_]->prolong(this->x_[this->level_], this->x_[this->level_+1]); this->mgTransfer_[this->level_]->prolong(this->xHierarchy_[this->level_], this->xHierarchy_[this->level_+1]);
} }
...@@ -102,12 +102,12 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -102,12 +102,12 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
int& level = this->level_; int& level = this->level_;
// Define references just for ease of notation // Define references just for ease of notation
std::vector<Dune::shared_ptr<const MatrixType> >& mat = this->mat_; std::vector<Dune::shared_ptr<const MatrixType> >& mat = this->matrixHierarchy_;
std::vector<VectorType>& x = this->x_; std::vector<Dune::shared_ptr<VectorType> >& x = this->xHierarchy_;
std::vector<VectorType>& rhs = this->rhs_; std::vector<VectorType>& rhs = this->rhsHierarchy_;
std::vector<std::vector<BoxConstraint<field_type,dim> > >& obstacles = *this->obstacles_; std::vector<std::vector<BoxConstraint<field_type,dim> > >& obstacles = *this->obstacles_;
Dune::BitSetVector<dim> critical(x[level].size(), false); Dune::BitSetVector<dim> critical(*x[level].size(), false);
// Solve directly if we're looking at the coarse problem // Solve directly if we're looking at the coarse problem
if (level == 0) { if (level == 0) {
...@@ -120,8 +120,8 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -120,8 +120,8 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
for (int j=0; j<dim; j++) { for (int j=0; j<dim; j++) {
if (obstacles[level][i].lower(j) >= x[level][i][j] - eps if (obstacles[level][i].lower(j) >= *x[level][i][j] - eps
|| obstacles[level][i].upper(j) <= x[level][i][j] + eps) { || obstacles[level][i].upper(j) <= *x[level][i][j] + eps) {
critical[i][j] = true; critical[i][j] = true;
} }
...@@ -133,7 +133,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -133,7 +133,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Presmoothing // Presmoothing
ProjectedBlockGSStep<MatrixType,VectorType>* presmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->presmoother_[level].get()); ProjectedBlockGSStep<MatrixType,VectorType>* presmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->presmoother_[level].get());
assert(presmoother); assert(presmoother);
presmoother->setProblem(*(this->mat_[level]), x[level], rhs[level]); presmoother->setProblem(*(mat[level]), *x[level], rhs[level]);
presmoother->obstacles_ = &(obstacles[level]); presmoother->obstacles_ = &(obstacles[level]);
presmoother->hasObstacle_ = &((*hasObstacle_)[level]); presmoother->hasObstacle_ = &((*hasObstacle_)[level]);
presmoother->ignoreNodes_ = this->ignoreNodesHierarchy_[level]; presmoother->ignoreNodes_ = this->ignoreNodesHierarchy_[level];
...@@ -146,7 +146,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -146,7 +146,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Compute defect obstacles // Compute defect obstacles
for (size_t i=0; i<(*obstacles_)[level].size(); i++) for (size_t i=0; i<(*obstacles_)[level].size(); i++)
obstacles[level][i] -= x[level][i]; obstacles[level][i] -= *x[level][i];
// /////////////////////// // ///////////////////////
// Truncation // Truncation
...@@ -181,13 +181,13 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -181,13 +181,13 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Restriction: fineResiduum = rhs[level] - mat[level] * x[level]; // Restriction: fineResiduum = rhs[level] - mat[level] * x[level];
// ////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////
VectorType fineResidual = rhs[level]; VectorType fineResidual = rhs[level];
mat[level]->mmv(x[level], fineResidual); mat[level]->mmv(*x[level], fineResidual);
// restrict residual // restrict residual
dynamic_cast<TruncatedMGTransfer<VectorType>*>(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 // Choose all zeros as the initial correction
x[level-1] = 0; *x[level-1] = 0;
// /////////////////////////////////////// // ///////////////////////////////////////
// Recursively solve the coarser system // Recursively solve the coarser system
...@@ -203,8 +203,8 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -203,8 +203,8 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// add correction to the presmoothed solution // add correction to the presmoothed solution
VectorType tmp; VectorType tmp;
dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[level-1])->prolong(x[level-1], tmp, critical); dynamic_cast<TruncatedMGTransfer<VectorType>*>(this->mgTransfer_[level-1])->prolong(*x[level-1], tmp, critical);
x[level] += tmp; *x[level] += tmp;
// restore the true (non-defect) obstacles // restore the true (non-defect) obstacles
obstacles[level] = obstacleBackup; obstacles[level] = obstacleBackup;
...@@ -213,11 +213,11 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -213,11 +213,11 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Debug: is the current iterate really admissible? // Debug: is the current iterate really admissible?
for (size_t i=0; i<obstacles[level].size(); i++) for (size_t i=0; i<obstacles[level].size(); i++)
for (int j=0; j<VectorType::block_type::dimension; j++) for (int j=0; j<VectorType::block_type::dimension; j++)
if (x[level][i][j] < obstacles[level][i].lower(j) if (*x[level][i][j] < obstacles[level][i].lower(j)
|| x[level][i][j] > obstacles[level][i].upper(j)) { || *x[level][i][j] > obstacles[level][i].upper(j)) {
std::cout << "Obstacle disregarded!\n"; std::cout << "Obstacle disregarded!\n";
std::cout << x[level][i] << std::endl << obstacles[level][i] << std::endl; std::cout << *x[level][i] << std::endl << obstacles[level][i] << std::endl;
printf("level: %d index: %d komponent: %d\n", level, i, j); printf("level: %d index: %d komponent: %d\n", level, i, j);
printf("is %s critical\n", (critical[i][j]) ? "" : "not"); printf("is %s critical\n", (critical[i][j]) ? "" : "not");
} }
...@@ -226,7 +226,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -226,7 +226,7 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Postsmoothing // Postsmoothing
ProjectedBlockGSStep<MatrixType,VectorType>* postsmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->postsmoother_[level].get()); ProjectedBlockGSStep<MatrixType,VectorType>* postsmoother = dynamic_cast<ProjectedBlockGSStep<MatrixType, VectorType>*>(this->postsmoother_[level].get());
assert(postsmoother); assert(postsmoother);
postsmoother->setProblem(*(mat[level]), x[level], rhs[level]); postsmoother->setProblem(*(mat[level]), *x[level], rhs[level]);
postsmoother->obstacles_ = &obstacles[level]; postsmoother->obstacles_ = &obstacles[level];
postsmoother->hasObstacle_ = &((*hasObstacle_)[level]); postsmoother->hasObstacle_ = &((*hasObstacle_)[level]);
postsmoother->ignoreNodes_ = this->ignoreNodesHierarchy_[level]; postsmoother->ignoreNodes_ = this->ignoreNodesHierarchy_[level];
...@@ -256,6 +256,6 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate() ...@@ -256,6 +256,6 @@ void MonotoneMGStep<MatrixType, VectorType>::iterate()
// Debug: output energy // Debug: output energy
if (level==this->numLevels_-1 && this->verbosity_==NumProc::FULL) if (level==this->numLevels_-1 && this->verbosity_==NumProc::FULL)
std::cout << "Total energy: " std::cout << "Total energy: "
<< std::setprecision(10) << computeEnergy(*mat[level], x[level], rhs[level]) << std::endl; << std::setprecision(10) << computeEnergy(*mat[level], *x[level], rhs[level]) << std::endl;
} }
...@@ -22,27 +22,44 @@ public: ...@@ -22,27 +22,44 @@ public:
MonotoneMGStep() {} MonotoneMGStep() {}
MonotoneMGStep(int numLevels) { MonotoneMGStep(int numLevels)
this->setNumberOfLevels(numLevels); DUNE_DEPRECATED_MSG("The number of levels is no longer set explicitely, but instead inferred from the number of transfer operators. Just erase the number of levels from the argument list in your constructor call.") :
} {}
MonotoneMGStep(const MatrixType& mat, MonotoneMGStep(const MatrixType& mat,
VectorType& x, VectorType& x,
VectorType& rhs, int numLevels) VectorType& rhs, int numLevels)
DUNE_DEPRECATED_MSG("The number of levels is no longer set explicitely, but instead inferred from the number of transfer operators. Just erase the number of levels from the argument list in your constructor call.") :
: MultigridStep<MatrixType, VectorType>(mat, x, rhs, numLevels) : MultigridStep<MatrixType, VectorType>(mat, x, rhs, numLevels)
{ {
oldCritical.resize(x.size(), false); oldCritical.resize(x.size(), false);
} }
MonotoneMGStep(const MatrixType& mat,
VectorType& x,
VectorType& rhs)
: MultigridStep<MatrixType, VectorType>(mat, x, rhs)
{
oldCritical.resize(x.size(), false);
}
virtual ~MonotoneMGStep() {} virtual ~MonotoneMGStep() {}
virtual void setProblem(const MatrixType& mat, virtual void setProblem(const MatrixType& mat,
VectorType& x, VectorType& x,
VectorType& rhs, VectorType& rhs,
int numLevels) int numLevels)
DUNE_DEPRECATED_MSG("Use setProblem(const MatrixType& mat,VectorType& x,const VectorType& rhs). The number of levels is no longer set explicitely, but instead inferred from the number of transfer operators.")
{
MultigridStep<MatrixType, VectorType>::setProblem(mat,x,rhs);
oldCritical.resize(x.size(), false);
}
virtual void setProblem(const MatrixType& mat,
VectorType& x,
VectorType& rhs)
{ {
MultigridStep<MatrixType, VectorType>::setProblem(mat,x,rhs, numLevels); MultigridStep<MatrixType, VectorType>::setProblem(mat,x,rhs);
oldCritical.resize(x.size(), false); oldCritical.resize(x.size(), false);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment