From c356f98d50616245d0d49f334eb598f320108a1f Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 21 Nov 2012 03:28:44 +0000 Subject: [PATCH] Fix a bug in DoFTools::make_flux_sparsity_pattern originally reported by Baerbel. git-svn-id: https://svn.dealii.org/trunk@27655 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 7 ++ deal.II/source/dofs/dof_tools.cc | 8 ++ tests/bits/dof_tools_18a_1d.cc | 154 ++++++++++++++++++++++++ tests/bits/dof_tools_18a_1d/cmp/generic | 10 ++ 4 files changed, 179 insertions(+) create mode 100644 tests/bits/dof_tools_18a_1d.cc create mode 100644 tests/bits/dof_tools_18a_1d/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index db2c26e5a2..3a5b562c21 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -154,6 +154,13 @@ DoFHandler, in particular removal of specializations.

Specific improvements

    +
  1. Fixed: The DoFTools::make_flux_sparsity_pattern() function +had a bug that triggered in 1d whenever there were neighboring +cells that differed in refinement level by more than one. This +is now fixed. +
    +(Wolfgang Bangerth, 2012/11/20) +
  2. New: The TrilinosWrappers::PreconditionBase class now has a function TrilinosWrappers::PreconditionBase::Tvmult that allows applying the transpose preconditioner. diff --git a/deal.II/source/dofs/dof_tools.cc b/deal.II/source/dofs/dof_tools.cc index 98e49222b9..8a08604065 100644 --- a/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/source/dofs/dof_tools.cc @@ -581,6 +581,14 @@ namespace DoFTools { typename DH::cell_iterator neighbor = cell->neighbor(face); + // in 1d, we do not need to worry whether the neighbor + // might have children and then loop over those children. + // rather, we may as well go straight to to cell behind + // this particular cell's most terminal child + if (DH::dimension==1) + while (neighbor->has_children()) + neighbor = neighbor->child(face==0 ? 1 : 0); + if (neighbor->has_children()) { for (unsigned int sub_nr = 0; diff --git a/tests/bits/dof_tools_18a_1d.cc b/tests/bits/dof_tools_18a_1d.cc new file mode 100644 index 0000000000..813f258525 --- /dev/null +++ b/tests/bits/dof_tools_18a_1d.cc @@ -0,0 +1,154 @@ +//---------------------------- dof_tools_1a.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2003, 2004, 2005, 2006, 2012 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_tools_1a.cc --------------------------- + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +// check +// DoFTools:: +// make_flux_sparsity_pattern (const DoFHandler &, +// SparsityPattern &, +// ConstraintMatrix &); +// this used to fail at one point because we forgot that in 1d +// neighboring cells can be more than one level apart. with +// FE_DGQ(0) elements, we get the following mesh and DoF indices: +// +// *-*-*-*-*-------* +// 1 2 3 4 0 +// +// we need to make sure that in row 0 there is a coupling to +// DoF 4. this was previously missing + + +std::string output_file_name = "dof_tools_18a_1d/output"; + + +template +void +check_this (const DoFHandler &dof_handler) +{ + // create sparsity pattern + SparsityPattern sp (dof_handler.n_dofs(), + dof_handler.max_couplings_between_dofs()*2); + DoFTools::make_flux_sparsity_pattern (dof_handler, sp, + ConstraintMatrix()); + sp.compress (); + + // write out 20 lines of this + // pattern (if we write out the + // whole pattern, the output file + // would be in the range of 40 MB) + for (unsigned int l=0; l1 ? 1 : 0)]); + deallog << hash << std::endl; +} + + +void +check_this () +{ + // create a mesh where two cells at levels + // 1 and 3 are adjacent + const int dim = 1; + Triangulation tr; + GridGenerator::hyper_cube (tr); + tr.refine_global(1); + tr.begin_active()->set_refine_flag(); + tr.execute_coarsening_and_refinement(); + for (Triangulation::active_cell_iterator + c=tr.begin_active(2); c!=tr.end_active(2); ++c) + c->set_refine_flag(); + tr.execute_coarsening_and_refinement(); + + FE_DGQ fe(0); + DoFHandler dof_handler(tr); + dof_handler.distribute_dofs (fe); + + check_this (dof_handler); +} + + +int +main() +{ + try + { + std::ofstream logfile(output_file_name.c_str()); + logfile << std::setprecision (2); + deallog << std::setprecision (2); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + check_this (); + return 0; + } + 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/dof_tools_18a_1d/cmp/generic b/tests/bits/dof_tools_18a_1d/cmp/generic new file mode 100644 index 0000000000..3e12661fa8 --- /dev/null +++ b/tests/bits/dof_tools_18a_1d/cmp/generic @@ -0,0 +1,10 @@ + +DEAL::0 4 +DEAL::1 2 +DEAL::2 1 3 +DEAL::3 2 4 +DEAL::4 0 3 +DEAL::4 +DEAL::3 +DEAL::13 +DEAL::110 -- 2.39.5