From ad2e6d00936527e0c77f711664c5fa2235f1e7fa Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Tue, 5 Sep 2017 16:50:06 +0200 Subject: [PATCH] Added quicktest for nanoflann. --- tests/quick_tests/CMakeLists.txt | 5 +++ tests/quick_tests/nanoflann.cc | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 tests/quick_tests/nanoflann.cc diff --git a/tests/quick_tests/CMakeLists.txt b/tests/quick_tests/CMakeLists.txt index 6d0e3acb43..e6a3529a02 100644 --- a/tests/quick_tests/CMakeLists.txt +++ b/tests/quick_tests/CMakeLists.txt @@ -136,6 +136,11 @@ IF (DEAL_II_WITH_GSL) make_quicktest("gsl" ${_mybuild} "") ENDIF() +# Test Nanoflann +IF (DEAL_II_WITH_NANOFLANN) + make_quicktest("nanoflann" ${_mybuild} "") +ENDIF() + # Test Arpack IF (DEAL_II_WITH_ARPACK AND DEAL_II_WITH_UMFPACK) make_quicktest("arpack" ${_mybuild} "") diff --git a/tests/quick_tests/nanoflann.cc b/tests/quick_tests/nanoflann.cc new file mode 100644 index 0000000000..d23350073c --- /dev/null +++ b/tests/quick_tests/nanoflann.cc @@ -0,0 +1,57 @@ +// --------------------------------------------------------------------- +// +// 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. +// +//--------------------------------------------------------------------- + +// Create a list of points, and compute the minimum distance from some other points +// to this set, using a kdtree library + +#include +#include + + +int main () +{ + KDTree<2> kdtree; + + std::vector > points; + + // Add four points + points.push_back(Point<2>(0,0)); + points.push_back(Point<2>(0,1)); + points.push_back(Point<2>(1,0)); + points.push_back(Point<2>(1,1)); + + deallog << "Distance from unit square:" << std::endl; + + std::vector > test_points; + test_points.push_back(Point<2>(.5, .5)); + test_points.push_back(Point<2>(2, 0)); + test_points.push_back(Point<2>(2, 2)); + + kdtree.set_points(points); + + for (auto &p : test_points) + { + auto res = kdtree.get_closest_points(p,1)[0]; + deallog << "P: " << p << ", distance: " << res.second << ", index: " << res.first << std::endl; + } + + deallog << "Consistency checking: the following are all the points in the set." << std::endl; + for (auto &p : points) + { + auto res = kdtree.get_closest_points(p,1)[0]; + deallog << "P: " << p << ", distance: " << res.second << ", index: " << res.first << std::endl; + Assert(res.second < 1e-10, ExcMessage("Should be zero!")); + } +} -- 2.39.5