From c17b95334f838c218765f93ba86d2d3bf57b120b Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 8 Jun 2023 15:54:48 -0400 Subject: [PATCH] find_active_cell_around_point(): add a simplex test. --- .../find_active_cell_around_point_01.cc | 87 +++++++++++++++++++ .../find_active_cell_around_point_01.output | 7 ++ 2 files changed, 94 insertions(+) create mode 100644 tests/simplex/find_active_cell_around_point_01.cc create mode 100644 tests/simplex/find_active_cell_around_point_01.output diff --git a/tests/simplex/find_active_cell_around_point_01.cc b/tests/simplex/find_active_cell_around_point_01.cc new file mode 100644 index 0000000000..82c2bdf668 --- /dev/null +++ b/tests/simplex/find_active_cell_around_point_01.cc @@ -0,0 +1,87 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2023 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +/* + * Like grid/find_active_cell_around_point_01, but for simplices. + */ +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +void +test(unsigned int n_ref, unsigned int n_points) +{ + deallog << "Testing " << dim << ", " << spacedim << std::endl; + + Triangulation tria; + GridGenerator::subdivided_hyper_cube_with_simplices(tria, 1); + tria.refine_global(n_ref); + DoFHandler dof_handler(tria); + + std::vector> points; + + deallog << "Points in study: " << n_points << std::endl; + for (std::size_t i = 0; i < n_points; ++i) + points.push_back(random_point()); + + auto v_to_c = GridTools::vertex_to_cell_map(tria); + auto v_to_c_d = GridTools::vertex_to_cell_centers_directions(tria, v_to_c); + + auto &mapping = tria.get_reference_cells() + .front() + .template get_default_linear_mapping(); + auto cell = tria.begin_active(); + for (auto &p : points) + { + auto c_and_p = GridTools::find_active_cell_around_point( + mapping, tria, p, v_to_c, v_to_c_d); + auto p2 = + mapping.transform_unit_to_real_cell(c_and_p.first, c_and_p.second); + if (p2.distance(p) > 1e-10) + deallog << "NOT OK!" << p << ", " << p2 << ", " << c_and_p.first + << std::endl; + cell = c_and_p.first; + } + deallog << "OK" << std::endl; +} + +int +main() +{ + initlog(); + + test<2, 2>(3, 20); + test<3, 3>(2, 30); +} diff --git a/tests/simplex/find_active_cell_around_point_01.output b/tests/simplex/find_active_cell_around_point_01.output new file mode 100644 index 0000000000..02d33f830e --- /dev/null +++ b/tests/simplex/find_active_cell_around_point_01.output @@ -0,0 +1,7 @@ + +DEAL::Testing 2, 2 +DEAL::Points in study: 20 +DEAL::OK +DEAL::Testing 3, 3 +DEAL::Points in study: 30 +DEAL::OK -- 2.39.5