From: Matthias Maier Date: Wed, 15 Apr 2015 15:43:45 +0000 (+0200) Subject: refactor internal helper classes X-Git-Tag: v8.3.0-rc1~242^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7baa46a8aebf08da5be530af23e23b8fb93837c9;p=dealii.git refactor internal helper classes --- diff --git a/include/deal.II/lac/block_vector.h b/include/deal.II/lac/block_vector.h index cf8800f5fc..0690e456da 100644 --- a/include/deal.II/lac/block_vector.h +++ b/include/deal.II/lac/block_vector.h @@ -23,7 +23,6 @@ #include #include -#include #include DEAL_II_NAMESPACE_OPEN @@ -461,57 +460,42 @@ void swap (BlockVector &u, } -#ifdef DEAL_II_WITH_CXX11 - namespace internal { namespace LinearOperator { - template class ReinitRangeFactory; - template class ReinitDomainFactory; + template class ReinitHelper; /** - * A factory class internally used in linear_operator.h. + * A helper class internally used in linear_operator.h. * Specialization for BlockVector. */ template - class ReinitRangeFactory > + class ReinitHelper > { public: template - std::function &, bool)> - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, + BlockVector &v, + bool fast) { - return [&matrix](BlockVector &v, bool fast) - { - v.reinit(matrix.get_row_indices(), fast); - }; + v.reinit(matrix.get_row_indices(), fast); } - }; - /** - * A factory class internally used in linear_operator.h. - * Specialization for BlockVector. - */ - template - class ReinitDomainFactory > - { - public: template - std::function &, bool)> - operator()(const Matrix &matrix) + static + void reinit_domain_vector(const Matrix &matrix, + BlockVector &v, + bool fast) { - return [&matrix](BlockVector &v, bool fast) - { - v.reinit(matrix.get_column_indices(), fast); - }; + v.reinit(matrix.get_column_indices(), fast); } }; + } /* namespace LinearOperator */ } /* namespace internal */ -#endif /* DEAL_II_WITH_CXX11 */ - DEAL_II_NAMESPACE_CLOSE #endif diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index cc532ff610..26d3ba2133 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -183,26 +183,26 @@ public: * Application of the LinearOperator object to a vector u of the @tref * Domain space giving a vector v of the @tref Range space. */ - std::function vmult; + std::function vmult; /** * Application of the LinearOperator object to a vector u of the @tref * Domain space. The result is added to the vector v. */ - std::function vmult_add; + std::function vmult_add; /** * Application of the transpose LinearOperator object to a vector u of * the @tref Range space giving a vector v of the @tref Domain * space. */ - std::function Tvmult; + std::function Tvmult; /** * Application of the transpose LinearOperator object to a vector @p u of * the @tref Range space.The result is added to the vector @p v. */ - std::function Tvmult_add; + std::function Tvmult_add; /** * Initializes a vector v of the Range space to be directly usable @@ -898,53 +898,54 @@ namespace internal namespace LinearOperator { /** - * A factory class that is responsible for the creation of a - * reinit_range_vector object for a given pair of vector type Range and matrix - * type Matrix. + * A helper class that is responsible for the initialization of a + * vector to be directly usable as the destination parameter, or source + * parameter in an application of vmult of a matrix. * * The generic version of this class just calls - * Range::reinit() with the result of - * Matrix::m(). This class is specialized for more complicated - * data structures, such as TrilinosWrappers::MPI::Vector, etc. + * Vector::reinit() with the result of + * Matrix::m() or Matrix::n(), respectively. + * This class is specialized for more complicated data structures, such + * as TrilinosWrappers::MPI::Vector, etc. */ - template - class ReinitRangeFactory + template + class ReinitHelper { public: + /** + * Initializes a vector v of the Range space to be directly usable + * as the destination parameter in an application of vmult. Similar to + * the reinit functions of the vector classes, the boolean determines + * whether a fast initalization is done, i.e., if it is set to false the + * content of the vector is set to 0. + * + * The generic version of this class just calls + * Vector::reinit() with the result of + * Matrix::m(). + */ template - std::function - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, Vector &v, bool fast) { - return [&matrix](Range &v, bool fast) - { - v.reinit(matrix.m(), fast); - }; + v.reinit(matrix.m(), fast); } - }; - - /** - * A factory class that is responsible for the creation of a - * reinit_domain_vector object for a given pair of vector type Domain and - * matrix type Matrix. - * - * The generic version of this class just calls - * Domain::reinit() with the result of - * Matrix::n(). This class is specialized for more complicated - * data structures, such as TrilinosWrappers::MPI::Vector, etc. - */ - template - class ReinitDomainFactory - { - public: + /** + * Initializes a vector of the Domain space to be directly usable as the + * source parameter in an application of vmult. Similar to the reinit + * functions of the vector classes, the boolean determines whether a fast + * initalization is done, i.e., if it is set to false the content of the + * vector is set to 0. + * + * The generic version of this class just calls + * Vector::reinit() with the result of + * Matrix::n(). + */ template - std::function - operator()(const Matrix &matrix) + static + void reinit_domain_vector (const Matrix &matrix, Vector &v, bool fast) { - return [&matrix](Domain &v, bool fast) - { - v.reinit(matrix.n(), fast); - }; + v.reinit(matrix.n(), fast); } }; } /* namespace LinearOperator */ @@ -1157,13 +1158,15 @@ linear_operator(const OperatorExemplar &operator_exemplar, // creation of a LinearOperator wrapper is respected - further a matrix // or an operator_exemplar cannot usually be copied... - return_op.reinit_range_vector = - internal::LinearOperator::ReinitRangeFactory().operator()( - operator_exemplar); + return_op.reinit_range_vector = [&operator_exemplar](Range &v, bool fast) + { + internal::LinearOperator::ReinitHelper::reinit_range_vector(operator_exemplar, v, fast); + }; - return_op.reinit_domain_vector = - internal::LinearOperator::ReinitDomainFactory().operator()( - operator_exemplar); + return_op.reinit_domain_vector = [&operator_exemplar](Domain &v, bool fast) + { + internal::LinearOperator::ReinitHelper::reinit_domain_vector(operator_exemplar, v, fast); + }; typename std::conditional< has_vmult_add::type::value, diff --git a/include/deal.II/lac/trilinos_block_vector.h b/include/deal.II/lac/trilinos_block_vector.h index 277a56f410..90c2d703ff 100644 --- a/include/deal.II/lac/trilinos_block_vector.h +++ b/include/deal.II/lac/trilinos_block_vector.h @@ -27,8 +27,6 @@ # include # include -# include - DEAL_II_NAMESPACE_OPEN // forward declaration @@ -454,57 +452,42 @@ namespace TrilinosWrappers /*@}*/ -#ifdef DEAL_II_WITH_CXX11 - namespace internal { namespace LinearOperator { - template class ReinitRangeFactory; - template class ReinitDomainFactory; + template class ReinitHelper; /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::BlockVector. + * A helper class internally used in linear_operator.h. + * Specialization for TrilinosWrappers::BlockVector. */ template<> - class ReinitRangeFactory + class ReinitHelper { public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, + TrilinosWrappers::BlockVector &v, + bool fast) { - return [&matrix](TrilinosWrappers::BlockVector &v, bool fast) - { - v.reinit(matrix.range_partitioner(), fast); - }; + v.reinit(matrix.range_partitioner(), fast); } - }; - /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::BlockVector. - */ - template<> - class ReinitDomainFactory - { - public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_domain_vector(const Matrix &matrix, + TrilinosWrappers::BlockVector &v, + bool fast) { - return [&matrix](TrilinosWrappers::BlockVector &v, bool fast) - { - v.reinit(matrix.domain_partitioner(), fast); - }; + v.reinit(matrix.domain_partitioner(), fast); } }; + } /* namespace LinearOperator */ } /* namespace internal */ -#endif /* DEAL_II_WITH_CXX11 */ - DEAL_II_NAMESPACE_CLOSE diff --git a/include/deal.II/lac/trilinos_parallel_block_vector.h b/include/deal.II/lac/trilinos_parallel_block_vector.h index 59a52b1346..a604916467 100644 --- a/include/deal.II/lac/trilinos_parallel_block_vector.h +++ b/include/deal.II/lac/trilinos_parallel_block_vector.h @@ -469,57 +469,42 @@ namespace TrilinosWrappers /*@}*/ -#ifdef DEAL_II_WITH_CXX11 - namespace internal { namespace LinearOperator { - template class ReinitRangeFactory; - template class ReinitDomainFactory; + template class ReinitHelper; /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::BlockVector. + * A helper class internally used in linear_operator.h. + * Specialization for TrilinosWrappers::MPI::BlockVector. */ template<> - class ReinitRangeFactory + class ReinitHelper { public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, + TrilinosWrappers::MPI::BlockVector &v, + bool fast) { - return [&matrix](TrilinosWrappers::MPI::BlockVector &v, bool fast) - { - v.reinit(matrix.range_partitioner(), fast); - }; + v.reinit(matrix.range_partitioner(), fast); } - }; - /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::BlockVector. - */ - template<> - class ReinitDomainFactory - { - public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_domain_vector(const Matrix &matrix, + TrilinosWrappers::MPI::BlockVector &v, + bool fast) { - return [&matrix](TrilinosWrappers::MPI::BlockVector &v, bool fast) - { - v.reinit(matrix.domain_partitioner(), fast); - }; + v.reinit(matrix.domain_partitioner(), fast); } }; + } /* namespace LinearOperator */ } /* namespace internal */ -#endif /* DEAL_II_WITH_CXX11 */ - DEAL_II_NAMESPACE_CLOSE diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index c61bac8536..b91cc94844 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -34,8 +34,6 @@ DEAL_II_DISABLE_EXTRA_DIAGNOSTICS # include "Epetra_LocalMap.h" DEAL_II_ENABLE_EXTRA_DIAGNOSTICS -# include - DEAL_II_NAMESPACE_OPEN @@ -942,95 +940,69 @@ namespace TrilinosWrappers /*@}*/ -#ifdef DEAL_II_WITH_CXX11 - namespace internal { namespace LinearOperator { - template class ReinitRangeFactory; - template class ReinitDomainFactory; + template class ReinitHelper; /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::Vector. + * A helper class internally used in linear_operator.h. + * Specialization for TrilinosWrappers::MPI::Vector. */ template<> - class ReinitRangeFactory + class ReinitHelper { public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, + TrilinosWrappers::MPI::Vector &v, + bool fast) { - return [&matrix](TrilinosWrappers::MPI::Vector &v, bool fast) - { - v.reinit(matrix.range_partitioner(), fast); - }; + v.reinit(matrix.range_partitioner(), fast); } - }; - /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::Vector. - */ - template<> - class ReinitDomainFactory - { - public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_domain_vector(const Matrix &matrix, + TrilinosWrappers::MPI::Vector &v, + bool fast) { - return [&matrix](TrilinosWrappers::MPI::Vector &v, bool fast) - { - v.reinit(matrix.domain_partitioner(), fast); - }; + v.reinit(matrix.domain_partitioner(), fast); } }; /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::Vector. + * A helper class internally used in linear_operator.h. + * Specialization for TrilinosWrappers::Vector. */ template<> - class ReinitRangeFactory + class ReinitHelper { public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_range_vector (const Matrix &matrix, + TrilinosWrappers::Vector &v, + bool fast) { - return [&matrix](TrilinosWrappers::Vector &v, bool fast) - { - v.reinit(matrix.range_partitioner(), fast); - }; + v.reinit(matrix.range_partitioner(), fast); } - }; - /** - * A factory class internally used in linear_operator.h. Specialization - * for TrilinosWrappers::MPI::Vector. - */ - template<> - class ReinitDomainFactory - { - public: template - std::function - operator()(const Matrix &matrix) + static + void reinit_domain_vector(const Matrix &matrix, + TrilinosWrappers::Vector &v, + bool fast) { - return [&matrix](TrilinosWrappers::Vector &v, bool fast) - { - v.reinit(matrix.domain_partitioner(), fast); - }; + v.reinit(matrix.domain_partitioner(), fast); } }; + } /* namespace LinearOperator */ } /* namespace internal */ -#endif /* DEAL_II_WITH_CXX11 */ - DEAL_II_NAMESPACE_CLOSE