From de49f92559bd36724f83088403073fa376fc0e2e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 20 Feb 2010 00:08:34 +0000 Subject: [PATCH] Only test for distorted cells if so instructed by the user. git-svn-id: https://svn.dealii.org/trunk@20655 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria.h | 83 +++++++++++++++++++++----- deal.II/deal.II/source/grid/tria.cc | 55 +++++++++++------ deal.II/doc/doxygen/headers/glossary.h | 12 +++- deal.II/doc/news/changes.h | 57 +++++++++--------- 4 files changed, 143 insertions(+), 64 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index 2d371d03c6..12f3b4070e 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -1119,8 +1119,8 @@ namespace internal * Therefore if your new boundary vertex is too near the center of * the old quadrilateral or hexahedron, the distance to the midpoint * vertex will become too small, thus generating distorted - * cells. Remedy: take care of such situations when defining the - * coarse grid. + * cells. This issue is discussed extensively in + * @ref GlossDistorted "distorted cells". * * *

Technical details

@@ -1388,7 +1388,13 @@ class Triangulation : public Subscriptor * execute_coarsening_and_refinement() * functions, and they can be * caught in user code if this - * condition is to be ignored. + * condition is to be + * ignored. Note, however, that + * such exceptions are only + * produced if the necessity for + * this check was indicated when + * calling the constructor of the + * Triangulation class. * * A cell is called * deformed if the @@ -1443,8 +1449,30 @@ class Triangulation : public Subscriptor * Create an empty * triangulation. Do not create * any cells. + * + * @param smooth_grid Determines + * the level of smoothness of the + * mesh size function that should + * be enforced upon mesh + * refinement. + * + * @param + * check_for_distorted_cells + * Determines whether the + * triangulation should check + * whether any of the cells that + * are created by + * create_triangulation() or + * execute_coarsening_and_refinement() + * are distorted (see @ref + * GlossDistorted "distorted + * cells"). If set, these two + * functions may throw an + * exception if they encounter + * distorted cells. */ - Triangulation (const MeshSmoothing smooth_grid = none); + Triangulation (const MeshSmoothing smooth_grid = none, + const bool check_for_distorted_cells = false); /** * Copy constructor. @@ -1672,19 +1700,24 @@ class Triangulation : public Subscriptor * and the GridIn and * GridReordering class. * - * At the very end of its - * operation, this function walks + * If the + * check_for_distorted_cells + * flag was specified upon + * creation of this object, at + * the very end of its operation, + * the current function walks * over all cells and verifies * that none of the cells is - * deformed (see - * the entry on @ref GlossDistorted in - * the glossary), where we call a cell - * deformed if the determinant of - * the Jacobian of the mapping - * from reference cell to real - * cell is negative at least at - * one of the vertices (this - * computation is done using the + * deformed (see the entry on + * @ref GlossDistorted "distorted + * cells" in the glossary), where + * we call a cell deformed if the + * determinant of the Jacobian of + * the mapping from reference + * cell to real cell is negative + * at least at one of the + * vertices (this computation is + * done using the * GeometryInfo::jacobian_determinants_at_vertices * function). If there are * deformed cells, this function @@ -1829,6 +1862,12 @@ class Triangulation : public Subscriptor * does not create such an * exception if no cells have * created distorted children. + * Note that for the check for + * distorted cells to happen, the + * check_for_distorted_cells + * flag has to be specified upon + * creation of a triangulation + * object. * * See the general docs for more * information. @@ -3202,7 +3241,11 @@ class Triangulation : public Subscriptor * of cells that have produced * children that satisfy the * criteria of - * @ref GlossDistorted "distorted cells". + * @ref GlossDistorted "distorted cells" + * if the + * check_for_distorted_cells + * flag was specified upon + * creation of this object, at */ DistortedCellList execute_refinement (); @@ -3289,6 +3332,14 @@ class Triangulation : public Subscriptor */ MeshSmoothing smooth_grid; + /** + * A flag that determines whether + * we are to check for distorted + * cells upon creation and + * refinement of a mesh. + */ + const bool check_for_distorted_cells; + /** * Cache to hold the numbers of lines, * quads, hexes, etc. These numbers diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index d2dc8a9ffb..335b99e467 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -4063,7 +4063,8 @@ namespace internal template static typename Triangulation<1,spacedim>::DistortedCellList - execute_refinement (Triangulation<1,spacedim> &triangulation) + execute_refinement (Triangulation<1,spacedim> &triangulation, + const bool check_for_distorted_cells) { const unsigned int dim = 1; @@ -4333,7 +4334,8 @@ namespace internal template static typename Triangulation<2,spacedim>::DistortedCellList - execute_refinement (Triangulation<2,spacedim> &triangulation) + execute_refinement (Triangulation<2,spacedim> &triangulation, + const bool check_for_distorted_cells) { const unsigned int dim = 2; @@ -4717,7 +4719,9 @@ namespace internal next_unused_cell, cell); - if (has_distorted_children (cell, + if ((check_for_distorted_cells == true) + && + has_distorted_children (cell, internal::int2type(), internal::int2type())) cells_with_distorted_children.distorted_cells.push_back (cell); @@ -4735,7 +4739,8 @@ namespace internal template static typename Triangulation<3,spacedim>::DistortedCellList - execute_refinement (Triangulation<3,spacedim> &triangulation) + execute_refinement (Triangulation<3,spacedim> &triangulation, + const bool check_for_distorted_cells) { const unsigned int dim = 3; @@ -8680,7 +8685,9 @@ namespace internal // and if so // add them to // our list - if (has_distorted_children (hex, + if ((check_for_distorted_cells == true) + && + has_distorted_children (hex, internal::int2type(), internal::int2type())) cells_with_distorted_children.distorted_cells.push_back (hex); @@ -9148,11 +9155,14 @@ Triangulation::dimension; template -Triangulation::Triangulation (const MeshSmoothing smooth_grid) +Triangulation:: +Triangulation (const MeshSmoothing smooth_grid, + const bool check_for_distorted_cells) : faces(NULL), anisotropic_refinement(false), - smooth_grid(smooth_grid) + smooth_grid(smooth_grid), + check_for_distorted_cells(check_for_distorted_cells) { // set default boundary for all // possible components @@ -9162,12 +9172,14 @@ Triangulation::Triangulation (const MeshSmoothing smooth_grid) template -Triangulation::Triangulation (const Triangulation &) +Triangulation:: +Triangulation (const Triangulation &) // do not set any subscriptors; // anyway, calling this constructor // is an error! : - Subscriptor() + Subscriptor(), + check_for_distorted_cells(check_for_distorted_cells) { Assert (false, ExcInternalError()); } @@ -9365,14 +9377,17 @@ create_triangulation (const std::vector > &v, // first collect all distorted // cells and then throw an // exception if there are any - DistortedCellList distorted_cells = collect_distorted_coarse_cells (*this); - // throw the array (and fill the - // various location fields) if - // there are distorted - // cells. otherwise, just fall off - // the end of the function - AssertThrow (distorted_cells.distorted_cells.size() == 0, - distorted_cells); + if (check_for_distorted_cells == true) + { + DistortedCellList distorted_cells = collect_distorted_coarse_cells (*this); + // throw the array (and fill the + // various location fields) if + // there are distorted + // cells. otherwise, just fall off + // the end of the function + AssertThrow (distorted_cells.distorted_cells.size() == 0, + distorted_cells); + } } @@ -12114,7 +12129,9 @@ Triangulation::execute_refinement () { const DistortedCellList cells_with_distorted_children - = internal::Triangulation::Implementation::execute_refinement (*this); + = + internal::Triangulation::Implementation:: + execute_refinement (*this,check_for_distorted_cells); diff --git a/deal.II/doc/doxygen/headers/glossary.h b/deal.II/doc/doxygen/headers/glossary.h index f438f05ba6..7d579b54fb 100644 --- a/deal.II/doc/doxygen/headers/glossary.h +++ b/deal.II/doc/doxygen/headers/glossary.h @@ -158,9 +158,10 @@ * as the result of mesh refinement if the boundary description in use * is sufficiently irregular. * - * The function Triangulation::create_triangulation, which is called + * If the appropriate flag is given upon creation of a triangulation, + * the function Triangulation::create_triangulation, which is called * by the various functions in GridGenerator and GridIn (but can also - * be called from user code, see step-14 will signal + * be called from user code, see step-14, will signal * the creation of coarse meshes with distorted cells by throwing an * exception of type Triangulation::DistortedCellList. There are * legitimate cases for creating meshes with distorted cells (in @@ -230,6 +231,13 @@ * fix up exactly these cells if possible by moving around the node at * the center of the cell. * + * Note that the Triangulation class does not test for the presence of + * distorted cells by default, since the determination whether a cell + * is distorted or not is not a cheap operation. If you want a + * Triangulation object to test for distortion of cells, you need to + * specify this upon creation of the object by passing the appropriate + * flag. + * * *
@anchor GlossFaceOrientation Face orientation
*
In a triangulation, the normal vector to a face diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index b8154b5239..9782420752 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -60,31 +60,6 @@ inconvenience this causes.
(GK 2009/08/04)

- -
  • -

    - Changed: Previously, the Triangulation::create_triangulation - function silently accepted input meshes with inverted cells - (i.e. cells with a zero or negative determinant of the Jacobian of - the mapping from the reference cell to the real cell). This has been - changed now: The function checks whether cells are distorted or - inverted, and may throw an exception containing a list of cells - for which this is the case. If you know that this is harmless, for - example if you have cells with collapsed vertices in your mesh but - you do not intend to integrate on them, then you can catch and - ignore this message. In all other cases, the output of your - computations are likely to be wrong anyway. -
    - The same is true for the Triangulation::execute_coarsening_and_refinement - function: if it creates cells that are distorted, it throws a list of cells - whose children are distorted. -
    - The whole issue is described in some detail in the entry on - @ref GlossDistorted "distorted cells" in the glossary. -
    - (WB 2009/06/29) -

    -
  • @@ -604,7 +579,7 @@ inconvenience this causes.

    New: The class MGTransferSelect is prepared for use on adaptively refined meshes.
    - (Bärbel Janssen 2010/02/05) + (Bärbel Janssen 2010/02/05)

    @@ -613,7 +588,7 @@ inconvenience this causes. New: The function Cuthill_McKee in namespace DoFRenumbering is now also compiled for MGDoFHandler as well as the make_sparsity_pattern functions in DoFTools.
    - (Bärbel Janssen 2010/01/08) + (Bärbel Janssen 2010/01/08)

    @@ -737,6 +712,34 @@ inconvenience this causes.

    +
  • +

    + New: Previously, the Triangulation::create_triangulation + function silently accepted input meshes with inverted cells + (i.e. cells with a zero or negative determinant of the Jacobian of + the mapping from the reference cell to the real cell). This can been + changed now: By passing the appropriate flag to the constructor of + the Triangulation class, the Triangulation::create_triangulation + function checks whether cells are distorted or + inverted, and may throw an exception containing a list of cells + for which this is the case. If you know that this is harmless, for + example if you have cells with collapsed vertices in your mesh but + you do not intend to integrate on them, then you can catch and + ignore this message. In all other cases, the output of your + computations are likely to be wrong anyway. +
    + The same is true for the Triangulation::execute_coarsening_and_refinement + function: if it creates cells that are distorted, it throws a list of cells + whose children are distorted. +
    + The whole issue is described in some detail in the entry on + @ref GlossDistorted "distorted cells" in the glossary. +
    + (WB 2009/06/29) +

    +
  • + +
  • New: The new hp::DoFHandler::set_active_fe_indices function allows -- 2.39.5