]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add new test.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 11 Feb 2011 03:17:54 +0000 (03:17 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 11 Feb 2011 03:17:54 +0000 (03:17 +0000)
git-svn-id: https://svn.dealii.org/trunk@23326 0785d39b-7218-0410-832d-ea1e28bc413d

tests/mpi/integrate_difference.cc [new file with mode: 0644]
tests/mpi/integrate_difference/ncpu_10/cmp/generic [new file with mode: 0644]
tests/mpi/integrate_difference/ncpu_4/cmp/generic [new file with mode: 0644]

diff --git a/tests/mpi/integrate_difference.cc b/tests/mpi/integrate_difference.cc
new file mode 100644 (file)
index 0000000..3883fcc
--- /dev/null
@@ -0,0 +1,153 @@
+//---------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2009, 2010, 2011 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.
+//
+//---------------------------------------------------------------------------
+
+
+// Test VectorTools::integrate_difference for parallel computations.
+
+#include "../tests.h"
+#include "coarse_grid_common.h"
+#include <base/logstream.h>
+#include <base/function.h>
+#include <base/tensor.h>
+#include <lac/trilinos_vector.h>
+#include <grid/tria.h>
+#include <grid/grid_generator.h>
+#include <distributed/tria.h>
+#include <grid/grid_generator.h>
+#include <grid/grid_out.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_tools.h>
+#include <grid/tria_accessor.h>
+#include <grid/tria_iterator.h>
+#include <dofs/dof_accessor.h>
+
+#include <fe/fe_q.h>
+#include <numerics/vectors.h>
+
+#include <fstream>
+
+
+template <int dim>
+class LinearFunction : public Function<dim> 
+{
+  public:
+    double value (const Point<dim> &p,
+                 const unsigned int) const
+      {
+       return p[0];
+      }
+};
+
+
+template<int dim>
+void test()
+{
+  parallel::distributed::Triangulation<dim> tr(MPI_COMM_WORLD);
+
+  GridGenerator::hyper_cube(tr);
+  tr.refine_global (2);
+
+  const FE_Q<dim> fe(2);
+  DoFHandler<dim> dofh(tr);
+  dofh.distribute_dofs (fe);
+
+  TrilinosWrappers::MPI::Vector interpolated(dofh.locally_owned_dofs(),
+                                            MPI_COMM_WORLD);
+  VectorTools::interpolate (dofh,
+                           LinearFunction<dim>(),
+                           interpolated);
+  
+  IndexSet relevant_set;
+  DoFTools::extract_locally_relevant_dofs (dofh, relevant_set);
+  TrilinosWrappers::MPI::Vector x_rel(relevant_set, MPI_COMM_WORLD);
+  x_rel = interpolated;
+
+                                  // integrate the difference between the
+                                  // linear function above and the zero
+                                  // function. for this case, we can
+                                  // compute the exact values by hand. the
+                                  // ones printed in the output are correct
+  Vector<float> results (tr.n_active_cells());
+  VectorTools::integrate_difference (dofh, x_rel,
+                                    ZeroFunction<dim>(),
+                                    results,
+                                    QGauss<dim>(3),
+                                    VectorTools::L2_norm);
+  double local = results.l2_norm() * results.l2_norm();
+  double global;
+
+  MPI_Allreduce (&local, &global, 1, MPI_DOUBLE,
+                MPI_SUM, 
+                tr.get_communicator());
+
+  if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "difference = " << std::sqrt(global)
+           << std::endl;
+
+                                  // we have f(\vec x)=x, so the difference
+                                  // squared is \int f(x)^2 = 1/3 and the
+                                  // norm is 1/sqrt(3)
+                                  //
+                                  // note that we have used a quadrature
+                                  // formula of sufficient order to get exact
+                                  // results
+  Assert (std::fabs(std::sqrt(global) - 1./std::sqrt(3.)) < 1e-6,
+         ExcInternalError());
+}
+
+
+int main(int argc, char *argv[])
+{
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+  MPI_Init (&argc,&argv);
+#else
+  (void)argc;
+  (void)argv;
+#endif
+
+  unsigned int myid = Utilities::System::get_this_mpi_process (MPI_COMM_WORLD);
+
+
+  deallog.push(Utilities::int_to_string(myid));
+
+  if (myid == 0)
+    {
+      std::ofstream logfile(output_file_for_mpi("integrate_difference").c_str());
+      deallog.attach(logfile);
+      deallog.depth_console(0);
+      deallog.threshold_double(1.e-10);
+
+      deallog.push("2d");
+      test<2>();
+      deallog.pop();
+
+      deallog.push("3d");
+      test<3>();
+      deallog.pop();
+    }
+  else
+    {
+      deallog.push("2d");
+      test<2>();
+      deallog.pop();
+
+      deallog.push("3d");
+      test<3>();
+      deallog.pop();
+    }
+
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+  MPI_Finalize();
+#endif
+}
diff --git a/tests/mpi/integrate_difference/ncpu_10/cmp/generic b/tests/mpi/integrate_difference/ncpu_10/cmp/generic
new file mode 100644 (file)
index 0000000..02b42b4
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL:0:2d::difference = 0.577350
+DEAL:0:3d::difference = 0.577350
diff --git a/tests/mpi/integrate_difference/ncpu_4/cmp/generic b/tests/mpi/integrate_difference/ncpu_4/cmp/generic
new file mode 100644 (file)
index 0000000..02b42b4
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL:0:2d::difference = 0.577350
+DEAL:0:3d::difference = 0.577350

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.