]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add test
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 Jan 2014 14:11:14 +0000 (14:11 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 Jan 2014 14:11:14 +0000 (14:11 +0000)
git-svn-id: https://svn.dealii.org/trunk@32357 0785d39b-7218-0410-832d-ea1e28bc413d

tests/petsc/copy_to_dealvec.cc [new file with mode: 0644]
tests/petsc/copy_to_dealvec.with_mpi=true.mpirun=4.output [new file with mode: 0644]

diff --git a/tests/petsc/copy_to_dealvec.cc b/tests/petsc/copy_to_dealvec.cc
new file mode 100644 (file)
index 0000000..2bb2c38
--- /dev/null
@@ -0,0 +1,120 @@
+// ---------------------------------------------------------------------
+// $Id$
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Test parallel::distributed::Vector::operator=(PETScWrappers::MPI::Vector&)
+
+#include "../tests.h"
+#include <deal.II/lac/petsc_parallel_vector.h>
+#include <deal.II/lac/parallel_vector.h>
+#include <deal.II/base/index_set.h>
+#include <fstream>
+#include <iostream>
+#include <iomanip>
+#include <vector>
+
+
+void test ()
+{
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD);
+
+  if (myid==0)
+    deallog << "numproc=" << numproc << std::endl;
+
+  // each processor owns 2 indices and all
+  // are ghosting Element 1 (the second)
+
+  IndexSet local_active(numproc*2);
+  local_active.add_range(myid*2,myid*2+2);
+  IndexSet local_relevant(numproc*2);
+  local_relevant.add_range(1,2);
+
+  PETScWrappers::MPI::Vector vb(local_active, MPI_COMM_WORLD);
+  PETScWrappers::MPI::Vector v(local_active, local_relevant, MPI_COMM_WORLD);
+
+  parallel::distributed::Vector<double> copied(local_active, local_relevant, MPI_COMM_WORLD);
+
+  // set local values
+  vb(myid*2)=myid*2.0;
+  vb(myid*2+1)=myid*2.0+1.0;
+
+  vb.compress(VectorOperation::insert);
+  vb*=2.0;
+  v=vb;
+  //v.update_ghost_values();
+
+  Assert(!vb.has_ghost_elements(), ExcInternalError());
+  Assert(v.has_ghost_elements(), ExcInternalError());
+
+  copied = vb;
+
+  // check local values
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    {
+      deallog << myid*2 << ":" << copied(myid*2) << std::endl;
+      deallog << myid*2+1 << ":" << copied(myid*2+1) << std::endl;
+    }
+
+  Assert(copied(myid*2) == myid*4.0, ExcInternalError());
+  Assert(copied(myid*2+1) == myid*4.0+2.0, ExcInternalError());
+
+  copied = v;
+
+  // check ghost values
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "ghost: " << copied(1) << std::endl;
+  Assert(copied(1) == 2.0, ExcInternalError());
+
+  // check local values
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    {
+      deallog << myid*2 << ":" << copied(myid*2) << std::endl;
+      deallog << myid*2+1 << ":" << copied(myid*2+1) << std::endl;
+    }
+
+  Assert(copied(myid*2) == myid*4.0, ExcInternalError());
+  Assert(copied(myid*2+1) == myid*4.0+2.0, ExcInternalError());
+
+
+  // done
+  if (myid==0)
+    deallog << "OK" << std::endl;
+}
+
+
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv);
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+
+  deallog.push(Utilities::int_to_string(myid));
+
+  if (myid == 0)
+    {
+      std::ofstream logfile("output");
+      deallog.attach(logfile);
+      deallog << std::setprecision(4);
+      deallog.depth_console(0);
+      deallog.threshold_double(1.e-10);
+
+      test();
+    }
+  else
+    test();
+}
diff --git a/tests/petsc/copy_to_dealvec.with_mpi=true.mpirun=4.output b/tests/petsc/copy_to_dealvec.with_mpi=true.mpirun=4.output
new file mode 100644 (file)
index 0000000..6ed3f01
--- /dev/null
@@ -0,0 +1,8 @@
+
+DEAL:0::numproc=4
+DEAL:0::0:0
+DEAL:0::1:2.000
+DEAL:0::ghost: 2.000
+DEAL:0::0:0
+DEAL:0::1:2.000
+DEAL:0::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.