From d433987fe4a68cddf080cc8716abe4daef34fba6 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 3 Oct 2017 13:27:55 -0600 Subject: [PATCH] Add a test. --- tests/grid/grid_tools_bounding_box_02.cc | 86 ++++++++++++++++++++ tests/grid/grid_tools_bounding_box_02.output | 7 ++ 2 files changed, 93 insertions(+) create mode 100644 tests/grid/grid_tools_bounding_box_02.cc create mode 100644 tests/grid/grid_tools_bounding_box_02.output diff --git a/tests/grid/grid_tools_bounding_box_02.cc b/tests/grid/grid_tools_bounding_box_02.cc new file mode 100644 index 0000000000..0647483b4d --- /dev/null +++ b/tests/grid/grid_tools_bounding_box_02.cc @@ -0,0 +1,86 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2001 - 2017 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. +// +// --------------------------------------------------------------------- + +// Short test to validate compute_bounding_box() +// +// like _01, but assign the result to a BoundingBox object + +#include "../tests.h" +#include +#include +#include +#include +#include + +template +bool +pred_mat_id(const typename Triangulation::active_cell_iterator &cell) +{ + return cell->material_id() == 2; +} + +template +void test () +{ + deallog << "dim = " << dim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + + typedef typename Triangulation::active_cell_iterator cell_iterator; + + // Mark a small block at the corner of the hypercube + cell_iterator + cell = tria.begin_active(), + endc = tria.end(); + for (; cell != endc; ++cell) + { + bool mark = true; + for (unsigned int d=0; d < dim; ++d) + if (cell->center()[d] > 0.33 ) + { + mark = false; + break; + } + + if (mark == true) + cell->set_material_id(2); + else + cell->set_material_id(1); + } + + std::function predicate = pred_mat_id; + + // Find bounding box that surrounds cells with material id 2 + BoundingBox bounding_box + = GridTools::compute_bounding_box(tria, predicate); // General predicate + + deallog << bounding_box.get_boundary_points ().first << " " + << bounding_box.get_boundary_points ().second + << std::endl; +} + + +int main () +{ + initlog(); + + test<1> (); + test<2> (); + test<3> (); + + return 0; +} diff --git a/tests/grid/grid_tools_bounding_box_02.output b/tests/grid/grid_tools_bounding_box_02.output new file mode 100644 index 0000000000..e045db72bf --- /dev/null +++ b/tests/grid/grid_tools_bounding_box_02.output @@ -0,0 +1,7 @@ + +DEAL::dim = 1 +DEAL::0.00000 0.250000 +DEAL::dim = 2 +DEAL::0.00000 0.00000 0.250000 0.250000 +DEAL::dim = 3 +DEAL::0.00000 0.00000 0.00000 0.250000 0.250000 0.250000 -- 2.39.5