]> https://gitweb.dealii.org/ - dealii.git/commitdiff
test has been added to verify the state of LAPACKFullMatrix after having computed...
authorNiklas Fehn <fehn@lnm.mw.tum.de>
Thu, 9 Mar 2017 10:21:34 +0000 (11:21 +0100)
committerNiklas Fehn <fehn@lnm.mw.tum.de>
Thu, 9 Mar 2017 10:21:34 +0000 (11:21 +0100)
source/lac/lapack_full_matrix.cc
tests/lapack/full_matrix_14.cc [new file with mode: 0644]
tests/lapack/full_matrix_14.output [new file with mode: 0644]

index d1e8fc612e08f8c888a273b860ca1bc1b2a46007..ae80e56929aff4605bae6463af906657e3a9f0a6 100644 (file)
@@ -504,10 +504,10 @@ LAPACKFullMatrix<number>::compute_lu_factorization()
   getrf(&mm, &nn, values, &mm, &ipiv[0], &info);
 
   Assert(info >= 0, ExcInternalError());
-  
+
   // if info >= 0, the factorization has been completed
   state = lu;
-    
+
   AssertThrow(info == 0, LACExceptions::ExcSingular());
 }
 
diff --git a/tests/lapack/full_matrix_14.cc b/tests/lapack/full_matrix_14.cc
new file mode 100644 (file)
index 0000000..77e3f1c
--- /dev/null
@@ -0,0 +1,68 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2014 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Tests LAPACKFullMatrix::operator*= and operator/=
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/lapack_full_matrix.h>
+
+#include <fstream>
+#include <iostream>
+
+
+
+void test(const bool is_singular)
+{
+  const unsigned int n=10;
+  LAPACKFullMatrix<double> A(n,n);
+  A = 0;
+
+  // generate a singular matrix if is_singular == true
+  for (unsigned int i=0; i<n; ++i)
+    for (unsigned int j=0; j<n; ++j)
+      if (i==j && (i != n-1 || !is_singular))
+        A(i,j) = 1.0;
+
+  try
+    {
+      A.compute_lu_factorization();
+    }
+  catch (std::exception &exc)
+    {
+      deallog << "matrix is singular" << std::endl;
+    }
+
+  Vector<double> v(n);
+  v = 1.0;
+  v(n-1) = 0.0;
+  // LU factorization can only be applied if state == lu!
+  A.apply_lu_factorization(v,false);
+
+  deallog << "apply lu factorization succeeded with norm " << v.l2_norm() << std::endl;
+}
+
+int main()
+{
+  const std::string logname = "output";
+  std::ofstream logfile(logname.c_str());
+  logfile.precision(3);
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  test(false);
+  test(true);
+}
diff --git a/tests/lapack/full_matrix_14.output b/tests/lapack/full_matrix_14.output
new file mode 100644 (file)
index 0000000..566cdbe
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::apply lu factorization succeeded with norm 3.00000
+DEAL::matrix is singular
+DEAL::apply lu factorization succeeded with norm 3.00000

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.