From 457ab3e572db6058a4dc273143a80b5c4dcddbb4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 11 Feb 2011 03:17:54 +0000 Subject: [PATCH] Add new test. git-svn-id: https://svn.dealii.org/trunk@23326 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/mpi/integrate_difference.cc | 153 ++++++++++++++++++ .../integrate_difference/ncpu_10/cmp/generic | 3 + .../integrate_difference/ncpu_4/cmp/generic | 3 + 3 files changed, 159 insertions(+) create mode 100644 tests/mpi/integrate_difference.cc create mode 100644 tests/mpi/integrate_difference/ncpu_10/cmp/generic create mode 100644 tests/mpi/integrate_difference/ncpu_4/cmp/generic diff --git a/tests/mpi/integrate_difference.cc b/tests/mpi/integrate_difference.cc new file mode 100644 index 0000000000..3883fcc4db --- /dev/null +++ b/tests/mpi/integrate_difference.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +template +class LinearFunction : public Function +{ + public: + double value (const Point &p, + const unsigned int) const + { + return p[0]; + } +}; + + +template +void test() +{ + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + tr.refine_global (2); + + const FE_Q fe(2); + DoFHandler dofh(tr); + dofh.distribute_dofs (fe); + + TrilinosWrappers::MPI::Vector interpolated(dofh.locally_owned_dofs(), + MPI_COMM_WORLD); + VectorTools::interpolate (dofh, + LinearFunction(), + 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 results (tr.n_active_cells()); + VectorTools::integrate_difference (dofh, x_rel, + ZeroFunction(), + results, + QGauss(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 index 0000000000..02b42b4570 --- /dev/null +++ b/tests/mpi/integrate_difference/ncpu_10/cmp/generic @@ -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 index 0000000000..02b42b4570 --- /dev/null +++ b/tests/mpi/integrate_difference/ncpu_4/cmp/generic @@ -0,0 +1,3 @@ + +DEAL:0:2d::difference = 0.577350 +DEAL:0:3d::difference = 0.577350 -- 2.39.5