]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Check l1- and l2-norm of complex vectors. Ignore test generated files.
authoryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Oct 2013 18:23:03 +0000 (18:23 +0000)
committeryoung <young@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Oct 2013 18:23:03 +0000 (18:23 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_petscscalar_complex@31320 0785d39b-7218-0410-832d-ea1e28bc413d

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

diff --git a/tests/petsc_scalar_complex/17.cc b/tests/petsc_scalar_complex/17.cc
new file mode 100644 (file)
index 0000000..8625638
--- /dev/null
@@ -0,0 +1,87 @@
+// ---------------------------------------------------------------------
+// $Id: 17.cc
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check PETScWrappers::Vector::l1_norm()
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (PETScWrappers::Vector &v)
+{
+  // set some elements of the vector
+  double norm = 0;
+  for (unsigned int k=0; k<v.size(); k+=1+k)
+    {
+      v(k) = PetscScalar (k,2.*k);
+      norm += std::fabs (1.*k+2.*k);
+    }
+  v.compress (VectorOperation::add);
+
+  // then check the norm
+  Assert (v.l1_norm() == norm, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv)
+{
+  std::ofstream logfile("17/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+      {
+        PETScWrappers::Vector v (100);
+        test (v);
+      }
+
+    }
+  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;
+    };
+}
diff --git a/tests/petsc_scalar_complex/17/cmp/generic b/tests/petsc_scalar_complex/17/cmp/generic
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/petsc_scalar_complex/18.cc b/tests/petsc_scalar_complex/18.cc
new file mode 100644 (file)
index 0000000..aa67b3e
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+// $Id: 18.cc 30045 2013-07-18 19:18:00Z maier $
+//
+// Copyright (C) 2004 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check PETScWrappers::Vector::l2_norm()
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (PETScWrappers::Vector &v)
+{
+  // set some elements of the vector
+  double norm = 0;
+  for (unsigned int k=0; k<v.size(); k+=1+k)
+    {
+      PetscScalar el = PetscScalar (k,2.*k);
+      v(k)  = el;
+
+      // norm += el*PetscConj (el);
+      norm += std::fabs (1.*k*1.*k /*+ 1.*k*2*ki - 1.*k*2*ki*/ + 2*k*2.*k/*i*/); 
+    }
+
+  v.compress (VectorOperation::add);
+
+  // then check the l2-norm
+  PetscReal l2_norm = v.l2_norm();
+  Assert (l2_norm==std::sqrt(norm), ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc,char **argv)
+{
+  std::ofstream logfile("18/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  try
+    {
+      Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+      {
+        PETScWrappers::Vector v (100);
+        test (v);
+      }
+
+    }
+  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;
+    };
+}
diff --git a/tests/petsc_scalar_complex/18/cmp/generic b/tests/petsc_scalar_complex/18/cmp/generic
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.