From 2a0e76b08235c0e6c6a0686aab66ca1cf0688feb Mon Sep 17 00:00:00 2001 From: ESeNonFossiIo Date: Tue, 2 Jun 2015 12:39:38 +0200 Subject: [PATCH] null operator --- include/deal.II/lac/linear_operator.h | 42 +++++++++++++++++++ tests/lac/linear_operator_01.cc | 7 ++++ .../linear_operator_01.with_cxx11=on.output | 1 + 3 files changed, 50 insertions(+) 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 -- 2.39.5