From a94a565299c7360c21aebd69be041861c1dc9514 Mon Sep 17 00:00:00 2001 From: Ralf Hartmann Date: Mon, 7 Mar 2005 15:23:45 +0000 Subject: [PATCH] Move 17 lines of code which were repeated 12 times (!) into new clear_despite_subscriptions function. git-svn-id: https://svn.dealii.org/trunk@10028 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria.h | 28 +++ deal.II/deal.II/source/grid/tria.cc | 256 ++++------------------------ 2 files changed, 57 insertions(+), 227 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index 6d9ac660ee..76e2c02745 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -3149,6 +3149,34 @@ class Triangulation : public Subscriptor std::istream &in); private: + + /** + * The (public) clear() will only + * work when the triangulation is + * not subscriped to by other + * users. The + * clear_despite_subscriptions() + * function now allows the + * triangulation being cleared + * even when there are + * subscriptions. + * + * Make sure, you know what you + * do, when calling this + * function, as its use is + * reasonable in very rare cases, + * only. For example, when the + * subscriptions were for the + * initially empty Triangulation + * and the Triangulation object + * wants to release its memory + * before throwing an assertion + * due to input errors (e.g. in + * the create_triangulation() + * function). + */ + void clear_despite_subscriptions (); + /** * Refine all cells on all levels which * were previously flagged for refinement. diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 20539f2bae..210061fc53 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -305,27 +305,7 @@ void Triangulation<1>::create_triangulation (const std::vector > &v, // a node must have one // or two adjacent // lines - - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, - // as the subscriptions - // were for the - // initially empty - // grid, and we want to - // clear it again now, - // so temporarily - // disable - // subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, // two boundary nodes if (boundary_nodes != 2) { - // clear will only work if - // there are no - // subscriptions. however, this - // is bogus here, as the - // subscriptions were for the - // initially empty grid, and we - // want to clear it again now, - // so temporarily disable - // subscriptions, clear, and - // then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, // error message const unsigned int n_vertices = vertices.size(); - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially - // empty grid, and we - // want to clear it again - // now, so temporarily - // disable subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, == needed_lines.end())) { - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, - // as the subscriptions - // were for the - // initially empty - // grid, and we want to - // clear it again now, - // so temporarily - // disable - // subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, if ( ! (* (std::min_element(vertex_touch_count.begin(), vertex_touch_count.end())) >= 2)) { - // clear will only work if - // there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially empty - // grid, and we want to - // clear it again now, so - // temporarily disable - // subscriptions, clear, - // and then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, if (! ((n_adj_cells >= 1) && (n_adj_cells <= 2))) { - // clear will only work if - // there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially empty - // grid, and we want to - // clear it again now, so - // temporarily disable - // subscriptions, clear, - // and then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, else { // line does not exist - - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, - // as the subscriptions - // were for the - // initially empty - // grid, and we want to - // clear it again now, - // so temporarily - // disable - // subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, if (line->boundary_indicator() != 0 && line->boundary_indicator() != 255) { - // clear will only work if - // there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially empty - // grid, and we want to - // clear it again now, so - // temporarily disable - // subscriptions, clear, - // and then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, // are given a boundary indicator if (line->boundary_indicator() == 255) { - // same as above - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, // include it in the // error message const unsigned int n_vertices = vertices.size(); - - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially - // empty grid, and we - // want to clear it again - // now, so temporarily - // disable subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, == needed_lines.end())) { - // clear will only work - // if there are no - // subscriptions. however, - // this is bogus here, - // as the subscriptions - // were for the - // initially empty - // grid, and we want to - // clear it again now, - // so temporarily - // disable - // subscriptions, - // clear, and then set - // them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, if (! (* (std::min_element(vertex_touch_count.begin(), vertex_touch_count.end())) >= 3)) { - // clear will only work if - // there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially empty - // grid, and we want to - // clear it again now, so - // temporarily disable - // subscriptions, clear, - // and then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::create_triangulation (const std::vector > &v, if (! ((n_adj_cells >= 1) && (n_adj_cells <= 2))) { - // clear will only work if - // there are no - // subscriptions. however, - // this is bogus here, as - // the subscriptions were - // for the initially empty - // grid, and we want to - // clear it again now, so - // temporarily disable - // subscriptions, clear, - // and then set them again - const unsigned int n=n_subscriptions(); - for (unsigned int i=0; i::execute_coarsening_and_refinement () } +template +void +Triangulation::clear_despite_subscriptions() +{ + // disable subscriptions, clear, + // and then set them again + const unsigned int n=n_subscriptions(); + for (unsigned int i=0; i -- 2.39.5