From: Martin Kronbichler Date: Fri, 21 Jan 2011 17:35:37 +0000 (+0000) Subject: New small test case to assess distribute in ConstraintMatrix with Trilinos vectors. X-Git-Tag: v8.0.0~4460 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e47c7b38b52eea658c93001fb7e67938c685b11d;p=dealii.git New small test case to assess distribute in ConstraintMatrix with Trilinos vectors. git-svn-id: https://svn.dealii.org/trunk@23232 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/mpi/p4est_2d_constraintmatrix_05.cc b/tests/mpi/p4est_2d_constraintmatrix_05.cc new file mode 100644 index 0000000000..a1e655a082 --- /dev/null +++ b/tests/mpi/p4est_2d_constraintmatrix_05.cc @@ -0,0 +1,129 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 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. +// +//--------------------------------------------------------------------------- + + +// check that ConstraintMatrix.distribute() is not doing anything in a +// distributed computation for a vector that already has the entries set +// correctly + +#include "../tests.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +template +void test() +{ + unsigned int myid = Utilities::System::get_this_mpi_process (MPI_COMM_WORLD); + unsigned int numproc = Utilities::System::get_n_mpi_processes (MPI_COMM_WORLD); + + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + + tr.refine_global (1); + tr.begin_active()->set_refine_flag (); + tr.execute_coarsening_and_refinement (); + + DoFHandler dofh(tr); + + static FE_Q fe(1); + + dofh.distribute_dofs (fe); + + IndexSet owned_set = dofh.locally_owned_dofs(); + + IndexSet relevant_set; + DoFTools::extract_locally_relevant_dofs (dofh, relevant_set); + + TrilinosWrappers::MPI::Vector x_ref; + x_ref.reinit(owned_set, MPI_COMM_WORLD); + VectorTools::interpolate(* static_cast* >(&dofh), + ConstantFunction (1.), + x_ref); + x_ref.compress(); + + TrilinosWrappers::MPI::Vector x1 (x_ref); + + // we have interpolated values, so + // ConstraintMatrix::distribute should not do + // anything + x1 = x_ref; + ConstraintMatrix cm(relevant_set); + DoFTools::make_hanging_node_constraints (* static_cast* >(&dofh), cm); + cm.distribute(x1); + + x1 -= x_ref; + double err = x1.linfty_norm(); + if (err>1.0e-12) + if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0) + deallog << "err:" << err << std::endl; + + // now test the same thing with a fresh vector + // that we manually fill with ones, not by a + // function in interpolate + TrilinosWrappers::MPI::Vector x2 (owned_set, MPI_COMM_WORLD); + x2 = 1; + cm.distribute(x2); + x2 -= x_ref; + err = x2.linfty_norm(); + if (err>1.0e-12) + if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0) + deallog << "err:" << err << std::endl; + + if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0) + deallog << "OK" << std::endl; +} + + +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("p4est_2d_constraintmatrix_05").c_str()); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + deallog.push("2d"); + test<2>(); + deallog.pop(); + } + else + test<2>(); + +#ifdef DEAL_II_COMPILER_SUPPORTS_MPI + MPI_Finalize(); +#endif +} diff --git a/tests/mpi/p4est_2d_constraintmatrix_05/ncpu_2/cmp/generic b/tests/mpi/p4est_2d_constraintmatrix_05/ncpu_2/cmp/generic new file mode 100644 index 0000000000..c802a6f0b4 --- /dev/null +++ b/tests/mpi/p4est_2d_constraintmatrix_05/ncpu_2/cmp/generic @@ -0,0 +1,2 @@ + +DEAL:0:2d::OK diff --git a/tests/mpi/p4est_3d_constraintmatrix_03.cc b/tests/mpi/p4est_3d_constraintmatrix_03.cc index dffc3b2727..14302119d3 100644 --- a/tests/mpi/p4est_3d_constraintmatrix_03.cc +++ b/tests/mpi/p4est_3d_constraintmatrix_03.cc @@ -1,8 +1,8 @@ //--------------------------------------------------------------------------- -// $Id: 2d_coarse_grid_01.cc 17444 2008-10-31 19:35:14Z bangerth $ +// $Id$ // Version: $Name$ // -// Copyright (C) 2009, 2010 by the deal.II authors +// 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 @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -153,8 +152,8 @@ void test() // GridGenerator::hyper_cube(tr); - - + + GridGenerator::hyper_shell (tr, Point(), R0, @@ -164,7 +163,7 @@ void test() static HyperShellBoundary boundary; // tr.set_boundary (0, boundary); //tr.set_boundary (1, boundary); - + tr.refine_global (1); if (1) for (unsigned int step=0; step<5;++step) @@ -172,22 +171,22 @@ void test() typename Triangulation::active_cell_iterator cell = tr.begin_active(), endc = tr.end(); - + for (; cell!=endc; ++cell) if (std::rand()%42==1) cell->set_refine_flag (); - + tr.execute_coarsening_and_refinement (); } - + DoFHandler dofh(tr); static FE_Q fe(3); - + dofh.distribute_dofs (fe); IndexSet owned_set = dofh.locally_owned_dofs(); - + IndexSet dof_set; DoFTools::extract_locally_active_dofs (dofh, dof_set); @@ -204,14 +203,14 @@ void test() TrilinosWrappers::MPI::Vector x_rel; x_rel.reinit(relevant_set, MPI_COMM_WORLD); x_rel = x; - + for (unsigned int steps=0;steps<7;++steps) - { + { { typename Triangulation::active_cell_iterator cell = tr.begin_active(), endc = tr.end(); - + for (; cell!=endc; ++cell) if (!cell->is_artificial() && !cell->is_ghost()) { @@ -219,7 +218,7 @@ void test() cell->set_refine_flag (); else if (std::rand()%7==1) cell->set_coarsen_flag (); - } + } } for (typename Triangulation::cell_iterator cell = tr.begin(); @@ -227,7 +226,7 @@ void test() { if (!cell->has_children()) continue; - + bool coarsen_me = false; for (unsigned int i=0;in_children();++i) if (cell->child(i)->coarsen_flag_set()) @@ -253,23 +252,23 @@ void test() } } - + parallel::distributed::SolutionTransfer trans(dofh); tr.prepare_coarsening_and_refinement(); - + trans.prepare_for_coarsening_and_refinement(x_rel); - + tr.execute_coarsening_and_refinement (); - + static FE_Q fe(1); - + dofh.distribute_dofs (fe); owned_set = dofh.locally_owned_dofs(); - + DoFTools::extract_locally_active_dofs (dofh, dof_set); DoFTools::extract_locally_relevant_dofs (dofh, relevant_set); @@ -277,17 +276,17 @@ void test() x.reinit(owned_set, MPI_COMM_WORLD); trans.interpolate(x); - + x_rel.reinit(relevant_set, MPI_COMM_WORLD); x_rel = 0; x_rel.compress(); - + ConstraintMatrix cm(relevant_set); DoFTools::make_hanging_node_constraints (* static_cast* >(&dofh), cm); /* std::vector velocity_mask (dim+1, true); - + velocity_mask[dim] = false; - + VectorTools::interpolate_boundary_values (static_cast&>(dofh), 0, ZeroFunction(1), @@ -303,27 +302,27 @@ void test() TrilinosWrappers::MPI::Vector x_ref; x_ref.reinit(owned_set, MPI_COMM_WORLD); - + VectorTools::interpolate(* static_cast* >(&dofh), TemperatureInitialValues(), x_ref); x_ref.compress(); - + x_ref -= x; double err = x_ref.linfty_norm(); if (err>1.0e-12) if (Utilities::System::get_this_mpi_process (MPI_COMM_WORLD) == 0) deallog << "err:" << err << std::endl; - + // x_rel=x_ref; //uncomment to output error - + std::vector solution_names(1,"T"); - + FilteredDataOut data_out (tr.locally_owned_subdomain()); data_out.attach_dof_handler (dofh); - + data_out.add_data_vector(x_rel, solution_names); - + data_out.build_patches (1); const std::string filename = ("p4est_3d_constraintmatrix_03/solution." + Utilities::int_to_string @@ -331,7 +330,7 @@ void test() ".vtu"); std::ofstream output (filename.c_str()); data_out.write_vtu (output); - + tr.set_boundary (0); tr.set_boundary (1);