]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fixed a bug in linear operator.
authorLuca Heltai <luca.heltai@sissa.it>
Mon, 11 May 2015 16:51:40 +0000 (18:51 +0200)
committerMatthias Maier <tamiko@43-1.org>
Mon, 11 May 2015 21:48:56 +0000 (23:48 +0200)
include/deal.II/lac/linear_operator.h
tests/lac/linear_operator_10.cc [new file with mode: 0644]
tests/lac/linear_operator_10.with_cxx11=on.output [new file with mode: 0644]

index f50e634834a3f7e88714b4cc4e8c4990fd785789..e465955f7a6c7f07fa16002e535c4ebf50663cad 100644 (file)
@@ -380,34 +380,60 @@ operator*(typename Range::value_type  number,
 
   LinearOperator<Range, Domain> return_op = op;
 
-  // ensure to have valid computation objects by catching number and op by
-  // value
 
-  return_op.vmult = [number, op](Range &v, const Domain &u)
-  {
-    op.vmult(v,u);
-    v *= number;
-  };
+  // the trivial case: number is zero
+  if (number == 0)
+    {
+      return_op.vmult = [] (Range &v, const Domain &)
+      {
+        v *= 0;
+      };
 
-  return_op.vmult_add = [number, op](Range &v, const Domain &u)
-  {
-    v /= number;
-    op.vmult_add(v,u);
-    v *= number;
-  };
+      return_op.vmult_add = [] (Range &, const Domain &)
+      {
+      };
 
-  return_op.Tvmult = [number, op](Domain &v, const Range &u)
-  {
-    op.Tvmult(v,u);
-    v *= number;
-  };
+      return_op.Tvmult = [](Domain &v, const Range &)
+      {
+        v *= 0;
+      };
 
-  return_op.Tvmult_add = [number, op](Domain &v, const Range &u)
-  {
-    v /= number;
-    op.Tvmult_add(v,u);
-    v *= number;
-  };
+      return_op.Tvmult_add = [](Domain &, const Range &)
+      {
+      };
+    }
+  else
+    {
+
+      // ensure to have valid computation objects by catching number and op by
+      // value
+
+      return_op.vmult = [number, op](Range &v, const Domain &u)
+      {
+        op.vmult(v,u);
+        v *= number;
+      };
+
+      return_op.vmult_add = [number, op](Range &v, const Domain &u)
+      {
+        v /= number;
+        op.vmult_add(v,u);
+        v *= number;
+      };
+
+      return_op.Tvmult = [number, op](Domain &v, const Range &u)
+      {
+        op.Tvmult(v,u);
+        v *= number;
+      };
+
+      return_op.Tvmult_add = [number, op](Domain &v, const Range &u)
+      {
+        v /= number;
+        op.Tvmult_add(v,u);
+        v *= number;
+      };
+    }
 
   return return_op;
 }
diff --git a/tests/lac/linear_operator_10.cc b/tests/lac/linear_operator_10.cc
new file mode 100644 (file)
index 0000000..a52661d
--- /dev/null
@@ -0,0 +1,61 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2015 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+// Test scaling with a number which might be 
+
+#include "../tests.h"
+
+#include <deal.II/lac/block_sparse_matrix.h>
+#include <deal.II/lac/block_vector.h>
+#include <deal.II/lac/dynamic_sparsity_pattern.h>
+#include <deal.II/lac/linear_operator.h>
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#define PRINTME(name, var) \
+  deallog << "Block vector: " name << ":" << std::endl; \
+  for (unsigned int i = 0; i < var.n_blocks(); ++i) \
+    deallog << "[block " << i << " ]  " << var.block(i);
+
+
+using namespace dealii;
+
+int main()
+{
+  initlog();
+  deallog << std::setprecision(10);
+
+  // SparseMatrix:
+  {
+    SparsityPattern sparsity_pattern (10, 5, 0);
+    sparsity_pattern.compress();
+
+    SparseMatrix<double> a (sparsity_pattern);
+
+    auto op_a = 0*linear_operator(a);
+
+    Vector<double> u;
+    op_a.reinit_domain_vector(u, false);
+    Vector<double> v;
+    op_a.reinit_range_vector(v, false);
+    op_a.vmult(v, u);
+    op_a.vmult_add(v, u);
+    op_a.Tvmult(u, v);
+    op_a.Tvmult_add(u, v);
+
+    deallog << "OK" << std::endl;
+  }
+}
+
diff --git a/tests/lac/linear_operator_10.with_cxx11=on.output b/tests/lac/linear_operator_10.with_cxx11=on.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.