From: young Date: Tue, 6 Jan 2009 14:23:48 +0000 (+0000) Subject: Test zero boundary constraints X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7952013dc132ac04d531803317711587e3590a3d;p=dealii-svn.git Test zero boundary constraints git-svn-id: https://svn.dealii.org/trunk@18098 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/bits/Makefile b/tests/bits/Makefile index d35b167863..06e71ed3a2 100644 --- a/tests/bits/Makefile +++ b/tests/bits/Makefile @@ -98,7 +98,8 @@ tests_x = grid_generator_?? \ max_n_cells_* \ joa_* \ neighboring_cells_at_two_faces \ - solution_transfer + solution_transfer \ + make_boundary_constraints_* # tests for the hp branch: # fe_collection_* diff --git a/tests/bits/make_boundary_constraints_01.cc b/tests/bits/make_boundary_constraints_01.cc new file mode 100644 index 0000000000..74be19f553 --- /dev/null +++ b/tests/bits/make_boundary_constraints_01.cc @@ -0,0 +1,178 @@ +//---------------------------- make_boundary_constraints_01.cc ------------------ +// $Id: make_boundary_constraints_01.cc $ +// Version: $Name$ +// +// Copyright (C) 2009 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. +// +//---------------------------- make_boundary_constraints_01.cc ------------------ + + +// check DoFTools::make_zero_boundary_constraints by comparing +// apply_boundary_values with a zero function to +// make_zero_boundary_constraints + +#include "../tests.h" +#include +#include +#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 + 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; + + // assign quadrature, set up a + // DoFHandler, and distribute dofs + FE_Q fe(1); + DoFHandler dof_handler (triangulation); + dof_handler.distribute_dofs (fe); + deallog << "Number of dofs : " + << dof_handler.n_dofs() << std::endl; + + // then set up a sparsity pattern + // and two matrices and vectors 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); + sparsity.compress (); + SparseMatrix A(sparsity), B(sparsity); + Vector a1 (dof_handler.n_dofs()); + + // initialize object denoting zero + // boundary values and boundary + // constraints + std::map boundary_values; + VectorTools::interpolate_boundary_values (dof_handler, + 0, + ConstantFunction(1.), + boundary_values); + ConstraintMatrix constraints; + constraints.clear(); + DoFTools::make_zero_boundary_constraints (dof_handler, + constraints); + constraints.close(); + + // then fill two matrices by + // setting up bogus matrix entries + // and for A applying constraints + // right away and for B applying + // constraints later on + std::vector local_dofs (fe.dofs_per_cell); + FullMatrix local_matrix (fe.dofs_per_cell, 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_matrix = 0; + + // create local matrices + for (unsigned int i=0; idistribute_local_to_global (local_matrix, A); + cell->distribute_local_to_global (local_vector, a1); + + // for matrix B cast constraint + // matrix + constraints.distribute_local_to_global (local_matrix, + local_dofs, + B); + } + + // here comes the check: compare + // the l1_norm of matrices A and B, + // their difference should be zero + deallog << "|A| = " << A.l1_norm() << std::endl; + deallog << "|B| = " << B.l1_norm() << std::endl; + Assert (A.l1_norm() - B.l1_norm() == 0, + ExcInternalError()); +} + +int main () +{ + std::ofstream logfile("make_boundary_constraints_01/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + try + { + test<1> (); + test<2> (); + test<3> (); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/bits/make_boundary_constraints_01/OK b/tests/bits/make_boundary_constraints_01/OK new file mode 100644 index 0000000000..6ab389274c --- /dev/null +++ b/tests/bits/make_boundary_constraints_01/OK @@ -0,0 +1 @@ +generic diff --git a/tests/bits/make_boundary_constraints_01/cmp/generic b/tests/bits/make_boundary_constraints_01/cmp/generic new file mode 100644 index 0000000000..b00245bbc5 --- /dev/null +++ b/tests/bits/make_boundary_constraints_01/cmp/generic @@ -0,0 +1,16 @@ + +DEAL::1D +DEAL::Number of cells: 115 +DEAL::Number of dofs : 116 +DEAL::|A| = 118784. +DEAL::|B| = 118784. +DEAL::2D +DEAL::Number of cells: 1186 +DEAL::Number of dofs : 1537 +DEAL::|A| = 2.33581e+08 +DEAL::|B| = 2.33581e+08 +DEAL::3D +DEAL::Number of cells: 736 +DEAL::Number of dofs : 1311 +DEAL::|A| = 2.03219e+09 +DEAL::|B| = 2.03219e+09 diff --git a/tests/bits/make_boundary_constraints_01/exe b/tests/bits/make_boundary_constraints_01/exe new file mode 100755 index 0000000000..6c4632a997 Binary files /dev/null and b/tests/bits/make_boundary_constraints_01/exe differ diff --git a/tests/bits/make_boundary_constraints_01/status b/tests/bits/make_boundary_constraints_01/status new file mode 100644 index 0000000000..ce1b499348 --- /dev/null +++ b/tests/bits/make_boundary_constraints_01/status @@ -0,0 +1 @@ +diff ok