From: ESeNonFossiIo Date: Tue, 2 Jun 2015 10:39:38 +0000 (+0200) Subject: null operator X-Git-Tag: v8.3.0-rc1~134^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F986%2Fhead;p=dealii.git null operator --- diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index e74aa2cf9a..5992a91765 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -682,6 +682,48 @@ identity_operator(const std::function &reinit_vector) } +/** + * @relates LinearOperator + * + * Returns a LinearOperator that is the null operator of the vector space + * @p Range. + * + * 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) +{ + LinearOperator return_op; + + return_op.reinit_range_vector = reinit_vector; + return_op.reinit_domain_vector = reinit_vector; + + return_op.vmult = [](Range &v, const Range &u) + { + v = 0; + }; + + return_op.vmult_add = [](Range &v, const Range &u) + {}; + + return_op.Tvmult = [](Range &v, const Range &u) + { + v = 0; + }; + + return_op.Tvmult_add = [](Range &v, const Range &u) + {}; + + return return_op; +} + + namespace internal { namespace LinearOperator diff --git a/tests/lac/linear_operator_01.cc b/tests/lac/linear_operator_01.cc index 31eb357d3b..2ed27d9611 100644 --- a/tests/lac/linear_operator_01.cc +++ b/tests/lac/linear_operator_01.cc @@ -229,4 +229,11 @@ int main() auto test3 = identity_operator(test2.reinit_range_vector) + test2; test3.vmult(w, u); deallog << "(1 + 2 * 4) * " << u.value << " = " << w.value << std::endl; + + // null operator + + auto test4 = null_operator(test2.reinit_range_vector); + test4.vmult(w, u); + deallog << " 0 * " << u.value << " = " << w.value << std::endl; + } diff --git a/tests/lac/linear_operator_01.with_cxx11=on.output b/tests/lac/linear_operator_01.with_cxx11=on.output index 2bceae3a83..c910ee55b3 100644 --- a/tests/lac/linear_operator_01.with_cxx11=on.output +++ b/tests/lac/linear_operator_01.with_cxx11=on.output @@ -17,3 +17,4 @@ DEAL::(4 * 4) * 24.0000 = 384.000 DEAL::(2 * 4) * 24.0000 = 192.000 DEAL::(2 * 4) * 1 * 24.0000 = 192.000 DEAL::(1 + 2 * 4) * 24.0000 = 216.000 +DEAL:: 0 * 24.0000 = 0.00000