From 0e4eb137cc662ba783d0bd27c3f2a399451f3b04 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sun, 26 Apr 2015 13:36:36 +0200 Subject: [PATCH] Add operator*=(number) variant to LinearOperator --- include/deal.II/lac/linear_operator.h | 12 ++++++++++++ tests/lac/linear_operator_01.cc | 9 +++++++++ tests/lac/linear_operator_01.with_cxx11=on.output | 2 ++ tests/lac/linear_operator_02.cc | 4 ++++ tests/lac/linear_operator_02.with_cxx11=on.output | 2 ++ 5 files changed, 29 insertions(+) diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index d1479c2a25..0366e35205 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -257,6 +257,18 @@ public: *this = *this * second_op; return *this; } + + /** + * Scalar multiplication of the LinearOperator with @p number from the + * right. + */ + LinearOperator + operator*=(typename Domain::value_type number) + { + *this = *this * number; + return *this; + } + }; diff --git a/tests/lac/linear_operator_01.cc b/tests/lac/linear_operator_01.cc index f227822c66..5b7fe75ece 100644 --- a/tests/lac/linear_operator_01.cc +++ b/tests/lac/linear_operator_01.cc @@ -194,6 +194,11 @@ int main() test.vmult(v, u); deallog << "(4 * 4) * " << u.value << " = " << v.value << std::endl; + test = multiply4; + test *= 4.; + test.vmult(v, u); + deallog << "(4 * 4) * " << u.value << " = " << v.value << std::endl; + test = multiply4 * 4.; test.vmult(v, u); deallog << "(4 * 4) * " << u.value << " = " << v.value << std::endl; @@ -205,6 +210,10 @@ int main() test2.vmult(w, u); deallog << "(2 * 4) * " << u.value << " = " << w.value << std::endl; + test2 *= identity_operator(test2.reinit_range_vector); + test2.vmult(w, u); + deallog << "(2 * 4) * 1 * " << u.value << " = " << w.value << std::endl; + // identity auto test3 = identity_operator(test2.reinit_range_vector) + test2; diff --git a/tests/lac/linear_operator_01.with_cxx11=on.output b/tests/lac/linear_operator_01.with_cxx11=on.output index 95b24c5f4c..2bceae3a83 100644 --- a/tests/lac/linear_operator_01.with_cxx11=on.output +++ b/tests/lac/linear_operator_01.with_cxx11=on.output @@ -13,5 +13,7 @@ DEAL::(2 - 4 + 2) * 24.0000 = 0.00000 DEAL::(2 - 4 + 2 - 4) * 24.0000 = -96.0000 DEAL::(4 * 4) * 24.0000 = 384.000 DEAL::(4 * 4) * 24.0000 = 384.000 +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 diff --git a/tests/lac/linear_operator_02.cc b/tests/lac/linear_operator_02.cc index 3fd0491463..be5d0cd494 100644 --- a/tests/lac/linear_operator_02.cc +++ b/tests/lac/linear_operator_02.cc @@ -142,6 +142,10 @@ int main() op_x.vmult(x, u); deallog << "(A*=B)u: " << x << std::endl; + op_x *= 4.; + op_x.vmult(x, u); + deallog << "(A*=B*=4.)u: " << x << std::endl; + // solver interface: SolverControl solver_control (1000, 1e-12); diff --git a/tests/lac/linear_operator_02.with_cxx11=on.output b/tests/lac/linear_operator_02.with_cxx11=on.output index a1c91305e1..923dc7ed25 100644 --- a/tests/lac/linear_operator_02.with_cxx11=on.output +++ b/tests/lac/linear_operator_02.with_cxx11=on.output @@ -23,6 +23,8 @@ DEAL::(A*B)u: -0.1073495370 -0.1866319444 -0.2039930556 -0.02199074074 -0.289351 DEAL:: DEAL::(A*=B)u: -0.1073495370 -0.1866319444 -0.2039930556 -0.02199074074 -0.2893518519 -0.07465277778 -0.3703703704 0.03877314815 -0.2986111111 -0.1487268519 0.6250000000 -0.2201967593 -0.2123842593 0.4710648148 -0.4762731481 -0.1672453704 1.145833333 0.8049768519 -0.3211805556 -0.2199074074 -0.4939236111 1.570023148 -0.2034143519 -0.2300347222 -0.4094328704 DEAL:: +DEAL::(A*=B*=4.)u: -0.4293981481 -0.7465277778 -0.8159722222 -0.08796296296 -1.157407407 -0.2986111111 -1.481481481 0.1550925926 -1.194444444 -0.5949074074 2.500000000 -0.8807870370 -0.8495370370 1.884259259 -1.905092593 -0.6689814815 4.583333333 3.219907407 -1.284722222 -0.8796296296 -1.975694444 6.280092593 -0.8136574074 -0.9201388889 -1.637731481 +DEAL:: DEAL::solve(B, v, u): 80.16326531 28.24489796 86.53061224 25.79591837 259.4285714 57.14285714 328.0000000 88.00000000 184.0000000 226.6122449 40.48979592 1446.693878 315.7551020 160.0000000 760.0000000 387.7551020 81.63265306 190.8571429 2286.693878 470.0408163 1140.571429 108.0816327 569.9591837 539.1020408 3018.448980 DEAL:: DEAL::inverse_operator(B)u: 80.16326531 28.24489796 86.53061224 25.79591837 259.4285714 57.14285714 328.0000000 88.00000000 184.0000000 226.6122449 40.48979592 1446.693878 315.7551020 160.0000000 760.0000000 387.7551020 81.63265306 190.8571429 2286.693878 470.0408163 1140.571429 108.0816327 569.9591837 539.1020408 3018.448980 -- 2.39.5