From 5881ba50eccadbc627e82beee9241bc2107c3faa Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 3 Jul 2015 15:28:19 +0200 Subject: [PATCH] Restructure null_operator This commit restructures the null_operator optimization in LinearOperator slightly and removes an ambiguous constructor variant. --- include/deal.II/lac/linear_operator.h | 77 ++++++++------------------- tests/lac/linear_operator_01.cc | 2 +- 2 files changed, 23 insertions(+), 56 deletions(-) diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index 71b44f5db1..f705e4997b 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -49,12 +49,7 @@ LinearOperator linear_operator (const Matrix &); template , typename Range = Domain> LinearOperator -null_operator(const std::function &, - const std::function &); - -template > -LinearOperator -null_operator(const std::function &); +null_operator(const LinearOperator &); /** @@ -120,9 +115,9 @@ public: * member objects are initialized with default variants that throw an * exception upon invocation. */ - LinearOperator (bool is_null_operator=false) + LinearOperator() : - is_null_operator(is_null_operator) + is_null_operator(false) { vmult = [](Range &, const Domain &) @@ -425,9 +420,7 @@ operator*(typename Range::value_type number, } else if (number == 0.) { - LinearOperator return_op = op; - return_op.is_null_operator = true; - return return_op; + return null_operator(op); } else { @@ -517,7 +510,10 @@ operator*(const LinearOperator &first_op, { if (first_op.is_null_operator || second_op.is_null_operator) { - return null_operator(second_op.reinit_domain_vector, first_op.reinit_range_vector); + LinearOperator return_op; + return_op.reinit_domain_vector = second_op.reinit_domain_vector; + return_op.reinit_range_vector = first_op.reinit_range_vector; + return null_operator(return_op); } else { @@ -727,68 +723,39 @@ identity_operator(const std::function &reinit_vector) /** * @relates LinearOperator * - * Returns a LinearOperator that is the null operator - * from the vector space @p Domain to the vector space @p Range. - * - * The function takes two std::function objects @ref - * reinit_range_vector and reinit_domain_vector as arguments to initialize the - * reinit_range_vector and reinit_domain_vector - * objects of the LinearOperator object. + * Returns a nulled variant of the LinearOperator @p op, i.e. with + * optimized LinearOperator::vmult, LinearOperator::vmult_add, etc. + * functions and with LinearOperator::is_null_operator set to true. * * @ingroup LAOperators */ - -template -LinearOperator -null_operator(const std::function &reinit_domain_vector, - const std::function &reinit_range_vector) +template +LinearOperator +null_operator(const LinearOperator &op) { - LinearOperator return_op(/*is_null_operator = */true); + auto return_op = op; - return_op.reinit_range_vector = reinit_range_vector; - return_op.reinit_domain_vector = reinit_domain_vector; + return_op.is_null_operator = true; - return_op.vmult = [](Range &v, const Domain &u) + return_op.vmult = [](Range &v, const Domain &) { - v = 0; + v = 0.; }; - return_op.vmult_add = [](Range &v, const Domain &u) + return_op.vmult_add = [](Range &, const Domain &) {}; - return_op.Tvmult = [](Range &v, const Domain &u) + return_op.Tvmult = [](Domain &v, const Range &) { - v = 0; + v = 0.; }; - return_op.Tvmult_add = [](Range &v, const Domain &u) + return_op.Tvmult_add = [](Domain &, const Range &) {}; return return_op; } -/** - * @relates LinearOperator - * - * Returns a LinearOperator that is the null operator - * of the vector space @p Range. (It is a specification of the previous - * function in the case of square matrices) - * - * The function takes an std::function object @ref - * reinit_vector as an argument to initialize the - * reinit_range_vector and reinit_domain_vector - * objects of the LinearOperator object. - * - * @ingroup LAOperators - */ -template -LinearOperator -null_operator(const std::function &reinit_vector) -{ - return null_operator(reinit_vector, reinit_vector); -} - namespace internal { diff --git a/tests/lac/linear_operator_01.cc b/tests/lac/linear_operator_01.cc index 2ed27d9611..0f47a0d139 100644 --- a/tests/lac/linear_operator_01.cc +++ b/tests/lac/linear_operator_01.cc @@ -232,7 +232,7 @@ int main() // null operator - auto test4 = null_operator(test2.reinit_range_vector); + auto test4 = null_operator(test2); test4.vmult(w, u); deallog << " 0 * " << u.value << " = " << w.value << std::endl; -- 2.39.5