From: Bruno Turcksin Date: Wed, 2 Mar 2016 21:06:34 +0000 (-0500) Subject: Filter range given an arbitrary number of IteratorFilters. X-Git-Tag: v8.5.0-rc1~1250^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bef88f4124fab790a2a7d7758d73ca13a1b2ddf;p=dealii.git Filter range given an arbitrary number of IteratorFilters. --- diff --git a/include/deal.II/grid/filtered_iterator.h b/include/deal.II/grid/filtered_iterator.h index 3ba88db584..82344cebca 100644 --- a/include/deal.II/grid/filtered_iterator.h +++ b/include/deal.II/grid/filtered_iterator.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -771,6 +772,99 @@ make_filtered_iterator (const BaseIterator &i, +#ifdef DEAL_II_WITH_CXX11 +/** + * Filter the given range of iterators using a Predicate. This allows to replace: + * @code + * DoFHandler dof_handler; + * ... + * for (auto cell : dof_handler.active_cell_iterators()) + * { + * if (cell->is_locally_owned()) + * { + * fe_values.reinit (cell); + * ...do the local integration on 'cell'...; + * } + * } + * @endcode + * by: + * @code + * DoFHandler dof_handler; + * ... + * for (auto cell : filter_iterators(dof_handler.active_cell_iterators(), + * IteratorFilters::LocallyOwned()) + * { + * fe_values.reinit (cell); + * ...do the local integration on 'cell'...; + * } + * @endcode + * + * @author Bruno Turcksin + * @relates FilteredIterator + * @ingroup CPP11 + */ +template +IteratorRange > +filter_iterators (IteratorRange i, + const Predicate &p) +{ + FilteredIterator fi(p, *(i.begin())); + FilteredIterator fi_end(p, *(i.end())); + + return IteratorRange > (fi, fi_end); +} +#endif + + + +#ifdef DEAL_II_WITH_CXX14 +/** + * Filter the given of iterators an arbitrary number of Predicates. This allows + * to replace: + * @code + * DoFHandler dof_handler; + * ... + * for (auto cell : dof_handler.active_cell_iterators()) + * { + * if (cell->is_locally_owned()) + * { + * if (cell->at_boundary()) + * { + * fe_values.reinit (cell); + * ...do the local integration on 'cell'...; + * } + * } + * } + * @endcode + * by: + * @code + * DoFHandler dof_handler; + * ... + * for (auto cell : filter_iterators(dof_handler.active_cell_iterators(), + * IteratorFilters::LocallyOwned(), + * IteratorFilters::AtBoundary()) + * { + * fe_values.reinit (cell); + * ...do the local integration on 'cell'...; + * } + * @endcode + * + * @note This function requires C++14 + * + * @author Bruno Turcksin + * @relates FilteredIterator + */ +template +auto +filter_iterators (IteratorRange i, + const Predicate &p, const Targs... args) +{ + auto fi = filter_iterators(i,p); + return filter_iterators(fi, args...); +} +#endif + + /* ------------------ Inline functions and templates ------------ */ diff --git a/tests/grid/filtered_iterator_04.cc b/tests/grid/filtered_iterator_04.cc index 2cae8c50d0..0742facba1 100644 --- a/tests/grid/filtered_iterator_04.cc +++ b/tests/grid/filtered_iterator_04.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// check filtered iterators using two predicate +// check filtered iterators using multiple predicate #include "../tests.h" #include @@ -57,15 +57,11 @@ void test () if ((cell->subdomain_id()==0) && (cell->at_boundary())) cell_set.insert(cell); - const IteratorFilters::AtBoundary predicate_1; - const IteratorFilters::SubdomainEqualTo predicate_2(0); - FilteredIterator fi_cell(predicate_1), - end_fi_cell(predicate_1, tria.end()); - fi_cell.set_to_next_positive(tria.begin_active()); - FilteredIterator > filtered_cell(predicate_2, fi_cell), - end_filtered_cell(predicate_2, end_fi_cell); + unsigned int n_filtered_cells = 0; - for (; filtered_cell!=end_filtered_cell; ++filtered_cell) + for (auto filtered_cell : filter_iterators(tria.active_cell_iterators(), + IteratorFilters::AtBoundary(), + IteratorFilters::SubdomainEqualTo(0))) { AssertThrow(cell_set.count(filtered_cell)==1, ExcMessage("Wrong cell filtered.")); ++n_filtered_cells; diff --git a/tests/grid/filtered_iterator_04.output b/tests/grid/filtered_iterator_04.with_cxx11=true.output similarity index 100% rename from tests/grid/filtered_iterator_04.output rename to tests/grid/filtered_iterator_04.with_cxx11=true.output