From 09342e44780a7269ae5b884f9e5a143805c29a4c Mon Sep 17 00:00:00 2001 From: Jonathan Robey Date: Tue, 20 Sep 2016 11:30:24 -0700 Subject: [PATCH] Change MGSmootherBlock to use shared memory pool, deprecate old constructor Test modified to use new constructor --- include/deal.II/multigrid/mg_block_smoother.h | 142 +++++++----------- tests/multigrid/smoother_block.cc | 2 +- 2 files changed, 52 insertions(+), 92 deletions(-) diff --git a/include/deal.II/multigrid/mg_block_smoother.h b/include/deal.II/multigrid/mg_block_smoother.h index 1408e90a94..9a8d9e7f37 100644 --- a/include/deal.II/multigrid/mg_block_smoother.h +++ b/include/deal.II/multigrid/mg_block_smoother.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include @@ -45,14 +45,26 @@ DEAL_II_NAMESPACE_OPEN */ template class MGSmootherBlock - : public MGSmootherBase > + : public MGSmoother > { public: /** + * @deprecated Since GrowingVectorMemory now uses a joint memory pool, it is + * recommended to use the constructor without the memory object. + * * Constructor. Sets memory and smoothing parameters. */ MGSmootherBlock (VectorMemory > &mem, const unsigned int steps = 1, + const bool variable = false, + const bool symmetric = false, + const bool transpose = false, + const bool reverse = false) DEAL_II_DEPRECATED; + + /** + * Constructor. + */ + MGSmootherBlock (const unsigned int steps = 1, const bool variable = false, const bool symmetric = false, const bool transpose = false, @@ -80,26 +92,6 @@ public: */ void clear (); - /** - * Modify the number of smoothing steps on finest level. - */ - void set_steps (const unsigned int); - - /** - * Switch on/off variable smoothing. - */ - void set_variable (const bool); - - /** - * Switch on/off symmetric smoothing. - */ - void set_symmetric (const bool); - - /** - * Switch on/off transposed. This is mutually exclusive with reverse(). - */ - void set_transpose (const bool); - /** * Switch on/off reversed. This is mutually exclusive with transpose(). */ @@ -113,6 +105,11 @@ public: virtual void smooth (const unsigned int level, BlockVector &u, const BlockVector &rhs) const; + + /** + * Memory used by this object. + */ + std::size_t memory_consumption () const; private: /** * Pointer to the matrices. @@ -124,26 +121,6 @@ private: */ MGLevelObject > > smoothers; - /** - * Number of smoothing steps. - */ - unsigned int steps; - - /** - * Variable smoothing? - */ - bool variable; - - /** - * Symmetric smoothing? - */ - bool symmetric; - - /* - * Transposed? - */ - bool transpose; - /** * Reverse? */ @@ -152,8 +129,7 @@ private: /** * Memory for auxiliary vectors. */ - VectorMemory > &mem; - + SmartPointer >, MGSmootherBlock > mem; }; /**@}*/ @@ -171,13 +147,22 @@ MGSmootherBlock::MGSmootherBlock const bool symmetric, const bool transpose, const bool reverse) - : - steps(steps), - variable(variable), - symmetric(symmetric), - transpose(transpose), - reverse(reverse), - mem(mem) + : MGSmoother >(steps, variable, symmetric, transpose), + reverse(reverse), + mem(&mem) +{} + +template +inline +MGSmootherBlock::MGSmootherBlock +(const unsigned int steps, + const bool variable, + const bool symmetric, + const bool transpose, + const bool reverse) + : MGSmoother >(steps, variable, symmetric, transpose), + reverse(reverse), + mem(&this->vector_memory) {} @@ -214,48 +199,25 @@ MGSmootherBlock::initialize (const MGMatrixT } } -template -inline void -MGSmootherBlock:: -set_steps (const unsigned int s) -{ - steps = s; -} - - -template -inline void -MGSmootherBlock:: -set_variable (const bool flag) -{ - variable = flag; -} - template inline void MGSmootherBlock:: -set_symmetric (const bool flag) -{ - symmetric = flag; -} - - -template -inline void -MGSmootherBlock:: -set_transpose (const bool flag) +set_reverse (const bool flag) { - transpose = flag; + reverse = flag; } template -inline void +inline std::size_t MGSmootherBlock:: -set_reverse (const bool flag) +memory_consumption () const { - reverse = flag; + return sizeof(*this) + + matrices.memory_consumption() + + smoothers.memory_consumption() + + this->vector_memory.memory_consumption(); } @@ -268,18 +230,18 @@ MGSmootherBlock::smooth(const unsigned int deallog.push("Smooth"); unsigned int maxlevel = matrices.max_level(); - unsigned int steps2 = steps; + unsigned int steps2 = this->steps; - if (variable) + if (this->variable) steps2 *= (1<<(maxlevel-level)); - BlockVector *r = mem.alloc(); - BlockVector *d = mem.alloc(); + typename VectorMemory >::Pointer r(*this->mem); + typename VectorMemory >::Pointer d(*this->mem); r->reinit(u); d->reinit(u); - bool T = transpose; - if (symmetric && (steps2 % 2 == 0)) + bool T = this->transpose; + if (this->symmetric && (steps2 % 2 == 0)) T = false; for (unsigned int i=0; i::smooth(const unsigned int smoothers[level].vmult(*d, *r); } u += *d; - if (symmetric) + if (this->symmetric) T = !T; } - mem.free(r); - mem.free(d); deallog.pop(); } diff --git a/tests/multigrid/smoother_block.cc b/tests/multigrid/smoother_block.cc index cf247e10dc..84a86cecf2 100644 --- a/tests/multigrid/smoother_block.cc +++ b/tests/multigrid/smoother_block.cc @@ -126,7 +126,7 @@ void check_smoother(const MGLevelObject &m, const MGLevelObject &r) { GrowingVectorMemory > mem; - MGSmootherBlock smoother(mem); + MGSmootherBlock smoother; smoother.initialize(m, r); -- 2.39.5