/**
* Memory for auxiliary vectors.
*/
- VectorMemory<VECTOR>& mem;
+ SmartPointer<VectorMemory<VECTOR>, MGSmoother<VECTOR> > mem;
};
symmetric(symmetric),
transpose(transpose),
debug(0),
- mem(mem)
+ mem(&mem)
{}
if (this->variable)
steps2 *= (1<<(maxlevel-level));
-
- VECTOR* r = this->mem.alloc();
- VECTOR* d = this->mem.alloc();
+
+ GrowingVectorMemory<VECTOR> mem2;
+ typename VectorMemory<VECTOR>::Pointer r((this->mem) ? *this->mem : mem2);
+ typename VectorMemory<VECTOR>::Pointer d((this->mem) ? *this->mem : mem2);
r->reinit(u);
d->reinit(u);
}
if (this->debug > 0)
deallog << std::endl;
-
- this->mem.free(r);
- this->mem.free(d);
}
#else
return sizeof(*this)
+ matrices.memory_consumption()
+ smoothers.memory_consumption()
- + this->mem.memory_consumption();
+ + this->mem->memory_consumption();
}
if (this->variable)
steps2 *= (1<<(maxlevel-level));
- VECTOR* r = this->mem.alloc();
- VECTOR* d = this->mem.alloc();
+ GrowingVectorMemory<VECTOR> mem2;
+ typename VectorMemory<VECTOR>::Pointer r((this->mem) ? *this->mem : mem2);
+ typename VectorMemory<VECTOR>::Pointer d((this->mem) ? *this->mem : mem2);
- try
+ r->reinit(u,true);
+ d->reinit(u,true);
+
+ bool T = this->transpose;
+ if (this->symmetric && (steps2 % 2 == 0))
+ T = false;
+ if (this->debug > 0)
+ deallog << 'S' << level << ' ';
+
+ for (unsigned int i=0; i<steps2; ++i)
{
- r->reinit(u,true);
- d->reinit(u,true);
-
- bool T = this->transpose;
- if (this->symmetric && (steps2 % 2 == 0))
- T = false;
- if (this->debug > 0)
- deallog << 'S' << level << ' ';
-
- for (unsigned int i=0; i<steps2; ++i)
+ if (T)
{
- if (T)
- {
- if (this->debug > 0)
- deallog << 'T';
- matrices[level].Tvmult(*r,u);
- r->sadd(-1.,1.,rhs);
- if (this->debug > 2)
- deallog << ' ' << r->l2_norm() << ' ';
- smoothers[level].Tvmult(*d, *r);
- if (this->debug > 1)
- deallog << ' ' << d->l2_norm() << ' ';
- } else {
- if (this->debug > 0)
- deallog << 'N';
- matrices[level].vmult(*r,u);
- r->sadd(-1.,rhs);
- if (this->debug > 2)
- deallog << ' ' << r->l2_norm() << ' ';
- smoothers[level].vmult(*d, *r);
- if (this->debug > 1)
- deallog << ' ' << d->l2_norm() << ' ';
- }
- u += *d;
- if (this->symmetric)
- T = !T;
- }
- if (this->debug > 0)
- deallog << std::endl;
-
- this->mem.free(r);
- this->mem.free(d);
- }
- catch (...)
- {
- // make sure we don't produce a
- // memory leak
- this->mem.free(r);
- this->mem.free(d);
-
- throw;
+ if (this->debug > 0)
+ deallog << 'T';
+ matrices[level].Tvmult(*r,u);
+ r->sadd(-1.,1.,rhs);
+ if (this->debug > 2)
+ deallog << ' ' << r->l2_norm() << ' ';
+ smoothers[level].Tvmult(*d, *r);
+ if (this->debug > 1)
+ deallog << ' ' << d->l2_norm() << ' ';
+ } else {
+ if (this->debug > 0)
+ deallog << 'N';
+ matrices[level].vmult(*r,u);
+ r->sadd(-1.,rhs);
+ if (this->debug > 2)
+ deallog << ' ' << r->l2_norm() << ' ';
+ smoothers[level].vmult(*d, *r);
+ if (this->debug > 1)
+ deallog << ' ' << d->l2_norm() << ' ';
+ }
+ u += *d;
+ if (this->symmetric)
+ T = !T;
}
+ if (this->debug > 0)
+ deallog << std::endl;
}
return sizeof(*this)
+ matrices.memory_consumption()
+ smoothers.memory_consumption()
- + this->mem.memory_consumption();
+ + this->mem->memory_consumption();
}