]> https://gitweb.dealii.org/ - dealii.git/commitdiff
New small test case to assess distribute in ConstraintMatrix with Trilinos vectors.
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 21 Jan 2011 17:35:37 +0000 (17:35 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 21 Jan 2011 17:35:37 +0000 (17:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@23232 0785d39b-7218-0410-832d-ea1e28bc413d

tests/mpi/p4est_2d_constraintmatrix_05.cc [new file with mode: 0644]
tests/mpi/p4est_2d_constraintmatrix_05/ncpu_2/cmp/generic [new file with mode: 0644]
tests/mpi/p4est_3d_constraintmatrix_03.cc

diff --git a/tests/mpi/p4est_2d_constraintmatrix_05.cc b/tests/mpi/p4est_2d_constraintmatrix_05.cc
new file mode 100644 (file)
index 0000000..a1e655a
--- /dev/null
@@ -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 <base/logstream.h>
+#include <base/function.h>
+#include <numerics/vectors.h>
+
+#include <grid/tria.h>
+#include <distributed/tria.h>
+#include <grid/grid_generator.h>
+#include <dofs/dof_handler.h>
+#include <dofs/dof_tools.h>
+#include <lac/trilinos_vector.h>
+#include <fe/fe_q.h>
+
+
+template<int dim>
+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<dim> tr(MPI_COMM_WORLD);
+
+  GridGenerator::hyper_cube(tr);
+
+  tr.refine_global (1);
+  tr.begin_active()->set_refine_flag ();
+  tr.execute_coarsening_and_refinement ();
+
+  DoFHandler<dim> dofh(tr);
+
+  static FE_Q<dim> 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<DoFHandler<dim>* >(&dofh),
+                          ConstantFunction<dim> (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<DoFHandler<dim>* >(&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 (file)
index 0000000..c802a6f
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL:0:2d::OK
index dffc3b272749eaafb72b36b77c7e735243e84a0b..14302119d3507217141f28d6b51fb2ca6ce0a4c0 100644 (file)
@@ -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 <grid/grid_out.h>
 #include <dofs/dof_handler.h>
 #include <distributed/solution_transfer.h>
-#include <dofs/dof_handler.h>
 #include <dofs/dof_tools.h>
 #include <grid/tria_accessor.h>
 #include <grid/tria_iterator.h>
@@ -153,8 +152,8 @@ void test()
 
 
 //  GridGenerator::hyper_cube(tr);
-  
-  
+
+
   GridGenerator::hyper_shell (tr,
                              Point<dim>(),
                              R0,
@@ -164,7 +163,7 @@ void test()
   static HyperShellBoundary<dim> 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<dim>::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<dim> dofh(tr);
 
   static FE_Q<dim> 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<dim>::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<dim>::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;i<cell->n_children();++i)
            if (cell->child(i)->coarsen_flag_set())
@@ -253,23 +252,23 @@ void test()
              }
 
        }
-      
+
       parallel::distributed::SolutionTransfer<dim,TrilinosWrappers::MPI::Vector>
        trans(dofh);
       tr.prepare_coarsening_and_refinement();
-       
+
 
       trans.prepare_for_coarsening_and_refinement(x_rel);
-       
+
       tr.execute_coarsening_and_refinement ();
-       
+
 
       static FE_Q<dim> 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<DoFHandler<dim>* >(&dofh), cm);
 /*  std::vector<bool> velocity_mask (dim+1, true);
-  
+
     velocity_mask[dim] = false;
-                                   
+
     VectorTools::interpolate_boundary_values (static_cast<const DoFHandler<dim>&>(dofh),
     0,
     ZeroFunction<dim>(1),
@@ -303,27 +302,27 @@ void test()
 
   TrilinosWrappers::MPI::Vector x_ref;
   x_ref.reinit(owned_set, MPI_COMM_WORLD);
-  
+
   VectorTools::interpolate(* static_cast<DoFHandler<dim>* >(&dofh),
                           TemperatureInitialValues<dim>(),
                           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<std::string> solution_names(1,"T");
-  
+
   FilteredDataOut<dim> 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);
 

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.