From: Wolfgang Bangerth Date: Mon, 15 Mar 2004 16:42:42 +0000 (+0000) Subject: Test ConstraintMatrix::distribute_local_to_global. X-Git-Tag: v8.0.0~15605 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29f6c00afb2a2a90a53007dc9214292cdce52b4c;p=dealii.git Test ConstraintMatrix::distribute_local_to_global. git-svn-id: https://svn.dealii.org/trunk@8743 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/bits/Makefile b/tests/bits/Makefile index 449742f13d..bc0db51e8d 100644 --- a/tests/bits/Makefile +++ b/tests/bits/Makefile @@ -52,7 +52,8 @@ tests_x = anna_? \ solver_selector \ deal_solver_* \ vector_* \ - subdomain_ids_* + subdomain_ids_* \ + dof_constraints_* ifeq ($(USE_CONTRIB_PETSC),yes) tests_x += petsc_* diff --git a/tests/bits/dof_constraints_01.cc b/tests/bits/dof_constraints_01.cc new file mode 100644 index 0000000000..b19a949af6 --- /dev/null +++ b/tests/bits/dof_constraints_01.cc @@ -0,0 +1,166 @@ +//---------------------------- dof_constraints_01.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 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. +// +//---------------------------- dof_constraints_01.cc --------------------------- + + +// check DoFConstraints::distribute_local_to_global for matrices + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +template +void test () +{ + deallog << dim << "D" << std::endl; + + Triangulation triangulation; + GridGenerator::hyper_cube (triangulation); + + // refine the mesh in a random way so as to + // generate as many hanging node + // constraints as possible +// triangulation.refine_global (4-dim); + triangulation.refine_global (1); + for (unsigned int i=0; i<1; ++i) + { + typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + for (unsigned int index=0; cell != triangulation.end(); ++cell, ++index) + if (index % (3*dim) == 0) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); + } + deallog << "Number of cells: " << triangulation.n_active_cells() << std::endl; + + // set up a DoFHandler and compute hanging + // node constraints + FE_Q fe(1); + DoFHandler dof_handler (triangulation); + dof_handler.distribute_dofs (fe); + deallog << "Number of dofs: " << dof_handler.n_dofs() << std::endl; + + ConstraintMatrix constraints; + DoFTools::make_hanging_node_constraints (dof_handler, constraints); + constraints.close (); + deallog << "Number of constraints: " << constraints.n_constraints() << std::endl; + + // then set up a sparsity pattern and two + // matrices on top of it + SparsityPattern sparsity (dof_handler.n_dofs(), + dof_handler.n_dofs(), + dof_handler.max_couplings_between_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, sparsity); + constraints.condense (sparsity); + SparseMatrix A(sparsity), B(sparsity); + + // then fill the two matrices by setting up + // bogus matrix entries and (1) writing + // them into the matrix and condensing away + // hanging node constraints later on, or + // (2) distributing them right away + std::vector local_dofs (fe.dofs_per_cell); + FullMatrix local_matrix (fe.dofs_per_cell, fe.dofs_per_cell); + for (typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(); + cell != dof_handler.end(); ++cell) + { + cell->get_dof_indices (local_dofs); + local_matrix.clear (); + for (unsigned int i=0; i (); +// test<2> (); + test<3> (); + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/bits/dof_constraints_02.cc b/tests/bits/dof_constraints_02.cc new file mode 100644 index 0000000000..10e70390c4 --- /dev/null +++ b/tests/bits/dof_constraints_02.cc @@ -0,0 +1,156 @@ +//---------------------------- dof_constraints_02.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2004 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. +// +//---------------------------- dof_constraints_02.cc --------------------------- + + +// check DoFConstraints::distribute_local_to_global for vectors + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +template +void test () +{ + deallog << dim << "D" << std::endl; + + Triangulation triangulation; + GridGenerator::hyper_cube (triangulation); + + // refine the mesh in a random way so as to + // generate as many hanging node + // constraints as possible + triangulation.refine_global (4-dim); + for (unsigned int i=0; i<11-2*dim; ++i) + { + typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + for (unsigned int index=0; cell != triangulation.end(); ++cell, ++index) + if (index % (3*dim) == 0) + cell->set_refine_flag(); + triangulation.execute_coarsening_and_refinement (); + } + deallog << "Number of cells: " << triangulation.n_active_cells() + << std::endl; + + // set up a DoFHandler and compute hanging + // node constraints + FE_Q fe(1); + DoFHandler dof_handler (triangulation); + dof_handler.distribute_dofs (fe); + deallog << "Number of dofs: " << dof_handler.n_dofs() << std::endl; + + ConstraintMatrix constraints; + DoFTools::make_hanging_node_constraints (dof_handler, constraints); + constraints.close (); + deallog << "Number of constraints: " << constraints.n_constraints() << std::endl; + + // then set up two vectors + Vector A(dof_handler.n_dofs()), B(dof_handler.n_dofs()); + + // then fill the two vectors by setting up + // bogus matrix entries and (1) writing + // them into the vector and condensing away + // hanging node constraints later on, or + // (2) distributing them right away + std::vector local_dofs (fe.dofs_per_cell); + Vector local_vector (fe.dofs_per_cell); + for (typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(); + cell != dof_handler.end(); ++cell) + { + cell->get_dof_indices (local_dofs); + local_vector.clear (); + for (unsigned int i=0; i (); + test<2> (); + test<3> (); + } + catch (std::exception &exc) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + std::cerr << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + std::cerr << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +}