From: Bruno Turcksin Date: Mon, 22 Feb 2016 23:08:41 +0000 (-0500) Subject: Add test for IteratorFilter::AtBoundary. X-Git-Tag: v8.5.0-rc1~1250^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0906959a33a5cb8416522dcca017f860af548f20;p=dealii.git Add test for IteratorFilter::AtBoundary. --- diff --git a/tests/grid/filtered_iterator_04.cc b/tests/grid/filtered_iterator_04.cc new file mode 100644 index 0000000000..2cae8c50d0 --- /dev/null +++ b/tests/grid/filtered_iterator_04.cc @@ -0,0 +1,88 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// check filtered iterators using two predicate + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include + +typedef Triangulation<2>::active_cell_iterator active_cell_iterator; + +void test () +{ + Triangulation<2> tria; + GridGenerator::hyper_cube(tria, -1, 1); + tria.refine_global (1); + tria.begin_active()->set_refine_flag (); + tria.execute_coarsening_and_refinement (); + tria.refine_global (2); + + // we now have a number of cells, + // flag them with some subdomain + // ids based on their position, in + // particular we take the quadrant + // (octant) + active_cell_iterator cell = tria.begin_active (), + endc = tria.end (); + for (unsigned int i=0; cell!=endc; ++cell) + { + unsigned int subdomain = i%3; + + cell->set_subdomain_id (subdomain); + ++i; + }; + + // Count the cells that are on the boundary and have a subdomain_id of 0 + std::set cell_set; + for (cell = tria.begin_active(); cell!=endc; ++cell) + 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) + { + AssertThrow(cell_set.count(filtered_cell)==1, ExcMessage("Wrong cell filtered.")); + ++n_filtered_cells; + } + AssertThrow(n_filtered_cells==cell_set.size(), ExcMessage("Filtered cells missing.")); +} + +int main () +{ + initlog(); + deallog << std::setprecision(4); + deallog.threshold_double(1.e-10); + + test (); + + deallog << "OK" << std::endl;; + + return 0; +} + diff --git a/tests/grid/filtered_iterator_04.output b/tests/grid/filtered_iterator_04.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/filtered_iterator_04.output @@ -0,0 +1,2 @@ + +DEAL::OK