From: richter Date: Tue, 10 Oct 2000 09:48:11 +0000 (+0000) Subject: add grid refinement with optimization X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b21bf26cd4bce7c1fe7dd5ed3e31ab2a13db6f3;p=dealii-svn.git add grid refinement with optimization git-svn-id: https://svn.dealii.org/trunk@3401 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/grid_refinement.h b/deal.II/deal.II/include/grid/grid_refinement.h index b93e3bfb7e..1815633c5a 100644 --- a/deal.II/deal.II/include/grid/grid_refinement.h +++ b/deal.II/deal.II/include/grid/grid_refinement.h @@ -14,6 +14,9 @@ #define __deal2__grid_refinement_h +#include +#include + // forward declarations template class Triangulation; template class Vector; @@ -214,7 +217,7 @@ class GridRefinement const Vector &criteria, const double top_fraction_of_cells, const double bottom_fraction_of_cells); - + /** * Refine the triangulation by * flagging those cells which @@ -248,6 +251,41 @@ class GridRefinement const double top_fraction, const double bottom_fraction); + + + /** + * 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. + * + * Refer to the general doc of + * this class for more + * information. + * + * Note that this function takes + * a vector of @p{float}s, rather + * than the usual @p{double}s, + * since accuracy is not so much + * needed here and saving memory + * may be a good goal when using + * many cells. + */ + + template + static void refine_and_coarsen_optimize (Triangulation &tria, + const Vector &criteria); + /** * Exception */ @@ -259,8 +297,28 @@ class GridRefinement * Exception */ DeclException0 (ExcInvalidParameterValue); + + + private: + + /** + * Sorts the vector ind as + * an index vector of a in + * increasing order. + * This implementation of + * quicksort seems to be faster + * than the STL version and is + * needed in + * @p{refine_and_coarsen_optimize} + */ + template + static void qsort_index(const Vector &a, + vector &ind, + int l, + int r); }; #endif //__deal2__grid_refinement_h + diff --git a/deal.II/deal.II/source/grid/grid_refinement.cc b/deal.II/deal.II/source/grid/grid_refinement.cc index df1e59b8b4..a6e36d378e 100644 --- a/deal.II/deal.II/source/grid/grid_refinement.cc +++ b/deal.II/deal.II/source/grid/grid_refinement.cc @@ -11,8 +11,6 @@ // //---------------------------- grid_refinement.cc --------------------------- - -#include #include #include #include @@ -22,6 +20,55 @@ #include #include +#include +#include + +template +void GridRefinement::qsort_index(const Vector &a, + vector &ind, + int l, + int r) +{ + int i,j,t; + number v; + + if (r<=l) + return; + + v = a(ind[r]); + i = l-1; + j = r; + do + { + do + { + ++i; + } + while ((a(ind[i])>v)&&(i0)); + + if (i &tria, +template +void +GridRefinement::refine_and_coarsen_optimize (Triangulation &tria, + const Vector &criteria) +{ + Assert (criteria.size() == tria.n_active_cells(), + ExcInvalidVectorSize(criteria.size(), tria.n_active_cells())); + + // get an increasing order on + // the error indicator + vector tmp(criteria.size()); + for (unsigned int i=0;i &, const Vector &, const double); @@ -234,3 +331,12 @@ template void GridRefinement const double top_fraction, const double bottom_fraction); +template void GridRefinement +::refine_and_coarsen_optimize (Triangulation &, + const Vector &criteria); + +template void GridRefinement +::refine_and_coarsen_optimize (Triangulation &, + const Vector &criteria); + +