From 957fb3e3800d2300bf76c2930f0f7630a52be2c5 Mon Sep 17 00:00:00 2001
From: Matthias Maier <tamiko@43-1.org>
Date: Mon, 11 May 2015 23:45:12 +0200
Subject: [PATCH] Bugfix: Also allow to multiply a PackagedOperation with 0

---
 include/deal.II/lac/linear_operator.h | 37 +++++++++++++++++++--------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h
index a6580ef735..f50e634834 100644
--- a/include/deal.II/lac/linear_operator.h
+++ b/include/deal.II/lac/linear_operator.h
@@ -1639,18 +1639,33 @@ operator*(const PackagedOperation<Range> &comp,
 
   return_comp.reinit_vector = comp.reinit_vector;
 
-  return_comp.apply = [comp, number](Range &v)
-  {
-    comp.apply(v);
-    v *= number;
-  };
+  // the trivial case: number is zero
+  if (number == 0.)
+    {
+      return_comp.apply = [](Range &v)
+      {
+        v = 0.;
+      };
 
-  return_comp.apply_add = [comp, number](Range &v)
-  {
-    v /= number;
-    comp.apply_add(v);
-    v *= number;
-  };
+      return_comp.apply_add = [](Range &)
+      {
+      };
+    }
+  else
+    {
+      return_comp.apply = [comp, number](Range &v)
+      {
+        comp.apply(v);
+        v *= number;
+      };
+
+      return_comp.apply_add = [comp, number](Range &v)
+      {
+        v /= number;
+        comp.apply_add(v);
+        v *= number;
+      };
+    }
 
   return return_comp;
 }
-- 
2.39.5