]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add test
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 2 Nov 2013 11:27:09 +0000 (11:27 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 2 Nov 2013 11:27:09 +0000 (11:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@31509 0785d39b-7218-0410-832d-ea1e28bc413d

tests/mpi/p4est_save_04.cc [new file with mode: 0644]
tests/mpi/p4est_save_04.with_petsc=true.mpirun=5.output [new file with mode: 0644]

diff --git a/tests/mpi/p4est_save_04.cc b/tests/mpi/p4est_save_04.cc
new file mode 100644 (file)
index 0000000..0d05f86
--- /dev/null
@@ -0,0 +1,160 @@
+// ---------------------------------------------------------------------
+// $Id: p4est_save_03.cc 31349 2013-10-20 19:07:06Z maier $
+//
+// Copyright (C) 2009 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// save and load a triangulation with a different number of cpus
+
+#include "../tests.h"
+#include "coarse_grid_common.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/tensor.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/distributed/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/base/utilities.h>
+#include <deal.II/distributed/solution_transfer.h>
+#include <deal.II/lac/petsc_parallel_vector.h>
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/dofs/dof_tools.h>
+
+
+#include <deal.II/fe/fe_q.h>
+
+#include <fstream>
+
+
+
+template<int dim>
+void test()
+{
+  unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD);
+  MPI_Comm com_all = MPI_COMM_WORLD;
+  MPI_Comm com_small;
+
+  // split the communicator in proc 0,1,2 and 3,4
+  MPI_Comm_split(com_all, (myid<3)?0:1, myid, &com_small);
+
+  // write with small com
+  if (myid<3)
+  {
+    deallog << "writing with " <<  Utilities::MPI::n_mpi_processes(com_small) << std::endl;
+    
+    parallel::distributed::Triangulation<dim> tr (com_small);
+    GridGenerator::hyper_cube (tr);
+    tr.refine_global (2);
+    for (typename Triangulation<dim>::active_cell_iterator
+         cell = tr.begin_active();
+         cell != tr.end(); ++cell)
+      if (!cell->is_ghost() && !cell->is_artificial())
+        if (cell->center().norm() < 0.3)
+          {
+            cell->set_refine_flag();
+          }
+
+    tr.execute_coarsening_and_refinement ();
+
+    FE_Q<dim> fe (1);
+    DoFHandler<dim> dh (tr);
+    dh.distribute_dofs (fe);
+
+    IndexSet locally_owned_dofs = dh.locally_owned_dofs ();
+    IndexSet locally_relevant_dofs;
+    DoFTools::extract_locally_relevant_dofs (dh, locally_relevant_dofs);
+
+    PETScWrappers::MPI::Vector x (locally_owned_dofs, com_small);
+    PETScWrappers::MPI::Vector rel_x (locally_owned_dofs, locally_relevant_dofs, com_small);
+
+    parallel::distributed::SolutionTransfer<dim, PETScWrappers::MPI::Vector> soltrans (dh);
+
+    for (unsigned int i = 0; i < locally_owned_dofs.n_elements(); ++i)
+      {
+        unsigned int idx = locally_owned_dofs.nth_index_in_set (i);
+        x (idx) = idx;
+        deallog << '[' << idx << ']' << ' ' << x(idx) << std::endl;
+      }
+
+    
+    x.compress(VectorOperation::insert);
+    rel_x=x;
+
+    soltrans.prepare_serialization (rel_x);
+
+    tr.save ("file");
+    //    tr.write_mesh_vtk("before");
+    deallog << "#cells = " << tr.n_global_active_cells() << " norm= " << x.l2_norm() << std::endl;
+    deallog << "Checksum: "
+            << tr.get_checksum ()
+            << std::endl;
+  }
+  
+  MPI_Barrier (MPI_COMM_WORLD);
+
+  deallog << "reading with " << Utilities::MPI::n_mpi_processes(com_all) << std::endl;
+  
+  {
+    parallel::distributed::Triangulation<dim> tr (com_all);
+
+    GridGenerator::hyper_cube (tr);
+    tr.load ("file");
+    FE_Q<dim> fe (1);
+    DoFHandler<dim> dh (tr);
+    dh.distribute_dofs (fe);
+
+    IndexSet locally_owned_dofs = dh.locally_owned_dofs ();
+    IndexSet locally_relevant_dofs;
+
+    DoFTools::extract_locally_relevant_dofs (dh, locally_relevant_dofs);
+
+    PETScWrappers::MPI::Vector solution (locally_owned_dofs, com_all);
+    solution = 0;
+    
+    parallel::distributed::SolutionTransfer<dim, PETScWrappers::MPI::Vector> soltrans (dh);
+    soltrans.deserialize (solution);
+
+    for (unsigned int i = 0; i < locally_owned_dofs.n_elements(); ++i)
+      {
+        unsigned int idx = locally_owned_dofs.nth_index_in_set (i);
+        deallog << '[' << idx << ']' << ' ' << solution(idx) << std::endl;
+      }
+
+    deallog << "#cells = " << tr.n_global_active_cells() << std::endl;
+    deallog << "Checksum: "
+            << tr.get_checksum ()
+            << std::endl;
+    deallog << "norm: "
+            << solution.l2_norm() 
+            << std::endl;
+    //    tr.write_mesh_vtk("after");
+  }
+
+  if (Utilities::MPI::this_mpi_process (MPI_COMM_WORLD) == 0)
+    deallog << "OK" << std::endl;
+}
+
+
+int main (int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll log;
+
+  test<2>();
+}
diff --git a/tests/mpi/p4est_save_04.with_petsc=true.mpirun=5.output b/tests/mpi/p4est_save_04.with_petsc=true.mpirun=5.output
new file mode 100644 (file)
index 0000000..6a6dafa
--- /dev/null
@@ -0,0 +1,99 @@
+
+DEAL:0::writing with 3
+DEAL:0::[0] 0.00000
+DEAL:0::[1] 1.00000
+DEAL:0::[2] 2.00000
+DEAL:0::[3] 3.00000
+DEAL:0::[4] 4.00000
+DEAL:0::[5] 5.00000
+DEAL:0::[6] 6.00000
+DEAL:0::[7] 7.00000
+DEAL:0::[8] 8.00000
+DEAL:0::[9] 9.00000
+DEAL:0::[10] 10.0000
+DEAL:0::[11] 11.0000
+DEAL:0::[12] 12.0000
+DEAL:0::#cells = 19 norm= 92.4932
+DEAL:0::Checksum: 136119115
+DEAL:0::reading with 5
+DEAL:0::[0] 7.00000
+DEAL:0::[1] 8.00000
+DEAL:0::[2] 9.00000
+DEAL:0::[3] 10.0000
+DEAL:0::[4] 0.00000
+DEAL:0::[5] 11.0000
+DEAL:0::[6] 4.00000
+DEAL:0::[7] 12.0000
+DEAL:0::[8] 2.00000
+DEAL:0::#cells = 19
+DEAL:0::Checksum: 136119115
+DEAL:0::norm: 92.4932
+DEAL:0::OK
+
+DEAL:1::writing with 3
+DEAL:1::[13] 13.0000
+DEAL:1::[14] 14.0000
+DEAL:1::[15] 15.0000
+DEAL:1::[16] 16.0000
+DEAL:1::[17] 17.0000
+DEAL:1::[18] 18.0000
+DEAL:1::[19] 19.0000
+DEAL:1::#cells = 19 norm= 92.4932
+DEAL:1::Checksum: 0
+DEAL:1::reading with 5
+DEAL:1::[9] 1.00000
+DEAL:1::[10] 3.00000
+DEAL:1::[11] 5.00000
+DEAL:1::[12] 6.00000
+DEAL:1::[13] 13.0000
+DEAL:1::#cells = 19
+DEAL:1::Checksum: 0
+DEAL:1::norm: 92.4932
+
+
+DEAL:2::writing with 3
+DEAL:2::[20] 20.0000
+DEAL:2::[21] 21.0000
+DEAL:2::[22] 22.0000
+DEAL:2::[23] 23.0000
+DEAL:2::[24] 24.0000
+DEAL:2::[25] 25.0000
+DEAL:2::[26] 26.0000
+DEAL:2::[27] 27.0000
+DEAL:2::[28] 28.0000
+DEAL:2::[29] 29.0000
+DEAL:2::#cells = 19 norm= 92.4932
+DEAL:2::Checksum: 0
+DEAL:2::reading with 5
+DEAL:2::[14] 14.0000
+DEAL:2::[15] 15.0000
+DEAL:2::[16] 16.0000
+DEAL:2::[17] 17.0000
+DEAL:2::[18] 18.0000
+DEAL:2::[19] 19.0000
+DEAL:2::#cells = 19
+DEAL:2::Checksum: 0
+DEAL:2::norm: 92.4932
+
+
+DEAL:3::reading with 5
+DEAL:3::[20] 20.0000
+DEAL:3::[21] 21.0000
+DEAL:3::[22] 22.0000
+DEAL:3::[23] 23.0000
+DEAL:3::[24] 24.0000
+DEAL:3::[25] 25.0000
+DEAL:3::#cells = 19
+DEAL:3::Checksum: 0
+DEAL:3::norm: 92.4932
+
+
+DEAL:4::reading with 5
+DEAL:4::[26] 26.0000
+DEAL:4::[27] 27.0000
+DEAL:4::[28] 28.0000
+DEAL:4::[29] 29.0000
+DEAL:4::#cells = 19
+DEAL:4::Checksum: 0
+DEAL:4::norm: 92.4932
+

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.