]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added functions to compute bounding box for triangulation, accessors 5160/head
authordanshapero <shapero.daniel@gmail.com>
Tue, 26 Sep 2017 21:49:06 +0000 (14:49 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Fri, 6 Oct 2017 20:08:09 +0000 (13:08 -0700)
include/deal.II/grid/grid_tools.h
include/deal.II/grid/tria_accessor.h
source/grid/grid_tools.cc
source/grid/grid_tools.inst.in
source/grid/tria_accessor.cc
tests/grid/grid_tools_bounding_box_03.cc [new file with mode: 0644]
tests/grid/grid_tools_bounding_box_03.output [new file with mode: 0644]
tests/grid/measure_et_al_02.cc
tests/grid/measure_et_al_02.output

index c03c8eb75b67d06b9ca55f5df92b9c0e258ced68..aea8291e4b1f8a7bf9c978ea9aaf385aa250e614 100644 (file)
@@ -18,6 +18,7 @@
 
 
 #include <deal.II/base/config.h>
+#include <deal.II/base/bounding_box.h>
 #include <deal.II/base/geometry_info.h>
 #include <deal.II/dofs/dof_handler.h>
 #include <deal.II/fe/mapping.h>
@@ -170,6 +171,22 @@ namespace GridTools
   template <int dim, typename T>
   double cell_measure (const T &, ...);
 
+  /**
+   * Compute the smallest box containing the entire triangulation.
+   *
+   * If the input triangulation is a `parallel::distributed::Triangulation`,
+   * then each processor will compute a bounding box enclosing all locally
+   * owned, ghost, and artificial cells. In the case of a domain without curved
+   * boundaries, these bounding boxes will all agree between processors because
+   * the union of the areas occupied by artificial and ghost cells equals the
+   * union of the areas occupied by the cells that other processors own.
+   * However, if the domain has curved boundaries, this is no longer the case.
+   * The bounding box returned may be appropriate for the current processor,
+   * but different from the bounding boxes computed on other processors.
+   */
+  template <int dim, int spacedim>
+  BoundingBox<spacedim> compute_bounding_box(const Triangulation<dim, spacedim> &triangulation);
+
   /*@}*/
   /**
    * @name Functions supporting the creation of meshes
index d45031260fafca6152e01d129a37080f0e74728b..81828d2a3b594bfb283ef37284b42ad15b765c4e 100644 (file)
@@ -17,6 +17,7 @@
 #define dealii_tria_accessor_h
 
 
+#include <deal.II/base/bounding_box.h>
 #include <deal.II/base/config.h>
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/geometry_info.h>
@@ -1300,6 +1301,11 @@ public:
    */
   std::pair<Point<spacedim>,double> enclosing_ball () const;
 
+  /**
+   * Return the smallest bounding box that encloses the object.
+   */
+  BoundingBox<spacedim> bounding_box () const;
+
   /**
    * Length of an object in the direction of the given axis, specified in the
    * local coordinate system. See the documentation of GeometryInfo for the
index e492b2fef4df0d0cf000ba0a03e7ca118f4b7276..6fd3160354fa40b33dab99245304aced6307b665 100644 (file)
@@ -364,6 +364,22 @@ namespace GridTools
   }
 
 
+
+  template <int dim, int spacedim>
+  BoundingBox<spacedim>
+  compute_bounding_box(const Triangulation<dim, spacedim> &tria)
+  {
+    using iterator = typename Triangulation<dim, spacedim>::active_cell_iterator;
+    const auto predicate = [](const iterator &)
+    {
+      return true;
+    };
+
+    return compute_bounding_box(tria, std::function<bool(const iterator &)>(predicate));
+  }
+
+
+
   template <int dim, int spacedim>
   void
   delete_unused_vertices (std::vector<Point<spacedim> >    &vertices,
index 2b3f29b8e1d8ecdea841ae7bd871531a30e6ab59..df32b3a31c7b6baa03baf56913474db5840cd1d9 100644 (file)
@@ -159,6 +159,11 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension :  SPACE_DIMENSIONS
     (const Triangulation<deal_II_dimension, deal_II_space_dimension> &,
      const Mapping<deal_II_dimension, deal_II_space_dimension> &);
 
+    template
+    BoundingBox<deal_II_space_dimension>
+    compute_bounding_box
+    (const Triangulation<deal_II_dimension, deal_II_space_dimension> &);
+
     template
     void delete_unused_vertices (std::vector<Point<deal_II_space_dimension> > &,
                                  std::vector<CellData<deal_II_dimension> > &,
index 106b9615a9bf825f3f930c6aac083a927d11bd39..74cf9b5fa96e06178dfbefd4e170c847c735154c 100644 (file)
@@ -1110,6 +1110,29 @@ measure () const
 
 
 
+template <int structdim, int dim, int spacedim>
+BoundingBox<spacedim>
+TriaAccessor<structdim, dim, spacedim>::
+bounding_box () const
+{
+  std::pair<Point<spacedim>, Point<spacedim> > boundary_points =
+    std::make_pair(this->vertex(0), this->vertex(0));
+
+  for (unsigned int v=1; v<GeometryInfo<structdim>::vertices_per_cell; ++v)
+    {
+      const Point<spacedim> &x = this->vertex(v);
+      for (unsigned int k=0; k<spacedim; ++k)
+        {
+          boundary_points.first[k] = std::min(boundary_points.first[k], x[k]);
+          boundary_points.second[k] = std::max(boundary_points.second[k], x[k]);
+        }
+    }
+
+  return BoundingBox<spacedim>(boundary_points);
+}
+
+
+
 template <>
 double TriaAccessor<1,1,1>::extent_in_direction(const unsigned int axis) const
 {
diff --git a/tests/grid/grid_tools_bounding_box_03.cc b/tests/grid/grid_tools_bounding_box_03.cc
new file mode 100644 (file)
index 0000000..a5939dc
--- /dev/null
@@ -0,0 +1,56 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 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.
+//
+// ---------------------------------------------------------------------
+
+// Check computing bounding boxes of entire triangulations and individual cells
+
+#include "../tests.h"
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+template <int dim, int spacedim>
+void test_tria_bounding_box()
+{
+  dealii::Point<dim> p1, p2;
+  for (unsigned int k = 0; k < dim; ++k)
+    {
+      p1[k] = k;
+      p2[k] = 2 * k + 1;
+    }
+
+  Triangulation<dim, spacedim> tria;
+  GridGenerator::hyper_rectangle(tria, p1, p2);
+  tria.refine_global(1);
+  const BoundingBox<spacedim> bounding_box = GridTools::compute_bounding_box(tria);
+  const std::pair<Point<spacedim>, Point<spacedim> > &boundary_points =
+    bounding_box.get_boundary_points();
+
+  deallog << boundary_points.first << ", " << boundary_points.second << std::endl;
+}
+
+int main(void)
+{
+  initlog();
+
+  test_tria_bounding_box<1, 1>();
+  test_tria_bounding_box<1, 2>();
+  test_tria_bounding_box<2, 2>();
+  test_tria_bounding_box<1, 3>();
+  test_tria_bounding_box<2, 3>();
+  test_tria_bounding_box<3, 3>();
+
+  return 0;
+}
+
diff --git a/tests/grid/grid_tools_bounding_box_03.output b/tests/grid/grid_tools_bounding_box_03.output
new file mode 100644 (file)
index 0000000..e7c415a
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::0.00000, 1.00000
+DEAL::0.00000 0.00000, 1.00000 0.00000
+DEAL::0.00000 1.00000, 1.00000 3.00000
+DEAL::0.00000 0.00000 0.00000, 1.00000 0.00000 0.00000
+DEAL::0.00000 1.00000 0.00000, 1.00000 3.00000 0.00000
+DEAL::0.00000 1.00000 2.00000, 1.00000 3.00000 5.00000
index 464871e1867adc49de2fccd18c2685225e844af8..31ce5f90bfc74c11042ed9190b118f8bf5d16230 100644 (file)
@@ -100,6 +100,11 @@ void test()
               << tria.begin_active()->extent_in_direction(0) << std::endl;
       deallog << "dim" << dim << ":case" << case_no << ":minimum_vertex_distance="
               << tria.begin_active()->minimum_vertex_distance() << std::endl;
+
+      const BoundingBox<dim> box = tria.begin_active()->bounding_box();
+      const std::pair<Point<dim>, Point<dim> > &pts = box.get_boundary_points();
+      deallog << "dim" << dim << ":case" << case_no << ":bounding_box="
+              << pts.first << ", " << pts.second << std::endl;
       tria.clear();
     }
 }
index e1db82bb4a0bd01de73c9348716d259d22c21dac..d7ec0015ed99ac5bcf9e0e5a38690341cffc98e5 100644 (file)
@@ -2,18 +2,24 @@
 DEAL::dim2:case0:diameter=2.8284
 DEAL::dim2:case0:extent_in_direction=2.0000
 DEAL::dim2:case0:minimum_vertex_distance=2.0000
+DEAL::dim2:case0:bounding_box=1.0000 1.0000, 3.0000 3.0000
 DEAL::dim2:case1:diameter=3.6056
 DEAL::dim2:case1:extent_in_direction=3.0000
 DEAL::dim2:case1:minimum_vertex_distance=2.0000
+DEAL::dim2:case1:bounding_box=0.0000 1.0000, 3.0000 3.0000
 DEAL::dim2:case2:diameter=4.4721
 DEAL::dim2:case2:extent_in_direction=3.0000
 DEAL::dim2:case2:minimum_vertex_distance=2.2361
+DEAL::dim2:case2:bounding_box=0.0000 1.0000, 4.0000 3.0000
 DEAL::dim3:case0:diameter=3.4641
 DEAL::dim3:case0:extent_in_direction=2.0000
 DEAL::dim3:case0:minimum_vertex_distance=2.0000
+DEAL::dim3:case0:bounding_box=1.0000 1.0000 1.0000, 3.0000 3.0000 3.0000
 DEAL::dim3:case1:diameter=4.1231
 DEAL::dim3:case1:extent_in_direction=3.0000
 DEAL::dim3:case1:minimum_vertex_distance=2.0000
+DEAL::dim3:case1:bounding_box=0.0000 1.0000 1.0000, 3.0000 3.0000 3.0000
 DEAL::dim3:case2:diameter=4.1231
 DEAL::dim3:case2:extent_in_direction=3.0000
 DEAL::dim3:case2:minimum_vertex_distance=2.0000
+DEAL::dim3:case2:bounding_box=0.0000 1.0000 1.0000, 3.0000 3.0000 3.0000

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.