From: Timo Heister Date: Sat, 2 Nov 2013 11:27:09 +0000 (+0000) Subject: add test X-Git-Tag: v8.1.0~428 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed19a5938b5fb602d6b1a6ba11fa7f8b09983d02;p=dealii.git add test git-svn-id: https://svn.dealii.org/trunk@31509 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/mpi/p4est_save_04.cc b/tests/mpi/p4est_save_04.cc new file mode 100644 index 0000000000..0d05f86a90 --- /dev/null +++ b/tests/mpi/p4est_save_04.cc @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + + +#include + +#include + + + +template +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 tr (com_small); + GridGenerator::hyper_cube (tr); + tr.refine_global (2); + for (typename Triangulation::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 fe (1); + DoFHandler 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 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 tr (com_all); + + GridGenerator::hyper_cube (tr); + tr.load ("file"); + FE_Q fe (1); + DoFHandler 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 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 index 0000000000..6a6dafa5e3 --- /dev/null +++ b/tests/mpi/p4est_save_04.with_petsc=true.mpirun=5.output @@ -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 +