]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 5193/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 3 Oct 2017 19:27:55 +0000 (13:27 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 3 Oct 2017 19:27:55 +0000 (13:27 -0600)
tests/grid/grid_tools_bounding_box_02.cc [new file with mode: 0644]
tests/grid/grid_tools_bounding_box_02.output [new file with mode: 0644]

diff --git a/tests/grid/grid_tools_bounding_box_02.cc b/tests/grid/grid_tools_bounding_box_02.cc
new file mode 100644 (file)
index 0000000..0647483
--- /dev/null
@@ -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 <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/base/bounding_box.h>
+
+template <int dim>
+bool
+pred_mat_id(const typename Triangulation<dim>::active_cell_iterator &cell)
+{
+  return cell->material_id() == 2;
+}
+
+template <int dim>
+void test ()
+{
+  deallog << "dim = " << dim << std::endl;
+
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(2);
+
+  typedef typename Triangulation<dim>::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<bool (const cell_iterator &)> predicate = pred_mat_id<dim>;
+
+  // Find bounding box that surrounds cells with material id 2
+  BoundingBox<dim> 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 (file)
index 0000000..e045db7
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.