]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Added tests for lac/ShiftedMatrix
authordakshina.ilangova <dakshina.ilangova@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 5 Apr 2014 19:33:09 +0000 (19:33 +0000)
committerdakshina.ilangova <dakshina.ilangova@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 5 Apr 2014 19:33:09 +0000 (19:33 +0000)
git-svn-id: https://svn.dealii.org/trunk@32720 0785d39b-7218-0410-832d-ea1e28bc413d

tests/lac/shifted_matrix_01.cc [new file with mode: 0644]
tests/lac/shifted_matrix_01.output [new file with mode: 0644]
tests/lac/shifted_matrix_02.cc [new file with mode: 0644]
tests/lac/shifted_matrix_02.output [new file with mode: 0644]
tests/lac/shifted_matrix_03.cc [new file with mode: 0644]
tests/lac/shifted_matrix_03.output [new file with mode: 0644]
tests/lac/shifted_matrix_04.cc [new file with mode: 0644]
tests/lac/shifted_matrix_04.output [new file with mode: 0644]
tests/lac/shifted_matrix_05.cc [new file with mode: 0644]
tests/lac/shifted_matrix_05.output [new file with mode: 0644]

diff --git a/tests/lac/shifted_matrix_01.cc b/tests/lac/shifted_matrix_01.cc
new file mode 100644 (file)
index 0000000..2d414c4
--- /dev/null
@@ -0,0 +1,73 @@
+// ---------------------------------------------------------------------
+// $Id: shifted_matrix.cc 32491 2014-03-13 dilangov $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+// check ShiftedMatrix::checkConstructor
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/shifted_matrix.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cmath>
+
+template<typename number>
+  void
+  checkConstructor(FullMatrix<number> &A, double sigma)
+  {
+    deallog << "constructor" << std::endl;
+
+    ShiftedMatrix < FullMatrix<number> > S(A, sigma);
+
+    deallog << "Multiplying with all ones vector" << std::endl;
+    Vector<number> V(A.n());
+    for (unsigned int i = 0; i < V.size(); ++i)
+      V(i) = 1;
+
+    Vector<number> O(A.m());
+
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+  }
+
+int
+main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  const double Adata[] =
+    { 2, 3, 4, 5 };
+
+  FullMatrix<double> A(2, 2);
+
+  A.fill(Adata);
+
+  checkConstructor<double>(A, 2);
+}
diff --git a/tests/lac/shifted_matrix_01.output b/tests/lac/shifted_matrix_01.output
new file mode 100644 (file)
index 0000000..b900772
--- /dev/null
@@ -0,0 +1,5 @@
+
+DEAL::constructor
+DEAL::Multiplying with all ones vector
+DEAL::Dimensions of result vector verified
+DEAL::7.0000   11.0000 
diff --git a/tests/lac/shifted_matrix_02.cc b/tests/lac/shifted_matrix_02.cc
new file mode 100644 (file)
index 0000000..1d7c296
--- /dev/null
@@ -0,0 +1,71 @@
+// ---------------------------------------------------------------------
+// $Id: shifted_matrix.cc 32491 2014-03-13 dilangov $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+// check ShiftedMatrix::checkVmult
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/shifted_matrix.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cmath>
+
+template<typename number>
+  void
+  checkVmult(FullMatrix<number> &A, double sigma, Vector<number> &V)
+  {
+    deallog << "vmult" << std::endl;
+
+    ShiftedMatrix < FullMatrix<number> > S(A, sigma);
+    Vector<number> O(A.m());
+
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+  }
+
+int
+main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  const double Adata[] =
+    { 2, 3, 4, 5 };
+
+  FullMatrix<double> A(2, 2);
+
+  A.fill(Adata);
+
+  Vector<double> V(2);
+  V(0) = 1;
+  V(1) = 2;
+
+  checkVmult<double>(A, 2, V);
+}
diff --git a/tests/lac/shifted_matrix_02.output b/tests/lac/shifted_matrix_02.output
new file mode 100644 (file)
index 0000000..5c9d5fc
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::vmult
+DEAL::Dimensions of result vector verified
+DEAL::10.0000  18.0000 
diff --git a/tests/lac/shifted_matrix_03.cc b/tests/lac/shifted_matrix_03.cc
new file mode 100644 (file)
index 0000000..fc4c1da
--- /dev/null
@@ -0,0 +1,81 @@
+// ---------------------------------------------------------------------
+// $Id: shifted_matrix.cc 32491 2014-03-13 dilangov $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+// check ShiftedMatrix::checkResidual
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/shifted_matrix.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cmath>
+
+template<typename number>
+  void
+  checkResidual(FullMatrix<number> &A, double sigma, Vector<number> &V,
+      Vector<number> &R)
+  {
+    deallog << "residual" << std::endl;
+
+    ShiftedMatrix < FullMatrix<number> > S(A, sigma);
+    Vector<number> O(A.m());
+    double residual;
+
+    residual = S.residual(O, V, R);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    deallog << "Residual vector" << std::endl;
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Residual value" << std::endl;
+    deallog << residual << std::endl;
+  }
+
+int
+main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  const double Adata[] =
+    { 2, 3, 4, 5 };
+
+  FullMatrix<double> A(2, 2);
+
+  A.fill(Adata);
+
+  Vector<double> V(2);
+  V(0) = 1;
+  V(1) = 2;
+
+  Vector<double> R(2);
+  R(0) = 1;
+  R(1) = 1;
+
+  checkResidual<double>(A, 2, V, R);
+}
diff --git a/tests/lac/shifted_matrix_03.output b/tests/lac/shifted_matrix_03.output
new file mode 100644 (file)
index 0000000..64cf220
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::residual
+DEAL::Dimensions of result vector verified
+DEAL::Residual vector
+DEAL::-9.0000  -17.0000        
+DEAL::Residual value
+DEAL::19.2354
diff --git a/tests/lac/shifted_matrix_04.cc b/tests/lac/shifted_matrix_04.cc
new file mode 100644 (file)
index 0000000..32355a0
--- /dev/null
@@ -0,0 +1,88 @@
+// ---------------------------------------------------------------------
+// $Id: shifted_matrix.cc 32491 2014-03-13 dilangov $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+// check ShiftedMatrix::checkSetSigma
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/shifted_matrix.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cmath>
+
+template<typename number>
+  void
+  checkSetSigma(FullMatrix<number> &A, double sigma)
+  {
+    deallog << "shift(sigma)" << std::endl;
+
+    deallog << "Init ShiftedMatrix with sigma=0" << std::endl;
+    ShiftedMatrix < FullMatrix<number> > S(A, 0);
+
+    deallog << "Multiplying with all ones vector" << std::endl;
+    Vector<number> V(A.n());
+    for (unsigned int i = 0; i < V.size(); ++i)
+      V(i) = 1;
+
+    Vector<number> O(A.m());
+
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Setting new sigma value" << std::endl;
+    S.shift(sigma);
+
+    deallog << "Multiplying with all ones vector" << std::endl;
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+  }
+
+int
+main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  const double Adata[] =
+    { 2, 3, 4, 5 };
+
+  FullMatrix<double> A(2, 2);
+
+  A.fill(Adata);
+
+  checkSetSigma<double>(A, 2);
+}
diff --git a/tests/lac/shifted_matrix_04.output b/tests/lac/shifted_matrix_04.output
new file mode 100644 (file)
index 0000000..822d2dd
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEAL::shift(sigma)
+DEAL::Init ShiftedMatrix with sigma=0
+DEAL::Multiplying with all ones vector
+DEAL::Dimensions of result vector verified
+DEAL::5.0000   9.0000  
+DEAL::Setting new sigma value
+DEAL::Multiplying with all ones vector
+DEAL::Dimensions of result vector verified
+DEAL::7.0000   11.0000 
diff --git a/tests/lac/shifted_matrix_05.cc b/tests/lac/shifted_matrix_05.cc
new file mode 100644 (file)
index 0000000..8af92c3
--- /dev/null
@@ -0,0 +1,97 @@
+// ---------------------------------------------------------------------
+// $Id: shifted_matrix.cc 32491 2014-03-13 dilangov $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+// check ShiftedMatrix::checkGetSigma
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/shifted_matrix.h>
+#include <deal.II/lac/full_matrix.h>
+#include <deal.II/lac/vector.h>
+
+#include <fstream>
+#include <iomanip>
+#include <cmath>
+
+template<typename number>
+  void
+  checkGetSigma(FullMatrix<number> &A)
+  {
+    deallog << "shift()" << std::endl;
+
+    deallog << "Init ShiftedMatrix with sigma=0" << std::endl;
+    ShiftedMatrix < FullMatrix<number> > S(A, 0);
+
+    deallog << "Multiplying with all ones vector" << std::endl;
+    Vector<number> V(A.n());
+    for (unsigned int i = 0; i < V.size(); ++i)
+      V(i) = 1;
+
+    Vector<number> O(A.m());
+
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+
+    deallog << "Setting new sigma value by incrementing old value by 1"
+        << std::endl;
+
+    deallog << "Old sigma value" << std::endl;
+    double sigma = S.shift();
+    deallog << sigma << std::endl;
+    sigma = sigma + 1;
+    deallog << "New sigma value" << std::endl;
+    deallog << sigma << std::endl;
+
+    S.shift(sigma);
+
+    deallog << "Multiplying with all ones vector" << std::endl;
+    S.vmult(O, V);
+
+    // Check the dimensions of the result matrix
+    Assert(A.m() == O.size(), ExcInternalError());
+    deallog << "Dimensions of result vector verified" << std::endl;
+
+    for (unsigned int i = 0; i < O.size(); ++i)
+      deallog << O(i) << '\t';
+    deallog << std::endl;
+  }
+
+int
+main()
+{
+  std::ofstream logfile("output");
+  deallog << std::fixed;
+  deallog << std::setprecision(4);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  const double Adata[] =
+    { 2, 3, 4, 5 };
+
+  FullMatrix<double> A(2, 2);
+
+  A.fill(Adata);
+
+  checkGetSigma<double>(A);
+}
diff --git a/tests/lac/shifted_matrix_05.output b/tests/lac/shifted_matrix_05.output
new file mode 100644 (file)
index 0000000..27f92db
--- /dev/null
@@ -0,0 +1,14 @@
+
+DEAL::shift()
+DEAL::Init ShiftedMatrix with sigma=0
+DEAL::Multiplying with all ones vector
+DEAL::Dimensions of result vector verified
+DEAL::5.0000   9.0000  
+DEAL::Setting new sigma value by incrementing old value by 1
+DEAL::Old sigma value
+DEAL::0
+DEAL::New sigma value
+DEAL::1.0000
+DEAL::Multiplying with all ones vector
+DEAL::Dimensions of result vector verified
+DEAL::6.0000   10.0000 

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.