From 786528cc2faa499f63cc86cd924e9d5a5c86b6d6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 28 May 1998 13:58:50 +0000 Subject: [PATCH] Prepare structure for coarsening of grid (not yet implemented, not documented). git-svn-id: https://svn.dealii.org/trunk@371 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/Todo | 3 ++ deal.II/deal.II/include/grid/tria.h | 28 ++++++++++++- deal.II/deal.II/include/grid/tria_accessor.h | 24 ++++++++++- deal.II/deal.II/source/grid/tria.cc | 42 +++++++++++++++++++- deal.II/deal.II/source/grid/tria_accessor.cc | 41 ++++++++++++++++++- 5 files changed, 133 insertions(+), 5 deletions(-) diff --git a/deal.II/deal.II/Todo b/deal.II/deal.II/Todo index 79ea4e7166..114b8ecd12 100644 --- a/deal.II/deal.II/Todo +++ b/deal.II/deal.II/Todo @@ -106,6 +106,9 @@ Remove the this-> coding in tria_iterator.templates.h. These were Re-enable printing of a preamble to ucd files in data_io.cc. +Implement coarsening of grids and update docs for that. + + DEAL: diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index ca89c5e6e1..781f87189a 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -83,6 +83,13 @@ class TriangulationLevel<0> { * that of the #quads# vector, etc. */ vector refine_flags; + + /** + * Same meaning as the one above, but + * specifies whether a cell must be + * coarsened. + */ + vector coarsen_flags; /** * Levels and indices of the neighbors @@ -1075,7 +1082,11 @@ class TriaDimensionInfo<2> { * * You may write other information to the output file between different sets * of refinement information, as long as you read it upon re-creation of the - * grid. + * grid. You should make sure that the other information in the new + * triangulation which is to be created from the saves flags, matches that of + * the old triangulation, for example the smoothing level; if not, the + * cells actually created from the flags may be other ones, since smoothing + * adds additional cells, but the number depending on the smoothing level. * * * \subsection{User flags} @@ -1507,6 +1518,21 @@ class Triangulation : public TriaDimensionInfo { * This function is dimension specific. */ void execute_refinement (); + + /** + * Coarsen all cells which were flagged for + * coarsening, or rather: delete all + * children of those cells of which all + * child cells are flagged for coarsening + * and several other constraints hold (see + * the general doc of this class). + * + * The function resets all refinement + * flags to false. + * + * This function is dimension specific. + */ + void execute_coarsening (); /*@}*/ /** diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 28566d98c6..042ea3a921 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -884,8 +884,9 @@ class CellAccessor : public TriaSubstructAccessor { bool refine_flag_set () const; /** - * Flag the cell pointed to - * for refinement. + * Flag the cell pointed to fo + * refinement. This function is only + * allowed for active cells. */ void set_refine_flag () const; @@ -894,6 +895,25 @@ class CellAccessor : public TriaSubstructAccessor { */ void clear_refine_flag () const; + + /** + * Return whether the coarsen flag + * is set or not. + */ + bool coarsen_flag_set () const; + + /** + * Flag the cell pointed to for + * coarsening. This function is only + * allowed for active cells. + */ + void set_coarsen_flag () const; + + /** + * Clear the coarsen flag. + */ + void clear_coarsen_flag () const; + /** * Return a pointer to the #i#th * child. Overloaded version which returns diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 0bd077b5d4..c133ffef77 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -2137,6 +2137,17 @@ void Triangulation<1>::execute_refinement () { #ifdef DEBUG for (unsigned int level=0; levelmonitor_memory (1); + + // check whether really all refinement flags + // are reset (also of previously non-active + // cells which we may not have touched. If + // the refinement flag of a non-active cell + // is set, something went wrong since the + // cell-accessors should have caught this) + cell_iterator cell = begin(), + endc = end(); + while (cell != endc) + Assert (!(cell++)->refine_flag_set(), ExcInternalError ()); #endif }; @@ -2710,10 +2721,28 @@ void Triangulation<2>::execute_refinement () { #ifdef DEBUG for (unsigned int level=0; levelmonitor_memory (2); + + // check whether really all refinement flags + // are reset (also of previously non-active + // cells which we may not have touched. If + // the refinement flag of a non-active cell + // is set, something went wrong since the + // cell-accessors should have caught this) + cell_iterator cell = begin(), + endc = end(); + while (cell != endc) + Assert (!(cell++)->refine_flag_set(), ExcInternalError ()); #endif }; - + + + +template +void Triangulation::execute_coarsening () { + Assert (false, ExcInternalError()); +}; + template @@ -2815,6 +2844,11 @@ void TriangulationLevel<0>::reserve_space (const unsigned int total_cells, refine_flags.insert (refine_flags.end(), total_cells - refine_flags.size(), false); + + coarsen_flags.reserve (total_cells); + coarsen_flags.insert (coarsen_flags.end(), + total_cells - coarsen_flags.size(), + false); neighbors.reserve (total_cells*(2*dimension)); neighbors.insert (neighbors.end(), @@ -2830,12 +2864,18 @@ void TriangulationLevel<0>::monitor_memory (const unsigned int true_dimension) c // refine_flags.size()<256, // ExcMemoryWasted ("refine_flags", // refine_flags.size(), refine_flags.capacity())); +// Assert (coarsen_flags.size() == coarsen_flags.capacity() || +// coarsen_flags.size()<256, +// ExcMemoryWasted ("coarsen_flags", +// coarsen_flags.size(), coarsen_flags.capacity())); // Assert (neighbors.size() == neighbors.capacity() || // neighbors.size()<256, // ExcMemoryWasted ("neighbors", // neighbors.size(), neighbors.capacity())); Assert (2*true_dimension*refine_flags.size() == neighbors.size(), ExcMemoryInexact (refine_flags.size(), neighbors.size())); + Assert (2*true_dimension*coarsen_flags.size() == neighbors.size(), + ExcMemoryInexact (coarsen_flags.size(), neighbors.size())); }; diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index 9f23965d26..75d49dbf64 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -651,7 +651,13 @@ bool CellAccessor::at_boundary (const unsigned int i) const { template bool CellAccessor::refine_flag_set () const { - Assert (used() && active(), + Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); + // cells flagged for refinement must be active + // (the #set_refine_flag# function checks this, + // but activity may change when refinement is + // executed and for some reason the refine + // flag is not cleared). + Assert (active() || !tria->levels[present_level]->refine_flags[present_index], typename TriaSubstructAccessor::ExcRefineCellNotActive()); return tria->levels[present_level]->refine_flags[present_index]; }; @@ -676,6 +682,39 @@ void CellAccessor::clear_refine_flag () const { +template +bool CellAccessor::coarsen_flag_set () const { + Assert (used(), typename TriaSubstructAccessor::ExcCellNotUsed()); + // cells flagged for coarsening must be active + // (the #set_refine_flag# function checks this, + // but activity may change when refinement is + // executed and for some reason the refine + // flag is not cleared). + Assert (active() || !tria->levels[present_level]->coarsen_flags[present_index], + typename TriaSubstructAccessor::ExcRefineCellNotActive()); + return tria->levels[present_level]->coarsen_flags[present_index]; +}; + + + +template +void CellAccessor::set_coarsen_flag () const { + Assert (used() && active(), + typename TriaSubstructAccessor::ExcRefineCellNotActive()); + tria->levels[present_level]->coarsen_flags[present_index] = true; +}; + + + +template +void CellAccessor::clear_coarsen_flag () const { + Assert (used() && active(), + typename TriaSubstructAccessor::ExcRefineCellNotActive()); + tria->levels[present_level]->coarsen_flags[present_index] = false; +}; + + + template TriaIterator > CellAccessor::neighbor (const unsigned int i) const { -- 2.39.5