]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
New tests.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 6 Apr 2004 02:32:38 +0000 (02:32 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 6 Apr 2004 02:32:38 +0000 (02:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@8975 0785d39b-7218-0410-832d-ea1e28bc413d

tests/bits/petsc_vector_assign_01.cc [new file with mode: 0644]
tests/bits/petsc_vector_assign_02.cc [new file with mode: 0644]
tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_01.output [new file with mode: 0644]
tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_02.output [new file with mode: 0644]

diff --git a/tests/bits/petsc_vector_assign_01.cc b/tests/bits/petsc_vector_assign_01.cc
new file mode 100644 (file)
index 0000000..2baccbb
--- /dev/null
@@ -0,0 +1,89 @@
+//----------------------------  petsc_vector_assign_01.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  petsc_vector_assign_01.cc  ---------------------------
+
+
+// when calling PETScWrappers::Vector::operator() (), the return type is a
+// reference object, not a reference to the actual element. this leads to the
+// funny situation that an assignment like v2(i)=v1(i) isn't really what it
+// looks like: it tries to copy the reference objects, not the values they
+// point to, as one would expect
+//
+// this was fixed 2004-04-05, and this test checks that it works
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>    
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (PETScWrappers::Vector &v,
+           PETScWrappers::Vector &w)
+{
+                                   // set the first vector
+  for (unsigned int i=0; i<v.size(); ++i)
+    v(i) = i;
+
+                                   // copy elements by reference
+  for (unsigned int i=0; i<v.size(); ++i)
+    w(i) = v(i);
+
+                                   // check that they're equal
+  Assert (v==w, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_vector_assign_01.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        PETScWrappers::Vector v (100);
+        PETScWrappers::Vector w (100);
+        test (v,w);
+      }
+      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;
+    };
+}
diff --git a/tests/bits/petsc_vector_assign_02.cc b/tests/bits/petsc_vector_assign_02.cc
new file mode 100644 (file)
index 0000000..d9f028d
--- /dev/null
@@ -0,0 +1,88 @@
+//----------------------------  petsc_vector_assign_02.cc  ---------------------------
+//    $Id$
+//    Version: $Name$ 
+//
+//    Copyright (C) 2004 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  petsc_vector_assign_02.cc  ---------------------------
+
+
+// this is equivalent to the petsc_vector_assign_02 test, except that we use
+// operator+= instead of operator=. Now, this does not present a problem,
+// since the compiler does not automatically generate a version of this
+// operator, but simply performs the conversion to PetscScalar, i.e. the
+// argument to the user-defined operator+=. This is not exciting, but since I
+// wrote the test to make sure it works this way, let's keep it then...
+
+#include "../tests.h"
+#include <lac/petsc_vector.h>    
+#include <fstream>
+#include <iostream>
+#include <vector>
+
+
+void test (PETScWrappers::Vector &v,
+           PETScWrappers::Vector &w)
+{
+                                   // set the first vector
+  for (unsigned int i=0; i<v.size(); ++i)
+    v(i) = i;
+
+                                   // add elements by reference
+  for (unsigned int i=0; i<v.size(); ++i)
+    w(i) += v(i);
+
+                                   // check that they're equal
+  Assert (v==w, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  std::ofstream logfile("petsc_vector_assign_02.output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  try
+    {
+      PetscInitialize(&argc,&argv,0,0);
+      {
+        PETScWrappers::Vector v (100);
+        PETScWrappers::Vector w (100);
+        test (v,w);
+      }
+      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;
+    };
+}
diff --git a/tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_01.output b/tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_01.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK
diff --git a/tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_02.output b/tests/results/i686-pc-linux-gnu+gcc3.2/bits/petsc_vector_assign_02.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.