From ea931c400f57b7eba45171fc55457111365b9cee Mon Sep 17 00:00:00 2001 From: bangerth Date: Fri, 16 Dec 2011 14:06:08 +0000 Subject: [PATCH] Patch by Christian Goll: Add an order parameter to GridRefinement::refine_and_coarsen_optimize and remove assumption that dim==2. git-svn-id: https://svn.dealii.org/trunk@24833 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 8 ++++ .../include/deal.II/grid/grid_refinement.h | 46 ++++++++++--------- deal.II/source/grid/grid_refinement.cc | 22 +++++---- deal.II/source/grid/grid_refinement.inst.in | 8 ++-- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 7ccff517e2..5a0bddcf52 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -73,6 +73,14 @@ enabled due to a missing include file in file

Specific improvements

    +
  1. Improved: The GridRefinement::refine_and_coarsen_optimize function +assumed that the expected convergence order was 2. It has now gotten an +argument by which the user can prescribe a different value. A bug has also +been fixed in which the function incorrectly assumed in its algorithm that +the mesh was two-dimensional. +
    +(Christian Goll, 2011/12/16) +
  2. Fixed: Restriction and prolongation didn't work for elements of kind FE_Nothing. Consequently, many other parts of the library also didn't work, such as the SolutionTransfer class. This is now fixed. diff --git a/deal.II/include/deal.II/grid/grid_refinement.h b/deal.II/include/deal.II/grid/grid_refinement.h index f67a38e72b..88889d7953 100644 --- a/deal.II/include/deal.II/grid/grid_refinement.h +++ b/deal.II/include/deal.II/grid/grid_refinement.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -150,7 +150,7 @@ namespace GridRefinement * to sort the array of criteria. Just like the other strategy * described above, this function only computes the threshold values * and then passes over to refine() and coarsen(). - * + * * @arg @p criteria: the refinement criterion computed on each mesh * cell. Entries may not be negative. * @@ -182,30 +182,34 @@ namespace GridRefinement /** - * Refine the triangulation by - * flagging certain cells to reach - * an optimal grid: - * We try to minimize the error - * multiplied with the number of - * cells in the new grid. All cells - * with large error indicator are - * refined to generate an optimal - * grid in the above sense. - * We assume that the error in one - * cell is reduced to a quarter - * after refinement. - * The new triangulation has three - * new cells for every flagged cell. + * Refine the triangulation by flagging + * certain cells to reach an optimal + * grid: We try to minimize the error + * multiplied with the number of cells in + * the new grid. All cells with large + * error indicator are refined to + * generate an optimal grid in the above + * sense. We assume that the error in + * one cell is reduced to 1-2^{-order} + * after refinement, if 'order' is the + * expected order of convergence. This + * expected order of convergence must be + * passed as an argument but is defaulted + * to 2. The new triangulation has + * ($2^d-1$) new cells for every flagged + * cell (the original cell is replaced by + * $2^d$ cells but it then made + * inactive). * * Refer to the general doc of * this class for more * information. */ - template void refine_and_coarsen_optimize (Triangulation &tria, - const Vector &criteria); + const Vector &criteria, + const unsigned int order=2); /** * Flag all mesh cells for which the value in @p criteria exceeds @p @@ -226,7 +230,7 @@ namespace GridRefinement void refine (Triangulation &tria, const Vector &criteria, const double threshold); - + /** * Flag all mesh cells for which the value in @p criteria * is less than @p threshold for coarsening. @@ -246,14 +250,14 @@ namespace GridRefinement void coarsen (Triangulation &tria, const Vector &criteria, const double threshold); - + /** * An exception thrown if the * vector with cell criteria contains * negative values */ DeclException0(ExcNegativeCriteria); - + /** * One of the threshold parameters * causes trouble. Or the diff --git a/deal.II/source/grid/grid_refinement.cc b/deal.II/source/grid/grid_refinement.cc index 6efcb42ac6..119c70b9f1 100644 --- a/deal.II/source/grid/grid_refinement.cc +++ b/deal.II/source/grid/grid_refinement.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -504,7 +504,8 @@ GridRefinement::refine_and_coarsen_fixed_fraction (Triangulation & template void GridRefinement::refine_and_coarsen_optimize (Triangulation &tria, - const Vector &criteria) + const Vector &criteria, + const unsigned int order=2) { Assert (criteria.size() == tria.n_active_cells(), ExcDimensionMismatch(criteria.size(), tria.n_active_cells())); @@ -518,7 +519,7 @@ GridRefinement::refine_and_coarsen_optimize (Triangulation &tria, qsort_index(criteria,tmp,0,criteria.size()-1); - double s0 = 0.75 * criteria(tmp[0]); + double s0 = (1-std::pow(2,-order)) * criteria(tmp[0]); double E = criteria.l1_norm(); unsigned int N = criteria.size(); @@ -529,23 +530,24 @@ GridRefinement::refine_and_coarsen_optimize (Triangulation &tria, // multiplied with the expected // number of cells. // We assume that the error is - // decreased by 3/4 a_K if the cell + // decreased by (1-2^(-order)) a_K if the cell // K with error indicator a_K is - // refined. + // refined and 'order' ist the expected + // order of convergence. // The expected number of cells is - // N+3*M (N is the current number + // N+(2^d-1)*M (N is the current number // of cells) - double min = (3.*(1.+M)+N) * (E-s0); + double min = ((std::pow(2.,dim)-1)*(1.+M)+N) * (E-s0); unsigned int minArg = N-1; for (M=1;M,deal_II_dimension> (Triangulation &, - const dealii::Vector &); + const dealii::Vector &, + const unsigned int); #if deal_II_dimension < 3 template @@ -100,6 +101,7 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS) GridRefinement:: refine_and_coarsen_optimize,deal_II_dimension+1> (Triangulation &, - const dealii::Vector &); + const dealii::Vector &, + const unsigned int); #endif } -- 2.39.5