From: vishalkenchan Date: Wed, 26 Apr 2017 08:35:52 +0000 (+0200) Subject: added test for find_active_cell_around_point X-Git-Tag: v9.0.0-rc1~1647^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33d8f7b1cfe173781e99bf4fb1d26500dc64ae8a;p=dealii.git added test for find_active_cell_around_point --- diff --git a/tests/bits/find_cell_13.cc b/tests/bits/find_cell_13.cc new file mode 100644 index 0000000000..8623684295 --- /dev/null +++ b/tests/bits/find_cell_13.cc @@ -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 +#include +#include +#include +#include +#include +#include + +#include + +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(Testing::rand())/static_cast(RAND_MAX), + static_cast(Testing::rand())/static_cast(RAND_MAX)/8. ); + + try + { + // don't mark any vertex at first + std::vector 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 index 0000000000..e10f71dffa --- /dev/null +++ b/tests/bits/find_cell_13.output @@ -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!