From 206b539749725351a50230194ac0b081c65e11eb Mon Sep 17 00:00:00 2001 From: kronbichler Date: Thu, 16 Sep 2010 14:49:35 +0000 Subject: [PATCH] Test mixing hanging nodes with Dirichlet boundary conditions. git-svn-id: https://svn.dealii.org/trunk@21993 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/deal.II/Makefile | 3 +- tests/deal.II/constraints_hanging_nodes_bc.cc | 147 ++++++++++++++++++ .../constraints_hanging_nodes_bc/cmp/generic | 5 + 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 tests/deal.II/constraints_hanging_nodes_bc.cc create mode 100644 tests/deal.II/constraints_hanging_nodes_bc/cmp/generic diff --git a/tests/deal.II/Makefile b/tests/deal.II/Makefile index 7b36bd8a93..5a323d5e13 100644 --- a/tests/deal.II/Makefile +++ b/tests/deal.II/Makefile @@ -23,8 +23,7 @@ default: run-tests tests_x = block_info block_matrices \ user_data_* \ - constraints \ - constraint_graph \ + constraint* \ inhomogeneous_constraints \ inhomogeneous_constraints_nonsymmetric \ inhomogeneous_constraints_block \ diff --git a/tests/deal.II/constraints_hanging_nodes_bc.cc b/tests/deal.II/constraints_hanging_nodes_bc.cc new file mode 100644 index 0000000000..b064e8e5e9 --- /dev/null +++ b/tests/deal.II/constraints_hanging_nodes_bc.cc @@ -0,0 +1,147 @@ +//------------------ constraints_hanging_nodes_bc.cc ------------------------ +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2010 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. +// +//------------------ constraints_hanging_nodes_bc.cc ------------------------ + + +// this function tests the correctness of the implementation of mixing hanging +// node constraints and Dirichlet boundary constraints. This is trivial in 2D +// because then hanging nodes never appear on the boundary, but needs to be +// checked in 3D. To do this, compare a constraint matrix that we fill +// manually with one that we get from using the library functions +// make_hanging_node_constraints and interpolate_boundary_values. + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +std::ofstream logfile("constraints_hanging_nodes_bc/output"); + + +template +void test () +{ + Triangulation tria; + GridGenerator::hyper_cube (tria); + tria.refine_global(1); + + // refine some of the cells. + typename Triangulation::active_cell_iterator + cell = tria.begin_active(), + endc = tria.end(); + for (unsigned int counter = 0; cell!=endc; ++cell, ++counter) + if (counter % 5 == 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + cell = tria.begin_active(); + endc = tria.end(); + for (unsigned int counter = 0; cell!=endc; ++cell, ++counter) + if (counter % 8 == 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + FE_Q fe(1); + DoFHandler dof (tria); + dof.distribute_dofs (fe); + + ConstraintMatrix correct_constraints, library_constraints; + + DoFTools::make_hanging_node_constraints (dof, correct_constraints); + library_constraints.merge (correct_constraints); + + { + std::map boundary_values; + VectorTools::interpolate_boundary_values (dof, + 0, + ConstantFunction(1.), + boundary_values); + std::map::const_iterator boundary_value = + boundary_values.begin(); + for ( ; boundary_value !=boundary_values.end(); ++boundary_value) + { + if (!correct_constraints.is_constrained(boundary_value->first)) + { + correct_constraints.add_line(boundary_value->first); + correct_constraints.set_inhomogeneity (boundary_value->first, + boundary_value->second); + } + } + } + correct_constraints.close(); + + deallog << "Number of DoFs: " << dof.n_dofs() << std::endl + << "Number of hanging nodes: " + << library_constraints.n_constraints() << std::endl + << "Total number of constraints: " + << correct_constraints.n_constraints() << std::endl; + + VectorTools::interpolate_boundary_values (dof, 0, ConstantFunction(1.), + library_constraints); + library_constraints.close(); + + // the two constraint matrices should look the + // same, so go through them and check + deallog << "Check that both constraint matrices are identical... "; + for (unsigned int i=0; i >& constraint_format; + if (correct_constraints.is_constrained(i)) + { + constraint_format correct = *correct_constraints.get_constraint_entries(i); + constraint_format library = *library_constraints.get_constraint_entries(i); + Assert (correct.size() == library.size(), ExcInternalError()); + for (unsigned int q=0; q(); + deallog.pop(); + } +} + diff --git a/tests/deal.II/constraints_hanging_nodes_bc/cmp/generic b/tests/deal.II/constraints_hanging_nodes_bc/cmp/generic new file mode 100644 index 0000000000..d86b4b70f8 --- /dev/null +++ b/tests/deal.II/constraints_hanging_nodes_bc/cmp/generic @@ -0,0 +1,5 @@ + +DEAL:3d::Number of DoFs: 163 +DEAL:3d::Number of hanging nodes: 33 +DEAL:3d::Total number of constraints: 134 +DEAL:3d::Check that both constraint matrices are identical... OK. -- 2.39.5