]> https://gitweb.dealii.org/ - dealii.git/commitdiff
added test for find_active_cell_around_point 4088/head
authorvishalkenchan <vishal.boddu@fau.de>
Wed, 26 Apr 2017 08:35:52 +0000 (10:35 +0200)
committervishalkenchan <vishal.boddu@fau.de>
Wed, 26 Apr 2017 08:35:52 +0000 (10:35 +0200)
tests/bits/find_cell_13.cc [new file with mode: 0644]
tests/bits/find_cell_13.output [new file with mode: 0644]

diff --git a/tests/bits/find_cell_13.cc b/tests/bits/find_cell_13.cc
new file mode 100644 (file)
index 0000000..8623684
--- /dev/null
@@ -0,0 +1,118 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2003 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// take a 2d mesh, provide a marked vertex such that the point is
+// outside of active cells adjacent to the marked vertex
+// and check that the function throws an exception
+// that it couldn't find an arbitrary point's cell
+
+// while not providing such marked vertex the function
+// executes normally as expected
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/grid_tools.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria_boundary_lib.h>
+
+#include <fstream>
+
+void check (Triangulation<2> &tria)
+{
+
+  // generate some random points bounded by [0., 0.2)^2 in R^2 space
+  // any point in this domain should be inside one of the cells
+  Point<2> p( static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX),
+              static_cast<double>(Testing::rand())/static_cast<double>(RAND_MAX)/8. );
+
+  try
+    {
+      // don't mark any vertex at first
+      std::vector<bool> marked_vertices (tria.n_vertices(), false);
+
+      // find the closes vertex to (1.,1.)
+      // (default call to find_closest_vertex() without passing marked_vertices)
+      unsigned int closest_vertex =
+        GridTools::find_closest_vertex(tria, Point<2>(1.,1.));
+
+      // mark the vertex closest to (1.,1.)
+      marked_vertices[closest_vertex] = true;
+
+      auto vertices = tria.get_vertices();
+      deallog << vertices[closest_vertex] << " is the closest vertex" << std::endl;
+
+      GridTools::find_active_cell_around_point(tria, p, marked_vertices);
+
+      // The test fails if the control reaches here.
+      deallog << "Garbage text to make the diff fail if the control "
+              << "reaches here:" << " Point: " << p;
+      deallog << std::endl; // Flush deallog buffer
+    }
+  catch ( GridTools::ExcPointNotFound<2>)
+    {
+      deallog << "The first call to the function find_closest_vertex() has thrown "
+              << "an exception. It is supposed to throw.";
+      deallog << std::endl;
+
+      // The default function call doesn't throw exceptions
+      // for this use case
+      Triangulation<2>::active_cell_iterator cell
+        = GridTools::find_active_cell_around_point (tria, p);
+
+      // check if the below function call actually finds appropriate cell
+      Assert (p.distance (cell->center()) < cell->diameter()/2,
+              ExcInternalError());
+      deallog << "Test passed!";
+      deallog << std::endl;
+
+    }
+  catch (...)
+    {
+      Assert (false,
+              ExcInternalError());
+    }
+
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-10);
+
+  {
+    Triangulation<2> coarse_grid;
+    GridGenerator::hyper_cube (coarse_grid);
+    coarse_grid.refine_global (2);
+    check (coarse_grid);
+  }
+
+  {
+
+    Triangulation<2> coarse_grid;
+    GridGenerator::hyper_ball (coarse_grid);
+    static const HyperBallBoundary<2> boundary;
+    coarse_grid.set_boundary (0, boundary);
+    coarse_grid.refine_global (2);
+    check (coarse_grid);
+
+  }
+}
diff --git a/tests/bits/find_cell_13.output b/tests/bits/find_cell_13.output
new file mode 100644 (file)
index 0000000..e10f71d
--- /dev/null
@@ -0,0 +1,7 @@
+
+DEAL::1.00000 1.00000 is the closest vertex
+DEAL::The first call to the function find_closest_vertex() has thrown an exception. It is supposed to throw.
+DEAL::Test passed!
+DEAL::0.707107 0.707107 is the closest vertex
+DEAL::The first call to the function find_closest_vertex() has thrown an exception. It is supposed to throw.
+DEAL::Test passed!

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.