From 0789ae9662c802f788563d3bb3053724cac9da19 Mon Sep 17 00:00:00 2001 From: heister Date: Wed, 31 Jul 2013 15:01:48 +0000 Subject: [PATCH] fix test git-svn-id: https://svn.dealii.org/trunk@30199 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/gla/block_mat_03.cc | 111 ++++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 9 deletions(-) diff --git a/tests/gla/block_mat_03.cc b/tests/gla/block_mat_03.cc index 4f9987e331..8a46835da2 100644 --- a/tests/gla/block_mat_03.cc +++ b/tests/gla/block_mat_03.cc @@ -84,16 +84,21 @@ void test () locally_owned_partitioning.push_back (locally_owned_dofs.get_view(0, dofs_per_block[0])); locally_owned_partitioning.push_back (locally_owned_dofs.get_view(dofs_per_block[0], dofs_per_block[0] + dofs_per_block[1])); + deallog << "owned: "; + locally_owned_dofs.print(deallog); + deallog << "relevant: "; + locally_relevant_dofs.print(deallog); + + ConstraintMatrix constraints(locally_relevant_dofs); constraints.close(); - BlockCompressedSimpleSparsityPattern bcsp (locally_owned_partitioning); + BlockCompressedSimpleSparsityPattern bcsp (locally_relevant_partitioning); DoFTools::make_sparsity_pattern (dof_handler, bcsp, constraints, false); - SparsityTools::distribute_sparsity_pattern (bcsp, dof_handler.n_locally_owned_dofs_per_processor (), MPI_COMM_WORLD, locally_relevant_dofs); + SparsityTools::distribute_sparsity_pattern (bcsp, dof_handler.locally_owned_dofs_per_processor (), MPI_COMM_WORLD, locally_relevant_dofs); typename LA::MPI::BlockSparseMatrix A; A.reinit(locally_owned_partitioning, bcsp, MPI_COMM_WORLD); - A.print(deallog.get_file_stream()); QGauss<3> quadrature (3); FEValues<3> fe_values (fe, quadrature, update_values); @@ -101,7 +106,6 @@ void test () std::vector local_dof_indices (fe.dofs_per_cell); FullMatrix local_matrix(fe.dofs_per_cell, fe.dofs_per_cell); - if (1) for (DoFHandler<3>::active_cell_iterator cell = dof_handler.begin_active (); cell != dof_handler.end (); ++cell) if (cell->is_locally_owned ()) { @@ -116,16 +120,102 @@ void test () local_matrix (i, j) += fe_values.shape_value(i, q_point) * fe_values.shape_value(j, q_point); } } + + cell->get_dof_indices (local_dof_indices); + constraints.distribute_local_to_global (local_matrix, local_dof_indices, A); + } + + A.compress(VectorOperation::add); + A.print(deallog.get_file_stream()); + + if (myid==0) + deallog << "OK" << std::endl; +} + +template +void test_alt() +{ + typedef LA_Trilinos LA; + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + unsigned int numproc = Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + + if (myid==0) + deallog << "numproc=" << numproc << std::endl; + + parallel::distributed::Triangulation<3> triangulation(MPI_COMM_WORLD); + GridGenerator::hyper_cube (triangulation, -1.0, 1.0); + triangulation.refine_global(2); + + FESystem<3> fe(FE_Q<3> (1), 2); + DoFHandler<3> dof_handler(triangulation); + dof_handler.distribute_dofs(fe); + DoFRenumbering::block_wise(dof_handler); + + std::vector dofs_per_block (fe.n_blocks()); + std::vector sub_blocks (fe.n_blocks(), 0); sub_blocks[1] = 1; + DoFTools::count_dofs_per_block (dof_handler, dofs_per_block, sub_blocks); + + deallog << "size: " << dofs_per_block[0] << " " << dofs_per_block[1] << std::endl; + + std::vector locally_relevant_partitioning; + std::vector locally_owned_partitioning; + IndexSet locally_relevant_dofs; + DoFTools::extract_locally_relevant_dofs (dof_handler, locally_relevant_dofs); + locally_relevant_partitioning.push_back (locally_relevant_dofs.get_view (0, dofs_per_block[0])); + locally_relevant_partitioning.push_back (locally_relevant_dofs.get_view (dofs_per_block[0], dofs_per_block[0] + dofs_per_block[1])); + + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs (); + locally_owned_partitioning.push_back (locally_owned_dofs.get_view(0, dofs_per_block[0])); + locally_owned_partitioning.push_back (locally_owned_dofs.get_view(dofs_per_block[0], dofs_per_block[0] + dofs_per_block[1])); + + deallog << "owned: "; + locally_owned_dofs.print(deallog); + deallog << "relevant: "; + locally_relevant_dofs.print(deallog); + + + ConstraintMatrix constraints(locally_relevant_dofs); + constraints.close(); + + TrilinosWrappers::BlockSparsityPattern sp (locally_owned_partitioning, + MPI_COMM_WORLD); + DoFTools::make_sparsity_pattern (dof_handler, sp, + constraints, false, + Utilities::MPI:: + this_mpi_process(MPI_COMM_WORLD)); + sp.compress(); + typename LA::MPI::BlockSparseMatrix A; +A.reinit(sp); + + QGauss<3> quadrature (3); + FEValues<3> fe_values (fe, quadrature, update_values); + + std::vector local_dof_indices (fe.dofs_per_cell); + FullMatrix local_matrix(fe.dofs_per_cell, fe.dofs_per_cell); + + for (DoFHandler<3>::active_cell_iterator cell = dof_handler.begin_active (); cell != dof_handler.end (); ++cell) + if (cell->is_locally_owned ()) + { + fe_values.reinit (cell); + local_matrix = 0.0; + + for (unsigned int q_point = 0; q_point < fe_values.n_quadrature_points; ++q_point) + { + for (unsigned int i = 0; i < fe.dofs_per_cell; ++i) + { + for (unsigned int j = 0; j < fe.dofs_per_cell; ++j) + local_matrix (i, j) += fe_values.shape_value(i, q_point) * fe_values.shape_value(j, q_point); + } + } + cell->get_dof_indices (local_dof_indices); - for (unsigned int i = 0; i < fe.dofs_per_cell; ++i) - deallog << local_dof_indices[i] << " "; - deallog << std::endl; - constraints.distribute_local_to_global (local_matrix, local_dof_indices, A); } A.compress(VectorOperation::add); + //A.print(deallog.get_file_stream()); + if (myid==0) deallog << "OK" << std::endl; } @@ -134,7 +224,7 @@ void test () int main (int argc, char **argv) { Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); - MPILogInitAll log(__FILE__, true); + MPILogInitAll log(__FILE__); { deallog.push("PETSc"); @@ -143,6 +233,9 @@ int main (int argc, char **argv) deallog.push("Trilinos"); test(); deallog.pop(); + deallog.push("Trilinos_alt"); + test_alt<3>(); + deallog.pop(); } // compile, don't run -- 2.39.5