]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Another matrix element access test.
authoryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Oct 2013 14:40:33 +0000 (14:40 +0000)
committeryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Oct 2013 14:40:33 +0000 (14:40 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31316 0785d39b-7218-0410-832d-ea1e28bc413d

tests/petsc_scalar_complex/element_access_03.cc [new file with mode: 0644]
tests/petsc_scalar_complex/element_access_03/cmp/generic [new file with mode: 0644]

diff --git a/tests/petsc_scalar_complex/element_access_03.cc b/tests/petsc_scalar_complex/element_access_03.cc
new file mode 100644 (file)
index 0000000..fbed258
--- /dev/null
@@ -0,0 +1,119 @@
+
+// ---------------------------------------------------------------------
+// $Id: 
+//
+// Copyright (C) 2013 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.
+//
+// ---------------------------------------------------------------------
+
+
+// deal.II includes
+#include "../tests.h"
+#include <deal.II/lac/petsc_sparse_matrix.h>
+#include <deal.II/base/numbers.h>
+    
+#include <fstream>
+#include <iostream>
+#include <cassert>
+
+#include <complex>
+
+// test read/write element access using unsigned int and double.
+
+
+// sparse matrix elements
+void test_matrix (PETScWrappers::SparseMatrix &m)
+{
+  deallog << "Check matrix access" << std::endl;
+
+  const double r =     dealii::numbers::PI;
+  const double i = -1.*dealii::numbers::PI;
+
+  // fill up a matrix with some numbers
+  for (unsigned int k=0; k<m.m(); ++k)
+    for (unsigned int l=0; l<m.n(); ++l)
+      m.set (k,l, PetscScalar ((k+l)*r,(k+l)*i));
+
+  m.compress (VectorOperation::add);
+
+  // Check elements have the correct value
+  for (unsigned int k=0; k<m.m(); ++k)
+    for (unsigned int l=0; l<m.n(); ++l)
+       Assert ((m(k,l).real () ==     (k+l)*dealii::numbers::PI) &&
+               (m(k,l).imag () == -1.*(k+l)*dealii::numbers::PI),
+               ExcInternalError());
+
+  // Use the conjugate to check elements have equal (and opposite)
+  // values.
+  for (unsigned int k=0; k<m.m(); ++k)
+    for (unsigned int l=0; l<m.n(); ++l)
+      {
+       PetscScalar m_conjugate = PetscConj (m(k,l));
+
+       Assert (m_conjugate.real () == m_conjugate.imag (),
+               ExcInternalError());
+      }
+
+  deallog << "OK" << std::endl;
+}
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile ("element_access_03/output");
+  dealii::deallog.attach (logfile);
+  dealii::deallog.depth_console (0);
+  deallog.threshold_double(1.e-10);
+  
+  try
+    {
+      PetscInitialize (&argc, &argv, (char*) 0, (char*) 0);
+      {
+       PETScWrappers::SparseMatrix m (5,5,5);
+       test_matrix (m);
+
+       deallog << "matrix:" << std::endl;
+       m.print (logfile);
+      }
+      PetscFinalize ();
+    }
+  
+  catch (std::exception &exc)
+    {
+      std::cerr << std::endl << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Exception on processing: " << std::endl
+                << exc.what() << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      
+      return 1;
+    }
+  catch (...)
+    {
+      std::cerr << std::endl << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      std::cerr << "Unknown exception!" << std::endl
+                << "Aborting!" << std::endl
+                << "----------------------------------------------------"
+                << std::endl;
+      return 1;
+    }
+  
+  logfile << std::endl;
+  
+  return 0;
+}
+
+
diff --git a/tests/petsc_scalar_complex/element_access_03/cmp/generic b/tests/petsc_scalar_complex/element_access_03/cmp/generic
new file mode 100644 (file)
index 0000000..2195d3d
--- /dev/null
@@ -0,0 +1,30 @@
+
+DEAL::Check matrix access
+DEAL::OK
+DEAL::matrix:
+(0,0) (0.00000,0.00000)
+(0,1) (3.14159,-3.14159)
+(0,2) (6.28319,-6.28319)
+(0,3) (9.42478,-9.42478)
+(0,4) (12.5664,-12.5664)
+(1,0) (3.14159,-3.14159)
+(1,1) (6.28319,-6.28319)
+(1,2) (9.42478,-9.42478)
+(1,3) (12.5664,-12.5664)
+(1,4) (15.7080,-15.7080)
+(2,0) (6.28319,-6.28319)
+(2,1) (9.42478,-9.42478)
+(2,2) (12.5664,-12.5664)
+(2,3) (15.7080,-15.7080)
+(2,4) (18.8496,-18.8496)
+(3,0) (9.42478,-9.42478)
+(3,1) (12.5664,-12.5664)
+(3,2) (15.7080,-15.7080)
+(3,3) (18.8496,-18.8496)
+(3,4) (21.9911,-21.9911)
+(4,0) (12.5664,-12.5664)
+(4,1) (15.7080,-15.7080)
+(4,2) (18.8496,-18.8496)
+(4,3) (21.9911,-21.9911)
+(4,4) (25.1327,-25.1327)
+

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.